package gradertool.view; import javax.swing.*; import java.awt.*; import java.awt.event.*; import gradertool.gradebook.NewClassDisplay; import gradertool.gradebook.NewClassUI; import gradertool.gradebook.ItemExplorerUI; import gradertool.charts.*; import gradertool.curve.*; /**** * * Class ViewMenu is the "View" pulldown menu in the GraderToolUI prototype. * Anonymous instances of JMenuItem are defined for each item in the menu. *

* This class serves as a good example for how items are added to a menu, and * how an item's "action listener" is given a simple prototype implementation. *

* As explained in the Java Swing Tutorial, an action listener is implemented * in a method named "actionPerformed". This method is specialized for all * clickable GUI components, such as menu items and buttons. In a complete * implementation, action listeners perform actual computations, by calling * methods in companion computational classes. *

* In a GUI prototype, action listeners don't do any real work. Instead, they * do one of two things: *

  1. * print a simple message to stdout, to indicate that a menu item or button has * been clicked on *
  2. * bring up another prototype GUI, such as a dialog or display window *
*

* In the full implementation next quarter in 309, these simple prototype * actions will be replaced by calls to methods that do real work. * */ public class ViewMenu extends JMenu { /** * Construct this by inserting each of its nine menu items into the * pulldown menu. The items are New, Open, Close, Close All, Save, Save * As, Save All, Print, and Exit. JSeparators are placed after the 'Close * All', 'Save All', and 'Print' items. */ public ViewMenu() { super("View"); /* * Add each of the items to the menu, with separators in the * appropriate places (per the requirements). */ addShowHistogramItem(); addShowPieChartItem(); addShowItemExplorerItem(); addShowGradeScaleItem(); add(new JSeparator()); addExpandColumnItem(); addCollapseColumnItem(); add(new JSeparator()); addDetachMenuItem(); addHideMenuItem(); addCombineWindowsItem(); addSeparateWindowsItem(); } /** * Add the 'Show Histogram' menu item. This and all other file menu items are created * using the following pattern: *

     *     JMenu.add(new JMenuItem("Item name")).addActionListener(
     *         new ActionListener() {
     *             public void actionPerformed(ActionEvent e) {
     *                 print a message to stdout, or bring up another GUI
     *             }
     *         }
     *     );
     *                                                                   
*/ protected void addShowHistogramItem() { /* * Use the standard menu item pattern for the item. */ add(new JMenuItem("Show Histogram")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Histogram h = new Histogram(); } } ); } /** * Add the 'Show Pie Chart' menu item. */ protected void addShowPieChartItem() { add(new JMenuItem("Show Pie Chart")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { PieChart p = new PieChart(); } } ); } /** * Add the 'Show Item Explorer' menu item. */ protected void addShowItemExplorerItem() { add(new JMenuItem("Show Item Explorer")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ItemExplorerUI itemExplorer = new ItemExplorerUI(); itemExplorer.getItemExplorerDisplay().setVisible(true); } } ); } /** * Add the 'Show Grade Scale' menu item. */ protected void addShowGradeScaleItem() { add(new JMenuItem("Show Grade Scale")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { CurveTool c = new CurveTool(); } } ); } /** * Add the 'Expand Column' menu item. It just prints a message. */ protected void addExpandColumnItem() { add(new JMenuItem("Expand Column")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("View->Expand Column selected."); } } ); } /** * Add the 'Collapse Column' menu item. It just prints a message. */ protected void addCollapseColumnItem() { add(new JMenuItem("Collapse Column")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("View->Collapse Column selected."); } } ); } /** * Add the 'Detach Menu' menu item. It just prints a message. */ protected void addDetachMenuItem() { add(new JMenuItem("Detach Menu")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("View->Detach Menu selected."); } } ); } /** * Add the 'Hide Menu' menu item. It just prints a message. */ protected void addHideMenuItem() { add(new JMenuItem("Hide Menu")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("View->Hide Menu selected"); } } ); } /** * Add the 'Combine Windows' menu item. It just prints a message. */ protected void addCombineWindowsItem() { add(new JMenuItem("Combine Windows")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("View->Combine Windows selected"); } } ); } /** * Add the 'Separate Windows' menu item. It just prints a message. */ protected void addSeparateWindowsItem() { add(new JMenuItem("Separate Windows")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("View->Separate Windows selected"); } } ); } }