import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class ComposeV
 extends WindowAdapter
 implements ActionListener {

//  +--------+
//  | Fields |
//  +--------+-----------------------------------------------------

  /** GUI fields */
  protected Frame gui;
  protected GridBagLayout grid;
  protected Label Gmail;
  protected TextField GUIfrom;
  protected TextField GUIcc;
  protected TextField GUIbcc;
  protected TextField GUIsubject;
  protected TextArea GUIBody;
  protected Button quit, delete, folders, compose, reply, replyall, forward, 
            preferences, inbox, help, picture;
  protected Compose comp;
  protected Checkbox html;

  public ComposeV(){
      gui = new Frame("Compose");
      GridBagConstraints c = new GridBagConstraints();
      GridBagLayout grid = new GridBagLayout();
      gui.setLayout(grid);
      Gmail = new Label("GMail Compose Window");
      Label lfrom = new Label("From: ");
      Label lCc = new Label("CC:     ");
      Label lBcc = new Label("BCC:     ");
      Label lSubject = new Label("Subject:  ");
      html = new Checkbox("Use HTML tags", false);
      GUIfrom = new TextField("rebelsky@grinnell.edu" , 50);
      GUIcc = new TextField(50);
      GUIbcc = new TextField(50);
      GUIsubject = new TextField("A Test");
      GUIBody = new TextArea("This is a test of sending mail with GMail");
      
      c.anchor=GridBagConstraints.NORTH;
      c.gridx = 0;
      c.gridy = 0;
      c.fill=GridBagConstraints.BOTH;
      c.gridwidth=GridBagConstraints.REMAINDER;
      grid.setConstraints(Gmail, c);
      gui.add(Gmail);
      
      delete = new Button("Delete");
      delete.addActionListener(this);
      delete.setBackground(Color.gray);
      delete.setForeground(Color.black);
      delete.setFont(new Font("Times", Font.BOLD, 15));
      c.gridwidth = 1;
      c.gridy = 1;
      grid.setConstraints(delete, c);
      gui.add(delete);
      
      folders = new Button("Folders");
      folders.addActionListener(this);
      folders.setBackground(Color.gray);
      folders.setForeground(Color.black);
      folders.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 1;
      c.gridy =  GridBagConstraints.RELATIVE;
      grid.setConstraints(folders, c);
      gui.add(folders);
      
      compose = new Button("Compose");
      compose.addActionListener(this);
      compose.setBackground(Color.gray);
      compose.setForeground(Color.black);
      compose.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 2;
      grid.setConstraints(compose, c);
      gui.add(compose);
      
      reply = new Button("Reply");
      reply.addActionListener(this);
      reply.setBackground(Color.gray);
      reply.setForeground(Color.black);
      reply.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 3;
      grid.setConstraints(reply, c);
      gui.add(reply);
      
      replyall = new Button("Reply All");
      replyall.addActionListener(this);
      replyall.setBackground(Color.gray);
      replyall.setForeground(Color.black);
      replyall.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 4;
      grid.setConstraints(replyall, c);
      gui.add(replyall);
      
      forward = new Button("Forward");
      forward.addActionListener(this);
      forward.setBackground(Color.gray);
      forward.setForeground(Color.black);
      forward.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 5;
      grid.setConstraints(forward, c);
      gui.add(forward);
      
      preferences = new Button("Preferences");
      preferences.addActionListener(this);
      preferences.setBackground(Color.gray);
      preferences.setForeground(Color.black);
      preferences.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 6;
      grid.setConstraints(preferences, c);
      gui.add(preferences);
      
      inbox = new Button("Inbox");
      inbox.addActionListener(this);
      inbox.setBackground(Color.gray);
      inbox.setForeground(Color.black);
      inbox.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 7;
      grid.setConstraints(inbox, c);
      gui.add(inbox);
      
      picture = new Button("Picture");
      picture.addActionListener(this);
      picture.setBackground(Color.gray);
      picture.setForeground(Color.black);
      picture.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 8;
      grid.setConstraints(picture, c);
      gui.add(picture);
      
      help = new Button("Help");
      help.addActionListener(this);
      help.setBackground(Color.gray);
      help.setForeground(Color.black);
      help.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 9;
      grid.setConstraints(help, c);
      gui.add(help);
      
      quit = new Button("Quit");
      quit.addActionListener(this);
      quit.setBackground(Color.gray);
      quit.setForeground(Color.black);
      quit.setFont(new Font("Times", Font.BOLD, 15));
      c.gridx = 10;
      grid.setConstraints(quit, c);
      gui.add(quit);
      
      c.gridx = 0;
      c.gridy = 2;
      c.gridwidth=1;
      grid.setConstraints(lfrom, c);
      gui.add(lfrom);
      
      c.gridx=1;
      c.weightx=1.0;
      c.gridwidth=GridBagConstraints.REMAINDER;
      grid.setConstraints(GUIfrom, c);
      gui.add(GUIfrom);
      
      c.gridy=3;
      c.gridx=0;
      c.gridwidth=1;
      c.weightx=0;
      grid.setConstraints(lCc, c);
      gui.add(lCc);
      
      c.gridx=1;
      c.weightx=1.0;
      c.gridwidth=GridBagConstraints.REMAINDER;
      grid.setConstraints(GUIcc, c);
      gui.add(GUIcc);
      
      c.gridy=4;
      c.gridx=0;
      c.gridwidth=1;
      c.weightx=0;
      grid.setConstraints(lBcc, c);
      gui.add(lBcc);
      
      c.gridx=1;
      c.weightx=1.0;
      c.gridwidth=GridBagConstraints.REMAINDER;
      grid.setConstraints(GUIbcc, c);
      gui.add(GUIbcc);
      
      c.gridy=5;
      c.gridx=0;
      c.gridwidth=1;
      c.weightx=0;
      grid.setConstraints(lSubject, c);
      gui.add(lSubject);
      
      c.gridx=1;
      c.weightx=1.0;
      c.gridwidth=GridBagConstraints.REMAINDER;
      grid.setConstraints(GUIsubject, c);
      gui.add(GUIsubject);
      
      c.gridy=6;
      c.gridx=0;
      grid.setConstraints(html, c);
      gui.add(html);
      
      c.gridy=7;
      c.weighty=1.0;
      c.gridwidth = GridBagConstraints.REMAINDER;
      grid.setConstraints(GUIBody, c);
      gui.add(GUIBody);

      
      gui.pack();
      gui.setSize(1000,700);
      gui.show();
   
  }

//  +----------------+
//  | Event Handlers |-------------------------------------------------
//  +----------------+
     
     public void actionPerformed(ActionEvent evt){
         String command = evt.getActionCommand();
         if(command.equals("Folders")) {
             new Folders();
         }
         else if(command.equals("Compose")) {
             new Compose1();
         }
         else if(command.equals("Preferences")) {
             new Preferences();
         }
         else if(command.equals("Help")) {
             new Help();
         }
         else if(command.equals("Inbox")) {
             MailList1 example = new MailList1("Inbox");
             example.addButton("Delete", "Folders", "Compose", "Reload" , "Preferences", "Help");
             example.addLabel("Message", "From","Subject", "Date", "Time");
             example.addMessage("Sam Rebelsky", "A Test", "12/08/99", "13.43");
             example.addMessage("Bill Gates", "Another Test", "14/08/99", "21.34" );
             example.addMessage("Ashfaqur Rahman", "Help!","14/08/99", "21.09" );
             example.addMessage("Mike Yohay", "More Help!", "14/08/99", "21.09" );
             example.addMessage("Jared Baszler", "Re: Help!", "09/08/99", "14.45");
         }
         else if(command.equals("Quit")) {
             gui.dispose();
         }
         else if(command.equals("Picture")) {
             PhotoStub photo = new PhotoStub("grin");
             try {
             photo.getPhoto();
             }
             catch (Exception e){}
             photo.setPhoto(Toolkit.getDefaultToolkit().getImage("/home/yohay/152/project/sam.jpg"));
             photo.displayPhoto();
         }
         else if(command.equals("Delete")) {
             MailList1 example = new MailList1("Inbox");
             example.addButton("Delete", "Folders", "Compose", "Reload" , "Preferences", "Help");
             example.addLabel("Message", "From","Subject", "Date", "Time");
             example.addMessage("Bill Gates", "Another Test", "14/08/99", "21.34" );
             example.addMessage("Ashfaqur Rahman", "Help!","14/08/99", "21.09" );
             example.addMessage("Mike Yohay", "More Help!", "14/08/99", "21.09" );
             example.addMessage("Jared Baszler", "Re: Help!", "09/08/99", "14.45");
         }

     } // actionPerformed()

                   
    public void windowClosing (WindowEvent event) {
        gui.dispose();
    } // windowClosing(event)
    

     /**
      * This is used for testing the window only.
      */
     public static void main(String[] args){
         new ComposeV();
     }

}

