KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Trace2DActionSetStroke, action to set a Stroke on 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.Stroke JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.beans.PropertyChangeEvent JavaDoc;
31
32 /**
33  * <p>
34  * <code>Action</code> that sets a constructor-given zIndex to the
35  * corresponding trace.
36  * </p>
37  *
38  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
39  *
40  * @version $Revision: 1.2 $
41  */

42 public final class Trace2DActionSetStroke extends ATrace2DAction {
43
44   /**
45    * Generated <code>serialVersionUID</code>.
46    */

47   private static final long serialVersionUID = 3978986583057707570L;
48
49   /**
50    * The stroke to set.
51    */

52   private Stroke JavaDoc m_stroke;
53
54   /**
55    * Create an <code>Action</code> that accesses the trace and identifies
56    * itself with the given action String.
57    * <p>
58    *
59    * @param trace
60    * the target the action will work on.
61    *
62    * @param description
63    * the descriptive <code>String</code> that will be displayed by
64    * {@link javax.swing.AbstractButton} subclasses that get this
65    * <code>Action</code> assigned (
66    * {@link javax.swing.AbstractButton#setAction(javax.swing.Action)}).
67    *
68    * @param stroke
69    * the stroke property to set to the corresponding trace (see
70    * {@link ITrace2D#setStroke(Stroke)})
71    */

72   public Trace2DActionSetStroke(final ITrace2D trace, final String JavaDoc description, final Stroke JavaDoc stroke) {
73     super(trace, description);
74     this.m_stroke = stroke;
75     trace.addPropertyChangeListener(ITrace2D.PROPERTY_STROKE, this);
76   }
77
78   /**
79    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
80    */

81   public void actionPerformed(final ActionEvent JavaDoc e) {
82     this.m_trace.setStroke(this.m_stroke);
83   }
84
85   /**
86    * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
87    */

88   public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
89     String JavaDoc property = evt.getPropertyName();
90     if (property.equals(ITrace2D.PROPERTY_STROKE)) {
91       Stroke JavaDoc newValue = (Stroke JavaDoc) evt.getNewValue();
92       // added
93
if (newValue.equals(this.m_stroke)) {
94         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
95             new Boolean JavaDoc(false), new Boolean JavaDoc(true));
96       } else {
97         this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED,
98             new Boolean JavaDoc(true), new Boolean JavaDoc(false));
99       }
100     }
101   }
102 }
103
Popular Tags