source: tmcsimulator-scriptbuilder/trunk/src/event/editor/CMSEvaluationPanel.java @ 89

Revision 89, 10.4 KB checked in by bmcguffin, 9 years ago (diff)

Added dropdown menu item to ScriptBuilderFrame?: "Delete Incident". When clicked, user may select an existing incident to delete. Program will prompt user to confirm the deletion, then remove the incident from the script and refresh the display.

Added button to individual event editor window: "Remove this event". When clicked, the currently displayed event will be removed from the timeslice it is in. The display will be refreshed accordingly. NOTE: This still has some bugs, namely that the last remaining event in a timeslice fails to be deleted.

Restructured Interface ScriptEventEditorPanel? to include a removeAssociatedEvent method, which calls a new method in I_ScriptEvent called removeThis, which causes the event to be removed from its timeslice.

Editor.Java previously contained several classes and enums, none of which were set to private scope. Moved these extra classes to their own files to decrease clutter in Editor.java and increase readability of all files.

Line 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.*;
5import javax.swing.JTable;
6import javax.swing.event.TableModelEvent;
7import javax.swing.event.TableModelListener;
8import scriptbuilder.structures.events.CMSEvaluationEvent;
9import scriptbuilder.structures.events.I_ScriptEvent;
10
11/**
12 *
13 * @author nathaniellehrer
14 */
15public class CMSEvaluationPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
16{
17
18    private HashMap<String, Class> properties;
19    private JTable dialogTable;
20    private ActionListener removeListener;
21    private CMSEvaluationEvent event;
22
23    /**
24     * Creates new form CMSEvaluation
25     */
26    public CMSEvaluationPanel()
27    {
28        initComponents();
29
30        dialogTable = GenericTable.genericizeNumberedTable(jScrollPane1, addButton, deleteButton);
31    }
32
33    public void setRemoveListener(ActionListener listener)
34    {
35        removeListener = listener;
36    }
37
38    @Override
39    public void getEventObject(I_ScriptEvent sei)
40    {
41        event = (CMSEvaluationEvent) sei;
42        txtID.setText(event.cmsID);
43        txtID.addKeyListener(new KeyListener()
44        {
45
46            @Override
47            public void keyTyped(KeyEvent e)
48            {
49            }
50
51            @Override
52            public void keyPressed(KeyEvent e)
53            {
54                if (e.getKeyCode() == KeyEvent.VK_ENTER)
55                {
56                    event.cmsID = txtID.getText();
57                }
58            }
59
60            @Override
61            public void keyReleased(KeyEvent e)
62            {
63            }
64        });
65        txtLocation.setText(event.location);
66        txtLocation.addKeyListener(new KeyListener()
67        {
68
69            @Override
70            public void keyTyped(KeyEvent e)
71            {
72            }
73
74            @Override
75            public void keyPressed(KeyEvent e)
76            {
77                if (e.getKeyCode() == KeyEvent.VK_ENTER)
78                {
79                    event.location = txtLocation.getText();
80                }
81            }
82
83            @Override
84            public void keyReleased(KeyEvent e)
85            {
86            }
87        });
88        txtMessage.setText("");
89        for (int i = 0; i < event.message.size(); i++)
90        {
91            ((MyTableModel) dialogTable.getModel()).addRow("" + (i + 1), event.message.get(i));
92        }
93        for (int i = 0; i < TypeDropdown.getItemCount(); i++)
94        {
95            if (event.cmsType.equalsIgnoreCase(TypeDropdown.getItemAt(i).toString()))
96            {
97                TypeDropdown.setSelectedIndex(i);
98            }
99        }
100        TypeDropdown.addActionListener(new ActionListener()
101        {
102
103            @Override
104            public void actionPerformed(ActionEvent e)
105            {
106                event.cmsType = TypeDropdown.getSelectedItem().toString();
107            }
108        });
109        addButton.addActionListener(new ActionListener()
110        {
111
112            @Override
113            public void actionPerformed(ActionEvent e)
114            {
115                event.message.add("");
116            }
117        });
118        dialogTable.getModel().addTableModelListener(new TableModelListener()
119        {
120
121            public void tableChanged(TableModelEvent e)
122            {
123                if (e.getType() == TableModelEvent.UPDATE)
124                {
125                    event.message.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
126                }
127                if (e.getType() == TableModelEvent.DELETE)
128                {
129                    event.message.remove(e.getLastRow());
130                }
131            }
132        });
133    }
134
135    public void update(Observable o, Object arg)
136    {
137        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
138    }
139   
140    @Override
141    public boolean removeAssociatedEvent()
142    {
143        event.removeThis();
144        event = null;
145        return true;
146    }
147
148    /**
149     * This method is called from within the constructor to initialize the form.
150     * WARNING: Do NOT modify this code. The content of this method is always
151     * regenerated by the Form Editor.
152     */
153    @SuppressWarnings("unchecked")
154    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
155    private void initComponents()
156    {
157
158        removeButton = new javax.swing.JButton();
159        jLabel3 = new javax.swing.JLabel();
160        txtLocation = new javax.swing.JTextField();
161        jLabel2 = new javax.swing.JLabel();
162        TypeDropdown = new javax.swing.JComboBox();
163        txtID = new javax.swing.JFormattedTextField();
164        jLabel1 = new javax.swing.JLabel();
165        deleteButton = new javax.swing.JButton();
166        jScrollPane1 = new javax.swing.JScrollPane();
167        txtMessage = new javax.swing.JTextArea();
168        addButton = new javax.swing.JButton();
169
170        removeButton.setText("Remove");
171        removeButton.setToolTipText("Removes this property");
172        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
173        {
174            public void mouseClicked(java.awt.event.MouseEvent evt)
175            {
176                removeButtonremoveThisProperty(evt);
177            }
178        });
179
180        jLabel3.setText("Location");
181
182        txtLocation.setToolTipText("Example: SB 55 @ WARNER AVE");
183
184        jLabel2.setText("Type");
185
186        TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "New", "Remove" }));
187
188        txtID.setToolTipText("Example: 72");
189
190        jLabel1.setText("CMS ID");
191
192        deleteButton.setText("Delete Selected Message");
193        deleteButton.setToolTipText("Deletes the selected message from the table");
194
195        jScrollPane1.setHorizontalScrollBar(null);
196
197        txtMessage.setColumns(20);
198        txtMessage.setRows(5);
199        jScrollPane1.setViewportView(txtMessage);
200
201        addButton.setText("Add Message");
202        addButton.setToolTipText("Adds a message to the table");
203
204        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
205        this.setLayout(layout);
206        layout.setHorizontalGroup(
207            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
208            .add(layout.createSequentialGroup()
209                .addContainerGap()
210                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
211                    .add(layout.createSequentialGroup()
212                        .add(6, 6, 6)
213                        .add(addButton)
214                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
215                        .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
216                        .add(293, 293, 293))
217                    .add(layout.createSequentialGroup()
218                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
219                            .add(jScrollPane1)
220                            .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
221                            .add(layout.createSequentialGroup()
222                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
223                                    .add(jLabel1)
224                                    .add(jLabel3)
225                                    .add(jLabel2))
226                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
227                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
228                                    .add(TypeDropdown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
229                                    .add(txtLocation)
230                                    .add(txtID))))
231                        .addContainerGap())))
232        );
233        layout.setVerticalGroup(
234            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
235            .add(layout.createSequentialGroup()
236                .add(17, 17, 17)
237                .add(removeButton)
238                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
239                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
240                    .add(jLabel1)
241                    .add(txtID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
242                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
243                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
244                    .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
245                    .add(jLabel2))
246                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
247                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
248                    .add(jLabel3)
249                    .add(txtLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
250                .add(31, 31, 31)
251                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
252                    .add(deleteButton)
253                    .add(addButton))
254                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
255                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
256                .addContainerGap())
257        );
258    }// </editor-fold>//GEN-END:initComponents
259
260    private void removeButtonremoveThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeButtonremoveThisProperty
261        if (removeListener != null)
262        {
263            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
264        }
265}//GEN-LAST:event_removeButtonremoveThisProperty
266
267
268    // Variables declaration - do not modify//GEN-BEGIN:variables
269    private javax.swing.JComboBox TypeDropdown;
270    private javax.swing.JButton addButton;
271    private javax.swing.JButton deleteButton;
272    private javax.swing.JLabel jLabel1;
273    private javax.swing.JLabel jLabel2;
274    private javax.swing.JLabel jLabel3;
275    private javax.swing.JScrollPane jScrollPane1;
276    private javax.swing.JButton removeButton;
277    private javax.swing.JFormattedTextField txtID;
278    private javax.swing.JTextField txtLocation;
279    private javax.swing.JTextArea txtMessage;
280    // End of variables declaration//GEN-END:variables
281
282}
Note: See TracBrowser for help on using the repository browser.