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

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

2017/07/18: Uploaded entire prototype to SVN repo.

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