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

Revision 76, 10.3 KB checked in by bmcguffin, 9 years ago (diff)

Added javadoc for several 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    /**
141     * This method is called from within the constructor to initialize the form.
142     * WARNING: Do NOT modify this code. The content of this method is always
143     * regenerated by the Form Editor.
144     */
145    @SuppressWarnings("unchecked")
146    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
147    private void initComponents()
148    {
149
150        removeButton = new javax.swing.JButton();
151        jLabel3 = new javax.swing.JLabel();
152        txtLocation = new javax.swing.JTextField();
153        jLabel2 = new javax.swing.JLabel();
154        TypeDropdown = new javax.swing.JComboBox();
155        txtID = new javax.swing.JFormattedTextField();
156        jLabel1 = new javax.swing.JLabel();
157        deleteButton = new javax.swing.JButton();
158        jScrollPane1 = new javax.swing.JScrollPane();
159        txtMessage = new javax.swing.JTextArea();
160        addButton = new javax.swing.JButton();
161
162        removeButton.setText("Remove");
163        removeButton.setToolTipText("Removes this property");
164        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
165        {
166            public void mouseClicked(java.awt.event.MouseEvent evt)
167            {
168                removeButtonremoveThisProperty(evt);
169            }
170        });
171
172        jLabel3.setText("Location");
173
174        txtLocation.setToolTipText("Example: SB 55 @ WARNER AVE");
175
176        jLabel2.setText("Type");
177
178        TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "New", "Remove" }));
179
180        txtID.setToolTipText("Example: 72");
181
182        jLabel1.setText("CMS ID");
183
184        deleteButton.setText("Delete Selected Message");
185        deleteButton.setToolTipText("Deletes the selected message from the table");
186
187        jScrollPane1.setHorizontalScrollBar(null);
188
189        txtMessage.setColumns(20);
190        txtMessage.setRows(5);
191        jScrollPane1.setViewportView(txtMessage);
192
193        addButton.setText("Add Message");
194        addButton.setToolTipText("Adds a message to the table");
195
196        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
197        this.setLayout(layout);
198        layout.setHorizontalGroup(
199            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
200            .add(layout.createSequentialGroup()
201                .addContainerGap()
202                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
203                    .add(layout.createSequentialGroup()
204                        .add(6, 6, 6)
205                        .add(addButton)
206                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
207                        .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
208                        .add(293, 293, 293))
209                    .add(layout.createSequentialGroup()
210                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
211                            .add(jScrollPane1)
212                            .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
213                            .add(layout.createSequentialGroup()
214                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
215                                    .add(jLabel1)
216                                    .add(jLabel3)
217                                    .add(jLabel2))
218                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
219                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
220                                    .add(TypeDropdown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
221                                    .add(txtLocation)
222                                    .add(txtID))))
223                        .addContainerGap())))
224        );
225        layout.setVerticalGroup(
226            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
227            .add(layout.createSequentialGroup()
228                .add(17, 17, 17)
229                .add(removeButton)
230                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
231                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
232                    .add(jLabel1)
233                    .add(txtID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
234                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
235                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
236                    .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
237                    .add(jLabel2))
238                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
239                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
240                    .add(jLabel3)
241                    .add(txtLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
242                .add(31, 31, 31)
243                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
244                    .add(deleteButton)
245                    .add(addButton))
246                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
247                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
248                .addContainerGap())
249        );
250    }// </editor-fold>//GEN-END:initComponents
251
252    private void removeButtonremoveThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeButtonremoveThisProperty
253        if (removeListener != null)
254        {
255            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
256        }
257}//GEN-LAST:event_removeButtonremoveThisProperty
258
259
260    // Variables declaration - do not modify//GEN-BEGIN:variables
261    private javax.swing.JComboBox TypeDropdown;
262    private javax.swing.JButton addButton;
263    private javax.swing.JButton deleteButton;
264    private javax.swing.JLabel jLabel1;
265    private javax.swing.JLabel jLabel2;
266    private javax.swing.JLabel jLabel3;
267    private javax.swing.JScrollPane jScrollPane1;
268    private javax.swing.JButton removeButton;
269    private javax.swing.JFormattedTextField txtID;
270    private javax.swing.JTextField txtLocation;
271    private javax.swing.JTextArea txtMessage;
272    // End of variables declaration//GEN-END:variables
273
274}
Note: See TracBrowser for help on using the repository browser.