KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > colorpicker > ColorPreview


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package examples.colorpicker;
21
22 /** ColorPreview class is a visual component that sets its background color according to
23  * given red, green and blue values.
24  */

25 public class ColorPreview extends javax.swing.JPanel JavaDoc {
26
27     private int red;
28     private java.beans.PropertyChangeSupport JavaDoc propertyChangeSupport;
29     private int green;
30     private int blue;
31
32     /** ColorPreview constructor.
33      */

34     public ColorPreview() {
35         propertyChangeSupport = new java.beans.PropertyChangeSupport JavaDoc(this);
36     }
37
38     /** Adds new property change listener to be registered with this bean.
39      * @param l PropertyChangeListener to be registered with this bean.
40      */

41     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
42         propertyChangeSupport.addPropertyChangeListener( l );
43     }
44
45     /** Removes previously added property added listener.
46      * @param l PropertyChangeListener to be unregistered from this bean.
47      */

48     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
49         propertyChangeSupport.removePropertyChangeListener( l );
50     }
51
52     /** Red value getter.
53      * @return Red value of this bean.
54      */

55     public int getRed() {
56         return red;
57     }
58
59     /** Red value setter.
60      * @param red Red value of this bean.
61      */

62     public void setRed(int red) {
63         int oldRed = this.red;
64         this.red = red;
65         propertyChangeSupport.firePropertyChange("red", new Integer JavaDoc(oldRed), new Integer JavaDoc(red));
66         setBackground(new java.awt.Color JavaDoc(red, green, blue));
67         repaint();
68     }
69
70     /** Green value getter.
71      * @return Green value of this bean.
72      */

73     public int getGreen() {
74         return green;
75     }
76
77     /** Green value setter.
78      * @param green Green value of this bean.
79      */

80     public void setGreen(int green) {
81         int oldGreen = this.green;
82         this.green = green;
83         propertyChangeSupport.firePropertyChange("green", new Integer JavaDoc(oldGreen), new Integer JavaDoc(green));
84         setBackground(new java.awt.Color JavaDoc(red, green, blue));
85         repaint();
86     }
87
88     /** Blue value getter.
89      * @return Blue value of this bean.
90      */

91     public int getBlue() {
92         return blue;
93     }
94
95     /** Blue value setter.
96      * @param blue Blue value of this bean.
97      */

98     public void setBlue(int blue) {
99         int oldBlue = this.blue;
100         this.blue = blue;
101         propertyChangeSupport.firePropertyChange("blue", new Integer JavaDoc(oldBlue), new Integer JavaDoc(blue));
102         setBackground(new java.awt.Color JavaDoc(red, green, blue));
103         repaint();
104     }
105 }
106
Popular Tags