import java.awt.*;
import java.awt.event.*;
 
/**
 * CSC 442F:    Software Engineering
 * Software:    Calendar Client
 * Component:   ModViewPanel class
 * Description: The ModViewPanel class produces a panel with buttons 
 *              "Ok", "Help", "Drop", "Delete", and "Modify". 
 * @author David Tam
 * @version 1.0
 */
public class ModViewPanel extends Panel implements ActionListener
{ 
  protected ViewMeetingDialog parent;
  protected Frame frame;
  protected ClientSocket socket;
  protected String response;

  // Buttons
  protected Button ok;
  protected Button help;
  protected Button drop;
  protected Button delete;
  protected Button modify;
  
  // GridBagLayout constraints
  protected GridBagConstraints constraints;

 /** 
  * Constructor
  * ===========
  *
  * @param parent_in   Passes container for disposal operations
  */
  public ModViewPanel(ViewMeetingDialog parent_in, Frame frame_in,
                      ClientSocket socket_in)
  {
    parent = parent_in;
    frame = frame_in;
    socket = socket_in;
    response = parent.response;
    
    // Button instantiation
    ok = new Button("Ok");
    help = new Button("Help");
    drop = new Button("Drop");
    delete = new Button("Delete");
    modify = new Button("Modify");
          
    // Constraints instantiation
    constraints = new GridBagConstraints();

    // Button event recievers
    ok.addActionListener(this);
    help.addActionListener(this);
    drop.addActionListener(this);
    delete.addActionListener(this);
    modify.addActionListener(this);


    // Determine where user has permission to edit
    if (!parent.owner.equals(parent.eventId.username))
    {
      delete.setEnabled(false);
      modify.setEnabled(false);
    }

    // Panel layout
    setLayout(new GridBagLayout());
    constraints.ipadx=1;
    constraints.ipady=1;
    constraints.gridy=0;
    constraints.gridx=0;
    constraints.insets= new Insets(20,0,0,0);
    constraints.gridheight=2;
    constraints.fill=constraints.VERTICAL;
    add(help, constraints);
    constraints.fill=constraints.NONE;
    constraints.gridheight=1;
    constraints.gridx=1;
    add(modify,constraints);
    constraints.gridx=2;
    add(drop, constraints);
    constraints.gridx=3;
    add(delete, constraints);
    constraints.insets= new Insets(0,0,20,0);
    constraints.gridy=1;
    constraints.gridx=1;
    constraints.gridwidth=3;
    constraints.fill=constraints.HORIZONTAL;
    add(ok, constraints);
    constraints.fill=constraints.NONE;
    constraints.ipadx=0;
    constraints.ipady=0;
    constraints.insets= new Insets(0,0,0,0);    
  }
  
  
  // Method to handle action events
  // ==============================
  public void actionPerformed(ActionEvent event)
  {
    DropReasonDialog dropReason;
    DeleteReasonDialog deleteReason;
    ModMeetingDialog modMeeting;
      
    // Determine who caused the event
    if (event.getSource() == ok)
      // Return without making changes
      parent.dispose();
    else if (event.getSource() == help)
      // Call help dialog
      parent.help();
    else if (event.getSource() == drop)
    {
      dropReason = new DropReasonDialog (parent, frame, socket);
      dropReason.setVisible(true);
    }
    else if (event.getSource() == delete)
    {
      deleteReason = new DeleteReasonDialog (parent, frame, socket);
      deleteReason.setVisible(true);
    }
    else if (event.getSource() == modify)
    {
       modMeeting = new ModMeetingDialog(frame, socket, parent.eventId, 
                                         response);
       modMeeting.setVisible(true);
    }
  }
}
