package view; import utilities.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; /**** * * Class ViewMenu is the "View" pulldown menu in the CalendarToolUI prototype. * Anonymous instances of JMenuItem are defined for each item in the menu. *

* The constructor for this class receives a reference to the containing * ViewUI. It uses this reference to access the dialogs that ViewUI * constructs. Since this class and ViewUI are in the same package, it has * access to its protected data fields. This is not the best practice for info * hiding, but it's fine in a rapid prototype. *

* In the current prototype, only the Month and Lists->Appointments items have * an action listener that brings up a dialog. The other items just print a * message to stdout. *

* See FileMenu.java documentation for further * discussion on setting up menu items. See * documentation for a description of the convenience class that constructs * menu items that do nothing but print a message to stdout. * */ public class ViewMenu extends JMenu { /** * Construct this by inserting each of its items, which are Item through. * Calendars. A JSepartor goes between item groupings, as shown in the * requirements. *

* The input parameter is used to reference the dialogs that ViewUI * creates. Note that it must be declared final, since it is referenced * inside an anonymous inner class. */ public ViewMenu(final ViewUI viewUI) { super("View"); add(new PrintOnlyMenuItem("View", "Item")); add(new PrintOnlyMenuItem("View", "Day")); add(new PrintOnlyMenuItem("View", "Week")); add(new JMenuItem("Month")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { viewUI.monthlyAgendaDisplay.setVisible(true); } } ); add(new PrintOnlyMenuItem("View", "Year")); add(new JSeparator()); add(new PrintOnlyMenuItem("View", "Next")); add(new PrintOnlyMenuItem("View", "Previous")); add(new PrintOnlyMenuItem("View", "Today")); add(new PrintOnlyMenuItem("View", "Goto Date ...")); add(new JSeparator()); add(constructListsSubmenu(viewUI)); add(new PrintOnlyMenuItem("View", "Filter ...")); add(new JSeparator()); add(new PrintOnlyMenuItem("View", "Other User ...")); add(new PrintOnlyMenuItem("View", "Group ...")); add(new JSeparator()); add(new PrintOnlyMenuItem("View", "Windows ->")); add(new PrintOnlyMenuItem("View", "Calendars ->")); } /** * Construct the pull-right submenu that appears under "Lists ->". As * explained in the 308 lecture notes, adding a JMenu to another JMenu * automatically makes the added menu a pull-right style submenu. */ JMenu constructListsSubmenu(final ViewUI viewUI) { JMenu menu = new JMenu("Lists"); menu.add(new JMenuItem("Appointments")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { viewUI.appointmentsListDisplay.setVisible(true); viewUI.appointmentsListDisplay. setLocation(new Point(75, 150)); } } ); menu.add(new PrintOnlyMenuItem("View", "Meetings")); menu.add(new PrintOnlyMenuItem("View", "Tasks")); menu.add(new PrintOnlyMenuItem("View", "Events")); menu.add(new PrintOnlyMenuItem("View", "All Items")); menu.add(new PrintOnlyMenuItem("View", "Custom ->")); return menu; } }