package caltool.view.help; import caltool.model.help.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import mvp.*; /**** * * Class HelpMenu is the pulldown menu view of the model class. The HelpMenu widget is a Java JMenu. Anonymous * instances of JMenuItem are defined for each item in the menu. * */ public class HelpMenu extends mvp.View { /** * Construct this with the give Help model. */ public HelpMenu(Screen screen, Help help, HelpUI helpUI) { super(screen, help); } /** * Compose this by inserting each of its three menu items into the pulldown * menu. The items are About, Show Quick Help, and Detailed Help. */ public Component compose() { /* * Make the widget of this the JMenu. */ widget = new JMenu("Help"); /* * Create a constant reference to the Help model for use in the * menu item action listeners. This is necessary due to the subtle * rules of anonymous inner classes in Java. */ final Help help = (Help) model; /* * Create the menu items using the following pattern: *
         *     JMenu.add(new JMenuItem("Item name").addActionListener(
         *         new ActionListener() {
         *             public void actionPerformed(ActionEvent e) {
         *                 Model.method()
         *                                                              
*/ /* * Add the 'About ...' menu item. */ ((JMenu) widget).add(new JMenuItem("About ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("In Help.about."); } } ); /* * add the 'Show Quick Help' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Show Quick Help")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("In Help.showQuickHelp."); } } ); /* * add the 'Detailed Help ...' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Detailed Help ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("In Help.detailedHelp."); } } ); return widget; } }