KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > events > JComponentActionSetBackground


1 /*
2  * JComponentActionSetBackground, action to set the background color of a JComponent.
3  * Copyright (C) Achim Westermann, created on 10.12.2004, 13:48:55
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  *
22  */

23 package info.monitorenter.gui.chart.events;
24
25 import info.monitorenter.gui.chart.Chart2D;
26 import info.monitorenter.gui.chart.layout.LayoutFactory.PropertyChangeCheckBoxMenuItem;
27
28 import java.awt.Color JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.beans.PropertyChangeEvent JavaDoc;
31
32 import javax.swing.JComponent JavaDoc;
33
34 /**
35  * <p>
36  * Performs the action of setting the background color
37  * ({@link javax.swing.JComponent#setBackground(java.awt.Color)}}
38  * of a <code>JComponent</code>.
39  * </p>
40  *
41  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
42  *
43  * @version $Revision: 1.2 $
44  */

45 public final class JComponentActionSetBackground extends AJComponentAction {
46
47   /**
48    * Generated <code>serialVersionUID</code>.
49    */

50   private static final long serialVersionUID = 3258131345116181297L;
51
52   /** The background color to set. */
53   private Color JavaDoc m_color;
54
55   /**
56    * Create an <code>Action</code> that accesses the <code>JComponent</code>
57    * and identifies itself with the given action String.<p>
58    *
59    * @param component
60    * the target the action will work on.
61    *
62    * @param colorName
63    * the descriptive <code>String</code> that will be displayed by
64    * {@link javax.swing.AbstractButton} subclasses that get this
65    * <code>Action</code> assigned (
66    * {@link javax.swing.AbstractButton#setAction(javax.swing.Action)}).
67    *
68    * @param color
69    * the <code>Color</code> to set as "background" of the internal
70    * <code>JComponent</code>.
71    */

72   public JComponentActionSetBackground(final JComponent JavaDoc component, final String JavaDoc colorName, final Color JavaDoc color) {
73     super(component, colorName);
74     this.m_color = color;
75     component.addPropertyChangeListener(Chart2D.PROPERTY_BACKGROUND_COLOR, this);
76   }
77
78   /**
79    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
80    */

81   public void actionPerformed(final ActionEvent JavaDoc e) {
82     this.m_component.setBackground(this.m_color);
83   }
84   
85   /**
86    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
87    */

88   public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
89     String JavaDoc property = evt.getPropertyName();
90     if (property.equals(Chart2D.PROPERTY_BACKGROUND_COLOR)) {
91       Color JavaDoc newColor = (Color JavaDoc) evt.getNewValue();
92       if (newColor.equals(this.m_color)) {
93         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
94             new Boolean JavaDoc(false), new Boolean JavaDoc(true));
95
96       } else {
97         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
98             new Boolean JavaDoc(true), new Boolean JavaDoc(false));
99       }
100     }
101   }
102 }
103
Popular Tags