/*
 *  Initiative - A role playing utility to track turns
 *  Copyright (C) 2002 Devon D Jones
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  The author of this program grants you the ability to use this code
 *  in conjunction with code that is covered under the Open Gaming License
 *
 * CastSpell.java
 *
 * Created on January 16, 2002, 3:08 PM
 */

package org.evilsoft.gaming.Init;

/**
 *
 * @author  devon
 */
public class CastSpell extends javax.swing.JDialog {

    /** Creates new form CastSpell */
    public CastSpell(java.awt.Frame parent, boolean modal, Initiative initiative) {
        super(parent, modal);
        initComponents();
        this.initiative = initiative;
    }

    public CastSpell(Initiative initiative) {
        initComponents();
        this.initiative = initiative;
    }

    public CastSpell(java.awt.Frame parent, boolean modal, Initiative initiative, String player, int init) {
        super(parent, modal);
        initComponents();
        this.initiative = initiative;
        tName.grabFocus();
        tPlayer.setText(player);
        sInit.setValue(init);
        setInit();
    }

    public CastSpell(Initiative initiative, String player, int init) {
        initComponents();
        this.initiative = initiative;
        tName.grabFocus();
        tPlayer.setText(player);
        sInit.setValue(init);
        setInit();
    }
    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        tName = new javax.swing.JTextField();
        tPlayer = new javax.swing.JTextField();
        sDuration = new javax.swing.JSlider();
        lDuration = new javax.swing.JLabel();
        bSave = new javax.swing.JButton();
        bCancel = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lInit = new javax.swing.JLabel();
        sInit = new javax.swing.JSlider();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jLabel1.setText("Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 10, 0);
        getContentPane().add(jLabel1, gridBagConstraints);

        jLabel2.setText("Player");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 0);
        getContentPane().add(jLabel2, gridBagConstraints);

        jLabel3.setText("Duration");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 0);
        getContentPane().add(jLabel3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 37;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        getContentPane().add(tName, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 37;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        getContentPane().add(tPlayer, gridBagConstraints);

        sDuration.setMinimum(1);
        sDuration.setValue(1);
        sDuration.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                sDurationKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                sDurationKeyReleased(evt);
            }
        });

        sDuration.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                sDurationMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                sDurationMouseReleased(evt);
            }
        });

        sDuration.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                sDurationMouseMoved(evt);
            }
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                sDurationMouseDragged(evt);
            }
        });

        sDuration.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                sDurationPropertyChange(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = -80;
        gridBagConstraints.ipady = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        getContentPane().add(sDuration, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
        getContentPane().add(lDuration, gridBagConstraints);

        bSave.setText("Save");
        bSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bSaveMouseClicked(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 0);
        getContentPane().add(bSave, gridBagConstraints);

        bCancel.setText("Cancel");
        bCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bCancelMouseClicked(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        getContentPane().add(bCancel, gridBagConstraints);

        jLabel5.setText("500");
        jLabel5.setForeground(new java.awt.Color(204, 204, 204));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
        getContentPane().add(jLabel5, gridBagConstraints);

        jLabel6.setText("Initiative");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 0);
        getContentPane().add(jLabel6, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
        getContentPane().add(lInit, gridBagConstraints);

        sInit.setMinimum(1);
        sInit.setMaximum(40);
        sInit.setValue(1);
        sInit.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                sInitKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                sInitKeyReleased(evt);
            }
        });

        sInit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                sInitMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                sInitMouseReleased(evt);
            }
        });

        sInit.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                sInitMouseMoved(evt);
            }
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                sInitMouseDragged(evt);
            }
        });

        sInit.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                sInitPropertyChange(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        getContentPane().add(sInit, gridBagConstraints);

        pack();
    }//GEN-END:initComponents

    private void sInitPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_sInitPropertyChange
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitPropertyChange

    private void sInitMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sInitMouseDragged
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitMouseDragged

    private void sInitMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sInitMouseMoved
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitMouseMoved

    private void sInitMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sInitMouseReleased
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitMouseReleased

    private void sInitMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sInitMousePressed
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitMousePressed

    private void sInitKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sInitKeyReleased
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitKeyReleased

    private void sInitKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sInitKeyPressed
        // Add your handling code here:
        setInit();
    }//GEN-LAST:event_sInitKeyPressed

    private void bSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bSaveMouseClicked
        // Add your handling code here:
        // Add your handling code here:
                
        initiative.initVector.add(new Spell("Spell: " + tName.getText(), tPlayer.getText(), sDuration.getValue(), sInit.getValue()));
        initiative.writeToCombatTabWithRound(tPlayer.getText() + " Casted " + tName.getText());
        initiative.refreshTable();
        initiative.grabFocus();
        initiative.focusNextInit();
        setVisible(false);
        dispose();        
    }//GEN-LAST:event_bSaveMouseClicked

    private void sDurationMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sDurationMouseReleased
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationMouseReleased

    private void sDurationMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sDurationMousePressed
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationMousePressed

    private void sDurationMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sDurationMouseDragged
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationMouseDragged

    private void sDurationMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sDurationMouseMoved
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationMouseMoved

    private void sDurationKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sDurationKeyReleased
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationKeyReleased

    private void sDurationKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sDurationKeyPressed
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationKeyPressed

    private void bCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bCancelMouseClicked
        // Add your handling code here:
        setVisible(false);
        dispose();
    }//GEN-LAST:event_bCancelMouseClicked

    private void sDurationPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_sDurationPropertyChange
        // Add your handling code here:
        setDuration();
    }//GEN-LAST:event_sDurationPropertyChange

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    /**
    * @param args the command line arguments
    */

    public void setDuration() {
        lDuration.setText("" + sDuration.getValue());
    }

    public void setInit() {
        lInit.setText("" + sInit.getValue());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField tPlayer;
    private javax.swing.JLabel lDuration;
    private javax.swing.JLabel lInit;
    private javax.swing.JSlider sDuration;
    private javax.swing.JSlider sInit;
    private javax.swing.JButton bSave;
    private javax.swing.JTextField tName;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton bCancel;
    // End of variables declaration//GEN-END:variables
    public Initiative initiative;
}
