KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Trace2DActionSetVisible, action to control the visibility of an ITrace2D.
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.ITrace2D;
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  * <p>
35  * Performs the action of setting a trace visible (
36  * {@link info.monitorenter.gui.chart.ITrace2D#setVisible(boolean)}) with the
37  * constructor given boolean.
38  * </p>
39  * <p>
40  * <b>This action only may be assigned to a
41  * {@link javax.swing.JCheckBoxMenuItem}</b> <br>
42  * The <em>source</em> <code>Object</code> of <code>ActionEvent</code>
43  * that is received in {@link #actionPerformed(ActionEvent)} is casted to this
44  * type to get the boolean state. If this <code>Action</code> is used with
45  * other <code>JComponent</code> instances <code>ClassCastExceptions</code>
46  * will be thrown!
47  * </p>
48  *
49  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
50  *
51  * @version $Revision: 1.2 $
52  */

53 public class Trace2DActionSetVisible extends ATrace2DAction {
54
55   /**
56    * Generated <code>serialVersionUID</code>.
57    */

58   private static final long serialVersionUID = 3689069560279937078L;
59
60   /**
61    * Create an <code>Action</code> that accesses the chart and identifies
62    * itself with the given action String.
63    * <p>
64    *
65    * @param trace
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 Trace2DActionSetVisible(final ITrace2D trace, final String JavaDoc description) {
76     super(trace, description);
77     trace.addPropertyChangeListener(ITrace2D.PROPERTY_VISIBLE, 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     this.m_trace.setVisible(item.getState());
86   }
87
88   /**
89    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
90    */

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