
package jp.riken.brain.ni.samuraigraph.base;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.SpinnerNumberModel;


/**
 * A dialog to set the properties of windows.
 */
public class SGWindowDialog  extends SGPropertyDialog
	implements SGIRootObjectConstants, PropertyChangeListener
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4062469276075732615L;


	/**
	 * 
	 */
	public static final String TITLE = "Window Properties";


	public static final String ERRMSG_INVALID_SCALING_FACTOR
		= "Scaling factor is invalid.";


    
    /** Creates new form SGWindowDialog */
    public SGWindowDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
        this.initProperty();
		this.initialize();
    }
    

    /** 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;

        mImageWidthLabel = new javax.swing.JLabel();
        mImageWidthSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mImageHeightLabel = new javax.swing.JLabel();
        mImageHeightSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mFixSizeRatioCheckBox = new javax.swing.JCheckBox();
        mWindowPanel = new javax.swing.JPanel();
        mWidthLabel = new javax.swing.JLabel();
        mHeightLabel = new javax.swing.JLabel();
        mWidthSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mHeightSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mSizeLabel = new javax.swing.JLabel();
        mColorLabel = new javax.swing.JLabel();
        mIntervalLabel = new javax.swing.JLabel();
        mGridLinesIntervalSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mBottomLabel = new javax.swing.JLabel();
        mGridLinesWidthSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mGridLabel = new javax.swing.JLabel();
        mGridLinesColorButton = new jp.riken.brain.ni.samuraigraph.base.SGColorSelectionButton();
        mBackgroundColorLabel1 = new javax.swing.JLabel();
        mGridLinesColorLabel = new javax.swing.JLabel();
        mBackgroundColorButton = new jp.riken.brain.ni.samuraigraph.base.SGColorSelectionButton();
        mSizeSeparator = new javax.swing.JSeparator();
        mGridSeparator = new javax.swing.JSeparator();
        mColorSeparator = new javax.swing.JSeparator();
        mLeftSpaceLabel = new javax.swing.JLabel();
        mRightSpaceLabel = new javax.swing.JLabel();
        mGridVisibleCheckBox = new jp.riken.brain.ni.samuraigraph.base.SGCheckBox();
        mImageLabel = new javax.swing.JLabel();
        mImageSeparator = new javax.swing.JSeparator();
        mImageXLabel = new javax.swing.JLabel();
        mImageXSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mImageYLabel = new javax.swing.JLabel();
        mImageYSpinner = new jp.riken.brain.ni.samuraigraph.base.SGSpinner();
        mImageScaleLabel = new javax.swing.JLabel();
        mImageScaleTextField = new jp.riken.brain.ni.samuraigraph.base.SGTextField();
        mButtonPanel = new javax.swing.JPanel();
        mOKButton = new javax.swing.JButton();
        mCancelButton = new javax.swing.JButton();
        mPreviewButton = new javax.swing.JButton();

        mImageWidthLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageWidthLabel.setText("Width");
        mImageWidthSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageWidthSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        mImageHeightLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageHeightLabel.setText("Height");
        mImageHeightSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageHeightSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        mFixSizeRatioCheckBox.setFont(new java.awt.Font("Dialog", 0, 12));
        mFixSizeRatioCheckBox.setText("Fixed Ratio");

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

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

        mWindowPanel.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
        mWidthLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mWidthLabel.setText("Width");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
        mWindowPanel.add(mWidthLabel, gridBagConstraints);

        mHeightLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mHeightLabel.setText("Height");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 5);
        mWindowPanel.add(mHeightLabel, gridBagConstraints);

        mWidthSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mWidthSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mWidthSpinner, gridBagConstraints);

        mHeightSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mHeightSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mHeightSpinner, gridBagConstraints);

        mSizeLabel.setFont(new java.awt.Font("Dialog", 3, 12));
        mSizeLabel.setText("Size");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 0, 5);
        mWindowPanel.add(mSizeLabel, gridBagConstraints);

        mColorLabel.setFont(new java.awt.Font("Dialog", 3, 12));
        mColorLabel.setText("Color");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        mWindowPanel.add(mColorLabel, gridBagConstraints);

        mIntervalLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mIntervalLabel.setText("Interval");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
        mWindowPanel.add(mIntervalLabel, gridBagConstraints);

        mGridLinesIntervalSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mGridLinesIntervalSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mGridLinesIntervalSpinner, gridBagConstraints);

        mBottomLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mBottomLabel.setText("Line width");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 5);
        mWindowPanel.add(mBottomLabel, gridBagConstraints);

        mGridLinesWidthSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mGridLinesWidthSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mGridLinesWidthSpinner, gridBagConstraints);

        mGridLabel.setFont(new java.awt.Font("Dialog", 3, 12));
        mGridLabel.setText("Grid");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        mWindowPanel.add(mGridLabel, gridBagConstraints);

        mGridLinesColorButton.setPreferredSize(new java.awt.Dimension(65, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mGridLinesColorButton, gridBagConstraints);

        mBackgroundColorLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        mBackgroundColorLabel1.setText("Background");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 5);
        mWindowPanel.add(mBackgroundColorLabel1, gridBagConstraints);

        mGridLinesColorLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mGridLinesColorLabel.setText("Grid");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
        mWindowPanel.add(mGridLinesColorLabel, gridBagConstraints);

        mBackgroundColorButton.setPreferredSize(new java.awt.Dimension(65, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mBackgroundColorButton, gridBagConstraints);

        mSizeSeparator.setRequestFocusEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 35, 0, 0);
        mWindowPanel.add(mSizeSeparator, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 35, 0, 0);
        mWindowPanel.add(mGridSeparator, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 42, 0, 0);
        mWindowPanel.add(mColorSeparator, gridBagConstraints);

        mLeftSpaceLabel.setText("    ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        mWindowPanel.add(mLeftSpaceLabel, gridBagConstraints);

        mRightSpaceLabel.setText("    ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        mWindowPanel.add(mRightSpaceLabel, gridBagConstraints);

        mGridVisibleCheckBox.setText("Visible");
        mGridVisibleCheckBox.setFont(new java.awt.Font("Dialog", 0, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        mWindowPanel.add(mGridVisibleCheckBox, gridBagConstraints);

        mImageLabel.setFont(new java.awt.Font("Dialog", 3, 12));
        mImageLabel.setText("Image");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
        mWindowPanel.add(mImageLabel, gridBagConstraints);

        mImageSeparator.setRequestFocusEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
        mWindowPanel.add(mImageSeparator, gridBagConstraints);

        mImageXLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageXLabel.setText("X ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 7, 5);
        mWindowPanel.add(mImageXLabel, gridBagConstraints);

        mImageXSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageXSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 7, 5);
        mWindowPanel.add(mImageXSpinner, gridBagConstraints);

        mImageYLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageYLabel.setText("Y ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 20, 7, 5);
        mWindowPanel.add(mImageYLabel, gridBagConstraints);

        mImageYSpinner.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageYSpinner.setPreferredSize(new java.awt.Dimension(75, 22));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 7, 5);
        mWindowPanel.add(mImageYSpinner, gridBagConstraints);

        mImageScaleLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        mImageScaleLabel.setText("Scale");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.insets = new java.awt.Insets(10, 15, 15, 5);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        mWindowPanel.add(mImageScaleLabel, gridBagConstraints);

        mImageScaleTextField.setColumns(6);
        mImageScaleTextField.setFont(new java.awt.Font("Dialog", 0, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 15, 5);
        mWindowPanel.add(mImageScaleTextField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        getContentPane().add(mWindowPanel, gridBagConstraints);

        mOKButton.setFont(new java.awt.Font("Dialog", 1, 12));
        mOKButton.setText("OK");
        mButtonPanel.add(mOKButton);

        mCancelButton.setFont(new java.awt.Font("Dialog", 1, 12));
        mCancelButton.setText("Cancel");
        mButtonPanel.add(mCancelButton);

        mPreviewButton.setFont(new java.awt.Font("Dialog", 1, 12));
        mPreviewButton.setText("Preview");
        mButtonPanel.add(mPreviewButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(mButtonPanel, gridBagConstraints);

        pack();
    }//GEN-END:initComponents
    
    
    // 変数宣言 - 編集不可//GEN-BEGIN:variables
    private jp.riken.brain.ni.samuraigraph.base.SGColorSelectionButton mBackgroundColorButton;
    private javax.swing.JLabel mBackgroundColorLabel1;
    private javax.swing.JLabel mBottomLabel;
    private javax.swing.JPanel mButtonPanel;
    private javax.swing.JButton mCancelButton;
    private javax.swing.JLabel mColorLabel;
    private javax.swing.JSeparator mColorSeparator;
    private javax.swing.JCheckBox mFixSizeRatioCheckBox;
    private javax.swing.JLabel mGridLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGColorSelectionButton mGridLinesColorButton;
    private javax.swing.JLabel mGridLinesColorLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mGridLinesIntervalSpinner;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mGridLinesWidthSpinner;
    private javax.swing.JSeparator mGridSeparator;
    private jp.riken.brain.ni.samuraigraph.base.SGCheckBox mGridVisibleCheckBox;
    private javax.swing.JLabel mHeightLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mHeightSpinner;
    private javax.swing.JLabel mImageHeightLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mImageHeightSpinner;
    private javax.swing.JLabel mImageLabel;
    private javax.swing.JLabel mImageScaleLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGTextField mImageScaleTextField;
    private javax.swing.JSeparator mImageSeparator;
    private javax.swing.JLabel mImageWidthLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mImageWidthSpinner;
    private javax.swing.JLabel mImageXLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mImageXSpinner;
    private javax.swing.JLabel mImageYLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mImageYSpinner;
    private javax.swing.JLabel mIntervalLabel;
    private javax.swing.JLabel mLeftSpaceLabel;
    private javax.swing.JButton mOKButton;
    private javax.swing.JButton mPreviewButton;
    private javax.swing.JLabel mRightSpaceLabel;
    private javax.swing.JLabel mSizeLabel;
    private javax.swing.JSeparator mSizeSeparator;
    private javax.swing.JLabel mWidthLabel;
    private jp.riken.brain.ni.samuraigraph.base.SGSpinner mWidthSpinner;
    private javax.swing.JPanel mWindowPanel;
    // 変数宣言の終わり//GEN-END:variables




    /**
	 * 
	 */
	private boolean initProperty()
	{

		// set the title
		this.setTitle( SGWindowDialog.TITLE );


		//
		// spinner
		//

		this.mWidthSpinner.initProperties(
			new SpinnerNumberModel(
				PAPER_WIDTH_MIN_VALUE,
				PAPER_WIDTH_MIN_VALUE,
				PAPER_WIDTH_MAX_VALUE,
				PAPER_STEP_SIZE ),
			PAPER_WIDTH_UNIT, 1, 1
		);

		this.mHeightSpinner.initProperties(
			new SpinnerNumberModel(
				PAPER_HEIGHT_MIN_VALUE,
				PAPER_HEIGHT_MIN_VALUE,
				PAPER_HEIGHT_MAX_VALUE,
				PAPER_STEP_SIZE ),
			PAPER_HEIGHT_UNIT, 1, 1
		);

		this.mGridLinesIntervalSpinner.initProperties(
			new SpinnerNumberModel(
				GRID_INTERVAL_MIN_VALUE,
				GRID_INTERVAL_MIN_VALUE,
				GRID_INTERVAL_MAX_VALUE,
				GRID_INTERVAL_STEP_SIZE ),
			GRID_INTERVAL_UNIT, 1, 2
		);

		this.mGridLinesWidthSpinner.initProperties(
			getLineWidthSpinnerNumberModel(), LINE_WIDTH_UNIT, 1, 2 );

		this.mImageXSpinner.initProperties(
			new SpinnerNumberModel(
				IMAGE_LOCATION_X_MIN_VALUE,
				IMAGE_LOCATION_X_MIN_VALUE,
				IMAGE_LOCATION_X_MAX_VALUE,
				IMAGE_LOCATION_STEP_SIZE ),
			IMAGE_LOCATION_UNIT, 1, 1
		);

		this.mImageYSpinner.initProperties(
			new SpinnerNumberModel(
				IMAGE_LOCATION_Y_MIN_VALUE,
				IMAGE_LOCATION_Y_MIN_VALUE,
				IMAGE_LOCATION_Y_MAX_VALUE,
				IMAGE_LOCATION_STEP_SIZE ),
			IMAGE_LOCATION_UNIT, 1, 1
		);

		this.mImageWidthSpinner.initProperties(
			new SpinnerNumberModel(
				IMAGE_WIDTH_MIN_VALUE,
				IMAGE_WIDTH_MIN_VALUE,
				IMAGE_WIDTH_MAX_VALUE,
				IMAGE_SIZE_STEP_SIZE ),
			IMAGE_SIZE_UNIT, 1, 1
		);

		this.mImageHeightSpinner.initProperties(
			new SpinnerNumberModel(
				IMAGE_HEIGHT_MIN_VALUE,
				IMAGE_HEIGHT_MIN_VALUE,
				IMAGE_HEIGHT_MAX_VALUE,
				IMAGE_SIZE_STEP_SIZE ),
			IMAGE_SIZE_UNIT, 1, 1
		);


		// add as an action listener
		this.mOKButton.addActionListener(this);
		this.mCancelButton.addActionListener(this);
		this.mPreviewButton.addActionListener(this);
		this.mGridVisibleCheckBox.addActionListener(this);
		this.mFixSizeRatioCheckBox.addActionListener(this);


		// add as a change listener
		this.mImageWidthSpinner.addPropertyChangeListener( this );
		this.mImageHeightSpinner.addPropertyChangeListener( this );


		// set focused button color
		this.mFocusedColorSetButton = this.mBackgroundColorButton;


		// set the name
		this.mWidthSpinner.setDescription("Size-> Width");
		this.mHeightSpinner.setDescription("Size-> Height");
		this.mGridLinesIntervalSpinner.setDescription("Grid-> Interval");
		this.mGridLinesWidthSpinner.setDescription("Grid-> Line Width");
		this.mImageXSpinner.setDescription("Image-> X");
		this.mImageYSpinner.setDescription("Image-> Y");
		this.mImageWidthSpinner.setDescription("Image-> Width");
		this.mImageHeightSpinner.setDescription("Image-> Height");
		this.mImageScaleTextField.setDescription("Image-> Scale");


		//
		// create component group
		//

		SGComponentGroupElement[] array = {
			new SGComponentGroupElement( this.mIntervalLabel ),
			new SGComponentGroupElement( this.mGridLinesIntervalSpinner ),
			new SGComponentGroupElement( this.mBottomLabel ),
			new SGComponentGroupElement( this.mGridLinesWidthSpinner ),
			new SGComponentGroupElement( this.mGridLinesColorLabel ),
			new SGComponentGroupElement( this.mGridLinesColorButton )
		};
		
		this.mGridVisibleComponentGroup.addElement( array );


		return true;
	}


