KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Chart2DActionSetCustomGridColor, action that sets a custom grid color to 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 import javax.swing.JColorChooser JavaDoc;
33
34 /**
35  * <code>Action</code> that sets a custom grid color to the corresponding
36  * chart ({@link Chart2D#setGridColor(Color)}) by showing a modal color
37  * chooser.
38  * <p>
39  *
40  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
41  *
42  * @version $Revision: 1.2 $
43  */

44 public final class Chart2DActionSetCustomGridColor extends AChart2DAction {
45   /**
46    * Generated <code>serialVersionUID</code>.
47    */

48   private static final long serialVersionUID = 3691034370412916788L;
49
50   /**
51    * Reference to the last custom color chosen to check wether the corresponding
52    * menu is selected.
53    */

54   private Color JavaDoc m_lastChosenColor;
55
56   /**
57    * Create an <code>Action</code> that accesses the trace and identifies
58    * itself with the given action String.
59    * <p>
60    *
61    * @param chart
62    * the target the action will work on
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   public Chart2DActionSetCustomGridColor(final Chart2D chart, final String JavaDoc colorName) {
70     super(chart, colorName);
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     Color JavaDoc chosen = JColorChooser.showDialog(this.m_chart, "choose color for "
79         + this.m_chart.getName(), this.m_chart.getGridColor());
80     this.m_lastChosenColor = chosen;
81     this.m_chart.setGridColor(chosen);
82   }
83
84   /**
85    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
86    */

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