KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * AxisActionSetPaintLabels.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.Chart2D;
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.Chart2D#setPaintLabels(boolean)} on a
36  * constructor given {@link info.monitorenter.gui.chart.Chart2D}.
37  * <p>
38  *
39  * This action is not used by the context menu labels of
40  * {@link info.monitorenter.gui.chart.layout.ChartPanel} because that instance
41  * deactivates this feature in order to use a custom {@link javax.swing.JLabel}
42  * that triggers a popup menu for trace controls.
43  * <p>
44  *
45  * <h2>Caution</h2>
46  * This implementation only works if assigned to a
47  * {@link javax.swing.JCheckBoxMenuItem}: It assumes that the source instance
48  * given to {@link #actionPerformed(ActionEvent)} within the action event is of
49  * that type as the state information (turn paint labels on or off) is needed.
50  * <p>
51  *
52  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann</a>
53  *
54  *
55  * @version $Revision: 1.2 $
56  */

57 public class Chart2DActionSetPaintLabels extends AChart2DAction {
58
59   /**
60    * Create an <code>Action</code> that accesses the axis, identifies itself
61    * with the given action String and invokes
62    * {@link info.monitorenter.gui.chart.Chart2D#setPaintLabels(boolean)} on the
63    * chart upon selection.
64    *
65    * @param chart
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    */

75   public Chart2DActionSetPaintLabels(final Chart2D chart, final String JavaDoc description) {
76     super(chart, description);
77     chart.addPropertyChangeListener(Chart2D.PROPERTY_PAINTLABELS, this);
78   }
79
80   /**
81    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
82    */

83   public void actionPerformed(final ActionEvent JavaDoc e) {
84     JCheckBoxMenuItem JavaDoc item = (JCheckBoxMenuItem JavaDoc) e.getSource();
85     boolean state = item.getState();
86     this.m_chart.setPaintLabels(state);
87   }
88
89   /**
90    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
91    */

92   public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
93     String JavaDoc property = evt.getPropertyName();
94     if (property.equals(Chart2D.PROPERTY_PAINTLABELS)) {
95       this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, evt.getOldValue(),
96           evt.getNewValue());
97     }
98   }
99 }
100
Popular Tags