KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > dnd > DragSourceEvent


1 /*
2  * @(#)DragSourceEvent.java 1.19 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt.dnd;
9
10 import java.awt.Point JavaDoc;
11
12 import java.util.EventObject JavaDoc;
13
14 /**
15  * This class is the base class for
16  * <code>DragSourceDragEvent</code> and
17  * <code>DragSourceDropEvent</code>.
18  * <p>
19  * <code>DragSourceEvent</code>s are generated whenever the drag enters, moves
20  * over, or exits a drop site, when the drop action changes, and when the drag
21  * ends. The location for the generated <code>DragSourceEvent</code> specifies
22  * the mouse cursor location in screen coordinates at the moment this event
23  * occured.
24  * <p>
25  * In a multi-screen environment without a virtual device, the cursor location is
26  * specified in the coordinate system of the <i>initiator</i>
27  * <code>GraphicsConfiguration</code>. The <i>initiator</i>
28  * <code>GraphicsConfiguration</code> is the <code>GraphicsConfiguration</code>
29  * of the <code>Component</code> on which the drag gesture for the current drag
30  * operation was recognized. If the cursor location is outside the bounds of
31  * the initiator <code>GraphicsConfiguration</code>, the reported coordinates are
32  * clipped to fit within the bounds of that <code>GraphicsConfiguration</code>.
33  * <p>
34  * In a multi-screen environment with a virtual device, the location is specified
35  * in the corresponding virtual coordinate system. If the cursor location is
36  * outside the bounds of the virtual device the reported coordinates are
37  * clipped to fit within the bounds of the virtual device.
38  *
39  * @since 1.2
40  */

41
42 public class DragSourceEvent extends EventObject JavaDoc {
43
44     private static final long serialVersionUID = -763287114604032641L;
45
46     /**
47      * The <code>boolean</code> indicating whether the cursor location
48      * is specified for this event.
49      *
50      * @serial
51      */

52     private final boolean locationSpecified;
53
54     /**
55      * The horizontal coordinate for the cursor location at the moment this
56      * event occured if the cursor location is specified for this event;
57      * otherwise zero.
58      *
59      * @serial
60      */

61     private final int x;
62
63     /**
64      * The vertical coordinate for the cursor location at the moment this event
65      * occured if the cursor location is specified for this event;
66      * otherwise zero.
67      *
68      * @serial
69      */

70     private final int y;
71
72     /**
73      * Construct a <code>DragSourceEvent</code>
74      * given a specified <code>DragSourceContext</code>.
75      * The coordinates for this <code>DragSourceEvent</code>
76      * are not specified, so <code>getLocation</code> will return
77      * <code>null</code> for this event.
78      *
79      * @param dsc the <code>DragSourceContext</code>
80      *
81      * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
82      *
83      * @see #getLocation
84      */

85
86     public DragSourceEvent(DragSourceContext JavaDoc dsc) {
87         super(dsc);
88         locationSpecified = false;
89         this.x = 0;
90         this.y = 0;
91     }
92
93     /**
94      * Construct a <code>DragSourceEvent</code> given a specified
95      * <code>DragSourceContext</code>, and coordinates of the cursor
96      * location.
97      *
98      * @param dsc the <code>DragSourceContext</code>
99      * @param x the horizontal coordinate for the cursor location
100      * @param y the vertical coordinate for the cursor location
101      *
102      * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
103      *
104      * @since 1.4
105      */

106     public DragSourceEvent(DragSourceContext JavaDoc dsc, int x, int y) {
107         super(dsc);
108         locationSpecified = true;
109         this.x = x;
110         this.y = y;
111     }
112
113     /**
114      * This method returns the <code>DragSourceContext</code> that
115      * originated the event.
116      * <P>
117      * @return the <code>DragSourceContext</code> that originated the event
118      */

119
120     public DragSourceContext JavaDoc getDragSourceContext() {
121     return (DragSourceContext JavaDoc)getSource();
122     }
123
124     /**
125      * This method returns a <code>Point</code> indicating the cursor
126      * location in screen coordinates at the moment this event occured, or
127      * <code>null</code> if the cursor location is not specified for this
128      * event.
129      *
130      * @return the <code>Point</code> indicating the cursor location
131      * or <code>null</code> if the cursor location is not specified
132      * @since 1.4
133      */

134     public Point JavaDoc getLocation() {
135         if (locationSpecified) {
136             return new Point JavaDoc(x, y);
137         } else {
138             return null;
139         }
140     }
141
142     /**
143      * This method returns the horizontal coordinate of the cursor location in
144      * screen coordinates at the moment this event occured, or zero if the
145      * cursor location is not specified for this event.
146      *
147      * @return an integer indicating the horizontal coordinate of the cursor
148      * location or zero if the cursor location is not specified
149      * @since 1.4
150      */

151     public int getX() {
152         return x;
153     }
154
155     /**
156      * This method returns the vertical coordinate of the cursor location in
157      * screen coordinates at the moment this event occured, or zero if the
158      * cursor location is not specified for this event.
159      *
160      * @return an integer indicating the vertical coordinate of the cursor
161      * location or zero if the cursor location is not specified
162      * @since 1.4
163      */

164     public int getY() {
165         return y;
166     }
167 }
168
169
Popular Tags