KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Chart2DActionSetGridColor, action to set a color for the grid of the chart.
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 /**
33  * Performs the action of setting the color of gridlines (
34  * {@link info.monitorenter.gui.chart.Chart2D#setGridColor(Color)}) of a
35  * <code>Chart2D</code> with the constructor given <code>Color</code>.
36  * <p>
37  *
38  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
39  *
40  * @version $Revision: 1.2 $
41  */

42 public class Chart2DActionSetGridColor extends AChart2DAction {
43
44   /**
45    * Generated <code>serialVersionUID</code>.
46    */

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

68   public Chart2DActionSetGridColor(final Chart2D chart, final String JavaDoc colorName, final Color JavaDoc color) {
69     super(chart, colorName);
70     this.m_color = color;
71     chart.addPropertyChangeListener(Chart2D.PROPERTY_GRID_COLOR, this);
72   }
73
74   /**
75    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
76    */

77   public void actionPerformed(final ActionEvent JavaDoc e) {
78     this.m_chart.setGridColor(this.m_color);
79   }
80
81   /**
82    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
83    */

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