package caltool.view.schedule;

import caltool.model.schedule.*;
import mvp.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/****
 *
 * Class RemindInfoSubDialog is a component of the ScheduleAppointment,
 * ConfirmMeeting, and ScheduleTask Dialogs.  The companion model is
 * RemindInfo.  RemindInfoSubDialog displays the row of remind information.
 */
public class RemindInfoSubdialog extends View {

    /**
     * Construct this with a parent view.  Since this is a subview, it need not
     * have its own model, since it only handles view details.  The parent
     * dialogs for appointments, meetings, and tasks communicate with the
     * model.
     */
    public RemindInfoSubdialog(Screen screen,
            ScheduleAppointmentDialog parentView) {
        super(screen, null);
        this.parentView = parentView;

        maxComponentHeight = 1.9;
        maxComponentWidth = 1200;
    }

    /**
     * Compose this as the default configuration consisting of a remind
     * checkbox, a time-before text field, a time-before combo box, and a
     * remind-location combo box.
     */
    public Component compose() {

        Box hbox = Box.createHorizontalBox();

        JLabel remindLabel = new JLabel("Remind?  ");
        remindLabel.setForeground(Color.black);
        remindCheckBox = new JCheckBox();
        remindCheckBox.addActionListener(new RemindCheckBoxListener(this));

        remindTimeTextField = new JTextField(3);
        remindTimeTextField.setMaximumSize(
            new Dimension(3 * remindTimeTextField.getFont().getSize(),
                (int)(maxComponentHeight *
                    remindTimeTextField.getFont().getSize())));

        remindTimeTextField.setEnabled(false);
        String[] selections =
            {"minutes before", "hours before", "days before"};
        remindTimeComboBox = new JComboBox(selections);
        remindTimeComboBox.setEnabled(false);
        remindTimeComboBox.setMaximumSize(
            new Dimension(maxComponentWidth, (int)(maxComponentHeight *
                remindTimeComboBox.getFont().getSize())));

        String[] selections2 = {"on screen", "email"};
        remindLocationComboBox = new JComboBox(selections2);
        remindLocationComboBox.setEnabled(false);
        remindLocationComboBox.setMaximumSize(
            new Dimension(maxComponentWidth, (int)(maxComponentHeight *
                remindLocationComboBox.getFont().getSize())));

        hbox.add(Box.createHorizontalStrut(15));
        hbox.add(remindLabel);
        hbox.add(remindCheckBox);
        hbox.add(remindTimeTextField);
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(remindTimeComboBox);
        hbox.add(Box.createHorizontalStrut(15));
        hbox.add(remindLocationComboBox);
        hbox.add(Box.createHorizontalStrut(15));

        return hbox;

    }

    public void update(Observable o, Object arg) {

        RemindInfo remindInfo = (RemindInfo) arg;

        remindCheckBox.setSelected(remindInfo.getIsReminded());
        remindTimeTextField.setText(Integer.toString(
            remindInfo.getWhen().getTime()));
        remindTimeComboBox.setSelectedIndex(remindInfo.getWhen().getTimeUnit().
            ordinal());
        remindLocationComboBox.setSelectedIndex(remindInfo.getWhere().
            ordinal());

    };

    /** The parent apppointment dialog view. */
    ScheduleAppointmentDialog parentView;

    /** The checkbox that indicates whether there's a reminder. */
    protected JCheckBox remindCheckBox;

    /** The remind time text field. */
    protected JTextField remindTimeTextField;

    /** The remind time combo box. */
    protected JComboBox remindTimeComboBox;

    /** The remind location combo box. */
    protected JComboBox remindLocationComboBox;

    /** The max height of a text field or combobox; this is necessary since
        these components strech when the outer frame is resized, and look very
        funky when they do */
    protected final double maxComponentHeight;

    /** The max width of any component; this is only necessary because the max
        height cannot be set separately, so we must pick some max width. */
    protected final int maxComponentWidth;

}