KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * AxisActionSetRangePolicy.java of project jchart2d
3  * Copyright 2006 (C) Achim Westermann, created on 00:13:29.
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.IAxis;
26 import info.monitorenter.gui.chart.layout.LayoutFactory.PropertyChangeCheckBoxMenuItem;
27
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.beans.PropertyChangeEvent JavaDoc;
30
31 import javax.swing.JCheckBoxMenuItem JavaDoc;
32
33 /**
34  * <code>Action</code> that invokes
35  * {@link info.monitorenter.gui.chart.AAxis#setPaintGrid(boolean)} on a
36  * constructor given {@link info.monitorenter.gui.chart.AAxis}.
37  * <p>
38  *
39  * <h2>Caution</h2>
40  * This implementation only works if assigned to a
41  * {@link javax.swing.JCheckBoxMenuItem}: It assumes that the source instance
42  * given to {@link #actionPerformed(ActionEvent)} within the action event is of
43  * that type as the state information (turn grid visible or turn grid invisible)
44  * is needed.
45  * <p>
46  *
47  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann</a>
48  *
49  *
50  * @version $Revision: 1.2 $
51  */

52 public class AxisActionSetGrid extends AAxisAction {
53
54   /**
55    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
56    */

57   public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
58     String JavaDoc property = evt.getPropertyName();
59     if (property.equals(IAxis.PROPERTY_PAINTGRID)) {
60       this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, evt.getOldValue(),
61           evt.getNewValue());
62     }
63   }
64
65   /**
66    * Create an <code>Action</code> that accesses the axis, identifies itself
67    * with the given action String and invokes
68    * {@link info.monitorenter.gui.chart.AAxis#setPaintGrid(boolean)} on the axis
69    * upon selection.
70    *
71    * @param axis
72    * the target the action will work on.
73    *
74    * @param description
75    * the descriptive <code>String</code> that will be displayed by
76    * {@link javax.swing.AbstractButton} subclasses that get this
77    * <code>Action</code> assigned (
78    * {@link javax.swing.AbstractButton#setAction(javax.swing.Action)}).
79    *
80    */

81   public AxisActionSetGrid(final IAxis axis, final String JavaDoc description) {
82     super(axis, description);
83     axis.addPropertyChangeListener(IAxis.PROPERTY_PAINTGRID, this);
84   }
85
86   /**
87    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
88    */

89   public void actionPerformed(final ActionEvent JavaDoc e) {
90     JCheckBoxMenuItem JavaDoc item = (JCheckBoxMenuItem JavaDoc) e.getSource();
91     boolean state = item.getState();
92     this.m_axis.setPaintGrid(state);
93   }
94 }
95
Popular Tags