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

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

Revision 89, 8.7 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 javax.swing.*;
5import java.util.*;
6import javax.swing.event.TableModelEvent;
7import javax.swing.event.TableModelListener;
8import scriptbuilder.structures.events.*;
9
10/**
11 *
12 * @author nathaniellehrer
13 */
14public class CHPRadioPanel extends javax.swing.JPanel implements ScriptEventEditorPanel
15{
16
17    private ActionListener removeListener;
18    private CHPRadioEvent event;
19    private JTable dialogTable;
20
21    /**
22     * Creates new form CHPRadioPanel
23     */
24    public CHPRadioPanel()
25    {
26        initComponents();
27        HashMap<JButton, String> buttonMap = new HashMap<JButton, String>();
28        buttonMap.put(addDispatchButton, "Dispatch");
29        buttonMap.put(addFieldButton, "Field");
30        dialogTable = GenericTable.genericizeTable(jScrollPane1, buttonMap, deleteSelectedButton);
31    }
32
33    @Override
34    public void getEventObject(I_ScriptEvent sei)
35    {
36        event = (CHPRadioEvent) sei;
37        audioText.setText(event.radioFile);
38        audioText.addKeyListener(new KeyListener()
39        {
40
41            public void keyTyped(KeyEvent e)
42            {
43            }
44
45            public void keyPressed(KeyEvent e)
46            {
47                if (e.getKeyCode() == KeyEvent.VK_ENTER)
48                {
49                    event.radioFile = audioText.getText();
50                }
51            }
52
53            public void keyReleased(KeyEvent e)
54            {
55            }
56        });
57        for (int i = 0; i < event.lines.size(); i++)
58        {
59            ((MyTableModel) dialogTable.getModel()).addRow(event.roles.get(i), event.lines.get(i));
60        }
61        addDispatchButton.addActionListener(new ActionListener() {
62
63            public void actionPerformed(ActionEvent e)
64            {
65                int i = event.roles.size();
66                event.roles.add("Dispatch");
67                event.lines.add("");
68            }
69        });
70        addFieldButton.addActionListener(new ActionListener() {
71
72            public void actionPerformed(ActionEvent e)
73            {
74                int i = event.roles.size();
75                event.roles.add("Field");
76                event.lines.add("");
77            }
78        });
79        dialogTable.getModel().addTableModelListener(new TableModelListener()
80        {
81
82            public void tableChanged(TableModelEvent e)
83            {
84                if (e.getType() == TableModelEvent.UPDATE)
85                {
86                    event.roles.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 0).toString());
87                    event.lines.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
88                }
89                if(e.getType() == TableModelEvent.DELETE)
90                {
91                    event.roles.remove(e.getLastRow());
92                    event.lines.remove(e.getLastRow());
93                }
94            }
95        });
96       
97    }
98
99    public void update(Observable o, Object arg)
100    {
101        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
102    }
103   
104    @Override
105    public boolean removeAssociatedEvent()
106    {
107        ((I_ScriptEvent)event).removeThis();
108        event = null;
109        return true;
110    }
111
112    /**
113     * This method is called from within the constructor to initialize the form.
114     * WARNING: Do NOT modify this code. The content of this method is always
115     * regenerated by the Form Editor.
116     */
117    @SuppressWarnings("unchecked")
118    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
119    private void initComponents()
120    {
121
122        jLabel4 = new javax.swing.JLabel();
123        audioText = new javax.swing.JTextField();
124        jButton2 = new javax.swing.JButton();
125        addDispatchButton = new javax.swing.JButton();
126        deleteSelectedButton = new javax.swing.JButton();
127        jScrollPane1 = new javax.swing.JScrollPane();
128        addFieldButton = new javax.swing.JButton();
129
130        jLabel4.setText("Radio File");
131
132        audioText.setToolTipText("The radio audio file");
133
134        jButton2.setText("Browse");
135        jButton2.setToolTipText("Browse for the radio audio file");
136        jButton2.addMouseListener(new java.awt.event.MouseAdapter()
137        {
138            public void mouseClicked(java.awt.event.MouseEvent evt)
139            {
140                browse(evt);
141            }
142        });
143
144        addDispatchButton.setText("Add Dispatch");
145        addDispatchButton.setToolTipText("Adds a row for dialog by the dispatch operator in the table");
146
147        deleteSelectedButton.setText("Delete Selected");
148        deleteSelectedButton.setToolTipText("Deletes the selected row from the table");
149
150        addFieldButton.setText("Add Field");
151        addFieldButton.setToolTipText("Adds a row for dialog by the field operator in the table");
152        addFieldButton.addActionListener(new java.awt.event.ActionListener()
153        {
154            public void actionPerformed(java.awt.event.ActionEvent evt)
155            {
156                addFieldButtonActionPerformed(evt);
157            }
158        });
159
160        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
161        this.setLayout(layout);
162        layout.setHorizontalGroup(
163            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164            .add(layout.createSequentialGroup()
165                .addContainerGap()
166                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
167                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 730, Short.MAX_VALUE)
168                    .add(layout.createSequentialGroup()
169                        .add(addDispatchButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
170                        .add(3, 3, 3)
171                        .add(addFieldButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
172                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
173                        .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
174                    .add(layout.createSequentialGroup()
175                        .add(jLabel4)
176                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
177                        .add(audioText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
178                        .add(18, 18, 18)
179                        .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
180                .addContainerGap())
181        );
182        layout.setVerticalGroup(
183            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184            .add(layout.createSequentialGroup()
185                .addContainerGap()
186                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
187                    .add(audioText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
188                    .add(jLabel4)
189                    .add(jButton2))
190                .add(18, 18, 18)
191                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
192                    .add(addDispatchButton)
193                    .add(addFieldButton)
194                    .add(deleteSelectedButton))
195                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
196                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
197                .addContainerGap())
198        );
199    }// </editor-fold>//GEN-END:initComponents
200
201    private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse
202        JFileChooser browser = new JFileChooser();
203        int returnVal = browser.showOpenDialog(this);
204        if (returnVal == JFileChooser.APPROVE_OPTION)
205        {
206            audioText.setText(browser.getSelectedFile().getPath());
207        }
208    }//GEN-LAST:event_browse
209
210    private void addFieldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFieldButtonActionPerformed
211        // TODO add your handling code here:
212    }//GEN-LAST:event_addFieldButtonActionPerformed
213
214    // Variables declaration - do not modify//GEN-BEGIN:variables
215    private javax.swing.JButton addDispatchButton;
216    private javax.swing.JButton addFieldButton;
217    private javax.swing.JTextField audioText;
218    private javax.swing.JButton deleteSelectedButton;
219    private javax.swing.JButton jButton2;
220    private javax.swing.JLabel jLabel4;
221    private javax.swing.JScrollPane jScrollPane1;
222    // End of variables declaration//GEN-END:variables
223
224}
Note: See TracBrowser for help on using the repository browser.