| 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.I_ScriptEvent; |
|---|
| 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 | /** |
|---|
| 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 | @Override |
|---|
| 98 | public boolean removeAssociatedEvent() |
|---|
| 99 | { |
|---|
| 100 | event.removeThis(); |
|---|
| 101 | event = null; |
|---|
| 102 | return true; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * This method is called from within the constructor to initialize the form. |
|---|
| 107 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 108 | * regenerated by the Form Editor. |
|---|
| 109 | */ |
|---|
| 110 | @SuppressWarnings("unchecked") |
|---|
| 111 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 112 | private void initComponents() |
|---|
| 113 | { |
|---|
| 114 | |
|---|
| 115 | removeButton = new javax.swing.JButton(); |
|---|
| 116 | jLabel1 = new javax.swing.JLabel(); |
|---|
| 117 | audioFileText = new javax.swing.JTextField(); |
|---|
| 118 | jLabel2 = new javax.swing.JLabel(); |
|---|
| 119 | audioLengthText = new javax.swing.JFormattedTextField(); |
|---|
| 120 | browseButton = new javax.swing.JButton(); |
|---|
| 121 | |
|---|
| 122 | removeButton.setText("Remove"); |
|---|
| 123 | removeButton.setToolTipText("Removes this property"); |
|---|
| 124 | removeButton.addMouseListener(new java.awt.event.MouseAdapter() |
|---|
| 125 | { |
|---|
| 126 | public void mouseClicked(java.awt.event.MouseEvent evt) |
|---|
| 127 | { |
|---|
| 128 | removeThisProperty(evt); |
|---|
| 129 | } |
|---|
| 130 | }); |
|---|
| 131 | removeButton.addActionListener(new java.awt.event.ActionListener() |
|---|
| 132 | { |
|---|
| 133 | public void actionPerformed(java.awt.event.ActionEvent evt) |
|---|
| 134 | { |
|---|
| 135 | removeButtonActionPerformed(evt); |
|---|
| 136 | } |
|---|
| 137 | }); |
|---|
| 138 | |
|---|
| 139 | jLabel1.setText("Audio File"); |
|---|
| 140 | |
|---|
| 141 | audioFileText.setToolTipText("The path to the audio file"); |
|---|
| 142 | |
|---|
| 143 | jLabel2.setText("Length"); |
|---|
| 144 | |
|---|
| 145 | audioLengthText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance()))); |
|---|
| 146 | |
|---|
| 147 | browseButton.setText("Browse"); |
|---|
| 148 | browseButton.setToolTipText("Browse for the audio file"); |
|---|
| 149 | browseButton.addMouseListener(new java.awt.event.MouseAdapter() |
|---|
| 150 | { |
|---|
| 151 | public void mouseClicked(java.awt.event.MouseEvent evt) |
|---|
| 152 | { |
|---|
| 153 | browse(evt); |
|---|
| 154 | } |
|---|
| 155 | }); |
|---|
| 156 | |
|---|
| 157 | org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
|---|
| 158 | this.setLayout(layout); |
|---|
| 159 | layout.setHorizontalGroup( |
|---|
| 160 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 161 | .add(layout.createSequentialGroup() |
|---|
| 162 | .addContainerGap() |
|---|
| 163 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 164 | .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton) |
|---|
| 165 | .add(layout.createSequentialGroup() |
|---|
| 166 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 167 | .add(jLabel1) |
|---|
| 168 | .add(jLabel2)) |
|---|
| 169 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 170 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 171 | .add(layout.createSequentialGroup() |
|---|
| 172 | .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 395, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 173 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 174 | .add(browseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)) |
|---|
| 175 | .add(audioLengthText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)))) |
|---|
| 176 | .addContainerGap()) |
|---|
| 177 | ); |
|---|
| 178 | layout.setVerticalGroup( |
|---|
| 179 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 180 | .add(layout.createSequentialGroup() |
|---|
| 181 | .addContainerGap() |
|---|
| 182 | .add(removeButton) |
|---|
| 183 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 184 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 185 | .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 186 | .add(jLabel1) |
|---|
| 187 | .add(browseButton)) |
|---|
| 188 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 189 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 190 | .add(audioLengthText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 191 | .add(jLabel2)) |
|---|
| 192 | .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
|---|
| 193 | ); |
|---|
| 194 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 195 | |
|---|
| 196 | private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed |
|---|
| 197 | // TODO add your handling code here: |
|---|
| 198 | }//GEN-LAST:event_removeButtonActionPerformed |
|---|
| 199 | |
|---|
| 200 | private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty |
|---|
| 201 | if (removeListener != null) |
|---|
| 202 | { |
|---|
| 203 | removeListener.actionPerformed(new ActionEvent(this, 0, "")); |
|---|
| 204 | } |
|---|
| 205 | }//GEN-LAST:event_removeThisProperty |
|---|
| 206 | |
|---|
| 207 | private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse |
|---|
| 208 | JFileChooser browser = new JFileChooser(); |
|---|
| 209 | int returnVal = browser.showOpenDialog(this); |
|---|
| 210 | if (returnVal == JFileChooser.APPROVE_OPTION) |
|---|
| 211 | { |
|---|
| 212 | audioFileText.setText(browser.getSelectedFile().getPath()); |
|---|
| 213 | } |
|---|
| 214 | }//GEN-LAST:event_browse |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 218 | private javax.swing.JTextField audioFileText; |
|---|
| 219 | private javax.swing.JFormattedTextField audioLengthText; |
|---|
| 220 | private javax.swing.JButton browseButton; |
|---|
| 221 | private javax.swing.JLabel jLabel1; |
|---|
| 222 | private javax.swing.JLabel jLabel2; |
|---|
| 223 | private javax.swing.JButton removeButton; |
|---|
| 224 | // End of variables declaration//GEN-END:variables |
|---|
| 225 | |
|---|
| 226 | } |
|---|