Warning: Can't use blame annotator:
svn blame failed on trunk/src/event/editor/CMSEvaluationPanel.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 140, 8.4 KB checked in by bmcguffin, 8 years ago (diff)

Fixed defect #67. Removing an event and then closing the event editor window no longer causes the program to hang; a null check for the event is encountered before taking action upon close of the window.

RevLine 
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 I_ScriptEventEditorPanel
16{
17
18    private HashMap<String, Class> properties;
19    private JTable dialogTable;
20    private CMSEvaluationEvent event;
21
22    /**
23     * Creates new form CMSEvaluation
24     */
25    public CMSEvaluationPanel()
26    {
27        initComponents();
28
29        dialogTable = GenericTable.genericizeNumberedTable(jScrollPane1, addButton, deleteButton);
30    }
31
32    @Override
33    public void getEventObject(I_ScriptEvent sei)
34    {
35        event = (CMSEvaluationEvent) sei;
36        txtID.setText(event.cmsID);
37
38        txtLocation.setText(event.location);
39
40        txtMessage.setText("");
41        for (int i = 0; i < event.message.size(); i++)
42        {
43            ((MyTableModel) dialogTable.getModel()).addRow("" + (i + 1), event.message.get(i));
44        }
45        for (int i = 0; i < TypeDropdown.getItemCount(); i++)
46        {
47            if (event.cmsType.equalsIgnoreCase(TypeDropdown.getItemAt(i).toString()))
48            {
49                TypeDropdown.setSelectedIndex(i);
50            }
51        }
52
53        addButton.addActionListener(new ActionListener()
54        {
55
56            @Override
57            public void actionPerformed(ActionEvent e)
58            {
59                event.message.add("");
60            }
61        });
62        dialogTable.getModel().addTableModelListener(new TableModelListener()
63        {
64
65            public void tableChanged(TableModelEvent e)
66            {
67                if (e.getType() == TableModelEvent.UPDATE)
68                {
69                    event.message.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
70                }
71                if (e.getType() == TableModelEvent.DELETE)
72                {
73                    event.message.remove(e.getLastRow());
74                }
75            }
76        });
77    }
78
79    @Override
80    public void update(Observable o, Object arg)
81    {
82        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
83    }
84
85    @Override
86    public boolean removeAssociatedEvent()
87    {
88        event.removeThis();
89        event = null;
90        return true;
91    }
92
93    @Override
94    public void uponClose()
95    {
96        if (event != null)
97        {
98            event.cmsID = txtID.getText();
99            event.location = txtLocation.getText();
100            event.cmsType = TypeDropdown.getSelectedItem().toString();
101        }
102    }
103
104    /**
105     * This method is called from within the constructor to initialize the form.
106     * WARNING: Do NOT modify this code. The content of this method is always
107     * regenerated by the Form Editor.
108     */
109    @SuppressWarnings("unchecked")
110    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
111    private void initComponents()
112    {
113
114        jLabel3 = new javax.swing.JLabel();
115        txtLocation = new javax.swing.JTextField();
116        jLabel2 = new javax.swing.JLabel();
117        TypeDropdown = new javax.swing.JComboBox();
118        txtID = new javax.swing.JFormattedTextField();
119        jLabel1 = new javax.swing.JLabel();
120        deleteButton = new javax.swing.JButton();
121        jScrollPane1 = new javax.swing.JScrollPane();
122        txtMessage = new javax.swing.JTextArea();
123        addButton = new javax.swing.JButton();
124
125        jLabel3.setText("Location");
126
127        txtLocation.setToolTipText("Example: SB 55 @ WARNER AVE");
128
129        jLabel2.setText("Type");
130
131        TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "New", "Remove" }));
132
133        txtID.setToolTipText("Example: 72");
134
135        jLabel1.setText("CMS ID");
136
137        deleteButton.setText("Delete Selected Message");
138        deleteButton.setToolTipText("Deletes the selected message from the table");
139
140        jScrollPane1.setHorizontalScrollBar(null);
141
142        txtMessage.setColumns(20);
143        txtMessage.setRows(5);
144        jScrollPane1.setViewportView(txtMessage);
145
146        addButton.setText("Add Message");
147        addButton.setToolTipText("Adds a message to the table");
148
149        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
150        this.setLayout(layout);
151        layout.setHorizontalGroup(
152            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153            .add(layout.createSequentialGroup()
154                .addContainerGap()
155                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
156                    .add(layout.createSequentialGroup()
157                        .add(6, 6, 6)
158                        .add(addButton)
159                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
160                        .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
161                        .add(293, 293, 293))
162                    .add(layout.createSequentialGroup()
163                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164                            .add(jScrollPane1)
165                            .add(layout.createSequentialGroup()
166                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
167                                    .add(jLabel1)
168                                    .add(jLabel3)
169                                    .add(jLabel2))
170                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
171                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
172                                    .add(TypeDropdown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
173                                    .add(txtLocation)
174                                    .add(txtID))))
175                        .addContainerGap())))
176        );
177        layout.setVerticalGroup(
178            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
179            .add(layout.createSequentialGroup()
180                .add(52, 52, 52)
181                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
182                    .add(jLabel1)
183                    .add(txtID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
184                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
185                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
186                    .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
187                    .add(jLabel2))
188                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
189                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
190                    .add(jLabel3)
191                    .add(txtLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
192                .add(31, 31, 31)
193                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
194                    .add(deleteButton)
195                    .add(addButton))
196                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
197                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
198                .addContainerGap())
199        );
200    }// </editor-fold>//GEN-END:initComponents
201
202
203    // Variables declaration - do not modify//GEN-BEGIN:variables
204    private javax.swing.JComboBox TypeDropdown;
205    private javax.swing.JButton addButton;
206    private javax.swing.JButton deleteButton;
207    private javax.swing.JLabel jLabel1;
208    private javax.swing.JLabel jLabel2;
209    private javax.swing.JLabel jLabel3;
210    private javax.swing.JScrollPane jScrollPane1;
211    private javax.swing.JFormattedTextField txtID;
212    private javax.swing.JTextField txtLocation;
213    private javax.swing.JTextArea txtMessage;
214    // End of variables declaration//GEN-END:variables
215
216}
Note: See TracBrowser for help on using the repository browser.