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

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

Revision 140, 8.2 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.Observable;
5import scriptbuilder.structures.events.I_ScriptEvent;
6import scriptbuilder.structures.events.UnitEvent;
7
8/**
9 *
10 * @author nathaniellehrer
11 */
12public class UnitPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
13{
14
15    private ActionListener removeListener;
16    private UnitEvent event;
17
18    /**
19     * Creates new form UnitPanel
20     */
21    public UnitPanel()
22    {
23        initComponents();
24
25        txtUnitNumber.addFocusListener(new FocusListener()
26        {
27
28            public void focusGained(FocusEvent e)
29            {
30                help.setText("Unit number is formatted as #-#\t\tExample: 5-5");
31            }
32
33            public void focusLost(FocusEvent e)
34            {
35                help.setText("");
36            }
37
38        });
39    }
40
41    @Override
42    public void getEventObject(I_ScriptEvent sei)
43    {
44        event = (UnitEvent) sei;
45        txtUnitNumber.setText(event.unitNum);
46        for (int i = 0; i < ActiveDropdown.getItemCount(); i++)
47        {
48            if (event.unitActive.equalsIgnoreCase((String) ActiveDropdown.getItemAt(i)))
49            {
50                ActiveDropdown.setSelectedIndex(i);
51            }
52        }
53
54        for (int i = 0; i < PrimaryDropdown.getItemCount(); i++)
55        {
56            if (event.unitPrimary.equalsIgnoreCase((String) PrimaryDropdown.getItemAt(i)))
57            {
58                PrimaryDropdown.setSelectedIndex(i);
59            }
60        }
61
62        boolean containsItem = false;
63        for (int i = 0; i < StatusDropdown.getItemCount() && !containsItem; i++)
64        {
65            if (event.unitStatus.equalsIgnoreCase((String) StatusDropdown.getItemAt(i)))
66            {
67                StatusDropdown.setSelectedIndex(i);
68                containsItem = true;
69            }
70        }
71        if (!containsItem)
72        {
73            StatusDropdown.addItem(event.unitStatus);
74            StatusDropdown.setSelectedItem(StatusDropdown.getItemCount() - 1);
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.unitNum = txtUnitNumber.getText();
99            event.unitActive = ActiveDropdown.getSelectedItem().toString();
100            event.unitPrimary = PrimaryDropdown.getSelectedItem().toString();
101            event.unitStatus = StatusDropdown.getSelectedItem().toString();
102        }
103    }
104
105    /**
106     * This method is called from within the constructor to initialize the form.
107     * WARNING: Do NOT modify this code. The content of this method is always
108     * regenerated by the Form Editor.
109     */
110    @SuppressWarnings("unchecked")
111    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
112    private void initComponents()
113    {
114
115        jLabel1 = new javax.swing.JLabel();
116        txtUnitNumber = new javax.swing.JFormattedTextField();
117        jLabel2 = new javax.swing.JLabel();
118        StatusDropdown = new javax.swing.JComboBox();
119        jLabel3 = new javax.swing.JLabel();
120        PrimaryDropdown = new javax.swing.JComboBox();
121        jLabel4 = new javax.swing.JLabel();
122        ActiveDropdown = new javax.swing.JComboBox();
123        help = new javax.swing.JLabel();
124
125        jLabel1.setText("Unit Number");
126
127        txtUnitNumber.setText("  -  ");
128        txtUnitNumber.setToolTipText("");
129
130        jLabel2.setText("Status");
131
132        StatusDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1098", "1097", "ENRT" }));
133
134        jLabel3.setText("Primary");
135
136        PrimaryDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));
137
138        jLabel4.setText("Active");
139
140        ActiveDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));
141
142        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
143        this.setLayout(layout);
144        layout.setHorizontalGroup(
145            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
146            .add(layout.createSequentialGroup()
147                .addContainerGap()
148                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
149                    .add(org.jdesktop.layout.GroupLayout.TRAILING, help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
150                    .add(layout.createSequentialGroup()
151                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
152                            .add(jLabel1)
153                            .add(jLabel2))
154                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
155                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
156                            .add(StatusDropdown, 0, 475, Short.MAX_VALUE)
157                            .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)))
158                    .add(layout.createSequentialGroup()
159                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
160                            .add(jLabel3)
161                            .add(jLabel4))
162                        .add(43, 43, 43)
163                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164                            .add(ActiveDropdown, 0, 475, Short.MAX_VALUE)
165                            .add(PrimaryDropdown, 0, 475, Short.MAX_VALUE))))
166                .addContainerGap())
167        );
168        layout.setVerticalGroup(
169            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
170            .add(layout.createSequentialGroup()
171                .add(47, 47, 47)
172                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
173                    .add(jLabel1)
174                    .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
175                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
176                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
177                    .add(jLabel2)
178                    .add(StatusDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
179                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
180                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
181                    .add(jLabel3)
182                    .add(PrimaryDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
183                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
184                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
185                    .add(jLabel4)
186                    .add(ActiveDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
187                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 128, Short.MAX_VALUE)
188                .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
189                .addContainerGap())
190        );
191    }// </editor-fold>//GEN-END:initComponents
192
193
194    // Variables declaration - do not modify//GEN-BEGIN:variables
195    private javax.swing.JComboBox ActiveDropdown;
196    private javax.swing.JComboBox PrimaryDropdown;
197    private javax.swing.JComboBox StatusDropdown;
198    private javax.swing.JLabel help;
199    private javax.swing.JLabel jLabel1;
200    private javax.swing.JLabel jLabel2;
201    private javax.swing.JLabel jLabel3;
202    private javax.swing.JLabel jLabel4;
203    private javax.swing.JFormattedTextField txtUnitNumber;
204    // End of variables declaration//GEN-END:variables
205
206}
Note: See TracBrowser for help on using the repository browser.