001/* ======================================================
002 * Orson : a free chart beans library based on JFreeChart
003 * ======================================================
004 *
005 * (C) Copyright 2007, by Object Refinery Limited.
006 *
007 * Project Info:  not-yet-released
008 *
009 * This library is free software; you can redistribute it and/or modify it 
010 * under the terms of the GNU Lesser General Public License as published by 
011 * the Free Software Foundation; either version 2.1 of the License, or 
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but 
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022 * USA.  
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025 * in the United States and other countries.]
026 */
027
028package org.jfree.beans.editors;
029
030import java.awt.BorderLayout;
031import java.awt.Color;
032import java.awt.Paint;
033
034import javax.swing.JColorChooser;
035import javax.swing.JPanel;
036import javax.swing.event.ChangeEvent;
037import javax.swing.event.ChangeListener;
038
039/**
040 * A GUI for editing paint instances.  INCOMPLETE.
041 */
042public class PaintEditorGUI extends JPanel implements ChangeListener {
043
044    JColorChooser chooser;
045    
046    /**
047     * Default constructor.
048     */
049    public PaintEditorGUI() {
050        setLayout(new BorderLayout());
051        this.chooser = new JColorChooser();
052        this.chooser.getSelectionModel().addChangeListener(this);
053        add(this.chooser);
054    }
055
056    /**
057     * Returns the paint.
058     * 
059     * @return The paint.
060     */
061    public Paint getPaint() {
062        return this.chooser.getColor();
063    }
064    
065    /**
066     * Sets the paint.
067     * 
068     * @param paint  the paint.
069     */
070    public void setPaint(Paint paint) {
071        if (paint instanceof Color) {
072            this.chooser.getSelectionModel().setSelectedColor((Color) paint);
073        }
074    }
075    
076    /* (non-Javadoc)
077     * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
078     */
079    public void stateChanged(ChangeEvent e) {
080        firePropertyChange("paint", null, this.chooser.getColor());  
081    }
082
083}