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

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

Added javadoc for several files.

Line 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.Observable;
5import javax.swing.*;
6import scriptbuilder.structures.events.AudioEvent;
7import scriptbuilder.structures.events.I_ScriptEvent;
8
9/**
10 *
11 * @author nathaniellehrer
12 */
13public class AudioPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
14{
15
16    private ActionListener removeListener;
17    private AudioEvent event;
18
19    /**
20     * Creates new form AudioPanel
21     */
22    public AudioPanel()
23    {
24        initComponents();
25
26    }
27
28    /**
29     * Load the script event associated with this editor panel.
30     *
31     * @param sei The script event in question
32     */
33    @Override
34    public void getEventObject(I_ScriptEvent sei)
35    {
36        event = (AudioEvent) sei;
37        audioFileText.setText(event.audioPath);
38        audioLengthText.setText(event.audioLength.toString());
39        audioFileText.addKeyListener(new KeyListener()
40        {
41
42            public void keyTyped(KeyEvent e)
43            {
44            }
45
46            public void keyPressed(KeyEvent e)
47            {
48                if (e.getKeyCode() == KeyEvent.VK_ENTER)
49                {
50                    event.audioPath = audioFileText.getText();
51                }
52            }
53
54            public void keyReleased(KeyEvent e)
55            {
56            }
57        });
58        audioLengthText.addKeyListener(new KeyListener()
59        {
60
61            public void keyTyped(KeyEvent e)
62            {
63            }
64
65            public void keyPressed(KeyEvent e)
66            {
67                if (e.getKeyCode() == KeyEvent.VK_ENTER)
68                {
69                    try
70                    {
71                        event.audioLength = Integer.parseInt(audioLengthText.getText());
72                    }
73                    catch (Exception ex)
74                    {
75
76                    }
77                }
78            }
79
80            public void keyReleased(KeyEvent e)
81            {
82            }
83        }
84        );
85    }
86
87    public void setRemoveListener(ActionListener listener)
88    {
89        removeListener = listener;
90    }
91
92    public void update(Observable o, Object arg)
93    {
94        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
95    }
96
97    /**
98     * This method is called from within the constructor to initialize the form.
99     * WARNING: Do NOT modify this code. The content of this method is always
100     * regenerated by the Form Editor.
101     */
102    @SuppressWarnings("unchecked")
103    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
104    private void initComponents()
105    {
106
107        removeButton = new javax.swing.JButton();
108        jLabel1 = new javax.swing.JLabel();
109        audioFileText = new javax.swing.JTextField();
110        jLabel2 = new javax.swing.JLabel();
111        audioLengthText = new javax.swing.JFormattedTextField();
112        browseButton = new javax.swing.JButton();
113
114        removeButton.setText("Remove");
115        removeButton.setToolTipText("Removes this property");
116        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
117        {
118            public void mouseClicked(java.awt.event.MouseEvent evt)
119            {
120                removeThisProperty(evt);
121            }
122        });
123        removeButton.addActionListener(new java.awt.event.ActionListener()
124        {
125            public void actionPerformed(java.awt.event.ActionEvent evt)
126            {
127                removeButtonActionPerformed(evt);
128            }
129        });
130
131        jLabel1.setText("Audio File");
132
133        audioFileText.setToolTipText("The path to the audio file");
134
135        jLabel2.setText("Length");
136
137        audioLengthText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
138
139        browseButton.setText("Browse");
140        browseButton.setToolTipText("Browse for the audio file");
141        browseButton.addMouseListener(new java.awt.event.MouseAdapter()
142        {
143            public void mouseClicked(java.awt.event.MouseEvent evt)
144            {
145                browse(evt);
146            }
147        });
148
149        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
150        this.setLayout(layout);
151        layout.setHorizontalGroup(
152            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153            .add(layout.createSequentialGroup()
154                .addContainerGap()
155                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
156                    .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
157                    .add(layout.createSequentialGroup()
158                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
159                            .add(jLabel1)
160                            .add(jLabel2))
161                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
162                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
163                            .add(layout.createSequentialGroup()
164                                .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 395, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
165                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
166                                .add(browseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))
167                            .add(audioLengthText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE))))
168                .addContainerGap())
169        );
170        layout.setVerticalGroup(
171            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
172            .add(layout.createSequentialGroup()
173                .addContainerGap()
174                .add(removeButton)
175                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
176                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
177                    .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
178                    .add(jLabel1)
179                    .add(browseButton))
180                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
181                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
182                    .add(audioLengthText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
183                    .add(jLabel2))
184                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
185        );
186    }// </editor-fold>//GEN-END:initComponents
187
188    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
189        // TODO add your handling code here:
190    }//GEN-LAST:event_removeButtonActionPerformed
191
192    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
193        if (removeListener != null)
194        {
195            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
196        }
197    }//GEN-LAST:event_removeThisProperty
198
199    private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse
200        JFileChooser browser = new JFileChooser();
201        int returnVal = browser.showOpenDialog(this);
202        if (returnVal == JFileChooser.APPROVE_OPTION)
203        {
204            audioFileText.setText(browser.getSelectedFile().getPath());
205        }
206    }//GEN-LAST:event_browse
207
208
209    // Variables declaration - do not modify//GEN-BEGIN:variables
210    private javax.swing.JTextField audioFileText;
211    private javax.swing.JFormattedTextField audioLengthText;
212    private javax.swing.JButton browseButton;
213    private javax.swing.JLabel jLabel1;
214    private javax.swing.JLabel jLabel2;
215    private javax.swing.JButton removeButton;
216    // End of variables declaration//GEN-END:variables
217
218}
Note: See TracBrowser for help on using the repository browser.