001 /*
002 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.awt.dnd;
027
028 import java.awt.Point;
029
030 import java.util.EventObject;
031
032 /**
033 * This class is the base class for
034 * <code>DragSourceDragEvent</code> and
035 * <code>DragSourceDropEvent</code>.
036 * <p>
037 * <code>DragSourceEvent</code>s are generated whenever the drag enters, moves
038 * over, or exits a drop site, when the drop action changes, and when the drag
039 * ends. The location for the generated <code>DragSourceEvent</code> specifies
040 * the mouse cursor location in screen coordinates at the moment this event
041 * occured.
042 * <p>
043 * In a multi-screen environment without a virtual device, the cursor location is
044 * specified in the coordinate system of the <i>initiator</i>
045 * <code>GraphicsConfiguration</code>. The <i>initiator</i>
046 * <code>GraphicsConfiguration</code> is the <code>GraphicsConfiguration</code>
047 * of the <code>Component</code> on which the drag gesture for the current drag
048 * operation was recognized. If the cursor location is outside the bounds of
049 * the initiator <code>GraphicsConfiguration</code>, the reported coordinates are
050 * clipped to fit within the bounds of that <code>GraphicsConfiguration</code>.
051 * <p>
052 * In a multi-screen environment with a virtual device, the location is specified
053 * in the corresponding virtual coordinate system. If the cursor location is
054 * outside the bounds of the virtual device the reported coordinates are
055 * clipped to fit within the bounds of the virtual device.
056 *
057 * @since 1.2
058 */
059
060 public class DragSourceEvent extends EventObject {
061
062 private static final long serialVersionUID = -763287114604032641L;
063
064 /**
065 * The <code>boolean</code> indicating whether the cursor location
066 * is specified for this event.
067 *
068 * @serial
069 */
070 private final boolean locationSpecified;
071
072 /**
073 * The horizontal coordinate for the cursor location at the moment this
074 * event occured if the cursor location is specified for this event;
075 * otherwise zero.
076 *
077 * @serial
078 */
079 private final int x;
080
081 /**
082 * The vertical coordinate for the cursor location at the moment this event
083 * occured if the cursor location is specified for this event;
084 * otherwise zero.
085 *
086 * @serial
087 */
088 private final int y;
089
090 /**
091 * Construct a <code>DragSourceEvent</code>
092 * given a specified <code>DragSourceContext</code>.
093 * The coordinates for this <code>DragSourceEvent</code>
094 * are not specified, so <code>getLocation</code> will return
095 * <code>null</code> for this event.
096 *
097 * @param dsc the <code>DragSourceContext</code>
098 *
099 * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
100 *
101 * @see #getLocation
102 */
103
104 public DragSourceEvent(DragSourceContext dsc) {
105 super (dsc);
106 locationSpecified = false;
107 this .x = 0;
108 this .y = 0;
109 }
110
111 /**
112 * Construct a <code>DragSourceEvent</code> given a specified
113 * <code>DragSourceContext</code>, and coordinates of the cursor
114 * location.
115 *
116 * @param dsc the <code>DragSourceContext</code>
117 * @param x the horizontal coordinate for the cursor location
118 * @param y the vertical coordinate for the cursor location
119 *
120 * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
121 *
122 * @since 1.4
123 */
124 public DragSourceEvent(DragSourceContext dsc, int x, int y) {
125 super (dsc);
126 locationSpecified = true;
127 this .x = x;
128 this .y = y;
129 }
130
131 /**
132 * This method returns the <code>DragSourceContext</code> that
133 * originated the event.
134 * <P>
135 * @return the <code>DragSourceContext</code> that originated the event
136 */
137
138 public DragSourceContext getDragSourceContext() {
139 return (DragSourceContext) getSource();
140 }
141
142 /**
143 * This method returns a <code>Point</code> indicating the cursor
144 * location in screen coordinates at the moment this event occured, or
145 * <code>null</code> if the cursor location is not specified for this
146 * event.
147 *
148 * @return the <code>Point</code> indicating the cursor location
149 * or <code>null</code> if the cursor location is not specified
150 * @since 1.4
151 */
152 public Point getLocation() {
153 if (locationSpecified) {
154 return new Point(x, y);
155 } else {
156 return null;
157 }
158 }
159
160 /**
161 * This method returns the horizontal coordinate of the cursor location in
162 * screen coordinates at the moment this event occured, or zero if the
163 * cursor location is not specified for this event.
164 *
165 * @return an integer indicating the horizontal coordinate of the cursor
166 * location or zero if the cursor location is not specified
167 * @since 1.4
168 */
169 public int getX() {
170 return x;
171 }
172
173 /**
174 * This method returns the vertical coordinate of the cursor location in
175 * screen coordinates at the moment this event occured, or zero if the
176 * cursor location is not specified for this event.
177 *
178 * @return an integer indicating the vertical coordinate of the cursor
179 * location or zero if the cursor location is not specified
180 * @since 1.4
181 */
182 public int getY() {
183 return y;
184 }
185 }
|