package event.editor; import java.awt.event.*; import java.util.Observable; import javax.swing.*; import scriptbuilder.structures.events.AudioEvent; import scriptbuilder.structures.events.I_ScriptEvent; /** * * @author nathaniellehrer */ public class AudioPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel { private ActionListener removeListener; private AudioEvent event; /** * Creates new form AudioPanel */ public AudioPanel() { initComponents(); } @Override public void getEventObject(I_ScriptEvent sei) { event = (AudioEvent) sei; audioFileText.setText(event.audioPath); audioLengthText.setText(event.audioLength.toString()); audioFileText.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.audioPath = audioFileText.getText(); } } public void keyReleased(KeyEvent e) { } }); audioLengthText.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { try { event.audioLength = Integer.parseInt(audioLengthText.getText()); } catch (Exception ex) { } } } public void keyReleased(KeyEvent e) { } } ); } @Override public void update(Observable o, Object arg) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public boolean removeAssociatedEvent() { event.removeThis(); event = null; return true; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); audioFileText = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); audioLengthText = new javax.swing.JFormattedTextField(); browseButton = new javax.swing.JButton(); jLabel1.setText("Audio File"); audioFileText.setToolTipText("The path to the audio file"); jLabel2.setText("Length"); audioLengthText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance()))); browseButton.setText("Browse"); browseButton.setToolTipText("Browse for the audio file"); browseButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { browse(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(jLabel2)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 395, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(browseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)) .add(audioLengthText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(41, 41, 41) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(audioFileText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel1) .add(browseButton)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(audioLengthText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel2)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse JFileChooser browser = new JFileChooser(); int returnVal = browser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { audioFileText.setText(browser.getSelectedFile().getPath()); } }//GEN-LAST:event_browse // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField audioFileText; private javax.swing.JFormattedTextField audioLengthText; private javax.swing.JButton browseButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration//GEN-END:variables }