//	/**
//	 * 
//	 */
//	public void dispose()
//	{
//		super.dispose();
//		this.mGridVisibleComponentGroup.dispose();
//	}


	/**
	 * 
	 */
	private SGComponentGroup mGridVisibleComponentGroup = new SGComponentGroup();


	/**
	 * 
	 */
	public Number getPaperWidth()
	{
		return this.mWidthSpinner.getNumber();
	}

	/**
	 * 
	 */
	public Number getPaperHeight()
	{
		return this.mHeightSpinner.getNumber();
	}

	/**
	 * 
	 */
	public Color getPaperColor()
	{
		return this.mBackgroundColorButton.getColor();
	}

	/**
	 * 
	 */    
	public Color getGridLineColor()
	{
		return this.mGridLinesColorButton.getColor();
	}

	/**
	 * 
	 * @return
	 */
	public Boolean isGridVisible()
	{
		return this.mGridVisibleCheckBox.getSelected();
	}

	/**
	 * 
	 */
	public Number getGridLineInterval()
	{
		return this.mGridLinesIntervalSpinner.getNumber();
	}


	/**
	 * 
	 */
	public Number getGridLineWidth()
	{
		return this.mGridLinesWidthSpinner.getNumber();
	}

	/**
	 * 
	 */
	public Number getImageLocationX()
	{
		return this.mImageXSpinner.getNumber();
	}

	/**
	 * 
	 */
	public Number getImageLocationY()
	{
		return this.mImageYSpinner.getNumber();
	}

	/**
	 * 
	 */
	public Number getImageWidth()
	{
		return this.mImageWidthSpinner.getNumber();
	}

	/**
	 * 
	 */
	public Number getImageHeight()
	{
		return this.mImageHeightSpinner.getNumber();
	}

	/**
	 * 
	 * @return
	 */
	public Number getImageScalingFactor()
	{
		return this.getNumber( this.mImageScaleTextField );
	}


	/**
	 * 
	 */
	public boolean setPaperWidth( final Object value )
	{
		return this.setValue( this.mWidthSpinner, value );
	}

	/**
	 * 
	 */
	public boolean setPaperHeight( final Object value )
	{
		return this.setValue( this.mHeightSpinner, value );
	}

	/**
	 * 
	 * @param b
	 * @return
	 */
	public boolean setGridVisible( final Boolean b )
	{
		this.mGridVisibleCheckBox.setSelected(b);
		this.setGridComponentEnabled(b);
		return true;
	}

	/**
	 * 
	 */
	public boolean setGridLineInterval( final Object value )
	{
		return this.setValue( this.mGridLinesIntervalSpinner, value );
	}

	/**
	 * 
	 */
	public boolean setGridLineWidth( final Object value )
	{
		return this.setValue( this.mGridLinesWidthSpinner, value );
	}

	/**
	 * 
	 */
	public boolean setPaperColor( final Color cl )
	{
		this.mBackgroundColorButton.setColor( cl );
		return true;
	}

	/**
	 * 
	 */
	public boolean setGridLineColor( final Color cl )
	{
		this.mGridLinesColorButton.setColor( cl );
		return true;
	}

	/**
	 * 
	 */
	public boolean setImageLocationX( final Object value )
	{
		return this.setValue( this.mImageXSpinner, value );
	}

	/**
	 * 
	 */
	public boolean setImageLocationY( final Object value )
	{
		return this.setValue( this.mImageYSpinner, value );
	}

	/**
	 * 
	 */
	public boolean setImageWidth( final Object value )
	{
		return this.setValue( this.mImageWidthSpinner, value );
	}

	/**
	 * 
	 */
	public boolean setImageHeight( final Object value )
	{
		return this.setValue( this.mImageHeightSpinner, value );
	}
	
	/**
	 * 
	 * @param value
	 * @return
	 */
	public boolean setImageScalingFactor( final Object value )
	{
		return this.setValue( this.mImageScaleTextField, value );
	}


	/**
	 * 
	 */
	public List getColorSelectionButtonsList()
	{
		final ArrayList list = new ArrayList();
		list.add(this.mBackgroundColorButton);
		list.add(this.mGridLinesColorButton);
		return list;
	}


	/**
	 * 
	 */
	public List getTextFieldComponentsList()
	{
		final List list = this.getFormattedTextFieldsListFromSpinners();
		list.addAll( this.getNumberTextFieldList() );
		return list;
	}


	/**
	 * Returns a list of text fields to set number.
	 * @return
	 */
	public List getNumberTextFieldList()
	{
		List list = new ArrayList();
		list.add( this.mImageScaleTextField );
		return list;
	}


	/**
	 * 
	 */
	public List getSpinnerList()
	{
		List list = new ArrayList();

		list.add( this.mWidthSpinner );
		list.add( this.mHeightSpinner );
		list.add( this.mGridLinesIntervalSpinner );
		list.add( this.mGridLinesWidthSpinner );
		list.add( this.mImageXSpinner );
		list.add( this.mImageYSpinner );

		return list;
	}



	/**
	 * 
	 */
	public void actionPerformed( final ActionEvent e )
	{
		super.actionPerformed(e);

		Object source = e.getSource();

		if( source.equals( this.mGridVisibleCheckBox ) )
		{
			this.setGridVisible( this.isGridVisible() );
		}
		if( source.equals( this.mFixSizeRatioCheckBox ) )
		{
			this.mFixSizeRatioFlag = this.mFixSizeRatioCheckBox.isSelected();
		}
		
	}


	/**
	 * 
	 */
	public void propertyChange( final PropertyChangeEvent e )
	{
		Object source = e.getSource();
//		String pName = e.getPropertyName();

		if( source.equals( this.mImageWidthSpinner) | source.equals( this.mImageHeightSpinner ) )
		{
			if( this.mFixSizeRatioFlag )
			{
				this.updateImageSizeSpinnerValues( (SGSpinner)source );
			}
			else
			{
				this.updateImageSizeRatio();
			}
		}

	}


	// whether to fix the ratio of image size
	private boolean mFixSizeRatioFlag = true;


	// Ratio of with to height of the image
	private double mImageSizeRatio = 1.0f;


	// update the size ratio
	private boolean updateImageSizeRatio()
	{
		Number w = this.mImageWidthSpinner.getNumber();
		Number h = this.mImageHeightSpinner.getNumber();
		if( w==null | h==null )
		{
			return false;
		}
		
		final double width = w.doubleValue();
		final double height = h.doubleValue();
		if( width==0.0 | height==0.0 )
		{
			return false;
		}

		this.mImageSizeRatio = width/height;
//System.out.println(this.mImageSizeRatio);
		return true;
	}


	// update the value in the spinner
	private boolean updateImageSizeSpinnerValues( SGSpinner s )
	{
		Number w = this.mImageWidthSpinner.getNumber();
		Number h = this.mImageHeightSpinner.getNumber();
		if( w==null | h==null )
		{
			return false;
		}

		final double width = w.doubleValue();
		final double height = h.doubleValue();
		if( width==0.0 | height==0.0 )
		{
			return false;
		}

		final double ratio = this.mImageSizeRatio;
		final Number valueNew = s.getNumber();
		final double v = valueNew.doubleValue();
		if( s.equals( this.mImageWidthSpinner ) )
		{
			this.mImageWidth = v;
			this.mImageHeight = v/ratio;
			this.setImageHeight( new Double( this.mImageHeight ) );
		}
		else if( s.equals( this.mImageHeightSpinner ) )
		{
			this.mImageHeight = v;
			this.mImageWidth = v*ratio;
			this.setImageWidth( new Double( this.mImageWidth ) );
		}

//System.out.println(ratio+"  "+this.mImageWidth+"  "+this.mImageHeight+"  "+this.mImageWidth/this.mImageHeight);
		return true;
	}


	private double mImageWidth;
	private double mImageHeight;


	/**
	 * 
	 * @param b
	 * @return
	 */
	private boolean setGridComponentEnabled( final Boolean flag )
	{
		boolean b = true;
		if( flag!=null )
		{
			b = flag.booleanValue();
		}

		this.setGridComponentEnabled(b);

		return true;
	}



	/**
	 * 
	 * @param b
	 * @return
	 */
	private boolean setGridComponentEnabled( final boolean b )
	{
//		this.mIntervalLabel.setEnabled(b);
//		this.mGridLinesIntervalSpinner.setEnabled(b);
//		this.mBottomLabel.setEnabled(b);
//		this.mGridLinesWidthSpinner.setEnabled(b);
//		this.mGridLinesColorLabel.setEnabled(b);
//		this.mGridLinesColorButton.setEnabled(b);

		this.mGridVisibleComponentGroup.setEnabled(b);

		if( this.mGridLinesColorButton.equals( this.mFocusedColorSetButton ) )
		{
			this.mFocusedColorSetButton = this.mBackgroundColorButton;
			this.setColorButtonBorder( true );
		}

		return true;
	}



	/**
	 * 
	 */
	public boolean setDialogProperty()
	{
		List list = this.mPropertyDialogObserverList;

		SGIWindowDialogObserver wnd0
			= (SGIWindowDialogObserver)list.get(0);

		final float width0 = wnd0.getPaperWidth( cm );
		final float height0 = wnd0.getPaperHeight( cm );
		final float gridInterval0 = wnd0.getGridLineInterval( cm );
		final float gridLineWidth0 = wnd0.getGridLineWidth( pt );
		final boolean gridVisible0 = wnd0.isGridLineVisible();
		final Color paperColor0 = wnd0.getPaperColor();
		final Color gridLineColor0 = wnd0.getGridLineColor();
		final float imageX0 = wnd0.getImageLocationX( cm );
		final float imageY0 = wnd0.getImageLocationY( cm );
		final float imageWidth0 = wnd0.getImageWidth( cm );
		final float imageHeight0 = wnd0.getImageHeight( cm );
		final float imageScalingFactor0 = wnd0.getImageScalingFactor();

		Float width = new Float( width0 );
		Float height = new Float( height0 );
		Float gridInterval = new Float( gridInterval0 );
		Float gridLineWidth = new Float( gridLineWidth0 );
		Boolean gridVisible = Boolean.valueOf( gridVisible0 );
		Color paperColor = paperColor0;
		Color gridLineColor = gridLineColor0;
		Float imageX = new Float( imageX0 );
		Float imageY = new Float( imageY0 );
//		Float imageWidth = new Float( imageWidth0 );
//		Float imageHeight = new Float( imageHeight0 );
		Float imageScalingFactor = new Float( imageScalingFactor0 );

		if( list.size() > 1 )
		{
			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float width1 = wnd1.getPaperWidth( cm );
				if( width0!=width1 )
				{
					width = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float height1 = wnd1.getPaperHeight( cm );
				if( height0!=height1 )
				{
					height = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float gridInterval1 = wnd1.getGridLineInterval( cm );
				if( gridInterval0!=gridInterval1 )
				{
					gridInterval = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float gridLineWidth1 = wnd1.getGridLineWidth( pt );
				if( gridLineWidth0!=gridLineWidth1 )
				{
					gridLineWidth = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final boolean gridLineVisible1 = wnd1.isGridLineVisible();
				if( gridVisible0!=gridLineVisible1 )
				{
					gridVisible = null;
					break;
				}
			}
			
			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final Color paperColor1 = wnd1.getPaperColor();
				if( paperColor0.equals(paperColor1) == false )
				{
					paperColor = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final Color gridLineColor1 = wnd1.getGridLineColor();
				if( gridLineColor0.equals(gridLineColor1) == false )
				{
					gridLineColor = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float imageX1 = wnd1.getImageLocationX( cm );
				if( imageX0!=imageX1 )
				{
					imageX = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float imageY1 = wnd1.getImageLocationY( cm );
				if( imageY0!=imageY1 )
				{
					imageY = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float imageWidth1 = wnd1.getImageWidth( cm );
				if( imageWidth0!=imageWidth1 )
				{
//					imageWidth = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float imageHeight1 = wnd1.getImageHeight( cm );
				if( imageHeight0!=imageHeight1 )
				{
//					imageHeight = null;
					break;
				}
			}

			for( int ii=1; ii<list.size(); ii++ )
			{
				SGIWindowDialogObserver wnd1
					= (SGIWindowDialogObserver)list.get(ii);
				final float imageScalingFactor1 = wnd1.getImageScalingFactor();
				if( imageScalingFactor0!=imageScalingFactor1 )
				{
					imageScalingFactor = null;
					break;
				}
			}

		}



		//
		this.setPaperWidth( width );
		this.setPaperHeight( height );
		this.setGridLineInterval( gridInterval );
		this.setGridLineWidth( gridLineWidth );
		this.setGridVisible( gridVisible );
		this.setPaperColor( paperColor );
		this.setGridLineColor( gridLineColor );
		this.setImageLocationX( imageX );
		this.setImageLocationY( imageY );
//		this.setImageWidth( imageWidth );
//		this.setImageHeight( imageHeight );
		this.setImageScalingFactor( imageScalingFactor );

//		this.mFixSizeRatioCheckBox.setSelected( this.mFixSizeRatioFlag );
		this.setColorButtonBorder(true);
//		this.updateImageSizeRatio();


		return true;
	}



	/**
	 * 
	 */
	public boolean setPropertiesToListeners( SGIPropertyDialogObserver l )
	{

		// check values
		Number imageScalingFactor = this.getImageScalingFactor();
		if( imageScalingFactor!=null )
		{
			final float num = imageScalingFactor.floatValue();
			if( num<IMAGE_SCALE_MIN_VALUE | num>IMAGE_SCALE_MAX_VALUE )
			{
				this.setInputErrorMessage( ERRMSG_INVALID_SCALING_FACTOR );
				return false;
			}
		}


		SGIWindowDialogObserver wnd = (SGIWindowDialogObserver)l;

		Number width = this.getPaperWidth();
		if( width!=null )
		{
			wnd.setPaperWidth( width.floatValue(), cm );
		}

		Number height = this.getPaperHeight();
		if( height!=null )
		{
			wnd.setPaperHeight( height.floatValue(), cm );
		}
		
		Number interval = this.getGridLineInterval();
		if( interval!=null )
		{
			wnd.setGridLineInterval( interval.floatValue(), cm );
		}

		Number lineWidth = this.getGridLineWidth();
		if( lineWidth!=null )
		{
			wnd.setGridLineWidth( lineWidth.floatValue(), pt );
		}
		
		Boolean gridVisible = this.isGridVisible();
		if( gridVisible!=null )
		{
			wnd.setGridLineVisible( gridVisible.booleanValue() );
		}
		
		Color paperColor = this.getPaperColor();
		if( paperColor!=null )
		{
			wnd.setPaperColor( paperColor );
		}
		
		Color lineColor = this.getGridLineColor();
		if( lineColor!=null )
		{
			wnd.setGridLineColor( lineColor );
		}
		
		Number imageX = this.getImageLocationX();
		if( imageX!=null )
		{
			wnd.setImageLocationX( imageX.floatValue(), cm );
		}

		Number imageY = this.getImageLocationY();
		if( imageY!=null )
		{
			wnd.setImageLocationY( imageY.floatValue(), cm );
		}

//		Number imageWidth = this.getImageWidth();
//		if( imageWidth!=null )
//		{
//			wnd.setImageWidth( imageWidth.floatValue(), cm );
//		}
//
//		Number imageHeight = this.getImageHeight();
//		if( imageHeight!=null )
//		{
//			wnd.setImageHeight( imageHeight.floatValue(), cm );
//		}

//		Number imageScalingFactor = this.getImageScalingFactor();
		if( imageScalingFactor!=null )
		{
			wnd.setImageScalingFactor( imageScalingFactor.floatValue() );
		}

		return true;
	}


//	/**
//	 * 
//	 * @return
//	 */
//	protected boolean preview()
//	{
//		if( super.preview()==false )
//		{
//			return false;
//		}
//		
//		this.updateImageSizeRatio();
//		return true;
//	}

}

