/*
 * JRParameterDialog.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  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 9 maggio 2003, 17.25
 */

package it.businesslogic.ireport.gui.style;
import it.businesslogic.ireport.IReportFont;
import it.businesslogic.ireport.Report;
import it.businesslogic.ireport.gui.JRParameterDialog;
import it.businesslogic.ireport.gui.event.SheetPropertyValueChangedListener;
import it.businesslogic.ireport.gui.sheet.*;
import it.businesslogic.ireport.Style;
import it.businesslogic.ireport.gui.MainFrame;
import it.businesslogic.ireport.gui.event.StyleChangedEvent;
import it.businesslogic.ireport.gui.sheet.FontSheetProperty;
import java.util.Enumeration;
import java.util.Vector;

/**
 *
 * @author  Administrator
 */
public class StyleDialog extends javax.swing.JDialog  implements SheetPropertyValueChangedListener {
        
    private Style style = null;
    private CategorySheetPanel sheetPanel = null;
    private boolean insertMode = true;
    private IReportFont ireportFont = null;
    private Report currentReport = null;
    
    //** Creates new dialog StyleDialog */
    public StyleDialog(java.awt.Dialog parent, boolean modal) {
        super(parent,modal);
        initAll();
    }
     
    /** Creates new dialog ChartPropertiesDialog */
    public StyleDialog(java.awt.Frame parent, boolean modal) {
        super(parent,modal);
        initAll();
    }
     
    public void initAll()
    {
        initComponents();
        
        style = new Style();
        
        this.setSize(420, 620);
        // Open in center...
        it.businesslogic.ireport.util.Misc.centerFrame(this);
           
        java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.fill = gridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(0, -1, -1, -1);
        sheetPanel = new CategorySheetPanel();
        sheetPanel.addSheetPropertyValueChangedListener(this);
        
        jPanelProperties.add(sheetPanel, gridBagConstraints);
        
        //applyI18n();
        
        // Add styles....
        SheetProperty customizerClassProperty = new SheetProperty( Style.ATTRIBUTE_name  ,"Style name", SheetProperty.STRING);
        sheetPanel.addSheetProperty("Style", customizerClassProperty);
        
        SheetProperty isDefaultProperty = new SheetProperty(Style.ATTRIBUTE_isDefault,"Default style", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Style", isDefaultProperty);
        
        SheetProperty modeProperty = new SheetProperty(Style.ATTRIBUTE_mode,"Mode", SheetProperty.COMBOBOX);
        modeProperty.setTags( new Tag[]{ new Tag(null,"Default"), new Tag("Opaque","Opaque"),
                                         new Tag("Transparent","Transparent")});
        sheetPanel.addSheetProperty("Common", modeProperty);
        
        SheetProperty forecolorProperty = new SheetProperty(Style.ATTRIBUTE_forecolor,"Forecolor", SheetProperty.COLOR);
        forecolorProperty.setValue( null );
        sheetPanel.addSheetProperty("Common", forecolorProperty);
        
        SheetProperty backcolorProperty = new SheetProperty(Style.ATTRIBUTE_backcolor,"Backcolor", SheetProperty.COLOR);
        backcolorProperty.setValue( null );
        sheetPanel.addSheetProperty("Common", backcolorProperty);
        
        ComboBoxSheetProperty styleProperty = new ComboBoxSheetProperty(Style.ATTRIBUTE_style,"Parent style");
        
        sheetPanel.addSheetProperty("Style", styleProperty);
        
        SheetProperty penProperty = new SheetProperty(Style.ATTRIBUTE_pen,"Pen", SheetProperty.COMBOBOX);
        penProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Thin","Thin"),
                                        new Tag("1Point","1Point"),
                                        new Tag("2Point","2Point"),
                                        new Tag("4Point","4Point"),
                                        new Tag("Dotted","Dotted")});
        sheetPanel.addSheetProperty("Common", penProperty);
        
        SheetProperty fillProperty = new SheetProperty(Style.ATTRIBUTE_fill,"Fill", SheetProperty.COMBOBOX);
        fillProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Solid","Solid")});
        sheetPanel.addSheetProperty("Common", fillProperty);
        
