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

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

Revision 89, 9.1 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 java.util.StringTokenizer;
6import scriptbuilder.structures.events.I_ScriptEvent;
7import scriptbuilder.structures.events.WitnessEvent;
8
9/**
10 *
11 * @author nathaniellehrer
12 */
13public class WitnessPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
14{
15
16    private ActionListener removeListener;
17    private WitnessEvent event;
18
19    /**
20     * Creates new form WitnessPanel
21     */
22    public WitnessPanel()
23    {
24        initComponents();
25    }
26
27    public void setRemoveListener(ActionListener listener)
28    {
29        removeListener = listener;
30    }
31
32    public void getEventObject(I_ScriptEvent sei)
33    {
34        event = (WitnessEvent) sei;
35        StringTokenizer st = new StringTokenizer(event.witnessName);
36        if (st.hasMoreTokens())
37        {
38            txtFirstName.setText(st.nextToken());
39        }
40        txtFirstName.addKeyListener(new KeyListener()
41        {
42            public void keyTyped(KeyEvent e)
43            {
44            }
45
46            public void keyPressed(KeyEvent e)
47            {
48                if (e.getKeyCode() == KeyEvent.VK_ENTER)
49                {
50                    event.witnessName = txtFirstName.getText() + " " + txtLastName.getText();
51                }
52            }
53
54            public void keyReleased(KeyEvent e)
55            {
56            }
57        });
58        txtLastName.setText("");
59        while (st.hasMoreTokens())
60        {
61            txtLastName.setText(txtLastName.getText() + st.nextToken());
62        }
63        txtLastName.addKeyListener(new KeyListener()
64        {
65            public void keyTyped(KeyEvent e)
66            {
67            }
68
69            public void keyPressed(KeyEvent e)
70            {
71                if (e.getKeyCode() == KeyEvent.VK_ENTER)
72                {
73                    event.witnessName = txtFirstName.getText() + " " + txtLastName.getText();
74                }
75            }
76
77            public void keyReleased(KeyEvent e)
78            {
79            }
80        });
81        txtPhoneNumber.setText("" + event.witnessNum);
82        txtPhoneNumber.addKeyListener(new KeyListener()
83        {
84            public void keyTyped(KeyEvent e)
85            {
86            }
87
88            public void keyPressed(KeyEvent e)
89            {
90                if (e.getKeyCode() == KeyEvent.VK_ENTER)
91                {
92                    event.witnessNum = txtPhoneNumber.getText();
93                }
94            }
95
96            public void keyReleased(KeyEvent e)
97            {
98            }
99        });
100        txtAddress.setText(event.witnessAddress);
101        txtAddress.addKeyListener(new KeyListener()
102        {
103            public void keyTyped(KeyEvent e)
104            {
105            }
106
107            public void keyPressed(KeyEvent e)
108            {
109                if (e.getKeyCode() == KeyEvent.VK_ENTER)
110                {
111                    event.witnessAddress = txtAddress.getText();
112                }
113            }
114
115            public void keyReleased(KeyEvent e)
116            {
117            }
118        });
119    }
120
121    public void update(Observable o, Object arg)
122    {
123        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
124    }
125   
126    @Override
127    public boolean removeAssociatedEvent()
128    {
129        event.removeThis();
130        event = null;
131        return true;
132    }
133
134    /**
135     * This method is called from within the constructor to initialize the form.
136     * WARNING: Do NOT modify this code. The content of this method is always
137     * regenerated by the Form Editor.
138     */
139    @SuppressWarnings("unchecked")
140    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
141    private void initComponents()
142    {
143
144        removeButton = new javax.swing.JButton();
145        jLabel1 = new javax.swing.JLabel();
146        txtFirstName = new javax.swing.JTextField();
147        jLabel2 = new javax.swing.JLabel();
148        txtLastName = new javax.swing.JTextField();
149        jLabel3 = new javax.swing.JLabel();
150        txtAddress = new javax.swing.JTextField();
151        jLabel4 = new javax.swing.JLabel();
152        txtPhoneNumber = new javax.swing.JFormattedTextField();
153
154        removeButton.setText("Remove");
155        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
156        {
157            public void mouseClicked(java.awt.event.MouseEvent evt)
158            {
159                removeThisProperty(evt);
160            }
161        });
162
163        jLabel1.setText("First Name");
164
165        jLabel2.setText("Last Name");
166
167        jLabel3.setText("Street Address");
168
169        jLabel4.setText("Phone Number");
170
171        txtPhoneNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("(###)###-####"))));
172
173        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
174        this.setLayout(layout);
175        layout.setHorizontalGroup(
176            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
177            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
178                .addContainerGap()
179                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
180                    .add(removeButton)
181                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
182                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
183                            .add(jLabel3)
184                            .add(jLabel1)
185                            .add(jLabel2))
186                        .add(15, 15, 15)
187                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
188                            .add(org.jdesktop.layout.GroupLayout.TRAILING, txtLastName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
189                            .add(txtAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
190                            .add(org.jdesktop.layout.GroupLayout.TRAILING, txtFirstName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)))
191                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
192                        .add(jLabel4)
193                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
194                        .add(txtPhoneNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)))
195                .addContainerGap())
196        );
197        layout.setVerticalGroup(
198            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
199            .add(layout.createSequentialGroup()
200                .addContainerGap()
201                .add(removeButton)
202                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
203                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
204                    .add(txtFirstName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
205                    .add(jLabel1))
206                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
207                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
208                    .add(txtLastName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
209                    .add(jLabel2))
210                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
211                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
212                    .add(txtAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
213                    .add(jLabel3))
214                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
215                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
216                    .add(jLabel4)
217                    .add(txtPhoneNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
218                .addContainerGap(168, Short.MAX_VALUE))
219        );
220    }// </editor-fold>//GEN-END:initComponents
221
222    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
223        if (removeListener != null)
224        {
225            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
226        }
227    }//GEN-LAST:event_removeThisProperty
228
229
230    // Variables declaration - do not modify//GEN-BEGIN:variables
231    private javax.swing.JLabel jLabel1;
232    private javax.swing.JLabel jLabel2;
233    private javax.swing.JLabel jLabel3;
234    private javax.swing.JLabel jLabel4;
235    private javax.swing.JButton removeButton;
236    private javax.swing.JTextField txtAddress;
237    private javax.swing.JTextField txtFirstName;
238    private javax.swing.JTextField txtLastName;
239    private javax.swing.JFormattedTextField txtPhoneNumber;
240    // End of variables declaration//GEN-END:variables
241
242}
Note: See TracBrowser for help on using the repository browser.