import view.*; import javax.swing.*; import java.awt.*; /**** * * Class CalendarToolUI is the top-level class for the GUI prototype. It * extends a JFrame, which is the Swing class most often used for stand-alone * GUI windows. *

* CalendarToolUI's constructor creates a menubar, and then calls the * constructors for the other prototype GUIs. These constructors, in turn, * create the menus that appear in the menubar, as well as the dialogs and * display windows that appear in response to menu item selection and button * presses. *

* All of the GUI components are organized into packages, corresponding to the * Calendar Tool's functional decomposition. This packaging is not strictly * necessary in a GUI prototype, but is useful for two significant reasons. * First, the packaging allows team members to work on their own GUI packages, * with a clear subdivision of labor. Second, the packaging will be helpful * next quarter in 309, when we integrate the GUI with computational classes * that do real work. * */ public class CalendarToolUI extends JFrame { /** * Construct this with its menubar and initial monthly display window. * Lower-level GUI classes are in turn responsible for constructing their * own GUI components, including the menus, menu items, dialogs, and * display windows. *

* This constructor also performs the following two initializations: (1) * set the title of the window to "Calendar Tool"; (2) call the * JFrame.pack() method, which tells swing to perform the necessary window * layout computations. Neglecting to call the pack method can lead to * improperly sized JFrames, so make sure you don't forget to do it. */ public CalendarToolUI() { /* * Construct the menubar. */ menuBar = new JMenuBar(); /* * Set the JFrame's built-in menu bar. */ setJMenuBar(menuBar); /* * Call the constructors for the top-level classes in each of the GUI * prototype packages. */ constructSubGUIs(); /* * Add the menus. These will have been constructed by the subGUI * classes, and made available in with a getMenu method. */ composeMenuBar(); /* * Bring up the initial monthly display window. As explained in the * comment for the Main class, the calling the method setVisible(true) * is the way to make a top-level window visible on the screen. The * setLocation call is a quick hack to get the monthly window to show * up below the menubar, instead on top of it in the upper left corner * of the screen. */ (monthlyAgendaDisplay = viewUI.getMonthlyAgendaDisplay()). setVisible(true); monthlyAgendaDisplay.setLocation(new Point(0, 80)); /* * Set the window title, which will appear in the banner of the window. */ setTitle("Calendar Tool"); /* * Call JFrame.pack to have Java size up the window properly. */ pack(); } /** * Call the constructor for each of the sub GUIs. */ protected void constructSubGUIs() { fileUI = new file.FileUI(); editUI = new edit.EditUI(); scheduleUI = new schedule.ScheduleUI(); viewUI = new view.ViewUI(); adminUI = new admin.AdminUI(); optionsUI = new options.OptionsUI(); } /** * Compose the menubar by adding each menu to it. */ protected void composeMenuBar() { menuBar.add(fileUI.getMenu()); menuBar.add(editUI.getMenu()); menuBar.add(scheduleUI.getMenu()); menuBar.add(viewUI.getMenu()); menuBar.add(adminUI.getMenu()); menuBar.add(optionsUI.getMenu()); } /*-* * Data fields */ /** The top-level menu bar. */ protected JMenuBar menuBar; /** The prototype UI for file-related functionality. */ protected file.FileUI fileUI; /** The prototype UI for editing functionality. */ protected edit.EditUI editUI; /** The prototype UI for scheduling functionality. */ protected schedule.ScheduleUI scheduleUI; /** The prototype UI for viewing functionality. */ protected view.ViewUI viewUI; /** The prototype UI for administrative functionality. */ protected admin.AdminUI adminUI; /** The prototype UI for options functionality. */ protected options.OptionsUI optionsUI; /** Monthly agenda initial window. */ protected view.MonthlyAgendaDisplay monthlyAgendaDisplay; }