< prev index next >

src/java.desktop/share/classes/java/awt/dnd/DragSourceEvent.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.dnd;
  27 
  28 import java.awt.Point;
  29 
  30 import java.util.EventObject;
  31 
  32 /**
  33  * This class is the base class for
  34  * <code>DragSourceDragEvent</code> and
  35  * <code>DragSourceDropEvent</code>.
  36  * <p>
  37  * <code>DragSourceEvent</code>s are generated whenever the drag enters, moves
  38  * over, or exits a drop site, when the drop action changes, and when the drag
  39  * ends. The location for the generated <code>DragSourceEvent</code> specifies
  40  * the mouse cursor location in screen coordinates at the moment this event
  41  * occurred.
  42  * <p>
  43  * In a multi-screen environment without a virtual device, the cursor location is
  44  * specified in the coordinate system of the <i>initiator</i>
  45  * <code>GraphicsConfiguration</code>. The <i>initiator</i>
  46  * <code>GraphicsConfiguration</code> is the <code>GraphicsConfiguration</code>
  47  * of the <code>Component</code> on which the drag gesture for the current drag
  48  * operation was recognized. If the cursor location is outside the bounds of
  49  * the initiator <code>GraphicsConfiguration</code>, the reported coordinates are
  50  * clipped to fit within the bounds of that <code>GraphicsConfiguration</code>.
  51  * <p>
  52  * In a multi-screen environment with a virtual device, the location is specified
  53  * in the corresponding virtual coordinate system. If the cursor location is
  54  * outside the bounds of the virtual device the reported coordinates are
  55  * clipped to fit within the bounds of the virtual device.
  56  *
  57  * @since 1.2
  58  */
  59 
  60 public class DragSourceEvent extends EventObject {
  61 
  62     private static final long serialVersionUID = -763287114604032641L;
  63 
  64     /**
  65      * The <code>boolean</code> indicating whether the cursor location
  66      * is specified for this event.
  67      *
  68      * @serial
  69      */
  70     private final boolean locationSpecified;
  71 
  72     /**
  73      * The horizontal coordinate for the cursor location at the moment this
  74      * event occurred if the cursor location is specified for this event;
  75      * otherwise zero.
  76      *
  77      * @serial
  78      */
  79     private final int x;
  80 
  81     /**
  82      * The vertical coordinate for the cursor location at the moment this event
  83      * occurred if the cursor location is specified for this event;
  84      * otherwise zero.
  85      *
  86      * @serial
  87      */
  88     private final int y;
  89 
  90     /**
  91      * Construct a <code>DragSourceEvent</code>
  92      * given a specified <code>DragSourceContext</code>.
  93      * The coordinates for this <code>DragSourceEvent</code>
  94      * are not specified, so <code>getLocation</code> will return
  95      * <code>null</code> for this event.
  96      *
  97      * @param dsc the <code>DragSourceContext</code>
  98      *
  99      * @throws IllegalArgumentException 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 IllegalArgumentException 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      *
 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 occurred, 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 occurred, 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() {


  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.dnd;
  27 
  28 import java.awt.Point;
  29 
  30 import java.util.EventObject;
  31 
  32 /**
  33  * This class is the base class for
  34  * {@code DragSourceDragEvent} and
  35  * {@code DragSourceDropEvent}.
  36  * <p>
  37  * {@code DragSourceEvent}s are generated whenever the drag enters, moves
  38  * over, or exits a drop site, when the drop action changes, and when the drag
  39  * ends. The location for the generated {@code DragSourceEvent} specifies
  40  * the mouse cursor location in screen coordinates at the moment this event
  41  * occurred.
  42  * <p>
  43  * In a multi-screen environment without a virtual device, the cursor location is
  44  * specified in the coordinate system of the <i>initiator</i>
  45  * {@code GraphicsConfiguration}. The <i>initiator</i>
  46  * {@code GraphicsConfiguration} is the {@code GraphicsConfiguration}
  47  * of the {@code Component} on which the drag gesture for the current drag
  48  * operation was recognized. If the cursor location is outside the bounds of
  49  * the initiator {@code GraphicsConfiguration}, the reported coordinates are
  50  * clipped to fit within the bounds of that {@code GraphicsConfiguration}.
  51  * <p>
  52  * In a multi-screen environment with a virtual device, the location is specified
  53  * in the corresponding virtual coordinate system. If the cursor location is
  54  * outside the bounds of the virtual device the reported coordinates are
  55  * clipped to fit within the bounds of the virtual device.
  56  *
  57  * @since 1.2
  58  */
  59 
  60 public class DragSourceEvent extends EventObject {
  61 
  62     private static final long serialVersionUID = -763287114604032641L;
  63 
  64     /**
  65      * The {@code boolean} indicating whether the cursor location
  66      * is specified for this event.
  67      *
  68      * @serial
  69      */
  70     private final boolean locationSpecified;
  71 
  72     /**
  73      * The horizontal coordinate for the cursor location at the moment this
  74      * event occurred if the cursor location is specified for this event;
  75      * otherwise zero.
  76      *
  77      * @serial
  78      */
  79     private final int x;
  80 
  81     /**
  82      * The vertical coordinate for the cursor location at the moment this event
  83      * occurred if the cursor location is specified for this event;
  84      * otherwise zero.
  85      *
  86      * @serial
  87      */
  88     private final int y;
  89 
  90     /**
  91      * Construct a {@code DragSourceEvent}
  92      * given a specified {@code DragSourceContext}.
  93      * The coordinates for this {@code DragSourceEvent}
  94      * are not specified, so {@code getLocation} will return
  95      * {@code null} for this event.
  96      *
  97      * @param dsc the {@code DragSourceContext}
  98      *
  99      * @throws IllegalArgumentException if {@code dsc} is {@code null}.
 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} given a specified
 113      * {@code DragSourceContext}, and coordinates of the cursor
 114      * location.
 115      *
 116      * @param dsc the {@code DragSourceContext}
 117      * @param x   the horizontal coordinate for the cursor location
 118      * @param y   the vertical coordinate for the cursor location
 119      *
 120      * @throws IllegalArgumentException if {@code dsc} is {@code null}.
 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} that
 133      * originated the event.
 134      *
 135      * @return the {@code DragSourceContext} that originated the event
 136      */
 137 
 138     public DragSourceContext getDragSourceContext() {
 139         return (DragSourceContext)getSource();
 140     }
 141 
 142     /**
 143      * This method returns a {@code Point} indicating the cursor
 144      * location in screen coordinates at the moment this event occurred, or
 145      * {@code null} if the cursor location is not specified for this
 146      * event.
 147      *
 148      * @return the {@code Point} indicating the cursor location
 149      *         or {@code null} 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 occurred, 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() {
< prev index next >