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());
    }

    @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()
    {
        //this makes it not possible to remove an AudioEvent from the script without deleting its respective I_AudioEvent.
//        event.removeThis();
//        event = null;
        return false;
    }

    @Override
    public void uponClose()
    {
        if (event != null)
        {
            event.audioPath = audioFileText.getText();
            try
            {
                event.audioLength = Integer.parseInt(audioLengthText.getText());
            }
            catch (Exception ex)
            {

            }
        }
    }

    /**
     * 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//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();

        jLabel1.setText("Audio File");

        audioFileText.setToolTipText("The path to the audio file");
        audioFileText.setEnabled(false);

        jLabel2.setText("Length");

        audioLengthText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));

        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(audioLengthText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
                    .add(audioFileText))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(44, 44, 44)
                .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))
                .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))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField audioFileText;
    private javax.swing.JFormattedTextField audioLengthText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

}
