001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.gvt.event;
020:
021: import java.awt.Point;
022: import java.awt.event.MouseEvent;
023: import java.awt.geom.Point2D;
024:
025: import org.apache.batik.gvt.GraphicsNode;
026:
027: /**
028: * An event which indicates that a mouse action occurred in a graphics node.
029: *
030: * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
031: * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
032: * @version $Id: GraphicsNodeMouseEvent.java 475477 2006-11-15 22:44:28Z cam $
033: */
034: public class GraphicsNodeMouseEvent extends GraphicsNodeInputEvent {
035:
036: /**
037: * The first number in the range of ids used for mouse events.
038: */
039: static final int MOUSE_FIRST = 500;
040:
041: /**
042: * The id for the "mouseClicked" event. This MouseEvent occurs when a mouse
043: * button is pressed and released.
044: */
045: public static final int MOUSE_CLICKED = MOUSE_FIRST;
046:
047: /**
048: * The id for the "mousePressed" event. This MouseEvent occurs when a mouse
049: * button is pushed down.
050: */
051: public static final int MOUSE_PRESSED = MOUSE_FIRST + 1;
052:
053: /**
054: * The id for the "mouseReleased" event. This MouseEvent occurs when a mouse
055: * button is let up.
056: */
057: public static final int MOUSE_RELEASED = MOUSE_FIRST + 2;
058:
059: /**
060: * The id for the "mouseMoved" event. This MouseMotionEvent occurs
061: * when the mouse position changes.
062: */
063: public static final int MOUSE_MOVED = MOUSE_FIRST + 3;
064:
065: /**
066: * The id for the "mouseEntered" event. This MouseEvent occurs
067: * when the mouse cursor enters a graphics node's area.
068: */
069: public static final int MOUSE_ENTERED = MOUSE_FIRST + 4;
070:
071: /**
072: * The id for the "mouseExited" event. This MouseEvent occurs when
073: * the mouse cursor leaves a graphics node's area.
074: */
075: public static final int MOUSE_EXITED = MOUSE_FIRST + 5;
076:
077: /**
078: * The id for the "mouseDragged" event. This MouseEvent
079: * occurs when the mouse position changes while the "drag"
080: * modifier is active (for example, the shift key).
081: */
082: public static final int MOUSE_DRAGGED = MOUSE_FIRST + 6;
083:
084: /**
085: * The graphics node mouse events x coordinate.
086: * The x value is relative to the graphics node that fired the event.
087: */
088: float x;
089:
090: /**
091: * The graphics node mouse events y coordinate.
092: * The y value is relative to the graphics node that fired the event.
093: */
094: float y;
095:
096: int clientX;
097:
098: int clientY;
099:
100: int screenX;
101:
102: int screenY;
103:
104: /**
105: * Indicates the number of quick consecutive clicks of a mouse button.
106: */
107: int clickCount;
108:
109: /**
110: * Additional information. For a MOUSE_EXITED, this will contain the
111: * destination node, for a MOUSE_ENTERED the last node and for
112: * a MOUSE_DRAGGED the node under the mouse pointer.
113: */
114: GraphicsNode relatedNode = null;
115:
116: /**
117: * Constructs a new graphics node mouse event.
118: * @param source the graphics node where the event originated
119: * @param id the id of this event
120: * @param when the time the event occurred
121: * @param modifiers the modifier keys down while event occurred
122: * @param x the mouse x coordinate
123: * @param y the mouse y coordinate
124: * @param screenX the mouse x coordinate relative to the screen
125: * @param screenY the mouse y coordinate relative to the screen
126: * @param clickCount the number of clicks
127: * @param relatedNode the related node
128: * @see #getRelatedNode
129: */
130: public GraphicsNodeMouseEvent(GraphicsNode source, int id,
131: long when, int modifiers, int lockState, float x, float y,
132: int clientX, int clientY, int screenX, int screenY,
133: int clickCount, GraphicsNode relatedNode) {
134: super (source, id, when, modifiers, lockState);
135: this .x = x;
136: this .y = y;
137: this .clientX = clientX;
138: this .clientY = clientY;
139: this .screenX = screenX;
140: this .screenY = screenY;
141: this .clickCount = clickCount;
142: this .relatedNode = relatedNode;
143: }
144:
145: /**
146: * Constructs a new graphics node mouse event from an AWT MouseEvent.
147: * @param source the source where the event originated
148: * @param evt the AWT mouse event which is the source of this
149: * GraphicsNodeEvent
150: */
151: public GraphicsNodeMouseEvent(GraphicsNode source, MouseEvent evt,
152: int lockState) {
153: super (source, evt, lockState);
154: this .x = evt.getX();
155: this .y = evt.getY();
156: this .clickCount = evt.getClickCount();
157: }
158:
159: /**
160: * Returns the horizontal x position of the event relative to the
161: * source graphics node.
162: * @return x a float indicating horizontal position relative to the node
163: */
164: public float getX() {
165: return x;
166: }
167:
168: /**
169: * Returns the vertical y position of the event relative to the source node.
170: * @return y a float indicating vertical position relative to the node
171: */
172: public float getY() {
173: return y;
174: }
175:
176: /**
177: * Returns the horizontal x position of the event relative to the
178: * source graphics node.
179: * @return x a float indicating horizontal position relative to the node
180: */
181: public float getClientX() {
182: return clientX;
183: }
184:
185: /**
186: * Returns the vertical y position of the event relative to the source node.
187: * @return y a float indicating vertical position relative to the node
188: */
189: public float getClientY() {
190: return clientY;
191: }
192:
193: /**
194: * Returns the horizontal x position of the event relative to the
195: * screen.
196: * @return x a float indicating horizontal position relative to the screen
197: */
198: public int getScreenX() {
199: return screenX;
200: }
201:
202: /**
203: * Returns the vertical y position of the event relative to the screen.
204: * @return y a float indicating vertical position relative to the screen
205: */
206: public int getScreenY() {
207: return screenY;
208: }
209:
210: /**
211: * Returns the (x, y) position of the event relative to the screen.
212: * @return a Point object containing the x and y coordinates
213: */
214: public Point getScreenPoint() {
215: return new Point(screenX, screenY);
216: }
217:
218: /**
219: * Returns the (x, y) position of the event relative to the screen.
220: * @return a Point object containing the x and y coordinates
221: */
222: public Point getClientPoint() {
223: return new Point(clientX, clientY);
224: }
225:
226: /**
227: * Returns the (x, y) position of the event relative to the source node.
228: * @return a Point object containing the x and y coordinates
229: */
230: public Point2D getPoint2D() {
231: return new Point2D.Float(x, y);
232: }
233:
234: /**
235: * Returns the number of mouse clicks associated with this event.
236: * @return integer value for the number of clicks
237: */
238: public int getClickCount() {
239: return clickCount;
240: }
241:
242: /**
243: * Returns the related node for this <code>GraphicsNodeMouseEvent</code>.
244: * For a <code>MOUSE_ENTERED</code> event it is the previous node target,
245: * for a <code>MOUSE_EXITED</code> event it is the next node target and
246: * for a <code>MOUSE_DRAGGED</code> event it is the node under the mouse
247: * pointer. Otherwise the value is <code>null</code>.
248: */
249: public GraphicsNode getRelatedNode() {
250: return relatedNode;
251: }
252: }
|