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 @ 89

Revision 89, 9.9 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.

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 RemoveablePanel, 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    public void setRemoveListener(ActionListener listener)
42    {
43        removeListener = listener;
44    }
45
46    public void getEventObject(I_ScriptEvent sei)
47    {
48        event = (UnitEvent) sei;
49        txtUnitNumber.setText(event.unitNum);
50        for (int i = 0; i < ActiveDropdown.getItemCount(); i++)
51        {
52            if (event.unitActive.equalsIgnoreCase((String) ActiveDropdown.getItemAt(i)))
53            {
54                ActiveDropdown.setSelectedIndex(i);
55            }
56        }
57        txtUnitNumber.addKeyListener(new KeyListener()
58        {
59            public void keyTyped(KeyEvent e)
60            {
61            }
62            public void keyPressed(KeyEvent e)
63            {
64                if (e.getKeyCode() == KeyEvent.VK_ENTER)
65                {
66                    event.unitNum = txtUnitNumber.getText();
67                }
68            }
69            public void keyReleased(KeyEvent e)
70            {
71            }
72        });
73        ActiveDropdown.addActionListener(new ActionListener()
74        {
75
76            public void actionPerformed(ActionEvent e)
77            {
78                event.unitActive = ActiveDropdown.getSelectedItem().toString();
79            }
80        });
81        for (int i = 0; i < PrimaryDropdown.getItemCount(); i++)
82        {
83            if (event.unitPrimary.equalsIgnoreCase((String) PrimaryDropdown.getItemAt(i)))
84            {
85                PrimaryDropdown.setSelectedIndex(i);
86            }
87        }
88        PrimaryDropdown.addActionListener(new ActionListener()
89        {
90
91            public void actionPerformed(ActionEvent e)
92            {
93                event.unitPrimary = PrimaryDropdown.getSelectedItem().toString();
94            }
95        });
96        boolean containsItem = false;
97        for (int i = 0; i < StatusDropdown.getItemCount() && !containsItem; i++)
98        {
99            if (event.unitStatus.equalsIgnoreCase((String) StatusDropdown.getItemAt(i)))
100            {
101                StatusDropdown.setSelectedIndex(i);
102                containsItem = true;
103            }
104        }
105        if (!containsItem)
106        {
107            StatusDropdown.addItem(event.unitStatus);
108            StatusDropdown.setSelectedItem(StatusDropdown.getItemCount() - 1);
109        }
110        StatusDropdown.addActionListener(new ActionListener()
111        {
112
113            public void actionPerformed(ActionEvent e)
114            {
115                event.unitStatus = StatusDropdown.getSelectedItem().toString();
116            }
117        });
118    }
119
120    public void update(Observable o, Object arg)
121    {
122        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
123    }
124   
125    @Override
126    public boolean removeAssociatedEvent()
127    {
128        event.removeThis();
129        event = null;
130        return true;
131    }
132
133    /**
134     * This method is called from within the constructor to initialize the form.
135     * WARNING: Do NOT modify this code. The content of this method is always
136     * regenerated by the Form Editor.
137     */
138    @SuppressWarnings("unchecked")
139    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
140    private void initComponents()
141    {
142
143        jLabel1 = new javax.swing.JLabel();
144        txtUnitNumber = new javax.swing.JFormattedTextField();
145        removeButton = new javax.swing.JButton();
146        jLabel2 = new javax.swing.JLabel();
147        StatusDropdown = new javax.swing.JComboBox();
148        jLabel3 = new javax.swing.JLabel();
149        PrimaryDropdown = new javax.swing.JComboBox();
150        jLabel4 = new javax.swing.JLabel();
151        ActiveDropdown = new javax.swing.JComboBox();
152        help = new javax.swing.JLabel();
153
154        jLabel1.setText("Unit Number");
155
156        txtUnitNumber.setText("  -  ");
157        txtUnitNumber.setToolTipText("");
158
159        removeButton.setText("Remove");
160        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
161        {
162            public void mouseClicked(java.awt.event.MouseEvent evt)
163            {
164                removeThisProperty(evt);
165            }
166        });
167
168        jLabel2.setText("Status");
169
170        StatusDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1098", "1097", "ENRT" }));
171
172        jLabel3.setText("Primary");
173
174        PrimaryDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));
175
176        jLabel4.setText("Active");
177
178        ActiveDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));
179
180        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
181        this.setLayout(layout);
182        layout.setHorizontalGroup(
183            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184            .add(layout.createSequentialGroup()
185                .addContainerGap()
186                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
187                    .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
188                    .add(org.jdesktop.layout.GroupLayout.TRAILING, help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
189                    .add(layout.createSequentialGroup()
190                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
191                            .add(jLabel1)
192                            .add(jLabel2))
193                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
194                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
195                            .add(StatusDropdown, 0, 475, Short.MAX_VALUE)
196                            .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)))
197                    .add(layout.createSequentialGroup()
198                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
199                            .add(jLabel3)
200                            .add(jLabel4))
201                        .add(43, 43, 43)
202                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
203                            .add(ActiveDropdown, 0, 475, Short.MAX_VALUE)
204                            .add(PrimaryDropdown, 0, 475, Short.MAX_VALUE))))
205                .addContainerGap())
206        );
207        layout.setVerticalGroup(
208            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
209            .add(layout.createSequentialGroup()
210                .addContainerGap()
211                .add(removeButton)
212                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
213                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
214                    .add(jLabel1)
215                    .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
216                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
217                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
218                    .add(jLabel2)
219                    .add(StatusDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
220                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
221                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
222                    .add(jLabel3)
223                    .add(PrimaryDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
224                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
225                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
226                    .add(jLabel4)
227                    .add(ActiveDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
228                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 128, Short.MAX_VALUE)
229                .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
230                .addContainerGap())
231        );
232    }// </editor-fold>//GEN-END:initComponents
233
234    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
235        if (removeListener != null)
236        {
237            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
238        }
239    }//GEN-LAST:event_removeThisProperty
240
241
242    // Variables declaration - do not modify//GEN-BEGIN:variables
243    private javax.swing.JComboBox ActiveDropdown;
244    private javax.swing.JComboBox PrimaryDropdown;
245    private javax.swing.JComboBox StatusDropdown;
246    private javax.swing.JLabel help;
247    private javax.swing.JLabel jLabel1;
248    private javax.swing.JLabel jLabel2;
249    private javax.swing.JLabel jLabel3;
250    private javax.swing.JLabel jLabel4;
251    private javax.swing.JButton removeButton;
252    private javax.swing.JFormattedTextField txtUnitNumber;
253    // End of variables declaration//GEN-END:variables
254
255}
Note: See TracBrowser for help on using the repository browser.