/*
 * SGColorDialog.java
 *
 * Created on 2004/07/12, 18:44
 */

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

import java.awt.*;
import javax.swing.*;
import javax.swing.colorchooser.*;

/**
 *
 * @author  kuromaru
 */
public class SGColorDialog extends JDialog
{

	/** Creates new form SGColorDialog */
	public SGColorDialog( final JDialog parent, final String title, final boolean modal )
	{
		super(parent, title, modal);
		initComponents();
		this.initProperty();
	}


    
    /** 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
        mColorChooserPanel = new javax.swing.JPanel();
        mColorChooser = new javax.swing.JColorChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        mColorChooserPanel.add(mColorChooser);

        getContentPane().add(mColorChooserPanel, java.awt.BorderLayout.CENTER);

        pack();
    }//GEN-END:initComponents
    
    
    // 変数宣言 - 編集不可//GEN-BEGIN:variables
    private javax.swing.JColorChooser mColorChooser;
    private javax.swing.JPanel mColorChooserPanel;
    // 変数宣言の終わり//GEN-END:variables




	/**
	 * 
	 */
	private boolean initProperty()
	{
		mColorChooser.setPreviewPanel( new JPanel() );
		mColorChooser.setSelectionModel( new OriginalColorSelectionModel() );

		pack();

		return true;
	}




	/**
	 * 
	 */
	public JColorChooser getColorChooser()
	{
		return this.mColorChooser;
	}



	/**
	 * 
	 */
	public static class OriginalColorSelectionModel extends DefaultColorSelectionModel
	{

		// 基本クラスに同じ名前の属性があるがprivateなので、ここで再定義
		private Color selectedColor;

		protected OriginalColorSelectionModel()
		{
			super();
			selectedColor = Color.white;
		}

		public OriginalColorSelectionModel(Color color) {
			super(color);
			selectedColor = color;
		}


		public Color getSelectedColor() {
			return selectedColor;
		}

		// 選択されている色と入力の色が同じ場合でも
		// ChangeEventを投げるように修正
		public void setSelectedColor( final Color color) {
			if (color != null) {
				selectedColor = color;
				fireStateChanged();
			}
		}


	}



    
}
