package event.editor;

import java.awt.event.*;
import java.util.Observable;
import scriptbuilder.structures.events.I_ScriptEvent;
import scriptbuilder.structures.events.TowEvent;

/**
 *
 * @author nathaniellehrer
 */
public class TowPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
{

    private ActionListener removeListener;
    private TowEvent event;

    /**
     * Creates new form TowPanel
     */
    public TowPanel()
    {
        initComponents();

        txtConfirmationNumber.addFocusListener(new FocusListener()
        {

            public void focusGained(FocusEvent e)
            {
                help.setText("Confirmation number is formated as a telephone number. Example: (555)555-5555");
            }

            public void focusLost(FocusEvent e)
            {
                help.setText("");
            }

        });

        txtPublicNumber.addFocusListener(new FocusListener()
        {

            public void focusGained(FocusEvent e)
            {
                help.setText("Public number is formated as a telephone number. Example: (555)555-5555");
            }

            public void focusLost(FocusEvent e)
            {
                help.setText("");
            }

        });

    }

    @Override
    public void getEventObject(I_ScriptEvent sei)
    {
        event = (TowEvent) sei;
        txtCompany.setText(event.towCompany);

        txtBeat.setText(event.towBeat);

        txtConfirmationNumber.setText("" + event.towConfNum);

        txtPublicNumber.setText("" + event.towPubNum);

    }

    @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;
    }

    @Override
    public void uponClose()
    {
        if (event != null)
        {
            event.towCompany = txtCompany.getText();
            event.towBeat = txtBeat.getText();
            event.towConfNum = txtConfirmationNumber.getText();
            event.towPubNum = txtPublicNumber.getText();
        }
    }

    /**
     * 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();
        txtCompany = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtConfirmationNumber = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        txtPublicNumber = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        txtBeat = new javax.swing.JTextField();
        help = new javax.swing.JLabel();

        jLabel1.setText("Company");

        jLabel2.setText("Confirmation Number");

        try
        {
            txtConfirmationNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)###-####")));
        } catch (java.text.ParseException ex)
        {
            ex.printStackTrace();
        }

        jLabel3.setText("Public Number");

        try
        {
            txtPublicNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)###-####")));
        } catch (java.text.ParseException ex)
        {
            ex.printStackTrace();
        }

        jLabel4.setText("Beat");

        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(help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jLabel2)
                            .add(jLabel3)
                            .add(jLabel4))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(txtBeat, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                            .add(txtCompany, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                            .add(txtConfirmationNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                            .add(txtPublicNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(47, 47, 47)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(txtCompany, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(txtConfirmationNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(txtPublicNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(txtBeat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 72, Short.MAX_VALUE)
                .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel help;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField txtBeat;
    private javax.swing.JTextField txtCompany;
    private javax.swing.JFormattedTextField txtConfirmationNumber;
    private javax.swing.JFormattedTextField txtPublicNumber;
    // End of variables declaration//GEN-END:variables

}
