/** * FinchDisplayAbstract *

* Main window of the program. The primary components are: *

* *

* Notes: *

*

* * @author Andrew H. Fagg * */ import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JFileChooser.*; import javax.swing.filechooser.*; import javax.swing.event.*; import javax.swing.border.*; abstract public class FinchDisplayAbstract extends JFrame { /** * Reference to the FinchData structure. */ protected FinchData finchData; /** * Menu bar * */ protected JMenuBar menuBar = new JMenuBar(); /** * The file menu */ protected JMenu fileMenu = new JMenu("File");; // Menu Items protected JMenuItem jmiLoadTextFile = new JMenuItem("Load Text File"); protected JMenuItem jmiMergeTextFile = new JMenuItem("Merge Text File"); protected JMenuItem jmiLoadBinaryFile = new JMenuItem("Load Binary File"); protected JMenuItem jmiMergeBinaryFile = new JMenuItem("Merge Binary File"); protected JMenuItem jmiSaveBinaryFile = new JMenuItem("Save Binary File"); protected JMenuItem jmiExit = new JMenuItem("Exit"); /** * Set to true if the program is to continue running. False will force * the program to quit. */ protected boolean closeFlag = true; /** * Constructor * * @param finchData Reference to the existing FinchData object */ public FinchDisplayAbstract(FinchData finchData) { // Save reference to the finchData object this.finchData = finchData; // Create the menu bar this.setJMenuBar(this.menuBar); // Add the File menu to the menu bar this.menuBar.add(this.fileMenu); // Put the menu together this.fileMenu.add(this.jmiLoadTextFile); this.fileMenu.add(this.jmiMergeTextFile); this.fileMenu.add(this.jmiLoadBinaryFile); this.fileMenu.add(this.jmiMergeBinaryFile); this.fileMenu.add(this.jmiSaveBinaryFile); this.fileMenu.addSeparator(); this.fileMenu.add(this.jmiExit); // Set up action listener for Load Text File this.jmiLoadTextFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ loadText(false); } }); // Set up action listener for Merge Text File this.jmiMergeTextFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ loadText(true); } }); // Set up action listener for Load Binary File this.jmiLoadBinaryFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ loadBinary(false); } }); // Set up action listener for Merge Binary File this.jmiMergeBinaryFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ loadBinary(true); } }); // Set up action listener for Save Binary File this.jmiSaveBinaryFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ saveBinary(); } }); // Set up action listener for Merge Text File this.jmiExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ exitChooser(); } }); ////////////////////////// // Detect when the window is closed this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent event) { closeFinch(); System.out.println("closing..."); } }); }; /////////////////////////////////////////////////////////////////////////////////// /** * Open the FinchAction editing dialog box. * *

* Algorithm: *

* *

* * @param existFlag true if we are editing an existing action ('Edit' has * been pressed). */ abstract protected void dialogAction(boolean existFlag); /** * Delete any actions that have been selected. * *

* Algorithm: *

*/ abstract protected void delete_list_items(); /** * Clean the master action list by removing duplicates. * *

* Algorithm: *

* */ abstract protected void clean(); /** * Execute the filtered action list *

* * Algorithm: *

* * @param reverse True if the actions should be executed in reverse order */ abstract protected void execute(boolean reverse); /** * Reset the display of the filtered action list * *

* Algorithm: *

* */ abstract protected void resetActionList(); /** * Initiate the closing down of the program * */ protected void closeFinch() { closeFlag = false; System.out.println("Initiate closing..."); } /** * Load a text file * *

* Algorithm: *

* * @param merge_flag True indicates that the loaded set of actions should be * merged with the existing ones. */ abstract protected void loadText(boolean merge_flag); /** * Load a binary file * *

* Algorithm: *

* * @param merge_flag True indicates that the loaded set of actions should be * merged with the existing ones. */ abstract protected void loadBinary(boolean merge_flag); /** * Save a binary file * *

* Algorithm: *

* */ abstract protected void saveBinary(); /** * *

* * Open a ConfirmDialog box that asks whether the user really wants to * quit the program. If "Yes" is selected, then the program is shut * down by calling closeFinch() * * Postconditions: *

    *
  1. this.closeFinch() will have been called if indicated by the user. *
* *

* * Notes: *

    *
  1. JOptionPane.showConfirmDialog will return a "0" if "Yes" is selected. *
  2. The dialog box should only present two buttons: "Yes" and "No" *
* */ protected void exitChooser() { int ret = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "Exiting ...", JOptionPane.YES_NO_OPTION); if(ret == 0){ // The "Yes" button was pressed closeFinch(); } } /** * Indicate whether the program should continue to execute * * @return True if the program should continue running (this method is * used by the driver method to continue it's wait for the termination of the * program. */ public boolean getCloseFlag(){ return(closeFlag); } }