KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Chart2DActionSetAxis, action for setting an axis implementation 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.AAxis;
26 import info.monitorenter.gui.chart.Chart2D;
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  * <code>Action</code> for setting an axis implementation of the chart.
34  * <p>
35  *
36  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
37  *
38  * @version $Revision: 1.2 $
39  */

40 public final class Chart2DActionSetAxis extends AChart2DAction {
41
42   /**
43    * Identifies where to set the axis on the chart. Either {@link Chart2D#X} or
44    * {@link Chart2D#Y}.
45    * <p>
46    */

47   private final int m_axisTarget;
48
49   /** The axis implementation to use. */
50   private final AAxis m_axis;
51
52   /**
53    * Create an <code>Action</code> that accesses the trace and identifies
54    * itself with the given action String.
55    * <p>
56    *
57    * @param chart
58    * the target the action will work on.
59    *
60    * @param axis
61    * the axis implementation to use.
62    *
63    * @param description
64    * the description of this action to show in the UI.
65    *
66    * @param axisTarget
67    * Identifies where to set the axis on the chart: either
68    * {@link Chart2D#X} or {@link Chart2D#Y}
69    *
70    * @throws IllegalArgumentException
71    * if the axis argument is invalid.
72    */

73   public Chart2DActionSetAxis(final Chart2D chart, final AAxis axis, final String JavaDoc description,
74       final int axisTarget) throws IllegalArgumentException JavaDoc {
75     super(chart, description);
76     if (axisTarget != Chart2D.X && axisTarget != Chart2D.Y) {
77       throw new IllegalArgumentException JavaDoc(
78           "Argument axisTarget is invalid, choose one of Chart2D.X, Chart2D.Y.");
79     }
80     this.m_axisTarget = axisTarget;
81     this.m_axis = axis;
82     chart.addPropertyChangeListener(Chart2D.PROPERTY_AXIS_X, this);
83     chart.addPropertyChangeListener(Chart2D.PROPERTY_AXIS_Y, 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     switch (this.m_axisTarget) {
91       case Chart2D.X:
92         this.m_chart.setAxisX(this.m_axis);
93         break;
94
95       case Chart2D.Y:
96         this.m_chart.setAxisY(this.m_axis);
97         break;
98
99       default:
100         // nop
101
break;
102
103     }
104   }
105
106   /**
107    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
108    */

109   public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
110     if (evt.getPropertyName().equals(Chart2D.PROPERTY_AXIS_X) && this.m_axisTarget == Chart2D.X) {
111
112       Class JavaDoc axisClass = evt.getNewValue().getClass();
113       if (this.m_axis.getClass() == axisClass) {
114         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
115             new Boolean JavaDoc(false), new Boolean JavaDoc(true));
116       } else {
117         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
118             new Boolean JavaDoc(true), new Boolean JavaDoc(false));
119       }
120     } else if (evt.getPropertyName().equals(Chart2D.PROPERTY_AXIS_Y)
121         && this.m_axisTarget == Chart2D.Y) {
122
123       Class JavaDoc axisClass = evt.getNewValue().getClass();
124       if (this.m_axis.getClass() == axisClass) {
125         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
126             new Boolean JavaDoc(false), new Boolean JavaDoc(true));
127       } else {
128         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
129             new Boolean JavaDoc(true), new Boolean JavaDoc(false));
130       }
131     }
132
133   }
134
135 }
136
Popular Tags