KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JComponentActionSetForeground, action for setting a foreground color to 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 foreground color (
37  * {@link javax.swing.JComponent#setForeground(java.awt.Color)}} of a
38  * <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 JComponentActionSetForeground extends AJComponentAction {
46
47   /**
48    * Generated for <code>serialVersionUID</code>.
49    */

50   private static final long serialVersionUID = 3258131345116181297L;
51
52   /** The foreground 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.
58    * <p>
59    *
60    * @param component
61    * the target the action will work on.
62    *
63    * @param colorName
64    * the descriptive <code>String</code> that will be displayed by
65    * {@link javax.swing.AbstractButton} subclasses that get this
66    * <code>Action</code> assigned (
67    * {@link javax.swing.AbstractButton#setAction(javax.swing.Action)}).
68    *
69    * @param color
70    * the <code>Color</code> to set as "foreground" of the internal
71    * <code>JComponent</code>.
72    */

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

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

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