/* * Copyright (c) 2007, Sun Microsystems, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package examples.colorpicker; /** ColorPreview class is a visual component that sets its background color according to * given red, green and blue values. */ public class ColorPreview extends javax.swing.JPanel { private int red; private java.beans.PropertyChangeSupport propertyChangeSupport; private int green; private int blue; /** ColorPreview constructor. */ public ColorPreview() { propertyChangeSupport = new java.beans.PropertyChangeSupport(this); } /** Adds new property change listener to be registered with this bean. * @param l PropertyChangeListener to be registered with this bean. */ public void addPropertyChangeListener(java.beans.PropertyChangeListener l) { propertyChangeSupport.addPropertyChangeListener( l ); } /** Removes previously added property added listener. * @param l PropertyChangeListener to be unregistered from this bean. */ public void removePropertyChangeListener(java.beans.PropertyChangeListener l) { propertyChangeSupport.removePropertyChangeListener( l ); } /** Red value getter. * @return Red value of this bean. */ public int getRed() { return red; } /** Red value setter. * @param red Red value of this bean. */ public void setRed(int red) { int oldRed = this.red; this.red = red; propertyChangeSupport.firePropertyChange("red", new Integer(oldRed), new Integer(red)); setBackground(new java.awt.Color(red, green, blue)); repaint(); } /** Green value getter. * @return Green value of this bean. */ public int getGreen() { return green; } /** Green value setter. * @param green Green value of this bean. */ public void setGreen(int green) { int oldGreen = this.green; this.green = green; propertyChangeSupport.firePropertyChange("green", new Integer(oldGreen), new Integer(green)); setBackground(new java.awt.Color(red, green, blue)); repaint(); } /** Blue value getter. * @return Blue value of this bean. */ public int getBlue() { return blue; } /** Blue value setter. * @param blue Blue value of this bean. */ public void setBlue(int blue) { int oldBlue = this.blue; this.blue = blue; propertyChangeSupport.firePropertyChange("blue", new Integer(oldBlue), new Integer(blue)); setBackground(new java.awt.Color(red, green, blue)); repaint(); } }