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

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

Revision 130, 5.5 KB checked in by bmcguffin, 9 years ago (diff)

Changed implementation of save function for event editor panels. Instead of updating their model objects whenever the enter key is pressed, panels are now notified when the window is closed and update their information then.

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