package gradertool.view; import javax.swing.*; import java.awt.*; import java.awt.event.*; import gradertool.charts.HistoricalTrends; import gradertool.gradebook.NewStudentDisplay; import gradertool.gradebook.*; /**** * * Class FileMenu is the "File" 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 ToolsMenu 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 ToolsMenu() { super("Tools"); /* * Add each of the items to the menu, with separators in the * appropriate places (per the requirements). */ //add(new JSeparator()); addAssignmentItem(); addStudentItem(); addGradeTrendsItem(); addClassOptionsItem(); } /** * Add the 'New' 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 addAssignmentItem() { JMenu subMenu = new JMenu("Graded Item"); subMenu.add(new JMenuItem("Add")).addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ GradedItemDisplay gid = new GradedItemDisplay("Add"); gid.setVisible(true); } } ); subMenu.add(new JMenuItem("Modify")).addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ GradedItemDisplay gid = new GradedItemDisplay("Modify"); gid.setVisible(true); } } ); subMenu.add(new JMenuItem("Delete")).addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ int n = JOptionPane.showConfirmDialog(new JFrame(),"Are you sure you want to delete this graded item?\nThis action cannot be undone", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.NO_OPTION){ System.out.println("No pressed"); } else if (n == JOptionPane.YES_OPTION){ System.out.println("Yes pressed"); } } } ); /* * Use the standard menu item pattern for the item. */ add(subMenu); } /** * Add the 'Open ...' menu item. Its action listener brings up a standard * Swing file choose, provided by the JFileChooser class. method. See the * description of the addNewItem * method for further info. */ protected void addStudentItem() { JMenu subMenu = new JMenu("Student"); subMenu.add(new JMenuItem("Add")).addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ NewStudentDisplay newStudentDisplay = new NewStudentDisplay(); newStudentDisplay.setVisible(true); } } ); subMenu.add(new JMenuItem("Modify")).addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ NewStudentDisplay newStudentDisplay = new NewStudentDisplay(); newStudentDisplay.setVisible(true); } } ); subMenu.add(new JMenuItem("Delete")).addActionListener( new ActionListener(){ public void actionPerformed (ActionEvent e){ DelStudentDisplay delStudentDisplay = new DelStudentDisplay(); delStudentDisplay.setVisible(true); } } ); add(subMenu); } /** * Add the 'Close' menu item. Its action listener just prints a message. * See the description of the addNewItem * method for further info. */ protected void addGradeTrendsItem() { final JMenuItem item; // Used by JFileChooser for placement add(new JMenuItem("Grade Trends")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { HistoricalTrends hist = new HistoricalTrends(); } } ); } /** * Add the 'Close All menu item. Its action listener just prints a * message. See the description of the * addNewItem method for further info. */ protected void addClassOptionsItem() { final JMenuItem item; // Used by JFileChooser for placement add(new JMenuItem("Class Options ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Class Options clicked"); } } ); } }