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 RemoveablePanel, ScriptEventEditorPanel { private ActionListener removeListener; private AudioEvent event; /** * Creates new form AudioPanel */ public AudioPanel() { initComponents(); } /** * Load the script event associated with this editor panel. * * @param sei The script event in question */ @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) { } } ); } public void setRemoveListener(ActionListener listener) { removeListener = listener; } 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() { removeButton = new javax.swing.JButton(); 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(); removeButton.setText("Remove"); removeButton.setToolTipText("Removes this property"); removeButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { removeThisProperty(evt); } }); removeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeButtonActionPerformed(evt); } }); 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(org.jdesktop.layout.GroupLayout.TRAILING, removeButton) .add(layout.createSequentialGroup() .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() .addContainerGap() .add(removeButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .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 removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed // TODO add your handling code here: }//GEN-LAST:event_removeButtonActionPerformed private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty if (removeListener != null) { removeListener.actionPerformed(new ActionEvent(this, 0, "")); } }//GEN-LAST:event_removeThisProperty 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; private javax.swing.JButton removeButton; // End of variables declaration//GEN-END:variables }