KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRangePolicy;
27 import info.monitorenter.gui.chart.layout.LayoutFactory.PropertyChangeCheckBoxMenuItem;
28
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.beans.PropertyChangeEvent JavaDoc;
31
32 /**
33  * Action that sets a constructor given
34  * {@link info.monitorenter.gui.chart.IRangePolicy} to a constructor given
35  * {@link info.monitorenter.gui.chart.AAxis}.
36  * <p>
37  *
38  * <h2>Warning</h2>
39  * This <code>Action</code> currently is only intended to be
40  *
41  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann</a>
42  *
43  *
44  * @version $Revision: 1.2 $
45  */

46 public class AxisActionSetRangePolicy extends AAxisAction {
47
48   /**
49    * Generated <code>serial version UID</code>.
50    */

51   private static final long serialVersionUID = -3093734349885438197L;
52
53   /**
54    * The range policy to set to the axis upon invocation of
55    * {@link #actionPerformed(ActionEvent)}.
56    */

57   private IRangePolicy m_rangePolicy;
58
59   /**
60    * Create an <code>Action</code> that accesses the axis, identifies itself
61    * with the given action String and sets the given
62    * {@link info.monitorenter.gui.chart.IRangePolicy} to the axis upon
63    * selection.
64    *
65    * @param axis
66    * the target the action will work on.
67    *
68    * @param description
69    * the descriptive <code>String</code> that will be displayed by
70    * {@link javax.swing.AbstractButton} subclasses that get this
71    * <code>Action</code> assigned (
72    * {@link javax.swing.AbstractButton#setAction(javax.swing.Action)}).
73    *
74    * @param rangePolicy
75    * The range policy to set to the axis upon invocation of
76    * {@link #actionPerformed(ActionEvent)}.
77    */

78   public AxisActionSetRangePolicy(final IAxis axis, final String JavaDoc description,
79       final IRangePolicy rangePolicy) {
80     super(axis, description);
81     this.m_rangePolicy = rangePolicy;
82     axis.addPropertyChangeListener(IAxis.PROPERTY_RANGEPOLICY, this);
83
84   }
85
86   /**
87    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
88    */

89   public void actionPerformed(final ActionEvent JavaDoc e) {
90     this.m_axis.setRangePolicy(this.m_rangePolicy);
91   }
92
93   /**
94    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
95    */

96   public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
97     String JavaDoc property = evt.getPropertyName();
98     if (property.equals(IAxis.PROPERTY_RANGEPOLICY)) {
99       Class JavaDoc rangepolicyClass = evt.getNewValue().getClass();
100       Boolean JavaDoc oldValue, newValue;
101       if (rangepolicyClass == this.m_rangePolicy.getClass()) {
102         oldValue = new Boolean JavaDoc(false);
103         newValue = new Boolean JavaDoc(true);
104       } else {
105         oldValue = new Boolean JavaDoc(true);
106         newValue = new Boolean JavaDoc(false);
107       }
108       this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, oldValue, newValue);
109     }
110   }
111 }
112
Popular Tags