package caltool.view.schedule; import caltool.model.schedule.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import mvp.*; /**** * * Class ScheduleMenu is the pulldown menu view of the model class. The first four items of the menu * correspond to the public Schedule methods. The last item corresponds to the * Categories component of Schedule, which is the editable list of scheduled * item categories. *

* The four items that correspond to methods each launch a method input dialog. * The last menu item, that corresponds to the categories list, launches a * non-modal category editing dialog. *

* In terms of Java Swing components, the ScheduleMenu widget is a Java JMenu. * Anonymous instances of JMenuItem are defined for each menu item. Details of * the dialog structures are given in their respective class definitions. * * @author Gene Fisher (gfisher@calpoly.edu) * @version 6feb04 * */ public class ScheduleMenu extends mvp.View { /** * Construct this with the given Schedule model and parent ScheduleUI view. */ public ScheduleMenu(Screen screen, Schedule schedule, ScheduleUI scheduleUI) { /* * Invoke the parent constructor. */ super(screen, schedule); /* * Store the local reference to the parent view. */ this.scheduleUI = scheduleUI; } /** * Compose this by inserting each of its five menu items into the pulldown * menu. The items are Appointment, Meeting, Task, Event, and Categories. * A JSeparator is placed after the 'Event ...' item. */ public Component compose() { /* * Make the widget of this the JMenu. */ widget = new JMenu("Schedule"); /* * Add the items. */ addAppointmentItem(); addMeetingItem(); addTaskItem(); addEventItem(); ((JMenu) widget).add(new JSeparator()); addCategoriesItem(); return widget; } /*-* * Protected methods */ /** * Add the 'Appointment ...' menu item. Its action listener invokes the * scheduleUI.getScheduleAppointmentDialog().show() method. */ void addAppointmentItem() { ((JMenu) widget).add(new JMenuItem("Appointment ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scheduleUI.getScheduleAppointmentDialog().show(); } } ); } /** * Add the 'Meeting ...' menu item. Its action listener invokes the * scheduleUI.getScheduleMeetingDialog().show() method. */ void addMeetingItem() { ((JMenu) widget).add(new JMenuItem("Meeting ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scheduleUI.getScheduleMeetingDialog().show(); } } ); } /** * Add the 'Task ...' menu item. Its action listener invokes the * scheduleUI.getScheduleTaskDialog().show() method. */ void addTaskItem() { ((JMenu) widget).add(new JMenuItem("Task ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scheduleUI.getScheduleTaskDialog().show(); } } ); } /** * Add the 'Event ...' menu item. Its action listener invokes the * scheduleUI.getScheduleTaskDialog().show() method. */ void addEventItem() { ((JMenu) widget).add(new JMenuItem("Event ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scheduleUI.getScheduleEventDialog().show(); } } ); } /** * Add the 'Categories ...' menu item. Its action listener invokes the * scheduleUI.getCategoriesEditor().show() method. */ void addCategoriesItem() { ((JMenu) widget).add(new JMenuItem("Categories ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scheduleUI.getCategoriesEditor().show(); } } ); } /*-* * Data fields */ /** The parent view. */ protected ScheduleUI scheduleUI; }