/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jaspersoft.ireport.components.table.wizard;

import com.jaspersoft.ireport.components.table.style.TableStyleDesigner;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import net.sf.jasperreports.engine.design.JasperDesign;

public final class TableVisualPanelStyle extends JPanel {

    private TableWizardPanelStyle wizardPanel = null;

    private TableStyleDesigner styleDesignerPanel = null;

    /** Creates new form TableVisualPanel1 */
    public TableVisualPanelStyle(TableWizardPanelStyle wizardPanel) {
        initComponents();
        this.wizardPanel = wizardPanel;
        styleDesignerPanel = new TableStyleDesigner();
        jPanelStyle.add(styleDesignerPanel, BorderLayout.CENTER);
        
    }

    @Override
    public String getName() {
        return "Table Style";
    }

    public void validateForm()
    {
        return;
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanelStyle = new javax.swing.JPanel();
        jCheckBoxTH = new javax.swing.JCheckBox();
        jCheckBoxTF = new javax.swing.JCheckBox();
        jCheckBoxCH = new javax.swing.JCheckBox();
        jCheckBoxCF = new javax.swing.JCheckBox();
        jCheckBoxGH = new javax.swing.JCheckBox();
        jCheckBoxGF = new javax.swing.JCheckBox();
        jCheckBox7 = new javax.swing.JCheckBox();

        jPanelStyle.setBackground(new java.awt.Color(153, 153, 153));
        jPanelStyle.setMinimumSize(new java.awt.Dimension(531, 257));
        jPanelStyle.setPreferredSize(new java.awt.Dimension(531, 257));
        jPanelStyle.setLayout(new java.awt.BorderLayout());

        jCheckBoxTH.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxTH, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBoxTH.text")); // NOI18N

        jCheckBoxTF.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxTF, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBoxTF.text")); // NOI18N
        jCheckBoxTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxTFActionPerformed(evt);
            }
        });

        jCheckBoxCH.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxCH, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBoxCH.text")); // NOI18N
        jCheckBoxCH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxCHActionPerformed(evt);
            }
        });

        jCheckBoxCF.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxCF, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBoxCF.text")); // NOI18N
        jCheckBoxCF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxCFActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxGH, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBoxGH.text")); // NOI18N
        jCheckBoxGH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxGHActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxGF, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBoxGF.text")); // NOI18N
        jCheckBoxGF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxGFActionPerformed(evt);
            }
        });

        jCheckBox7.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(jCheckBox7, org.openide.util.NbBundle.getMessage(TableVisualPanelStyle.class, "TableVisualPanelStyle.jCheckBox7.text")); // NOI18N

        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(jCheckBox7)
                    .add(jPanelStyle, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jCheckBoxTF)
                            .add(jCheckBoxTH))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jCheckBoxCF)
                            .add(jCheckBoxCH))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jCheckBoxGF)
                            .add(jCheckBoxGH))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(jCheckBox7)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelStyle, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jCheckBoxGH)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBoxGF))
                    .add(layout.createSequentialGroup()
                        .add(jCheckBoxTH)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBoxTF))
                    .add(layout.createSequentialGroup()
                        .add(jCheckBoxCH)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBoxCF)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBoxTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxTFActionPerformed

    private void jCheckBoxCHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxCHActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxCHActionPerformed

    private void jCheckBoxCFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxCFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxCFActionPerformed

    private void jCheckBoxGHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxGHActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxGHActionPerformed

    private void jCheckBoxGFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxGFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxGFActionPerformed

    public JasperDesign getJasperDesign()
    {
        return (JasperDesign) this.getWizardPanel().getWizard().getProperty("jasperdesign");
    }

    // You can use a settings object to keep track of state. Normally the
    // settings object will be the WizardDescriptor, so you can use
    // WizardDescriptor.getProperty & putProperty to store information entered
    // by the user.
    public void readSettings(Object settings) {
    }

    public void storeSettings(Object settings) {
        this.getWizardPanel().getWizard().putProperty("create_styles", jCheckBox7.isSelected());
        this.getWizardPanel().getWizard().putProperty("th", jCheckBoxTH.isSelected());
        this.getWizardPanel().getWizard().putProperty("tf", jCheckBoxTF.isSelected());
        this.getWizardPanel().getWizard().putProperty("ch", jCheckBoxCH.isSelected());
        this.getWizardPanel().getWizard().putProperty("cf", jCheckBoxCF.isSelected());
        this.getWizardPanel().getWizard().putProperty("gh", jCheckBoxGH.isSelected());
        this.getWizardPanel().getWizard().putProperty("gf", jCheckBoxGF.isSelected());

        //Check the first available basename...
        String basename = "table";
        for (int i=0; ; i++)
        {
            String name = basename;
            if (i > 0)
            {
                name = basename + " "+ i;
            }

            if (!getJasperDesign().getStylesMap().containsKey(name))
            {
                basename = name;
                break;
            }

        }
        this.getWizardPanel().getWizard().putProperty("styles", styleDesignerPanel.createStyles(basename));
        this.getWizardPanel().getWizard().putProperty("basename",basename);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox jCheckBox7;
    private javax.swing.JCheckBox jCheckBoxCF;
    private javax.swing.JCheckBox jCheckBoxCH;
    private javax.swing.JCheckBox jCheckBoxGF;
    private javax.swing.JCheckBox jCheckBoxGH;
    private javax.swing.JCheckBox jCheckBoxTF;
    private javax.swing.JCheckBox jCheckBoxTH;
    private javax.swing.JPanel jPanelStyle;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the wizardPanel
     */
    public TableWizardPanelStyle getWizardPanel() {
        return wizardPanel;
    }

    public boolean isFinishPanel()
    {
        return true;
    }
}

