package caltool.view.options; import caltool.model.options.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import mvp.*; /**** * * Class OptionsMenu is the pulldown menu view of the model class. The OptionsMenu widget is a Java JMenu. * Anonymous instances of JMenuItem are defined for each item in the menu. * */ public class OptionsMenu extends mvp.View { /** * Construct this with the given Options model. */ public OptionsMenu(Screen screen, Options options, OptionsUI optionsUI) { super(screen, options); this.optionsUI = optionsUI; } /** * Compose this by inserting each of its three menu items into the pulldown * menu. The items are Times and Dates, Scheduling, Viewing, and * Administrative. */ public Component compose() { /* * Make the widget of this the JMenu. */ widget = new JMenu("Options"); /* * Create a constant reference to the Options model for use in the * menu item action listeners. This is necessary due to the subtle * rules of anonymous inner classes in Java. */ final Options options = (Options) 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 'Times and Dates' menu item. */ ((JMenu) widget).add(new JMenuItem("Times and Dates ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { optionsUI.show(); optionsUI.selectTab("Times and Dates"); // System.out.println("In Options.timesAndDates."); } } ); /* * add the 'Fonts ...' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Fonts ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { optionsUI.show(); optionsUI.selectTab("Fonts"); // System.out.println("In Options.viewing."); } } ); /* * Add the 'Scheduling ...' menu item.); */ ((JMenu) widget).add(new JMenuItem("Scheduling ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { optionsUI.show(); optionsUI.selectTab("Scheduling"); // System.out.println("In Options.scheduling."); } } ); /* * add the 'Viewing ...' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Viewing ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { optionsUI.show(); optionsUI.selectTab("Viewing"); // System.out.println("In Options.viewing."); } } ); /* * add the 'Administrative ...' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Administrative ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { optionsUI.show(); optionsUI.selectTab("Administrative"); // System.out.println("In Options.administrative."); } } ); /* * Add a separator. */ ((JMenu) widget).add(new JSeparator()); /* * add the 'Global ...' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Global ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("In OptionsMenu 'Global' listener."); } } ); /* * Add a separator. */ ((JMenu) widget).add(new JSeparator()); /* * add the 'Restore Defaults' menu item.);); */ ((JMenu) widget).add(new JMenuItem("Restore Defaults")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("In OptionsMenu 'Restore Defaults' listener."); } } ); return widget; } /** Parent view */ protected OptionsUI optionsUI; }