        SheetProperty radiusProperty = new SheetProperty(Style.ATTRIBUTE_radius,"Radius", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Graphics", radiusProperty);
        
        SheetProperty scaleImageProperty = new SheetProperty(Style.ATTRIBUTE_scaleImage,"Scale image", SheetProperty.COMBOBOX);
        scaleImageProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Clip","Clip"),
                                               new Tag("FillFrame","FillFrame"),
                                               new Tag("RetainShape","RetainShape")});
        sheetPanel.addSheetProperty("Graphics", scaleImageProperty);
        
        SheetProperty hAlignProperty = new SheetProperty(Style.ATTRIBUTE_hAlign,"Horizontal align", SheetProperty.COMBOBOX);
        hAlignProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Left","Left"),
                                               new Tag("Center","Center"),
                                               new Tag("Right","Right"),
                                               new Tag("Justified","Justified")});
        sheetPanel.addSheetProperty("Graphics", hAlignProperty);
        
	SheetProperty vAlignProperty = new SheetProperty(Style.ATTRIBUTE_vAlign,"Vertical align", SheetProperty.COMBOBOX);
        vAlignProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Top","Top"),
                                               new Tag("Middle","Middle"),
                                               new Tag("Bottom","Bottom")});
        sheetPanel.addSheetProperty("Graphics", vAlignProperty);
        

	SheetProperty borderProperty = new SheetProperty(Style.ATTRIBUTE_border,"Border", SheetProperty.COMBOBOX);
        borderProperty.setTags( new Tag[]{new Tag(null,"Default"),
                                        new Tag("Thin","Thin"),
                                        new Tag("1Point","1Point"),
                                        new Tag("2Point","2Point"),
                                        new Tag("4Point","4Point"),
                                        new Tag("Dotted","Dotted")});
        sheetPanel.addSheetProperty("Border and padding", borderProperty);
        
        SheetProperty borderColorProperty = new SheetProperty(Style.ATTRIBUTE_borderColor,"Border color", SheetProperty.COLOR);
        sheetPanel.addSheetProperty("Border and padding", borderColorProperty);
        
        SheetProperty paddingProperty = new SheetProperty(Style.ATTRIBUTE_padding,"Padding", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Border and padding", paddingProperty);
        
        SheetProperty topBorderProperty = new SheetProperty(Style.ATTRIBUTE_topBorder,"Top border", SheetProperty.COMBOBOX);
        topBorderProperty.setTags( new Tag[]{ 
                                        new Tag(null,"Default"),
                                        new Tag("Thin","Thin"),
                                        new Tag("1Point","1Point"),
                                        new Tag("2Point","2Point"),
                                        new Tag("4Point","4Point"),
                                        new Tag("Dotted","Dotted")});
        sheetPanel.addSheetProperty("Border and padding", topBorderProperty);
        
        SheetProperty topBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_topBorderColor,"Top border color", SheetProperty.COLOR);
        sheetPanel.addSheetProperty("Border and padding", topBorderColorProperty);
        
        SheetProperty topPaddingProperty = new SheetProperty(Style.ATTRIBUTE_topPadding,"Top padding", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Border and padding", topPaddingProperty);
        
        SheetProperty leftBorderProperty = new SheetProperty(Style.ATTRIBUTE_leftBorder,"Left border", SheetProperty.COMBOBOX);
        leftBorderProperty.setTags( new Tag[]{ 
                                        new Tag(null,"Default"),
                                        new Tag("Thin","Thin"),
                                        new Tag("1Point","1Point"),
                                        new Tag("2Point","2Point"),
                                        new Tag("4Point","4Point"),
                                        new Tag("Dotted","Dotted")});
        sheetPanel.addSheetProperty("Border and padding", leftBorderProperty);
        
        SheetProperty leftBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_leftBorderColor,"Left border color", SheetProperty.COLOR);
        sheetPanel.addSheetProperty("Border and padding", leftBorderColorProperty);
        
        SheetProperty leftPaddingProperty = new SheetProperty(Style.ATTRIBUTE_leftPadding,"Left padding", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Border and padding", leftPaddingProperty);
        
        SheetProperty bottomBorderProperty = new SheetProperty(Style.ATTRIBUTE_bottomBorder,"Bottom border", SheetProperty.COMBOBOX);
        bottomBorderProperty.setTags( new Tag[]{ 
                                        new Tag(null,"Default"),
                                        new Tag("Thin","Thin"),
                                        new Tag("1Point","1Point"),
                                        new Tag("2Point","2Point"),
                                        new Tag("4Point","4Point"),
                                        new Tag("Dotted","Dotted")});
        sheetPanel.addSheetProperty("Border and padding", bottomBorderProperty);
        
        SheetProperty bottomBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_bottomBorderColor,"Bottom border color", SheetProperty.COLOR);
        sheetPanel.addSheetProperty("Border and padding", bottomBorderColorProperty);
        
        SheetProperty bottomPaddingProperty = new SheetProperty(Style.ATTRIBUTE_bottomPadding,"Bottom padding", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Border and padding", bottomPaddingProperty);
        
        SheetProperty rightBorderProperty = new SheetProperty(Style.ATTRIBUTE_rightBorder,"Right border", SheetProperty.COMBOBOX);
        rightBorderProperty.setTags( new Tag[]{ 
                                        new Tag(null,"Default"),
                                        new Tag("Thin","Thin"),
                                        new Tag("1Point","1Point"),
                                        new Tag("2Point","2Point"),
                                        new Tag("4Point","4Point"),
                                        new Tag("Dotted","Dotted")});
        sheetPanel.addSheetProperty("Border and padding", rightBorderProperty);
        
        SheetProperty rightBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_rightBorderColor,"Right border color", SheetProperty.COLOR);
        sheetPanel.addSheetProperty("Border and padding", rightBorderColorProperty);
        
        SheetProperty rightPaddingProperty = new SheetProperty(Style.ATTRIBUTE_rightPadding,"Right padding", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Border and padding", rightPaddingProperty);

        SheetProperty rotationProperty = new SheetProperty(Style.ATTRIBUTE_rotation,"Rotation", SheetProperty.COMBOBOX);
        rotationProperty.setTags( new Tag[]{ new Tag(null,"Default"),
                                             new Tag("None","None"),
                                             new Tag("Left","Left"),
                                             new Tag("Right","Right")});
        sheetPanel.addSheetProperty("Text properties", rotationProperty);
                
        SheetProperty patternProperty = new SheetProperty(Style.ATTRIBUTE_pattern,"Pattern", SheetProperty.STRING);
        sheetPanel.addSheetProperty("Text properties", patternProperty);
        
        SheetProperty isBlankWhenNullProperty = new SheetProperty(Style.ATTRIBUTE_isBlankWhenNull,"Is Blank when Null", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Text properties", isBlankWhenNullProperty);
	
        // FONT...
        FontSheetProperty theFontSpacingProperty = new FontSheetProperty("style.font","Font");
        theFontSpacingProperty.setFontMode( 3 );
        sheetPanel.addSheetProperty("Text properties", theFontSpacingProperty);
        
        SheetProperty lineSpacingProperty = new SheetProperty(Style.ATTRIBUTE_lineSpacing,"Line spacing", SheetProperty.COMBOBOX);
        lineSpacingProperty.setTags( new Tag[]{ new Tag(null,"Default"),
                                             new Tag("Single","Single"),
                                             new Tag("1_1_2","1_1_2"),
                                             new Tag("Double","Double")});
        sheetPanel.addSheetProperty("Text properties", lineSpacingProperty);
        
        /*
        SheetProperty fontNameProperty = new SheetProperty("style.fontName","Font", SheetProperty.COMBOBOX);
        fontNameProperty.setTags( new Tag[]{ });
        sheetPanel.addSheetProperty("Text properties", fontNameProperty);
        
        SheetProperty isBoldProperty = new SheetProperty("style.isBold","Bold", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Text properties", isBoldProperty);
        
        SheetProperty isItalicProperty = new SheetProperty("style.isItalic","Italic", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Text properties", isItalicProperty);
        
        SheetProperty isUnderlineProperty = new SheetProperty("style.isUnderline","Underline", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Text properties", isUnderlineProperty);
        
        SheetProperty isStrikeThroughProperty = new SheetProperty("style.isStrikeThrough","StrikeThrough", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Text properties", isStrikeThroughProperty);
        
        SheetProperty fontSizeProperty = new SheetProperty("style.fontSize","Font size", SheetProperty.INTEGER);
        sheetPanel.addSheetProperty("Text properties", fontSizeProperty);
        
        
        SheetProperty pdfFontNameProperty = new SheetProperty("style.pdfFontName","PDF Font name", SheetProperty.COMBOBOX);
        pdfFontNameProperty.setTags( new Tag[]{ });
        sheetPanel.addSheetProperty("Text properties", pdfFontNameProperty);
        
        SheetProperty pdfEncodingProperty = new SheetProperty("style.pdfEncoding","PDF Encoding", SheetProperty.STRING);
        sheetPanel.addSheetProperty("Text properties", pdfEncodingProperty);
        
	SheetProperty isPdfEmbeddedProperty = new SheetProperty("style.isPdfEmbedded","Embed PDF fonts", SheetProperty.STRING);
        sheetPanel.addSheetProperty("Text properties", isPdfEmbeddedProperty);
        
        */
        
        SheetProperty isStyledTextProperty = new SheetProperty(Style.ATTRIBUTE_isStyledText,"Is Styled Text", SheetProperty.BOOLEAN);
        sheetPanel.addSheetProperty("Text properties", isStyledTextProperty);
        // FINE FONT...
        sheetPanel.recreateSheet();
        
        this.updateStyleValues();
    }
    
      
    /** 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() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jButtonOK = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jPanelProperties = new javax.swing.JPanel();

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

        setTitle("Add/modify group");
        setModal(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

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

        jButtonOK.setText("OK");
        jButtonOK.setMnemonic('o');
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jPanel1.add(jButtonOK);

        jButtonCancel.setText("Cancel");
        jButtonCancel.setMnemonic('c');
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        jPanel1.add(jButtonCancel);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        getContentPane().add(jPanel1, gridBagConstraints);

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

        jPanelProperties.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        getContentPane().add(jPanelProperties, gridBagConstraints);

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }
    // </editor-fold>//GEN-END:initComponents

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        setVisible(false);
        this.setDialogResult( javax.swing.JOptionPane.CANCEL_OPTION);
        dispose();
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed

        if (this.sheetPanel.getPropertyValue(Style.ATTRIBUTE_name) == null || (this.sheetPanel.getPropertyValue(Style.ATTRIBUTE_name)+"").trim().length() <= 0)
        {
            javax.swing.JOptionPane.showMessageDialog(this,"Please insert a valid name for the style!","Invalid name!",javax.swing.JOptionPane.WARNING_MESSAGE );
            return;
        }
        
        String newName =this.sheetPanel.getPropertyValue(Style.ATTRIBUTE_name)+"";
        
        // check for duplicate name....
        Enumeration e = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles().elements();
        while (e.hasMoreElements())
        {
            Style st = (Style)e.nextElement();
            if (st.getAttributeString( st.ATTRIBUTE_name ,"").equals(newName) && st != getStyle())
            {
                javax.swing.JOptionPane.showMessageDialog(this,"The name \"" + newName + "\" is already in use!\nPlease change it.","Invalid name!",javax.swing.JOptionPane.WARNING_MESSAGE );
                return;
            }
        }
        
        // Store all values...
        Vector properties = this.sheetPanel.getProperties();
        getStyle().getAttributes().clear();
        for (int i=0; i<properties.size(); ++i)
        {
            SheetProperty sp = (SheetProperty)properties.get(i);
            if ( sp.getValue() != null)
            {
                getStyle().getAttributes().put( sp.getKeyName(),  sp.getValue());
            }
        }
        
        if ( getStyle().getAttributes().get(getStyle().ATTRIBUTE_style) != null && 
             !(getStyle().getAttributes().get(getStyle().ATTRIBUTE_style) instanceof Style))
        {
            String sname = ""+getStyle().getAttributes().get(getStyle().ATTRIBUTE_style);
            for (int j=0; j<currentReport.getStyles().size(); ++j)
            {
                Style sparent = (Style)currentReport.getStyles().elementAt(j);
                if (sparent.getName().equals( sname ))
                {
                    getStyle().getAttributes().put(getStyle().ATTRIBUTE_style, sparent);
                }
            }
        }
        
        if (getStyle().getAttributeBoolean(getStyle().ATTRIBUTE_isDefault, false))
        {
            Enumeration enum_s = MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles().elements();
            while (enum_s.hasMoreElements())
            {
                Style tmp_s = (Style)enum_s.nextElement();
                if (tmp_s != getStyle())
                {
                    tmp_s.getAttributes().remove( getStyle().ATTRIBUTE_isDefault);
                }
            }
        }
        
        if (ireportFont != null)
        {
                getStyle().getAttributes().put( Style.ATTRIBUTE_fontName,  ireportFont.getFontName() );
                getStyle().getAttributes().put( Style.ATTRIBUTE_fontSize, new Integer(ireportFont.getFontSize()));

                getStyle().getAttributes().put( style.ATTRIBUTE_isBold, new Boolean( ireportFont.isBold()));
                getStyle().getAttributes().put( style.ATTRIBUTE_isItalic, new Boolean( ireportFont.isItalic()));
                getStyle().getAttributes().put( style.ATTRIBUTE_isUnderline, new Boolean( ireportFont.isUnderline()));
                getStyle().getAttributes().put( style.ATTRIBUTE_isStrikeThrough, new Boolean( ireportFont.isStrikeTrought()));
                getStyle().getAttributes().put( style.ATTRIBUTE_isPdfEmbedded, new Boolean( ireportFont.isPdfEmbedded()));
                getStyle().getAttributes().put( Style.ATTRIBUTE_pdfFontName,   ireportFont.getPDFFontName());
        }
        
        if (isInsertMode())
        {
            MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles().add( getStyle() );
        }
            
        MainFrame.getMainInstance().getActiveReportFrame().getReport().fireStyleChangedListenerStyleChanged(
                        new StyleChangedEvent(
                        MainFrame.getMainInstance().getActiveReportFrame().getReport(),
                        ( isInsertMode() ) ? StyleChangedEvent.ADDED : StyleChangedEvent.CHANGED,
                        getStyle(),
                        getStyle()));
        
        setVisible(false);
        this.setDialogResult( javax.swing.JOptionPane.OK_OPTION);
        dispose();
    }//GEN-LAST:event_jButtonOKActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        this.setDialogResult( javax.swing.JOptionPane.CLOSED_OPTION);
        dispose();
    }//GEN-LAST:event_closeDialog
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new JRParameterDialog(new javax.swing.JFrame(), true).show();
    }
    
     
    /** Getter for property dialogResult.
     * @return Value of property dialogResult.
     *
     */
    public int getDialogResult() {
        return dialogResult;
    }
    
    /** Setter for property dialogResult.
     * @param dialogResult New value of property dialogResult.
     *
     */
    public void setDialogResult(int dialogResult) {
        this.dialogResult = dialogResult;
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelProperties;
    // End of variables declaration//GEN-END:variables

    private int dialogResult;    

    public CategorySheetPanel getSheetPanel() {
        return sheetPanel;
    }

    public void setSheetPanel(CategorySheetPanel sheetPanel) {
        this.sheetPanel = sheetPanel;
    }

    public void sheetPropertyValueChanged(it.businesslogic.ireport.gui.event.SheetPropertyValueChangedEvent evt) {
    
        if (evt.getPropertyName() != null && evt.getPropertyName().equals("style.font"))
        {
            setIreportFont( (IReportFont)evt.getNewValue());
        }
    
    }

    public Style getStyle() {
        return style;
    }
    
    public void updateStyleValues()
    {
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_name,getStyle().getAttribute(style.ATTRIBUTE_name));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_backcolor,getStyle().getAttribute(style.ATTRIBUTE_backcolor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_borderColor,getStyle().getAttribute(style.ATTRIBUTE_borderColor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_border,getStyle().getAttribute(style.ATTRIBUTE_border));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_bottomBorderColor,getStyle().getAttribute(style.ATTRIBUTE_bottomBorderColor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_bottomBorder,getStyle().getAttribute(style.ATTRIBUTE_bottomBorder));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_bottomPadding,getStyle().getAttribute(style.ATTRIBUTE_bottomPadding));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_fill,getStyle().getAttribute(style.ATTRIBUTE_fill));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_forecolor,getStyle().getAttribute(style.ATTRIBUTE_forecolor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_hAlign,getStyle().getAttribute(style.ATTRIBUTE_hAlign));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isBlankWhenNull,getStyle().getAttribute(style.ATTRIBUTE_isBlankWhenNull));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isDefault,getStyle().getAttribute(style.ATTRIBUTE_isDefault));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_leftBorderColor,getStyle().getAttribute(style.ATTRIBUTE_leftBorderColor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_leftBorder,getStyle().getAttribute(style.ATTRIBUTE_leftBorder));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_leftPadding,getStyle().getAttribute(style.ATTRIBUTE_leftPadding));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_lineSpacing,getStyle().getAttribute(style.ATTRIBUTE_lineSpacing));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_mode,getStyle().getAttribute(style.ATTRIBUTE_mode));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_padding,getStyle().getAttribute(style.ATTRIBUTE_padding));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_pattern,getStyle().getAttribute(style.ATTRIBUTE_pattern));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_pen,getStyle().getAttribute(style.ATTRIBUTE_pen));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_radius,getStyle().getAttribute(style.ATTRIBUTE_radius));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rightBorderColor,getStyle().getAttribute(style.ATTRIBUTE_rightBorderColor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rightBorder,getStyle().getAttribute(style.ATTRIBUTE_rightBorder));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rightPadding,getStyle().getAttribute(style.ATTRIBUTE_rightPadding));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rotation,getStyle().getAttribute(style.ATTRIBUTE_rotation));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_scaleImage,getStyle().getAttribute(style.ATTRIBUTE_scaleImage));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_style,getStyle().getAttribute(style.ATTRIBUTE_style));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isStyledText,getStyle().getAttribute(style.ATTRIBUTE_isStyledText));
        
        sheetPanel.setPropertyValue("style.font", getIreportFont());
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_topBorderColor,getStyle().getAttribute(style.ATTRIBUTE_topBorderColor));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_topBorder,getStyle().getAttribute(style.ATTRIBUTE_topBorder));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_topPadding,getStyle().getAttribute(style.ATTRIBUTE_topPadding));
        sheetPanel.setPropertyValue(Style.ATTRIBUTE_vAlign,getStyle().getAttribute(style.ATTRIBUTE_vAlign));
    
    
    }

    public void setStyle(Style myStyle) {
        this.style = myStyle;
    
        // currentReport
        if (it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame() != null &&
            currentReport != it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport())
        {
            currentReport = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport();
            Enumeration enum_styles = currentReport.getStyles().elements();

            Vector tags = new Vector();                    
            while (enum_styles.hasMoreElements())
            {
                Style s = (Style)enum_styles.nextElement();
                if (s != myStyle)
                {
                   tags.add(s); //new Tag(s)
                }
            }
            ComboBoxSheetProperty sp = (ComboBoxSheetProperty)getSheetPanel().getSheetProperty(Style.ATTRIBUTE_style);
            sp.updateValues(tags,true);
        }   
        
        setIreportFont(new IReportFont());
        getIreportFont().setBold( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isBold, false));
        getIreportFont().setFontName( myStyle.getAttributeString( myStyle.ATTRIBUTE_fontName, getIreportFont().getFontName()));
        getIreportFont().setFontSize( myStyle.getAttributeInteger( myStyle.ATTRIBUTE_fontSize, getIreportFont().getFontSize()));
        getIreportFont().setItalic( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isItalic, false));
        
        getIreportFont().setPdfEmbedded( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isPdfEmbedded, false));
        getIreportFont().setPdfEncoding( myStyle.getAttributeString( myStyle.ATTRIBUTE_pdfEncoding,  getIreportFont().getPdfEncoding()));
        getIreportFont().setStrikeTrought( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isStrikeThrough, false));
        
        // TODO = We have to understand what kind of font is this...
        getIreportFont().setPDFFontName( myStyle.getAttributeString( myStyle.ATTRIBUTE_pdfFontName, getIreportFont().getPDFFontName()));
        getIreportFont().setUnderline( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isUnderline, false));       
        
        updateStyleValues();
    }

    public boolean isInsertMode() {
        return insertMode;
    }

    public void setInsertMode(boolean insertMode) {
        this.insertMode = insertMode;
    }

    public IReportFont getIreportFont() {
        return ireportFont;
    }

    public void setIreportFont(IReportFont ireportFont) {
        this.ireportFont = ireportFont;
    }
    
}
