/** * Dialog box for editing individual Finch Actions. * *
* Approach: *
* @author Andrew H. Fagg * */ import javax.swing.JColorChooser; import javax.swing.JDialog; 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 FinchActionDialogAbstract extends JDialog { // Panel that contains a label and a combo box to represent the different // types of Finch Actions. protected JComboBox aComboBox = new JComboBox(new String[]{"Jog", "Beak Color", "Tone", "Guarded Jog", "Guarded Orientation"}); protected JLabel lComboBox = new JLabel("Action Type: "); protected JPanel pComboBox = new JPanel(); // Index constants that correspond to the strings used to define the Combo Box static final protected int JOG = 0; static final protected int BEAK = 1; static final protected int TONE = 2; static final protected int GUARDED_JOG = 3; static final protected int GUARDED_ORIENT = 4; // Panel that contains the label and the text field for the name of the action protected JTextField aName = new JTextField("", 15); protected JLabel lName = new JLabel("Name: "); protected JPanel pName = new JPanel(); // Panel that contains the label and slider for the duration protected JSlider aDuration = new JSlider(0, 10000, 1000); protected JLabel lDuration = new JLabel("Duration (ms): "); protected JPanel pDuration = new JPanel(); // Panel containing the buttons at the bottom of the dialog box protected JPanel jpbuttons = new JPanel(); protected JButton jbtOK = new JButton("OK"); protected JButton jbtCancel = new JButton("Cancel"); /////// // Finch action that corresponds to the values entered into the // dialog box. This field is filled in as the dialog box is // closing. A value of null indicates no action has been specified // (e.g., in the case of a 'Cancel' action). protected FinchAction action; // The nose color for the FlashBeak Action protected Color noseColor = new Color(0,0,0); /////////////////////////////////////////////////////// /** * Constructor * *
* Creates the action type combo box and the action name. * */ public FinchActionDialogAbstract(){ // Call the JDialog constructor super((java.awt.Frame) null, true); // Configure the look of the dialog box this.setTitle("Edit Finch Action"); this.setLayout(new GridLayout(0,1,10,10)); ////// // First row: combo box containing the combo box for selecting action type // Label pComboBox.add(lComboBox); // Combo box pComboBox.add(aComboBox); // Add this panel to the dialog frame this.add(pComboBox); // When the combo box state changes, update the fields that are visible aComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ reconfigureDialog(); } }); ////// // Second row: Text field containing the name of the Finch Action // Label pName.add(lName); // The actual text field pName.add(aName); // Add this panel to the dialog frame this.add(pName); //////////////////////// // Action listeners for the Buttons. Note: // the buttons have not been added to the frame // OK jbtOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ // Create the action that corresponds to the values in the dialog box createNewAction(); // Close the dialog box setVisible(false); } }); // Cancel button jbtCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ // Close the dialog box setVisible(false); } }); ///////////////////////////////////////////////////////////// } /** * Given an existing FinchAction, configure the dialog box values * to reflect this action as soon as it is opened. *
* *
* Algorithm: *
* * Postconditions: *
* * Algorithm: *
* Algorithm: *
* * Algorithm: *