package event.editor;

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

/**
 *
 * @author nathaniellehrer
 */
public class CADLogPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
{

    private ActionListener removeListener;
    private CADEvent event;

    /**
     * Creates new form DetailPanel
     */
    public CADLogPanel()
    {
        initComponents();
    }

    public void setRemoveListener(ActionListener listener)
    {
        removeListener = listener;
    }

    public void getEventObject(I_ScriptEvent sei)
    {
        event = (CADEvent) sei;
        CadTextField.setText(event.detail);
        CadTextField.addKeyListener(new KeyListener()
        {

            public void keyTyped(KeyEvent e)
            {
            }

            public void keyPressed(KeyEvent e)
            {
                if(e.getKeyCode() == KeyEvent.VK_ENTER)
                {
                    event.detail = CadTextField.getText();
                }
            }

            public void keyReleased(KeyEvent e)
            {
            }
        });
    }

    public void update(Observable o, Object arg)
    {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    /**
     * 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()
    {

        removeButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        CadTextField = new javax.swing.JTextArea();

        removeButton.setText("Remove");
        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
        {
            public void mouseClicked(java.awt.event.MouseEvent evt)
            {
                removeButtonremoveThisProperty(evt);
            }
        });

        jLabel1.setText("Cad Log Text");

        CadTextField.setColumns(20);
        CadTextField.setRows(5);
        jScrollPane1.setViewportView(CadTextField);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 330, Short.MAX_VALUE)
                        .add(removeButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(removeButton)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void removeButtonremoveThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeButtonremoveThisProperty
        if (removeListener != null)
        {
            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
        }
}//GEN-LAST:event_removeButtonremoveThisProperty


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea CadTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton removeButton;
    // End of variables declaration//GEN-END:variables

}
