KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > event > GraphicsNodeMouseEvent


1 /*
2
3    Copyright 2000-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.gvt.event;
19
20 import java.awt.Point JavaDoc;
21 import java.awt.event.MouseEvent JavaDoc;
22 import java.awt.geom.Point2D JavaDoc;
23
24 import org.apache.batik.gvt.GraphicsNode;
25
26 /**
27  * An event which indicates that a mouse action occurred in a graphics node.
28  *
29  * @author <a HREF="mailto:cjolif@ilog.fr">Christophe Jolif</a>
30  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
31  * @version $Id: GraphicsNodeMouseEvent.java,v 1.13 2005/03/27 08:58:34 cam Exp $
32  */

33 public class GraphicsNodeMouseEvent extends GraphicsNodeInputEvent {
34
35     /**
36      * The first number in the range of ids used for mouse events.
37      */

38     static final int MOUSE_FIRST = 500;
39
40     /**
41      * The id for the "mouseClicked" event. This MouseEvent occurs when a mouse
42      * button is pressed and released.
43      */

44     public static final int MOUSE_CLICKED = MOUSE_FIRST;
45
46     /**
47      * The id for the "mousePressed" event. This MouseEvent occurs when a mouse
48      * button is pushed down.
49      */

50     public static final int MOUSE_PRESSED = MOUSE_FIRST + 1;
51
52     /**
53      * The id for the "mouseReleased" event. This MouseEvent occurs when a mouse
54      * button is let up.
55      */

56     public static final int MOUSE_RELEASED = MOUSE_FIRST + 2;
57
58     /**
59      * The id for the "mouseMoved" event. This MouseMotionEvent occurs
60      * when the mouse position changes.
61      */

62     public static final int MOUSE_MOVED = MOUSE_FIRST + 3;
63
64     /**
65      * The id for the "mouseEntered" event. This MouseEvent occurs
66      * when the mouse cursor enters a graphics node's area.
67      */

68     public static final int MOUSE_ENTERED = MOUSE_FIRST + 4;
69
70     /**
71      * The id for the "mouseExited" event. This MouseEvent occurs when
72      * the mouse cursor leaves a graphics node's area.
73      */

74     public static final int MOUSE_EXITED = MOUSE_FIRST + 5;
75
76     /**
77      * The id for the "mouseDragged" event. This MouseEvent
78      * occurs when the mouse position changes while the "drag"
79      * modifier is active (for example, the shift key).
80      */

81     public static final int MOUSE_DRAGGED = MOUSE_FIRST + 6;
82
83     /**
84      * The graphics node mouse events x coordinate.
85      * The x value is relative to the graphics node that fired the event.
86      */

87     float x;
88
89     /**
90      * The graphics node mouse events y coordinate.
91      * The y value is relative to the graphics node that fired the event.
92      */

93     float y;
94
95     int clientX;
96
97     int clientY;
98
99     int screenX;
100
101     int screenY;
102
103     /**
104      * Indicates the number of quick consecutive clicks of a mouse button.
105      */

106     int clickCount;
107
108     /**
109      * Additional information. For a MOUSE_EXITED, this will contain the
110      * destination node, for a MOUSE_ENTERED the last node and for
111      * a MOUSE_DRAGGED the node under the mouse pointer.
112      */

113     GraphicsNode relatedNode = null;
114
115     /**
116      * Constructs a new graphics node mouse event.
117      * @param source the graphics node where the event originated
118      * @param id the id of this event
119      * @param when the time the event occurred
120      * @param modifiers the modifier keys down while event occurred
121      * @param x the mouse x coordinate
122      * @param y the mouse y coordinate
123      * @param screenX the mouse x coordinate relative to the screen
124      * @param screenY the mouse y coordinate relative to the screen
125      * @param clickCount the number of clicks
126      * @param relatedNode the related node
127      * @see #getRelatedNode
128      */

129     public GraphicsNodeMouseEvent(GraphicsNode source, int id,
130                                   long when, int modifiers,
131                                   float x, float y,
132                                   int clientX, int clientY,
133                                   int screenX, int screenY,
134                                   int clickCount,
135                                   GraphicsNode relatedNode) {
136         super(source, id, when, modifiers);
137         this.x = x;
138         this.y = y;
139         this.clientX = clientX;
140         this.clientY = clientY;
141         this.screenX = screenX;
142         this.screenY = screenY;
143         this.clickCount = clickCount;
144         this.relatedNode = relatedNode;
145     }
146
147     /**
148      * Constructs a new graphics node mouse event from an AWT MouseEvent.
149      * @param source the source where the event originated
150      * @param evt the AWT mouse event which is the source of this
151      * GraphicsNodeEvent
152      */

153     public GraphicsNodeMouseEvent(GraphicsNode source, MouseEvent JavaDoc evt) {
154         super(source, evt);
155         this.x = evt.getX();
156         this.y = evt.getY();
157         this.clickCount = evt.getClickCount();
158     }
159
160     /**
161      * Returns the horizontal x position of the event relative to the
162      * source graphics node.
163      * @return x a float indicating horizontal position relative to the node
164      */

165     public float getX() {
166         return x;
167     }
168
169     /**
170      * Returns the vertical y position of the event relative to the source node.
171      * @return y a float indicating vertical position relative to the node
172      */

173     public float getY() {
174         return y;
175     }
176
177     /**
178      * Returns the horizontal x position of the event relative to the
179      * source graphics node.
180      * @return x a float indicating horizontal position relative to the node
181      */

182     public float getClientX() {
183         return clientX;
184     }
185
186     /**
187      * Returns the vertical y position of the event relative to the source node.
188      * @return y a float indicating vertical position relative to the node
189      */

190     public float getClientY() {
191         return clientY;
192     }
193
194     /**
195      * Returns the horizontal x position of the event relative to the
196      * screen.
197      * @return x a float indicating horizontal position relative to the screen
198      */

199     public int getScreenX() {
200         return screenX;
201     }
202
203     /**
204      * Returns the vertical y position of the event relative to the screen.
205      * @return y a float indicating vertical position relative to the screen
206      */

207     public int getScreenY() {
208         return screenY;
209     }
210
211     /**
212      * Returns the (x, y) position of the event relative to the screen.
213      * @return a Point object containing the x and y coordinates
214      */

215     public Point JavaDoc getScreenPoint() {
216         return new Point JavaDoc(screenX, screenY);
217     }
218
219     /**
220      * Returns the (x, y) position of the event relative to the screen.
221      * @return a Point object containing the x and y coordinates
222      */

223     public Point JavaDoc getClientPoint() {
224         return new Point JavaDoc(clientX, clientY);
225     }
226
227     /**
228      * Returns the (x, y) position of the event relative to the source node.
229      * @return a Point object containing the x and y coordinates
230      */

231     public Point2D JavaDoc getPoint2D() {
232         return new Point2D.Float JavaDoc(x, y);
233     }
234
235     /**
236      * Returns the number of mouse clicks associated with this event.
237      * @return integer value for the number of clicks
238      */

239     public int getClickCount() {
240         return clickCount;
241     }
242
243     /**
244      * Returns the related node for this <code>GraphicsNodeMouseEvent</code>.
245      * For a <code>MOUSE_ENTERED</code> event it is the previous node target,
246      * for a <code>MOUSE_EXITED</code> event it is the next node target and
247      * for a <code>MOUSE_DRAGGED</code> event it is the node under the mouse
248      * pointer. Otherwise the value is <code>null</code>.
249      */

250     public GraphicsNode getRelatedNode() {
251         return relatedNode;
252     }
253 }
254
Popular Tags