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