/*
 * TableTopPanel.java
 *
 * Created on November 13, 2002, 5:12 PM
 */

package org.evilsoft.gaming.RPGeneration;

import java.util.*;
/**
 *
 * @author  devon
 */
public class TableTopPanel extends TopPanel {
    
    /** Creates new form TableTopPanel */
    public TableTopPanel() {
        initComponents();
        initRest();
    }
    
    /** 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
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbTableName = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        selectNum = new javax.swing.JSlider();
        selectNumValue = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        finalButton = new javax.swing.JRadioButton();
        publicButton = new javax.swing.JRadioButton();
        privateButton = new javax.swing.JRadioButton();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel1.setText("Table");
        jPanel1.add(jLabel1);

        cbTableName.setPreferredSize(new java.awt.Dimension(350, 25));
        cbTableName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTableNameActionPerformed(evt);
            }
        });

        jPanel1.add(cbTableName);

        add(jPanel1);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel2.setText("Number To Select");
        jPanel2.add(jLabel2);

        selectNum.setMinimum(1);
        selectNum.setValue(1);
        selectNum.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                selectNumStateChanged(evt);
            }
        });

        selectNum.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                selectNumKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                selectNumKeyReleased(evt);
            }
        });

        selectNum.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                selectNumMouseDragged(evt);
            }
        });

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

        jPanel2.add(selectNum);

        jPanel2.add(selectNumValue);

        add(jPanel2);

        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        finalButton.setSelected(true);
        finalButton.setText("End User Tables");
        finalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                finalButtonActionPerformed(evt);
            }
        });

        jPanel3.add(finalButton);

        publicButton.setText("Useful Tables");
        publicButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                publicButtonActionPerformed(evt);
            }
        });

        jPanel3.add(publicButton);

        privateButton.setText("All Tables");
        privateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                privateButtonActionPerformed(evt);
            }
        });

        jPanel3.add(privateButton);

        add(jPanel3);

    }//GEN-END:initComponents

    private void privateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_privateButtonActionPerformed
        // Add your handling code here:
        initDropDown();
    }//GEN-LAST:event_privateButtonActionPerformed

    private void publicButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_publicButtonActionPerformed
        // Add your handling code here:
        initDropDown();
    }//GEN-LAST:event_publicButtonActionPerformed

    private void finalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finalButtonActionPerformed
        // Add your handling code here:
        initDropDown();
    }//GEN-LAST:event_finalButtonActionPerformed

    private void selectNumStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_selectNumStateChanged
        // Add your handling code here:
        selectNumValue.setText(selectNum.getValue() + "");
    }//GEN-LAST:event_selectNumStateChanged

    private void selectNumKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_selectNumKeyReleased
        // Add your handling code here:
        selectNumValue.setText(selectNum.getValue() + "");
    }//GEN-LAST:event_selectNumKeyReleased

    private void selectNumKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_selectNumKeyPressed
        // Add your handling code here:
        selectNumValue.setText(selectNum.getValue() + "");
    }//GEN-LAST:event_selectNumKeyPressed

    private void selectNumMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_selectNumMouseDragged
        // Add your handling code here:
        selectNumValue.setText(selectNum.getValue() + "");
    }//GEN-LAST:event_selectNumMouseDragged

    private void selectNumPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_selectNumPropertyChange
        // Add your handling code here:
        selectNumValue.setText(selectNum.getValue() + "");
    }//GEN-LAST:event_selectNumPropertyChange

    private void cbTableNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTableNameActionPerformed
        // Add your handling code here:
    }//GEN-LAST:event_cbTableNameActionPerformed

    private void initRest() {
        buttonGroup1.add(finalButton);
        buttonGroup1.add(publicButton);
        buttonGroup1.add(privateButton);
    }
    
    private void initDropDown() {
        Collection col = tables.values();
        Iterator itr = col.iterator();
        
        java.util.Vector list = new java.util.Vector();
        while(itr.hasNext()) {
            Trait table = (Trait)itr.next();
            if(finalButton.isSelected() && table.getUsage().equals("Final")) {
                Operation op = new Operation("Set", "TableName", table.getType(), table.getType());
                list.add(op);
            }
            else if(publicButton.isSelected() && !table.getUsage().equals("Private")) {
                Operation op = new Operation("Set", "TableName", table.getType(), table.getType());
                list.add(op);
            }
            else if(privateButton.isSelected()) {
                Operation op = new Operation("Set", "TableName", table.getType(), table.getType());
                list.add(op);
            }
        }
        Collections.sort(list);
        javax.swing.DefaultComboBoxModel cbModel = new javax.swing.DefaultComboBoxModel(list);
        cbTableName.setModel(cbModel);
    }

    public String getName() {
        return cbTableName.getSelectedItem().toString();
    }

    public java.util.ArrayList getOperations() {
        java.util.ArrayList operationList = new java.util.ArrayList();
        operationList.add(cbTableName.getSelectedItem());
        int num = selectNum.getValue() - 1;
        operationList.add(new Operation("Set", "NumSelections", num + ""));
        return operationList;
    }
    
    public void setTables(HashMap tables) {
        this.tables = tables;
        initDropDown();
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton finalButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton privateButton;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JComboBox cbTableName;
    private javax.swing.JRadioButton publicButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel selectNumValue;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSlider selectNum;
    // End of variables declaration//GEN-END:variables
    private HashMap tables = new HashMap();
}
