source: tmcsimulator-scriptbuilder/trunk/src/event/editor/GenericEvaluationPanel.java @ 130

Revision 130, 6.4 KB checked in by bmcguffin, 9 years ago (diff)

Changed implementation of save function for event editor panels. Instead of updating their model objects whenever the enter key is pressed, panels are now notified when the window is closed and update their information then.

Line 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.ArrayList;
5import java.util.Observable;
6import javax.swing.JTable;
7import javax.swing.event.TableModelEvent;
8import javax.swing.event.TableModelListener;
9import scriptbuilder.structures.events.I_EvaluationEvent;
10import scriptbuilder.structures.events.I_ScriptEvent;
11
12/**
13 *
14 * @author nathaniellehrer
15 */
16public class GenericEvaluationPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
17{
18
19    private I_EvaluationEvent event;
20    private JTable dialogTable;
21
22    /**
23     * Creates new form GenericEvaluation
24     */
25    public GenericEvaluationPanel()
26    {
27        initComponents();
28
29        dialogTable = GenericTable.genericizeTable(
30                scrollPane, CriteriaDropdown, addButton, deleteButton, "Scale", "Criteria");
31    }
32
33    @Override
34    public void getEventObject(I_ScriptEvent sei)
35    {
36        if (sei instanceof I_EvaluationEvent)
37        {
38            event = (I_EvaluationEvent) sei;
39            ArrayList<String> strs = event.getExpectedActions();
40            for (String s : strs)
41            {
42                ((MyTableModel) dialogTable.getModel()).addRow(
43                        CriteriaDropdown.getItemAt(0).toString(), s);
44            }
45
46        }
47        addButton.addActionListener(new ActionListener()
48        {
49
50            public void actionPerformed(ActionEvent e)
51            {
52                event.addAction("");
53            }
54        });
55        dialogTable.getModel().addTableModelListener(new TableModelListener()
56        {
57
58            public void tableChanged(TableModelEvent e)
59            {
60                if (e.getType() == TableModelEvent.UPDATE)
61                {
62                    event.updateAction(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
63                }
64                if (e.getType() == TableModelEvent.DELETE)
65                {
66                    event.removeAction(e.getLastRow());
67                }
68            }
69        });
70    }
71
72    @Override
73    public void update(Observable o, Object arg)
74    {
75        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
76    }
77   
78    @Override
79    public boolean removeAssociatedEvent()
80    {
81        ((I_ScriptEvent)event).removeThis();
82        event = null;
83        return true;
84    }
85
86    @Override
87    public void uponClose()
88    {
89        //No change is necessary here; this panel saves its state continually
90    }
91
92    /**
93     * This method is called from within the constructor to initialize the form.
94     * WARNING: Do NOT modify this code. The content of this method is always
95     * regenerated by the Form Editor.
96     */
97    @SuppressWarnings("unchecked")
98    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
99    private void initComponents()
100    {
101
102        addButton = new javax.swing.JButton();
103        deleteButton = new javax.swing.JButton();
104        scrollPane = new javax.swing.JScrollPane();
105        txtNotes = new javax.swing.JTextArea();
106        CriteriaDropdown = new javax.swing.JComboBox();
107        jLabel1 = new javax.swing.JLabel();
108
109        addButton.setText("Add Criteria");
110        addButton.setToolTipText("Adds a new row in the table below");
111
112        deleteButton.setText("Delete Selected Criteria");
113        deleteButton.setToolTipText("Deletes the selected row in the table below");
114
115        scrollPane.setToolTipText("");
116
117        txtNotes.setColumns(20);
118        txtNotes.setRows(5);
119        scrollPane.setViewportView(txtNotes);
120
121        CriteriaDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yes/No", "1-5", "1-10", "Written" }));
122        CriteriaDropdown.setToolTipText("The type of criteria evaluation scale to be used");
123
124        jLabel1.setText("Criteria Evaluation Scale:");
125
126        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
127        this.setLayout(layout);
128        layout.setHorizontalGroup(
129            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
130            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
131                .addContainerGap()
132                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
133                    .add(org.jdesktop.layout.GroupLayout.LEADING, scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 598, Short.MAX_VALUE)
134                    .add(layout.createSequentialGroup()
135                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
136                            .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
137                            .add(CriteriaDropdown, 0, 293, Short.MAX_VALUE))
138                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
139                        .add(addButton)
140                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
141                        .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
142                .add(23, 23, 23))
143        );
144        layout.setVerticalGroup(
145            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
146            .add(layout.createSequentialGroup()
147                .addContainerGap()
148                .add(jLabel1)
149                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
150                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
151                    .add(CriteriaDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
152                    .add(deleteButton)
153                    .add(addButton))
154                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
155                .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
156                .addContainerGap())
157        );
158    }// </editor-fold>//GEN-END:initComponents
159
160
161    // Variables declaration - do not modify//GEN-BEGIN:variables
162    private javax.swing.JComboBox CriteriaDropdown;
163    private javax.swing.JButton addButton;
164    private javax.swing.JButton deleteButton;
165    private javax.swing.JLabel jLabel1;
166    private javax.swing.JScrollPane scrollPane;
167    private javax.swing.JTextArea txtNotes;
168    // End of variables declaration//GEN-END:variables
169
170}
Note: See TracBrowser for help on using the repository browser.