package caltool.view.schedule; import caltool.model.schedule.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; /**** * * Class OKScheduleEventButtonListener defines the action listener that is * attached to the OK button in the schedule appointment dialog. When the * class is constructed, it is passed references to the classes that need to be * accessed in the actionPerformed method. In this case, the required classes * are the Schedule model class and the ScheduleEventDialog view class. *

* Access to the model is for calling the scheduleEvent method. Access to the * view is for gathering the data values that are sent to scheduleEvent. * * @author Gene Fisher (gfisher@calpoly.edu) * @version 6feb04 * */ public class OKScheduleEventButtonListener implements ActionListener { /** * Construct this with the given Schedule model and parent dialog view. * Access to the model is for calling its scheduleEvent method. Access to * the parent view is for gathering data to be sent to scheduleEvent. */ public OKScheduleEventButtonListener(Schedule schedule, ScheduleEventDialog dialog) { this.schedule = schedule; this.dialog = dialog; } /** * Respond to a press of the OK button by calling ScheduleEvent with a new * Event. The Event data are gathered from the JTextFields and JComboBox * in the parent dialog. */ public void actionPerformed(ActionEvent e) { try { schedule.scheduleEvent( new caltool.model.schedule.Event( dialog.getTitle(), // Title as a string dialog.getStartDate(), // Start date as a Date dialog.getEndDate(), // Start date as a Date dialog.getCategory(), // Category as a Category dialog.getSecurity() // Security as a SimpleSecurity ) ); } catch (ScheduleEventPrecondViolation errors) { dialog.displayErrors(errors); } } /** The companion model */ protected Schedule schedule; /** The parent view */ protected ScheduleEventDialog dialog; }