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

Revision 89, 7.6 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.CCTVEvent;
6import scriptbuilder.structures.events.I_ScriptEvent;
7
8/**
9 *
10 * @author nathaniellehrer
11 */
12public class CCTVPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
13{
14
15    private ActionListener removeListener;
16    private CCTVEvent event;
17
18    /**
19     * Creates new form CCTVInfoPanel
20     */
21    public CCTVPanel()
22    {
23        initComponents();
24
25        txtDirField.addFocusListener(new FocusListener()
26        {
27
28            public void focusGained(FocusEvent e)
29            {
30                help.setText("Dir is an integer or decimal");
31            }
32
33            public void focusLost(FocusEvent e)
34            {
35                help.setText("");
36            }
37
38        });
39
40        txtToggleField.addFocusListener(new FocusListener()
41        {
42
43            public void focusGained(FocusEvent e)
44            {
45                help.setText("toggle is an integer or decimal");
46            }
47
48            public void focusLost(FocusEvent e)
49            {
50                help.setText("");
51            }
52
53        });
54    }
55
56    @Override
57    public void setRemoveListener(ActionListener listener)
58    {
59        removeListener = listener;
60    }
61
62    @Override
63    public void getEventObject(I_ScriptEvent sei)
64    {
65        event = (CCTVEvent) sei;
66        txtIDField.setText("NOT CURRENTLY IMPLEMENTED. NO EFFECT.");
67        txtDirField.setText("NOT CURRENTLY IMPLEMENTED. NO EFFECT.");
68        txtToggleField.setText("NOT CURRENTLY IMPLEMENTED. NO EFFECT.");
69        //TODO: Add listeners for text fields
70    }
71
72    @Override
73    public void update(Observable o, Object arg)
74    {
75        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
76    }
77   
78    @Override
79    public boolean removeAssociatedEvent()
80    {
81        event.removeThis();
82        event = null;
83        return true;
84    }
85
86    /**
87     * This method is called from within the constructor to initialize the form.
88     * WARNING: Do NOT modify this code. The content of this method is always
89     * regenerated by the Form Editor.
90     */
91    @SuppressWarnings("unchecked")
92    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
93    private void initComponents()
94    {
95
96        removeButton = new javax.swing.JButton();
97        jLabel1 = new javax.swing.JLabel();
98        txtDirField = new javax.swing.JFormattedTextField();
99        jLabel3 = new javax.swing.JLabel();
100        txtIDField = new javax.swing.JTextField();
101        jLabel2 = new javax.swing.JLabel();
102        txtToggleField = new javax.swing.JFormattedTextField();
103        help = new javax.swing.JLabel();
104
105        removeButton.setText("Remove");
106        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
107        {
108            public void mouseClicked(java.awt.event.MouseEvent evt)
109            {
110                removeButtonremoveThisProperty(evt);
111            }
112        });
113        removeButton.addActionListener(new java.awt.event.ActionListener()
114        {
115            public void actionPerformed(java.awt.event.ActionEvent evt)
116            {
117                removeButtonActionPerformed(evt);
118            }
119        });
120
121        jLabel1.setText("ID");
122
123        txtDirField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
124
125        jLabel3.setText("Toggle");
126
127        jLabel2.setText("Dir");
128
129        txtToggleField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
130
131        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
132        this.setLayout(layout);
133        layout.setHorizontalGroup(
134            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
135            .add(layout.createSequentialGroup()
136                .addContainerGap()
137                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
138                    .add(org.jdesktop.layout.GroupLayout.TRAILING, help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
139                    .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
140                    .add(layout.createSequentialGroup()
141                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
142                            .add(jLabel1)
143                            .add(jLabel2)
144                            .add(jLabel3))
145                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
146                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
147                            .add(txtIDField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
148                            .add(txtDirField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
149                            .add(txtToggleField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE))))
150                .addContainerGap())
151        );
152        layout.setVerticalGroup(
153            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154            .add(layout.createSequentialGroup()
155                .addContainerGap()
156                .add(removeButton)
157                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
158                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
159                    .add(jLabel1)
160                    .add(txtIDField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
161                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
162                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
163                    .add(jLabel2)
164                    .add(txtDirField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
165                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
166                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
167                    .add(jLabel3)
168                    .add(txtToggleField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
169                .add(48, 48, 48)
170                .add(help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 13, Short.MAX_VALUE)
171                .addContainerGap())
172        );
173    }// </editor-fold>//GEN-END:initComponents
174
175    private void removeButtonremoveThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeButtonremoveThisProperty
176        if (removeListener != null)
177        {
178            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
179        }
180}//GEN-LAST:event_removeButtonremoveThisProperty
181
182    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
183        // TODO add your handling code here:
184}//GEN-LAST:event_removeButtonActionPerformed
185
186
187    // Variables declaration - do not modify//GEN-BEGIN:variables
188    private javax.swing.JLabel help;
189    private javax.swing.JLabel jLabel1;
190    private javax.swing.JLabel jLabel2;
191    private javax.swing.JLabel jLabel3;
192    private javax.swing.JButton removeButton;
193    private javax.swing.JFormattedTextField txtDirField;
194    private javax.swing.JTextField txtIDField;
195    private javax.swing.JFormattedTextField txtToggleField;
196    // End of variables declaration//GEN-END:variables
197
198}
Note: See TracBrowser for help on using the repository browser.