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

Revision 140, 5.6 KB checked in by bmcguffin, 8 years ago (diff)

Fixed defect #67. Removing an event and then closing the event editor window no longer causes the program to hang; a null check for the event is encountered before taking action upon close of the window.

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 I_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    @Override
28    public void getEventObject(I_ScriptEvent sei)
29    {
30        event = (AudioEvent) sei;
31        audioFileText.setText(event.audioPath);
32        audioLengthText.setText(event.audioLength.toString());
33    }
34
35    @Override
36    public void update(Observable o, Object arg)
37    {
38        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
39    }
40
41    @Override
42    public boolean removeAssociatedEvent()
43    {
44        event.removeThis();
45        event = null;
46        return true;
47    }
48
49    @Override
50    public void uponClose()
51    {
52        if (event != null)
53        {
54            event.audioPath = audioFileText.getText();
55            try
56            {
57                event.audioLength = Integer.parseInt(audioLengthText.getText());
58            }
59            catch (Exception ex)
60            {
61
62            }
63        }
64    }
65
66    /**
67     * This method is called from within the constructor to initialize the form.
68     * WARNING: Do NOT modify this code. The content of this method is always
69     * regenerated by the Form Editor.
70     */
71    @SuppressWarnings("unchecked")
72    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
73    private void initComponents()
74    {
75
76        jLabel1 = new javax.swing.JLabel();
77        audioFileText = new javax.swing.JTextField();
78        jLabel2 = new javax.swing.JLabel();
79        audioLengthText = new javax.swing.JFormattedTextField();
80        browseButton = new javax.swing.JButton();
81
82        jLabel1.setText("Audio File");
83
84        audioFileText.setToolTipText("The path to the audio file");
85
86        jLabel2.setText("Length");
87
88        audioLengthText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
89
90        browseButton.setText("Browse");
91        browseButton.setToolTipText("Browse for the audio file");
92        browseButton.addMouseListener(new java.awt.event.MouseAdapter()
93        {
94            public void mouseClicked(java.awt.event.MouseEvent evt)
95            {
96                browse(evt);
97            }
98        });
99
100        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
101        this.setLayout(layout);
102        layout.setHorizontalGroup(
103            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
104            .add(layout.createSequentialGroup()
105                .addContainerGap()
106                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
107                    .add(jLabel1)
108                    .add(jLabel2))
109                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
110                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
111                    .add(layout.createSequentialGroup()
112                        .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 395, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
113                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
114                        .add(browseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))
115                    .add(audioLengthText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE))
116                .addContainerGap())
117        );
118        layout.setVerticalGroup(
119            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
120            .add(layout.createSequentialGroup()
121                .add(41, 41, 41)
122                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
123                    .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
124                    .add(jLabel1)
125                    .add(browseButton))
126                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
127                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
128                    .add(audioLengthText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
129                    .add(jLabel2))
130                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
131        );
132    }// </editor-fold>//GEN-END:initComponents
133
134    private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse
135        JFileChooser browser = new JFileChooser();
136        int returnVal = browser.showOpenDialog(this);
137        if (returnVal == JFileChooser.APPROVE_OPTION)
138        {
139            audioFileText.setText(browser.getSelectedFile().getPath());
140        }
141    }//GEN-LAST:event_browse
142
143
144    // Variables declaration - do not modify//GEN-BEGIN:variables
145    private javax.swing.JTextField audioFileText;
146    private javax.swing.JFormattedTextField audioLengthText;
147    private javax.swing.JButton browseButton;
148    private javax.swing.JLabel jLabel1;
149    private javax.swing.JLabel jLabel2;
150    // End of variables declaration//GEN-END:variables
151
152}
Note: See TracBrowser for help on using the repository browser.