package gradertool.view; import javax.swing.*; import java.awt.*; import java.awt.event.*; import gradertool.gradebook.NewClassDisplay; import gradertool.gradebook.NewClassUI; import gradertool.gradebook.GradeSpreadsheetUI; import gradertool.admin.ExportUI; /**** * * Class FileMenu is the "File" pulldown menu in the GraderToolUI prototype. * */ public class FileMenu 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 FileMenu() { super("File"); /* * Add each of the items to the menu, with separators in the * appropriate places (per the requirements). */ addNewItem(); addOpenItem(); addCloseItem(); addCloseAllItem(); addSaveItem(); addSaveAsItem(); addSaveAllItem(); addManageTAItem(); addPrintItem(); addExportItem(); addExitItem(); } /** * Add the 'New' menu item. This and all other file menu items are created * using the following pattern: */ protected void addNewItem() { /* * Use the standard menu item pattern for the item. */ add(new JMenuItem("New ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { NewClassUI newClassUI = new NewClassUI(); newClassUI.getNewClassDisplay().setVisible(true); } } ); } /** * 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 addOpenItem() { final JMenuItem item; // Used by JFileChooser for placement add( item = new JMenuItem("Open ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(item); GradeSpreadsheetUI gSheet = new GradeSpreadsheetUI(); gSheet.getGradeSpreadsheetDisplay().setVisible(true); } } ); } /** * Add the 'Close' menu item. Its action listener just prints a message. * See the description of the addNewItem * method for further info. */ protected void addCloseItem() { add(new JMenuItem("Close")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("File->Close selected."); } } ); } /** * 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 addCloseAllItem() { add(new JMenuItem("Close All")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("File->CloseAll selected."); } } ); } /** * Add the 'Save' menu item. Its action listener just prints a message. * See the description of the addNewItem * method for further info. */ protected void addSaveItem() { add(new JMenuItem("Save")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("File->Save selected."); } } ); } /** * Add the 'Save As ...' menu item. Its action listener displays a file * chooser to select the file on which to save. See the description of the * addNewItem method for further * info. */ protected void addSaveAsItem() { final JMenuItem item; // Used by JFileChooser for placement add( item = new JMenuItem("Save As ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { (new JFileChooser()).showSaveDialog(item); } } ); } /** * Add the 'Save All' menu item. Its action listener just prints a * message. method. See the description of the addNewItem method for further info. */ protected void addSaveAllItem() { add(new JMenuItem("Save All")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("File->Save All selected."); } } ); } /** * Add the 'Manage TA' menu item. */ protected void addManageTAItem() { final JMenuItem item; add(new JMenuItem("Manage TA")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { /* * For the prototype, just display a quickie dialog * that will be refined later. */ JOptionPane.showInputDialog("Choose a TA: "); } } ); } /** * Add the 'Print ...' menu item. Its action listener invokes the * File.print method. See the description of the addNewItem method for further info. */ protected void addPrintItem() { final JMenuItem item; // Used by JFileChooser for placement add(new JMenuItem("Print ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { /* * For the prototype, just display a quickie dialog * that will be refined later. */ JOptionPane.showInputDialog("Choose a printer: "); } } ); } /** * Add the 'Export ...' menu item. */ protected void addExportItem() { final JMenuItem item; // Used by JFileChooser for placement add(new JMenuItem("Export ...")).addActionListener( new ActionListener() { // public void actionPerformed(ActionEvent e) { // /* // * For the prototype, just display a quickie dialog // * that will be refined later. // */ // JOptionPane.showInputDialog("Export grades: "); // } public void actionPerformed(ActionEvent e) { ExportUI exportUI = new ExportUI(); exportUI.getExportDisplay().setVisible(true); } } ); } /** * Add the 'Exit' menu item. Its action listener calls System.exit. As * such it's the only action listener that does any real work. */ protected void addExitItem() { add(new JMenuItem("Exit")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); } }