/*
 * ClassName.java
 *
 * Created on 16. April 2000, 20:40
 */
 
package com.wiley.compbooks.brose.chapter10.office;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/** 
 *
 * @author  brose
 * @version 
 */
public class AppointmentDialog 
    extends JDialog 
    implements ActionListener
{
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton OK;
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextArea descriptionTextArea;
    private javax.swing.JLabel dateLabel;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel timeLabel;
    private javax.swing.JComboBox hoursComboBox;

    private javax.swing.JLabel partnerLabel;
    private javax.swing.JComboBox meetComboBox;

    private javax.swing.JLabel locationLabel;
    private javax.swing.JComboBox locationComboBox;

    private static String[] hours = 
	new String[]{ "08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};

    private String[] partners;
    private String[] locations;
    private String title;
    private boolean cancelled = false;

    /** Creates new form ClassName */

    public AppointmentDialog(Frame parent, 
			     boolean modal, 
			     String title, 
			     String[] partners,
			     String[] locations
			     ) 
    {
	super(parent, modal);
	this.partners = partners;
	this.title = title;
	this.locations = locations;
	initComponents();
	pack();
	setVisible(true);
    }

    /** This method is called from within the init() method to
     * initialize the form.
     */

    private void initComponents () 
    {
	setTitle("Enter Appointment");

	buttonPanel = new javax.swing.JPanel ();

	OK = new javax.swing.JButton ();
	cancelButton = new javax.swing.JButton ();
	descriptionTextArea = new javax.swing.JTextArea (10,10);

	dateLabel = new javax.swing.JLabel ();
	jPanel3 = new javax.swing.JPanel ();

	timeLabel = new javax.swing.JLabel ();
	hoursComboBox = new javax.swing.JComboBox (hours);
	hoursComboBox.setSize(100,50);

	locationLabel = new JLabel();
	locationComboBox = new JComboBox(locations);
	locationComboBox.setSize(100,50);

	partnerLabel = new javax.swing.JLabel ();
	meetComboBox = new javax.swing.JComboBox(partners);
	meetComboBox.setSize(100,50);

	getContentPane().setLayout (new java.awt.BorderLayout ());

	OK.setActionCommand ("OK");
	OK.setLabel ("OK");
	OK.addActionListener(this);
  
	buttonPanel.add (OK);
  
	cancelButton.setActionCommand ("cancel");
	cancelButton.setLabel ("Cancel");
	cancelButton.addActionListener(this);

	buttonPanel.add (cancelButton);

	getContentPane().add (buttonPanel, java.awt.BorderLayout.SOUTH);
	getContentPane().add (descriptionTextArea, java.awt.BorderLayout.CENTER);

	dateLabel.setText (title);
	dateLabel.setHorizontalAlignment (javax.swing.SwingConstants.CENTER);
	dateLabel.setFont (new java.awt.Font ("Dialog", 1, 14));

	getContentPane().add (dateLabel, java.awt.BorderLayout.NORTH);

	jPanel3.setLayout (new java.awt.GridLayout (4, 1));

	timeLabel.setText ("Time");
  
	jPanel3.add (timeLabel);
	jPanel3.add (hoursComboBox);
  
	partnerLabel.setText ("Meet with...");
  
	jPanel3.add (partnerLabel);  
	jPanel3.add (meetComboBox);  

	locationLabel.setText("Locations");
	jPanel3.add (locationLabel);  
	jPanel3.add (locationComboBox);  

	getContentPane().add (jPanel3, java.awt.BorderLayout.WEST);
    }


    public void actionPerformed (java.awt.event.ActionEvent evt) 
    {
	if( evt.getActionCommand().equals("OK") )
	{
	    cancelled = false;
	}
	else if( evt.getActionCommand().startsWith("cancel"))
	{
	    cancelled = true;
	}
	setVisible (false);
	dispose ();
    }

    boolean getData(String[] data)
    {
	if( data.length != 4 || cancelled )
	    return false;

	data[0] = descriptionTextArea.getText();
	data[1] = (String)locationComboBox.getSelectedItem();
	data[2] = (String)hoursComboBox.getSelectedItem();
	data[3] = (String)meetComboBox.getSelectedItem();
	return true;

    }
    

}
