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

Revision 76, 8.6 KB checked in by bmcguffin, 9 years ago (diff)

Added javadoc for several files.

Line 
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    /**
105     * This method is called from within the constructor to initialize the form.
106     * WARNING: Do NOT modify this code. The content of this method is always
107     * regenerated by the Form Editor.
108     */
109    @SuppressWarnings("unchecked")
110    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
111    private void initComponents() {
112
113        jLabel4 = new javax.swing.JLabel();
114        audioText = new javax.swing.JTextField();
115        jButton2 = new javax.swing.JButton();
116        addDispatchButton = new javax.swing.JButton();
117        deleteSelectedButton = new javax.swing.JButton();
118        jScrollPane1 = new javax.swing.JScrollPane();
119        addFieldButton = new javax.swing.JButton();
120
121        jLabel4.setText("Radio File");
122
123        audioText.setToolTipText("The radio audio file");
124
125        jButton2.setText("Browse");
126        jButton2.setToolTipText("Browse for the radio audio file");
127        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
128            public void mouseClicked(java.awt.event.MouseEvent evt) {
129                browse(evt);
130            }
131        });
132
133        addDispatchButton.setText("Add Dispatch");
134        addDispatchButton.setToolTipText("Adds a row for dialog by the dispatch operator in the table");
135
136        deleteSelectedButton.setText("Delete Selected");
137        deleteSelectedButton.setToolTipText("Deletes the selected row from the table");
138
139        addFieldButton.setText("Add Field");
140        addFieldButton.setToolTipText("Adds a row for dialog by the field operator in the table");
141        addFieldButton.addActionListener(new java.awt.event.ActionListener() {
142            public void actionPerformed(java.awt.event.ActionEvent evt) {
143                addFieldButtonActionPerformed(evt);
144            }
145        });
146
147        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
148        this.setLayout(layout);
149        layout.setHorizontalGroup(
150            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
151            .add(layout.createSequentialGroup()
152                .addContainerGap()
153                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 730, Short.MAX_VALUE)
155                    .add(layout.createSequentialGroup()
156                        .add(addDispatchButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
157                        .add(3, 3, 3)
158                        .add(addFieldButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
159                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
160                        .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
161                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
162                    .add(layout.createSequentialGroup()
163                        .add(jLabel4)
164                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
165                        .add(audioText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
166                        .add(18, 18, 18)
167                        .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
168                .addContainerGap())
169        );
170        layout.setVerticalGroup(
171            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
172            .add(layout.createSequentialGroup()
173                .addContainerGap()
174                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
175                    .add(audioText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
176                    .add(jLabel4)
177                    .add(jButton2))
178                .add(18, 18, 18)
179                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
180                    .add(addDispatchButton)
181                    .add(addFieldButton)
182                    .add(deleteSelectedButton))
183                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
184                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
185                .addContainerGap())
186        );
187    }// </editor-fold>//GEN-END:initComponents
188
189    private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse
190        JFileChooser browser = new JFileChooser();
191        int returnVal = browser.showOpenDialog(this);
192        if (returnVal == JFileChooser.APPROVE_OPTION)
193        {
194            audioText.setText(browser.getSelectedFile().getPath());
195        }
196    }//GEN-LAST:event_browse
197
198    private void addFieldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFieldButtonActionPerformed
199        // TODO add your handling code here:
200    }//GEN-LAST:event_addFieldButtonActionPerformed
201
202    // Variables declaration - do not modify//GEN-BEGIN:variables
203    private javax.swing.JButton addDispatchButton;
204    private javax.swing.JButton addFieldButton;
205    private javax.swing.JTextField audioText;
206    private javax.swing.JButton deleteSelectedButton;
207    private javax.swing.JButton jButton2;
208    private javax.swing.JLabel jLabel4;
209    private javax.swing.JScrollPane jScrollPane1;
210    // End of variables declaration//GEN-END:variables
211
212}
Note: See TracBrowser for help on using the repository browser.