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

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

Line 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.Observable;
5import scriptbuilder.structures.events.I_ScriptEvent;
6import scriptbuilder.structures.events.TowEvent;
7
8/**
9 *
10 * @author nathaniellehrer
11 */
12public class TowPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
13{
14
15    private ActionListener removeListener;
16    private TowEvent event;
17
18    /**
19     * Creates new form TowPanel
20     */
21    public TowPanel()
22    {
23        initComponents();
24
25        txtConfirmationNumber.addFocusListener(new FocusListener()
26        {
27
28            public void focusGained(FocusEvent e)
29            {
30                help.setText("Confirmation number is formated as a telephone number. Example: (555)555-5555");
31            }
32
33            public void focusLost(FocusEvent e)
34            {
35                help.setText("");
36            }
37
38        });
39
40        txtPublicNumber.addFocusListener(new FocusListener()
41        {
42
43            public void focusGained(FocusEvent e)
44            {
45                help.setText("Public number is formated as a telephone number. Example: (555)555-5555");
46            }
47
48            public void focusLost(FocusEvent e)
49            {
50                help.setText("");
51            }
52
53        });
54
55    }
56
57    public void setRemoveListener(ActionListener listener)
58    {
59        removeListener = listener;
60    }
61
62    public void getEventObject(I_ScriptEvent sei)
63    {
64        event = (TowEvent) sei;
65        txtCompany.setText(event.towCompany);
66        txtCompany.addKeyListener(new KeyListener()
67        {
68            public void keyTyped(KeyEvent e)
69            {
70            }
71            public void keyPressed(KeyEvent e)
72            {
73                if (e.getKeyCode() == KeyEvent.VK_ENTER)
74                {
75                    event.towCompany = txtCompany.getText();
76                }
77            }
78            public void keyReleased(KeyEvent e)
79            {
80            }
81        });
82        txtBeat.setText(event.towBeat);
83        txtBeat.addKeyListener(new KeyListener()
84        {
85            public void keyTyped(KeyEvent e)
86            {
87            }
88            public void keyPressed(KeyEvent e)
89            {
90                if (e.getKeyCode() == KeyEvent.VK_ENTER)
91                {
92                    event.towBeat = txtBeat.getText();
93                }
94            }
95            public void keyReleased(KeyEvent e)
96            {
97            }
98        });
99        txtConfirmationNumber.setText("" + event.towConfNum);
100        txtConfirmationNumber.addKeyListener(new KeyListener()
101        {
102            public void keyTyped(KeyEvent e)
103            {
104            }
105            public void keyPressed(KeyEvent e)
106            {
107                if (e.getKeyCode() == KeyEvent.VK_ENTER)
108                {
109                    event.towConfNum = txtConfirmationNumber.getText();
110                }
111            }
112            public void keyReleased(KeyEvent e)
113            {
114            }
115        });
116        txtPublicNumber.setText("" + event.towPubNum);
117        txtPublicNumber.addKeyListener(new KeyListener()
118        {
119            public void keyTyped(KeyEvent e)
120            {
121            }
122            public void keyPressed(KeyEvent e)
123            {
124                if (e.getKeyCode() == KeyEvent.VK_ENTER)
125                {
126                    event.towPubNum = txtPublicNumber.getText();
127                }
128            }
129            public void keyReleased(KeyEvent e)
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    @Override
141    public boolean removeAssociatedEvent()
142    {
143        event.removeThis();
144        event = null;
145        return true;
146    }
147
148    /**
149     * This method is called from within the constructor to initialize the form.
150     * WARNING: Do NOT modify this code. The content of this method is always
151     * regenerated by the Form Editor.
152     */
153    @SuppressWarnings("unchecked")
154    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
155    private void initComponents()
156    {
157
158        removeButton = new javax.swing.JButton();
159        jLabel1 = new javax.swing.JLabel();
160        txtCompany = new javax.swing.JTextField();
161        jLabel2 = new javax.swing.JLabel();
162        txtConfirmationNumber = new javax.swing.JFormattedTextField();
163        jLabel3 = new javax.swing.JLabel();
164        txtPublicNumber = new javax.swing.JFormattedTextField();
165        jLabel4 = new javax.swing.JLabel();
166        txtBeat = new javax.swing.JTextField();
167        help = new javax.swing.JLabel();
168
169        removeButton.setText("Remove");
170        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
171        {
172            public void mouseClicked(java.awt.event.MouseEvent evt)
173            {
174                removeThisProperty(evt);
175            }
176        });
177        removeButton.addActionListener(new java.awt.event.ActionListener()
178        {
179            public void actionPerformed(java.awt.event.ActionEvent evt)
180            {
181                removeButtonActionPerformed(evt);
182            }
183        });
184
185        jLabel1.setText("Company");
186
187        jLabel2.setText("Confirmation Number");
188
189        try
190        {
191            txtConfirmationNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)###-####")));
192        } catch (java.text.ParseException ex)
193        {
194            ex.printStackTrace();
195        }
196
197        jLabel3.setText("Public Number");
198
199        try
200        {
201            txtPublicNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)###-####")));
202        } catch (java.text.ParseException ex)
203        {
204            ex.printStackTrace();
205        }
206
207        jLabel4.setText("Beat");
208
209        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
210        this.setLayout(layout);
211        layout.setHorizontalGroup(
212            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
213            .add(layout.createSequentialGroup()
214                .addContainerGap()
215                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
216                    .add(help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
217                    .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
218                    .add(layout.createSequentialGroup()
219                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
220                            .add(jLabel1)
221                            .add(jLabel2)
222                            .add(jLabel3)
223                            .add(jLabel4))
224                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
225                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
226                            .add(txtBeat, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
227                            .add(txtCompany, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
228                            .add(txtConfirmationNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
229                            .add(txtPublicNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE))))
230                .addContainerGap())
231        );
232        layout.setVerticalGroup(
233            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
234            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
235                .addContainerGap()
236                .add(removeButton)
237                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
238                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
239                    .add(jLabel1)
240                    .add(txtCompany, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
241                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
242                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
243                    .add(jLabel2)
244                    .add(txtConfirmationNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
245                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
246                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
247                    .add(jLabel3)
248                    .add(txtPublicNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
249                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
250                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
251                    .add(jLabel4)
252                    .add(txtBeat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
253                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 72, Short.MAX_VALUE)
254                .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
255                .addContainerGap())
256        );
257    }// </editor-fold>//GEN-END:initComponents
258
259    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
260        // TODO add your handling code here:
261    }//GEN-LAST:event_removeButtonActionPerformed
262
263    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
264        if (removeListener != null)
265        {
266            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
267        }
268    }//GEN-LAST:event_removeThisProperty
269
270
271    // Variables declaration - do not modify//GEN-BEGIN:variables
272    private javax.swing.JLabel help;
273    private javax.swing.JLabel jLabel1;
274    private javax.swing.JLabel jLabel2;
275    private javax.swing.JLabel jLabel3;
276    private javax.swing.JLabel jLabel4;
277    private javax.swing.JButton removeButton;
278    private javax.swing.JTextField txtBeat;
279    private javax.swing.JTextField txtCompany;
280    private javax.swing.JFormattedTextField txtConfirmationNumber;
281    private javax.swing.JFormattedTextField txtPublicNumber;
282    // End of variables declaration//GEN-END:variables
283
284}
Note: See TracBrowser for help on using the repository browser.