* JMenu.add(new JMenuItem("Item name")).addActionListener( * new ActionListener() { * public void actionPerformed(ActionEvent e) { * Model.method() **/ protected void addNewItem() { /* * Use the standard menu item pattern for the item. */ menu.add(new JMenuItem("New")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { /* * Call the stubbed-out model method. */ file.fileNew(); } } ); } /** * Add the 'Open ...' menu item. Its action listener invokes the File.open * method. See the description of the * addNewItem method for further info. */ protected void addOpenItem() { final JMenuItem item; // Used by JFileChooser for placement menu.add( item = new JMenuItem("Open ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { /* * For the stubbed design, just display a JFileChooser. * When things are refined, we'll actually use the file * chooser to select a file. */ (new JFileChooser()).showOpenDialog(item); /* * Call the stubbed-out model method. */ file.open(null); } } ); } /** * Add the 'Close' menu item. Its action listener invokes the File.close * method. See the description of the * addNewItem method for further info. */ protected void addCloseItem() { menu.add(new JMenuItem("Close")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { file.close(); } } ); } /** * Add the 'Close All menu item. Its action listener invokes the * File.closeAll method. See the description of the addNewItem method for further info. */ protected void addCloseAllItem() { menu.add(new JMenuItem("Close All")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { file.closeAll(); } } ); } /** * Add the 'Save' menu item. Its action listener invokes the File.save * method. See the description of the * addNewItem method for further info. */ protected void addSaveItem() { menu.add(new JMenuItem("Save")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { file.save(); } } ); } /** * Add the 'Save As ...' menu item. Its action listener invokes the * File.saveAs method. See the description of the addNewItem method for further info. */ protected void addSaveAsItem() { final JMenuItem item; // Used by JFileChooser for placement menu.add( item = new JMenuItem("Save As ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { (new JFileChooser()).showSaveDialog(item); file.saveAs(null); } } ); } /** * Add the 'Save All' menu item. Its action listener invokes the * File.saveAll method. See the description of the addNewItem method for further info. */ protected void addSaveAllItem() { menu.add(new JMenuItem("Save All")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { file.saveAll(); } } ); } /** * Add the 'Save Config' menu item. Its action listener invokes the * File.saveConfig method. See the description of the addNewItem method for further info. */ protected void addSaveConfigItem() { final JMenuItem item; // Used by JFileChooser for placement menu.add( item = new JMenuItem("Save Config ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { (new JFileChooser()).showSaveDialog(item); file.saveConfig(); } } ); } /** * Add the 'Print ...' menu item. Its action listener invokes the * File.print method. See the description of the addNewItem method for further info. */ protected void addPrintItem() { final JMenuItem item; // Used by JFileChooser for placement menu.add(new JMenuItem("Print ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { /* * For the stubbed design, just display a quickie dialog * that will be refined later. */ JOptionPane.showInputDialog("Choose a printer: "); file.print(null); } } ); } /** * Add the 'Exit' menu item. Its action listener invokes the File.exit * method. See the description of the * addNewItem method for further info. */ protected void addExitItem() { menu.add(new JMenuItem("Exit")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { file.exit(); } } ); } /** * Add menu items to perform any system tests that may be useful during * development. This submenu goes away in the production version of the * system. */ protected void addSystemTestItems() { JMenu smenu = new JMenu("System Tests"); menu.add(smenu); /* * Add the 'Dump User Cal' menu item. */ smenu.add(new JMenuItem("Dump User Cal")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { file.dumpUserCal(); } } ); } /*-* * Data fields */ /** Local reference to super.model for convenience to avoid casting * everywhere; i.e., file is set equal to (File)super.model once in the * constructor. */ File file; /** Local reference to (JMenu)super.widget for convenience to avoid * casting; i.e., menu is set equal to (File)super.widget once in the * constructor. */ JMenu menu; }