* 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) {
JFileChooser chooser = new JFileChooser();
java.io.File f;
chooser.showOpenDialog(item);
if ((f = chooser.getSelectedFile()) != null) {
file.open(f.getName());
}
}
}
);
}
/**
* 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 displays a file
* chooser to select the file on which to save, then 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 'Load Settings' menu item. Its action listener displays a load
* settings dialog, from which the File.loadSettings method is invoked.
* See the description of the addNewItem
* method for further info.
*/
protected void addLoadSettingsItem() {
final JMenuItem item; // Used by JFileChooser for placement
menu.add(
item = new JMenuItem("Load Settings ...")).addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*
* For the stubbed design, just display a quickie dialog
* that will be refined later.
*/
JOptionPane.showInputDialog("... Load Settings stuff goes here ...");
}
}
);
}
/**
* Add the 'Load Settings' menu item. Its action listener displays a save
* settings dialog, from which the File.saveSettings method is invoked.
* FileMenu.html#addNewItem> addNewItem method for further info.
*/
protected void addSaveSettingsItem() {
final JMenuItem item; // Used by JFileChooser for placement
menu.add(
item = new JMenuItem("Save Settings ...")).addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*
* For the stubbed design, just display a quickie dialog
* that will be refined later.
*/
JOptionPane.showInputDialog("... Save Settings stuff goes here ...");
}
}
);
}
/**
* Add the 'Page Setup ...' menu item. Its action listener displays a Page
* Setup dialog, from which the File.pageSetup method is invoked. See the
* description of the addNewItem
* method for further info.
*/
protected void addPageSetupItem() {
final JMenuItem item; // Used by JFileChooser for placement
menu.add(new JMenuItem("Page Setup ...")).addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*
* For the stubbed design, just display a quickie dialog
* that will be refined later.
*/
JOptionPane.showInputDialog("... Page Setup stuff goes here ...");
}
}
);
}
/**
* 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 menu = new JMenu("System Tests");
menu.add(menu);
/*
* Add the 'Dump User Cal' menu item.
*/
menu.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;
}