/*
 * ValuesDialog.java
 *
 * iReport  --  Visual designer for generating JasperReports Documents
 *  Copyright (C) 2002-2003  Giulio Toffoli gt@businesslogic.it
 *
 *  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.
 *
 *  Giulio Toffoli
 *  Via T.Aspetti, 233
 *  35100 Padova ITALY
 *  gt@businesslogic.it
 *
 * Created on 7 maggio 2003, 23.43
 */
package it.businesslogic.ireport.gui;

import it.businesslogic.ireport.*;
import it.businesslogic.ireport.gui.event.*;
import it.businesslogic.ireport.util.*;

import java.util.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;


/**
 * @author Administrator
 */
public class ValuesDialog
    extends javax.swing.JDialog
    implements SubDatasetObjectChangedListener
{


    private ValuesPanel valuesPanel = null;

    /**
     * Creates new form ValuesDialog
     * @param parent DOCUMENT ME!
     * @param modal DOCUMENT ME!
     */
    public ValuesDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
        initAll();
    }
    
    public ValuesDialog(java.awt.Dialog parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
        initAll();
    }
    
    public void initAll()
    {
        valuesPanel = new ValuesPanel();
        this.getContentPane().add("Center", valuesPanel);

        valuesPanel.applyI18n();
        applyI18n();
        
        this.setSize(500, 300);

        // Open in center...
        it.businesslogic.ireport.util.Misc.centerFrame(this);
    }


    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

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

        pack();
    }
    // </editor-fold>//GEN-END:initComponents

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

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        new ValuesDialog(new javax.swing.JFrame(), true).show();
    }

    /**
     * Getter for property jReportFrame.
     * 
     * @return Value of property jReportFrame.
     */
    public it.businesslogic.ireport.gui.JReportFrame getJReportFrame()
    {
        return jReportFrame;
    }

    /**
     * Setter for property jReportFrame.
     * 
     * @param jReportFrame New value of property jReportFrame.
     */
    public void setJReportFrame(it.businesslogic.ireport.gui.JReportFrame jReportFrame)
    {
        this.jReportFrame = jReportFrame;

        // Update all...
        if (jReportFrame == null)
        {
            setVisible(false);
        }
        else if (isVisible())
        {
            this.setTitle(jReportFrame.getReport().getName() + " values...");
            this.getValuesPanel().setSubDataset( getJReportFrame().getReport() );
        }
        if( jReportFrame != null )
        {
            this.getValuesPanel().setSubDataset( getJReportFrame().getReport() );
        }
    }

   

    /**
     * DOCUMENT ME!
     */
    public void applyI18n()
    {
        this.getValuesPanel().applyI18n();
    }

    /**
     * DOCUMENT ME!
     * 
     * @param evt DOCUMENT ME!
     */
    public void languageChanged(LanguageChangedEvent evt)
    {
        this.applyI18n();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    private JReportFrame jReportFrame;

    /**
     * DOCUMENT ME!
     * 
     * @param visible DOCUMENT ME!
     */
    public void setVisible(boolean visible)
    {

        if (visible == isVisible())
        {

            return;
        }

        super.setVisible(visible);

        if (visible == true)
        {
            this.setJReportFrame(jReportFrame);
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param p DOCUMENT ME!
     */
    public void modifyErrorParameter(it.businesslogic.ireport.JRParameter p)
    {

        this.getValuesPanel().modifyErrorParameter(p);
    }

    /**
     * DOCUMENT ME!
     * 
     * @param tab DOCUMENT ME!
     */
    public void gotoTab(String tab)
    {

        this.getValuesPanel().gotoTab(tab);
    }

    /**
     * DOCUMENT ME!
     * 
     * @return DOCUMENT ME! 
     */
    public Vector getClipboardFields()
    {
        return getValuesPanel().getClipboardFields();
    }

    /**
     * DOCUMENT ME!
     * 
     * @param clipboardFields DOCUMENT ME!
     */
    public void setClipboardFields(Vector clipboardFields)
    {
        getValuesPanel().setClipboardFields(clipboardFields);
    }

    /**
     * DOCUMENT ME!
     * 
     * @return DOCUMENT ME! 
     */
    public Vector getClipboardVariables()
    {

        return getValuesPanel().getClipboardVariables();
    }

    /**
     * DOCUMENT ME!
     * 
     * @param clipboardVariables DOCUMENT ME!
     */
    public void setClipboardVariables(Vector clipboardVariables)
    {
        getValuesPanel().setClipboardVariables(clipboardVariables);
    }

    /**
     * DOCUMENT ME!
     * 
     * @return DOCUMENT ME! 
     */
    public Vector getClipboardParameters()
    {

        return getValuesPanel().getClipboardParameters();
    }

    /**
     * DOCUMENT ME!
     * 
     * @param clipboardParameters DOCUMENT ME!
     */
    public void setClipboardParameters(Vector clipboardParameters)
    {
        getValuesPanel().setClipboardParameters(clipboardParameters);
    }


    /**
     * DOCUMENT ME!
     * 
     * @param evt DOCUMENT ME!
     */
    public void subDatasetObjectChanged(SubDatasetObjectChangedEvent evt)
    {
        if ( evt.getSource() == getValuesPanel().getSubDataset() )
        {
            if (evt.getType() == evt.PARAMETER)
            {
                getValuesPanel().updateParameters();
            }
            else if (evt.getType() == evt.VARIABLE)
            {
                getValuesPanel().updateVariables();
            }
            else if (evt.getType() == evt.FIELD)
            {
                getValuesPanel().updateFields();
            }
        }
    }

    public ValuesPanel getValuesPanel() {
        return valuesPanel;
    }

    public void setValuesPanel(ValuesPanel valuesPanel) {
        this.valuesPanel = valuesPanel;
    }
}
