package caltool.model.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 <a href = "Help.html" * Help </a> 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: * <pre> * JMenu.add(new JMenuItem("<em>Item name</em>").addActionListener( * new ActionListener() { * public void actionPerformed(ActionEvent e) { * <em>Model.method()</em> * </pre> */ /* * 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; } }