Showing the changes to java/pkg/java/awt/dnd (62 of 18352 files). Show all
Unified · Split
Binary file not shown.
| @@ -0,0 +1,80 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.Insets; | ||
| 29 | import java.awt.Point; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * During DnD operations it is possible that a user may wish to drop the | ||
| 33 | * subject of the operation on a region of a scrollable GUI control that is | ||
| 34 | * not currently visible to the user. | ||
| 35 | * <p> | ||
| 36 | * In such situations it is desirable that the GUI control detect this | ||
| 37 | * and institute a scroll operation in order to make obscured region(s) | ||
| 38 | * visible to the user. This feature is known as autoscrolling. | ||
| 39 | * <p> | ||
| 40 | * If a GUI control is both an active <code>DropTarget</code> | ||
| 41 | * and is also scrollable, it | ||
| 42 | * can receive notifications of autoscrolling gestures by the user from | ||
| 43 | * the DnD system by implementing this interface. | ||
| 44 | * <p> | ||
| 45 | * An autoscrolling gesture is initiated by the user by keeping the drag | ||
| 46 | * cursor motionless with a border region of the <code>Component</code>, | ||
| 47 | * referred to as | ||
| 48 | * the "autoscrolling region", for a predefined period of time, this will | ||
| 49 | * result in repeated scroll requests to the <code>Component</code> | ||
| 50 | * until the drag <code>Cursor</code> resumes its motion. | ||
| 51 | * | ||
| 52 | * @since 1.2 | ||
| 53 | */ | ||
| 54 | |||
| 55 | public interface Autoscroll { | ||
| 56 | |||
| 57 | /** | ||
| 58 | * This method returns the <code>Insets</code> describing | ||
| 59 | * the autoscrolling region or border relative | ||
| 60 | * to the geometry of the implementing Component. | ||
| 61 | * <P> | ||
| 62 | * This value is read once by the <code>DropTarget</code> | ||
| 63 | * upon entry of the drag <code>Cursor</code> | ||
| 64 | * into the associated <code>Component</code>. | ||
| 65 | * <P> | ||
| 66 | * @return the Insets | ||
| 67 | */ | ||
| 68 | |||
| 69 | public Insets getAutoscrollInsets(); | ||
| 70 | |||
| 71 | /** | ||
| 72 | * notify the <code>Component</code> to autoscroll | ||
| 73 | * <P> | ||
| 74 | * @param cursorLocn A <code>Point</code> indicating the | ||
| 75 | * location of the cursor that triggered this operation. | ||
| 76 | */ | ||
| 77 | |||
| 78 | public void autoscroll(Point cursorLocn); | ||
| 79 | |||
| 80 | } | ||
Binary file not shown.
| @@ -0,0 +1,83 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | /** | ||
| 29 | * This class contains constant values representing | ||
| 30 | * the type of action(s) to be performed by a Drag and Drop operation. | ||
| 31 | * @since 1.2 | ||
| 32 | */ | ||
| 33 | |||
| 34 | public final class DnDConstants { | ||
| 35 | |||
| 36 | private DnDConstants() {} // define null private constructor. | ||
| 37 | |||
| 38 | /** | ||
| 39 | * An <code>int</code> representing no action. | ||
| 40 | */ | ||
| 41 | public static final int ACTION_NONE = 0x0; | ||
| 42 | |||
| 43 | /** | ||
| 44 | * An <code>int</code> representing a "copy" action. | ||
| 45 | */ | ||
| 46 | public static final int ACTION_COPY = 0x1; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * An <code>int</code> representing a "move" action. | ||
| 50 | */ | ||
| 51 | public static final int ACTION_MOVE = 0x2; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * An <code>int</code> representing a "copy" or | ||
| 55 | * "move" action. | ||
| 56 | */ | ||
| 57 | public static final int ACTION_COPY_OR_MOVE = ACTION_COPY | ACTION_MOVE; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * An <code>int</code> representing a "link" action. | ||
| 61 | * | ||
| 62 | * The link verb is found in many, if not all native DnD platforms, and the | ||
| 63 | * actual interpretation of LINK semantics is both platform | ||
| 64 | * and application dependent. Broadly speaking, the | ||
| 65 | * semantic is "do not copy, or move the operand, but create a reference | ||
| 66 | * to it". Defining the meaning of "reference" is where ambiguity is | ||
| 67 | * introduced. | ||
| 68 | * | ||
| 69 | * The verb is provided for completeness, but its use is not recommended | ||
| 70 | * for DnD operations between logically distinct applications where | ||
| 71 | * misinterpretation of the operations semantics could lead to confusing | ||
| 72 | * results for the user. | ||
| 73 | */ | ||
| 74 | |||
| 75 | public static final int ACTION_LINK = 0x40000000; | ||
| 76 | |||
| 77 | /** | ||
| 78 | * An <code>int</code> representing a "reference" | ||
| 79 | * action (synonym for ACTION_LINK). | ||
| 80 | */ | ||
| 81 | public static final int ACTION_REFERENCE = ACTION_LINK; | ||
| 82 | |||
| 83 | } | ||
Binary file not shown.
| @@ -0,0 +1,231 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | package java.awt.dnd; | ||
| 26 | |||
| 27 | import java.awt.AWTEventMulticaster; | ||
| 28 | import java.io.ObjectOutputStream; | ||
| 29 | import java.io.IOException; | ||
| 30 | import java.util.EventListener; | ||
| 31 | |||
| 32 | |||
| 33 | /** | ||
| 34 | * A class extends <code>AWTEventMulticaster</code> to implement efficient and | ||
| 35 | * thread-safe multi-cast event dispatching for the drag-and-drop events defined | ||
| 36 | * in the java.awt.dnd package. | ||
| 37 | * | ||
| 38 | * @since 1.4 | ||
| 39 | * @see AWTEventMulticaster | ||
| 40 | */ | ||
| 41 | |||
| 42 | class DnDEventMulticaster extends AWTEventMulticaster | ||
| 43 | implements DragSourceListener, DragSourceMotionListener { | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Creates an event multicaster instance which chains listener-a | ||
| 47 | * with listener-b. Input parameters <code>a</code> and <code>b</code> | ||
| 48 | * should not be <code>null</code>, though implementations may vary in | ||
| 49 | * choosing whether or not to throw <code>NullPointerException</code> | ||
| 50 | * in that case. | ||
| 51 | * | ||
| 52 | * @param a listener-a | ||
| 53 | * @param b listener-b | ||
| 54 | */ | ||
| 55 | protected DnDEventMulticaster(EventListener a, EventListener b) { | ||
| 56 | super(a,b); | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Handles the <code>DragSourceDragEvent</code> by invoking | ||
| 61 | * <code>dragEnter</code> on listener-a and listener-b. | ||
| 62 | * | ||
| 63 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 64 | */ | ||
| 65 | public void dragEnter(DragSourceDragEvent dsde) { | ||
| 66 | ((DragSourceListener)a).dragEnter(dsde); | ||
| 67 | ((DragSourceListener)b).dragEnter(dsde); | ||
| 68 | } | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Handles the <code>DragSourceDragEvent</code> by invoking | ||
| 72 | * <code>dragOver</code> on listener-a and listener-b. | ||
| 73 | * | ||
| 74 | * @param e the <code>DragSourceDragEvent</code> | ||
| 75 | */ | ||
| 76 | public void dragOver(DragSourceDragEvent dsde) { | ||
| 77 | ((DragSourceListener)a).dragOver(dsde); | ||
| 78 | ((DragSourceListener)b).dragOver(dsde); | ||
| 79 | } | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Handles the <code>DragSourceDragEvent</code> by invoking | ||
| 83 | * <code>dropActionChanged</code> on listener-a and listener-b. | ||
| 84 | * | ||
| 85 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 86 | */ | ||
| 87 | public void dropActionChanged(DragSourceDragEvent dsde) { | ||
| 88 | ((DragSourceListener)a).dropActionChanged(dsde); | ||
| 89 | ((DragSourceListener)b).dropActionChanged(dsde); | ||
| 90 | } | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Handles the <code>DragSourceEvent</code> by invoking | ||
| 94 | * <code>dragExit</code> on listener-a and listener-b. | ||
| 95 | * | ||
| 96 | * @param dse the <code>DragSourceEvent</code> | ||
| 97 | */ | ||
| 98 | public void dragExit(DragSourceEvent dse) { | ||
| 99 | ((DragSourceListener)a).dragExit(dse); | ||
| 100 | ((DragSourceListener)b).dragExit(dse); | ||
| 101 | } | ||
| 102 | |||
| 103 | /** | ||
| 104 | * Handles the <code>DragSourceDropEvent</code> by invoking | ||
| 105 | * <code>dragDropEnd</code> on listener-a and listener-b. | ||
| 106 | * | ||
| 107 | * @param dsde the <code>DragSourceDropEvent</code> | ||
| 108 | */ | ||
| 109 | public void dragDropEnd(DragSourceDropEvent dsde) { | ||
| 110 | ((DragSourceListener)a).dragDropEnd(dsde); | ||
| 111 | ((DragSourceListener)b).dragDropEnd(dsde); | ||
| 112 | } | ||
| 113 | |||
| 114 | /** | ||
| 115 | * Handles the <code>DragSourceDragEvent</code> by invoking | ||
| 116 | * <code>dragMouseMoved</code> on listener-a and listener-b. | ||
| 117 | * | ||
| 118 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 119 | */ | ||
| 120 | public void dragMouseMoved(DragSourceDragEvent dsde) { | ||
| 121 | ((DragSourceMotionListener)a).dragMouseMoved(dsde); | ||
| 122 | ((DragSourceMotionListener)b).dragMouseMoved(dsde); | ||
| 123 | } | ||
| 124 | |||
| 125 | /** | ||
| 126 | * Adds drag-source-listener-a with drag-source-listener-b and | ||
| 127 | * returns the resulting multicast listener. | ||
| 128 | * | ||
| 129 | * @param a drag-source-listener-a | ||
| 130 | * @param b drag-source-listener-b | ||
| 131 | */ | ||
| 132 | public static DragSourceListener add(DragSourceListener a, | ||
| 133 | DragSourceListener b) { | ||
| 134 | return (DragSourceListener)addInternal(a, b); | ||
| 135 | } | ||
| 136 | |||
| 137 | /** | ||
| 138 | * Adds drag-source-motion-listener-a with drag-source-motion-listener-b and | ||
| 139 | * returns the resulting multicast listener. | ||
| 140 | * | ||
| 141 | * @param a drag-source-motion-listener-a | ||
| 142 | * @param b drag-source-motion-listener-b | ||
| 143 | */ | ||
| 144 | public static DragSourceMotionListener add(DragSourceMotionListener a, | ||
| 145 | DragSourceMotionListener b) { | ||
| 146 | return (DragSourceMotionListener)addInternal(a, b); | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Removes the old drag-source-listener from drag-source-listener-l | ||
| 151 | * and returns the resulting multicast listener. | ||
| 152 | * | ||
| 153 | * @param l drag-source-listener-l | ||
| 154 | * @param oldl the drag-source-listener being removed | ||
| 155 | */ | ||
| 156 | public static DragSourceListener remove(DragSourceListener l, | ||
| 157 | DragSourceListener oldl) { | ||
| 158 | return (DragSourceListener)removeInternal(l, oldl); | ||
| 159 | } | ||
| 160 | |||
| 161 | /** | ||
| 162 | * Removes the old drag-source-motion-listener from | ||
| 163 | * drag-source-motion-listener-l and returns the resulting multicast | ||
| 164 | * listener. | ||
| 165 | * | ||
| 166 | * @param l drag-source-motion-listener-l | ||
| 167 | * @param ol the drag-source-motion-listener being removed | ||
| 168 | */ | ||
| 169 | public static DragSourceMotionListener remove(DragSourceMotionListener l, | ||
| 170 | DragSourceMotionListener ol) { | ||
| 171 | return (DragSourceMotionListener)removeInternal(l, ol); | ||
| 172 | } | ||
| 173 | |||
| 174 | /** | ||
| 175 | * Returns the resulting multicast listener from adding listener-a | ||
| 176 | * and listener-b together. | ||
| 177 | * If listener-a is null, it returns listener-b; | ||
| 178 | * If listener-b is null, it returns listener-a | ||
| 179 | * If neither are null, then it creates and returns | ||
| 180 | * a new AWTEventMulticaster instance which chains a with b. | ||
| 181 | * @param a event listener-a | ||
| 182 | * @param b event listener-b | ||
| 183 | */ | ||
| 184 | protected static EventListener addInternal(EventListener a, EventListener b) { | ||
| 185 | if (a == null) return b; | ||
| 186 | if (b == null) return a; | ||
| 187 | return new DnDEventMulticaster(a, b); | ||
| 188 | } | ||
| 189 | |||
| 190 | /** | ||
| 191 | * Removes a listener from this multicaster and returns the | ||
| 192 | * resulting multicast listener. | ||
| 193 | * @param oldl the listener to be removed | ||
| 194 | */ | ||
| 195 | protected EventListener remove(EventListener oldl) { | ||
| 196 | if (oldl == a) return b; | ||
| 197 | if (oldl == b) return a; | ||
| 198 | EventListener a2 = removeInternal(a, oldl); | ||
| 199 | EventListener b2 = removeInternal(b, oldl); | ||
| 200 | if (a2 == a && b2 == b) { | ||
| 201 | return this; // it's not here | ||
| 202 | } | ||
| 203 | return addInternal(a2, b2); | ||
| 204 | } | ||
| 205 | |||
| 206 | /** | ||
| 207 | * Returns the resulting multicast listener after removing the | ||
| 208 | * old listener from listener-l. | ||
| 209 | * If listener-l equals the old listener OR listener-l is null, | ||
| 210 | * returns null. | ||
| 211 | * Else if listener-l is an instance of AWTEventMulticaster, | ||
| 212 | * then it removes the old listener from it. | ||
| 213 | * Else, returns listener l. | ||
| 214 | * @param l the listener being removed from | ||
| 215 | * @param oldl the listener being removed | ||
| 216 | */ | ||
| 217 | protected static EventListener removeInternal(EventListener l, EventListener oldl) { | ||
| 218 | if (l == oldl || l == null) { | ||
| 219 | return null; | ||
| 220 | } else if (l instanceof DnDEventMulticaster) { | ||
| 221 | return ((DnDEventMulticaster)l).remove(oldl); | ||
| 222 | } else { | ||
| 223 | return l; // it's not here | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | protected static void save(ObjectOutputStream s, String k, EventListener l) | ||
| 228 | throws IOException { | ||
| 229 | AWTEventMulticaster.save(s, k, l); | ||
| 230 | } | ||
| 231 | } | ||
Binary file not shown.
| @@ -0,0 +1,384 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | |||
| 27 | package java.awt.dnd; | ||
| 28 | |||
| 29 | import java.awt.Component; | ||
| 30 | import java.awt.Cursor; | ||
| 31 | |||
| 32 | import java.awt.Image; | ||
| 33 | import java.awt.Point; | ||
| 34 | |||
| 35 | import java.awt.event.InputEvent; | ||
| 36 | |||
| 37 | import java.awt.datatransfer.Transferable; | ||
| 38 | |||
| 39 | import java.util.EventObject; | ||
| 40 | |||
| 41 | import java.util.Collections; | ||
| 42 | import java.util.List; | ||
| 43 | import java.util.Iterator; | ||
| 44 | |||
| 45 | import java.io.IOException; | ||
| 46 | import java.io.ObjectInputStream; | ||
| 47 | import java.io.ObjectOutputStream; | ||
| 48 | |||
| 49 | |||
| 50 | /** | ||
| 51 | * A <code>DragGestureEvent</code> is passed | ||
| 52 | * to <code>DragGestureListener</code>'s | ||
| 53 | * dragGestureRecognized() method | ||
| 54 | * when a particular <code>DragGestureRecognizer</code> detects that a | ||
| 55 | * platform dependent drag initiating gesture has occurred | ||
| 56 | * on the <code>Component</code> that it is tracking. | ||
| 57 | * | ||
| 58 | * The {@code action} field of any {@code DragGestureEvent} instance should take one of the following | ||
| 59 | * values: | ||
| 60 | * <ul> | ||
| 61 | * <li> {@code DnDConstants.ACTION_COPY} | ||
| 62 | * <li> {@code DnDConstants.ACTION_MOVE} | ||
| 63 | * <li> {@code DnDConstants.ACTION_LINK} | ||
| 64 | * </ul> | ||
| 65 | * Assigning the value different from listed above will cause an unspecified behavior. | ||
| 66 | * | ||
| 67 | * @see java.awt.dnd.DragGestureRecognizer | ||
| 68 | * @see java.awt.dnd.DragGestureListener | ||
| 69 | * @see java.awt.dnd.DragSource | ||
| 70 | * @see java.awt.dnd.DnDConstants | ||
| 71 | */ | ||
| 72 | |||
| 73 | public class DragGestureEvent extends EventObject { | ||
| 74 | |||
| 75 | private static final long serialVersionUID = 9080172649166731306L; | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Constructs a <code>DragGestureEvent</code> object given by the | ||
| 79 | * <code>DragGestureRecognizer</code> instance firing this event, | ||
| 80 | * an {@code act} parameter representing | ||
| 81 | * the user's preferred action, an {@code ori} parameter | ||
| 82 | * indicating the origin of the drag, and a {@code List} of | ||
| 83 | * events that comprise the gesture({@code evs} parameter). | ||
| 84 | * <P> | ||
| 85 | * @param dgr The <code>DragGestureRecognizer</code> firing this event | ||
| 86 | * @param act The user's preferred action. | ||
| 87 | * For information on allowable values, see | ||
| 88 | * the class description for {@link DragGestureEvent} | ||
| 89 | * @param ori The origin of the drag | ||
| 90 | * @param evs The <code>List</code> of events that comprise the gesture | ||
| 91 | * <P> | ||
| 92 | * @throws IllegalArgumentException if any parameter equals {@code null} | ||
| 93 | * @throws IllegalArgumentException if the act parameter does not comply with | ||
| 94 | * the values given in the class | ||
| 95 | * description for {@link DragGestureEvent} | ||
| 96 | * @see java.awt.dnd.DnDConstants | ||
| 97 | */ | ||
| 98 | |||
| 99 | public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori, | ||
| 100 | List<? extends InputEvent> evs) | ||
| 101 | { | ||
| 102 | super(dgr); | ||
| 103 | |||
| 104 | if ((component = dgr.getComponent()) == null) | ||
| 105 | throw new IllegalArgumentException("null component"); | ||
| 106 | if ((dragSource = dgr.getDragSource()) == null) | ||
| 107 | throw new IllegalArgumentException("null DragSource"); | ||
| 108 | |||
| 109 | if (evs == null || evs.isEmpty()) | ||
| 110 | throw new IllegalArgumentException("null or empty list of events"); | ||
| 111 | |||
| 112 | if (act != DnDConstants.ACTION_COPY && | ||
| 113 | act != DnDConstants.ACTION_MOVE && | ||
| 114 | act != DnDConstants.ACTION_LINK) | ||
| 115 | throw new IllegalArgumentException("bad action"); | ||
| 116 | |||
| 117 | if (ori == null) throw new IllegalArgumentException("null origin"); | ||
| 118 | |||
| 119 | events = evs; | ||
| 120 | action = act; | ||
| 121 | origin = ori; | ||
| 122 | } | ||
| 123 | |||
| 124 | /** | ||
| 125 | * Returns the source as a <code>DragGestureRecognizer</code>. | ||
| 126 | * <P> | ||
| 127 | * @return the source as a <code>DragGestureRecognizer</code> | ||
| 128 | */ | ||
| 129 | |||
| 130 | public DragGestureRecognizer getSourceAsDragGestureRecognizer() { | ||
| 131 | return (DragGestureRecognizer)getSource(); | ||
| 132 | } | ||
| 133 | |||
| 134 | /** | ||
| 135 | * Returns the <code>Component</code> associated | ||
| 136 | * with this <code>DragGestureEvent</code>. | ||
| 137 | * <P> | ||
| 138 | * @return the Component | ||
| 139 | */ | ||
| 140 | |||
| 141 | public Component getComponent() { return component; } | ||
| 142 | |||
| 143 | /** | ||
| 144 | * Returns the <code>DragSource</code>. | ||
| 145 | * <P> | ||
| 146 | * @return the <code>DragSource</code> | ||
| 147 | */ | ||
| 148 | |||
| 149 | public DragSource getDragSource() { return dragSource; } | ||
| 150 | |||
| 151 | /** | ||
| 152 | * Returns a <code>Point</code> in the coordinates | ||
| 153 | * of the <code>Component</code> over which the drag originated. | ||
| 154 | * <P> | ||
| 155 | * @return the Point where the drag originated in Component coords. | ||
| 156 | */ | ||
| 157 | |||
| 158 | public Point getDragOrigin() { | ||
| 159 | return origin; | ||
| 160 | } | ||
| 161 | |||
| 162 | /** | ||
| 163 | * Returns an <code>Iterator</code> for the events | ||
| 164 | * comprising the gesture. | ||
| 165 | * <P> | ||
| 166 | * @return an Iterator for the events comprising the gesture | ||
| 167 | */ | ||
| 168 | |||
| 169 | public Iterator<InputEvent> iterator() { return events.iterator(); } | ||
| 170 | |||
| 171 | /** | ||
| 172 | * Returns an <code>Object</code> array of the | ||
| 173 | * events comprising the drag gesture. | ||
| 174 | * <P> | ||
| 175 | * @return an array of the events comprising the gesture | ||
| 176 | */ | ||
| 177 | |||
| 178 | public Object[] toArray() { return events.toArray(); } | ||
| 179 | |||
| 180 | /** | ||
| 181 | * Returns an array of the events comprising the drag gesture. | ||
| 182 | * <P> | ||
| 183 | * @param array the array of <code>EventObject</code> sub(types) | ||
| 184 | * <P> | ||
| 185 | * @return an array of the events comprising the gesture | ||
| 186 | */ | ||
| 187 | |||
| 188 | public Object[] toArray(Object[] array) { return events.toArray(array); } | ||
| 189 | |||
| 190 | /** | ||
| 191 | * Returns an <code>int</code> representing the | ||
| 192 | * action selected by the user. | ||
| 193 | * <P> | ||
| 194 | * @return the action selected by the user | ||
| 195 | */ | ||
| 196 | |||
| 197 | public int getDragAction() { return action; } | ||
| 198 | |||
| 199 | /** | ||
| 200 | * Returns the initial event that triggered the gesture. | ||
| 201 | * <P> | ||
| 202 | * @return the first "triggering" event in the sequence of the gesture | ||
| 203 | */ | ||
| 204 | |||
| 205 | public InputEvent getTriggerEvent() { | ||
| 206 | return getSourceAsDragGestureRecognizer().getTriggerEvent(); | ||
| 207 | } | ||
| 208 | |||
| 209 | /** | ||
| 210 | * Starts the drag operation given the <code>Cursor</code> for this drag | ||
| 211 | * operation and the <code>Transferable</code> representing the source data | ||
| 212 | * for this drag operation. | ||
| 213 | * <br> | ||
| 214 | * If a <code>null</code> <code>Cursor</code> is specified no exception will | ||
| 215 | * be thrown and default drag cursors will be used instead. | ||
| 216 | * <br> | ||
| 217 | * If a <code>null</code> <code>Transferable</code> is specified | ||
| 218 | * <code>NullPointerException</code> will be thrown. | ||
| 219 | * @param dragCursor The initial {@code Cursor} for this drag operation | ||
| 220 | * or {@code null} for the default cursor handling; | ||
| 221 | * see | ||
| 222 | * <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> | ||
| 223 | * for more details on the cursor handling mechanism | ||
| 224 | * during drag and drop | ||
| 225 | * @param transferable The <code>Transferable</code> representing the source | ||
| 226 | * data for this drag operation. | ||
| 227 | * | ||
| 228 | * @throws InvalidDnDOperationException if the Drag and Drop | ||
| 229 | * system is unable to initiate a drag operation, or if the user | ||
| 230 | * attempts to start a drag while an existing drag operation is | ||
| 231 | * still executing. | ||
| 232 | * @throws NullPointerException if the {@code Transferable} is {@code null} | ||
| 233 | * @since 1.4 | ||
| 234 | */ | ||
| 235 | public void startDrag(Cursor dragCursor, Transferable transferable) | ||
| 236 | throws InvalidDnDOperationException { | ||
| 237 | dragSource.startDrag(this, dragCursor, transferable, null); | ||
| 238 | } | ||
| 239 | |||
| 240 | /** | ||
| 241 | * Starts the drag given the initial <code>Cursor</code> to display, | ||
| 242 | * the <code>Transferable</code> object, | ||
| 243 | * and the <code>DragSourceListener</code> to use. | ||
| 244 | * <P> | ||
| 245 | * @param dragCursor The initial {@code Cursor} for this drag operation | ||
| 246 | * or {@code null} for the default cursor handling; | ||
| 247 | * see | ||
| 248 | * <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> | ||
| 249 | * for more details on the cursor handling mechanism | ||
| 250 | * during drag and drop | ||
| 251 | * @param transferable The source's Transferable | ||
| 252 | * @param dsl The source's DragSourceListener | ||
| 253 | * <P> | ||
| 254 | * @throws InvalidDnDOperationException if | ||
| 255 | * the Drag and Drop system is unable to | ||
| 256 | * initiate a drag operation, or if the user | ||
| 257 | * attempts to start a drag while an existing | ||
| 258 | * drag operation is still executing. | ||
| 259 | */ | ||
| 260 | |||
| 261 | public void startDrag(Cursor dragCursor, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException { | ||
| 262 | dragSource.startDrag(this, dragCursor, transferable, dsl); | ||
| 263 | } | ||
| 264 | |||
| 265 | /** | ||
| 266 | * Start the drag given the initial <code>Cursor</code> to display, | ||
| 267 | * a drag <code>Image</code>, the offset of | ||
| 268 | * the <code>Image</code>, | ||
| 269 | * the <code>Transferable</code> object, and | ||
| 270 | * the <code>DragSourceListener</code> to use. | ||
| 271 | * <P> | ||
| 272 | * @param dragCursor The initial {@code Cursor} for this drag operation | ||
| 273 | * or {@code null} for the default cursor handling; | ||
| 274 | * see | ||
| 275 | * <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> | ||
| 276 | * for more details on the cursor handling mechanism | ||
| 277 | * during drag and drop | ||
| 278 | * @param dragImage The source's dragImage | ||
| 279 | * @param imageOffset The dragImage's offset | ||
| 280 | * @param transferable The source's Transferable | ||
| 281 | * @param dsl The source's DragSourceListener | ||
| 282 | * <P> | ||
| 283 | * @throws InvalidDnDOperationException if | ||
| 284 | * the Drag and Drop system is unable to | ||
| 285 | * initiate a drag operation, or if the user | ||
| 286 | * attempts to start a drag while an existing | ||
| 287 | * drag operation is still executing. | ||
| 288 | */ | ||
| 289 | |||
| 290 | public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException { | ||
| 291 | dragSource.startDrag(this, dragCursor, dragImage, imageOffset, transferable, dsl); | ||
| 292 | } | ||
| 293 | |||
| 294 | /** | ||
| 295 | * Serializes this <code>DragGestureEvent</code>. Performs default | ||
| 296 | * serialization and then writes out this object's <code>List</code> of | ||
| 297 | * gesture events if and only if the <code>List</code> can be serialized. | ||
| 298 | * If not, <code>null</code> is written instead. In this case, a | ||
| 299 | * <code>DragGestureEvent</code> created from the resulting deserialized | ||
| 300 | * stream will contain an empty <code>List</code> of gesture events. | ||
| 301 | * | ||
| 302 | * @serialData The default serializable fields, in alphabetical order, | ||
| 303 | * followed by either a <code>List</code> instance, or | ||
| 304 | * <code>null</code>. | ||
| 305 | * @since 1.4 | ||
| 306 | */ | ||
| 307 | private void writeObject(ObjectOutputStream s) throws IOException { | ||
| 308 | s.defaultWriteObject(); | ||
| 309 | |||
| 310 | s.writeObject(SerializationTester.test(events) ? events : null); | ||
| 311 | } | ||
| 312 | |||
| 313 | /** | ||
| 314 | * Deserializes this <code>DragGestureEvent</code>. This method first | ||
| 315 | * performs default deserialization for all non-<code>transient</code> | ||
| 316 | * fields. An attempt is then made to deserialize this object's | ||
| 317 | * <code>List</code> of gesture events as well. This is first attempted | ||
| 318 | * by deserializing the field <code>events</code>, because, in releases | ||
| 319 | * prior to 1.4, a non-<code>transient</code> field of this name stored the | ||
| 320 | * <code>List</code> of gesture events. If this fails, the next object in | ||
| 321 | * the stream is used instead. If the resulting <code>List</code> is | ||
| 322 | * <code>null</code>, this object's <code>List</code> of gesture events | ||
| 323 | * is set to an empty <code>List</code>. | ||
| 324 | * | ||
| 325 | * @since 1.4 | ||
| 326 | */ | ||
| 327 | private void readObject(ObjectInputStream s) | ||
| 328 | throws ClassNotFoundException, IOException | ||
| 329 | { | ||
| 330 | ObjectInputStream.GetField f = s.readFields(); | ||
| 331 | |||
| 332 | dragSource = (DragSource)f.get("dragSource", null); | ||
| 333 | component = (Component)f.get("component", null); | ||
| 334 | origin = (Point)f.get("origin", null); | ||
| 335 | action = f.get("action", 0); | ||
| 336 | |||
| 337 | // Pre-1.4 support. 'events' was previously non-transient | ||
| 338 | try { | ||
| 339 | events = (List)f.get("events", null); | ||
| 340 | } catch (IllegalArgumentException e) { | ||
| 341 | // 1.4-compatible byte stream. 'events' was written explicitly | ||
| 342 | events = (List)s.readObject(); | ||
| 343 | } | ||
| 344 | |||
| 345 | // Implementation assumes 'events' is never null. | ||
| 346 | if (events == null) { | ||
| 347 | events = Collections.EMPTY_LIST; | ||
| 348 | } | ||
| 349 | } | ||
| 350 | |||
| 351 | /* | ||
| 352 | * fields | ||
| 353 | */ | ||
| 354 | |||
| 355 | private transient List events; | ||
| 356 | |||
| 357 | /** | ||
| 358 | * The DragSource associated with this DragGestureEvent. | ||
| 359 | * | ||
| 360 | * @serial | ||
| 361 | */ | ||
| 362 | private DragSource dragSource; | ||
| 363 | |||
| 364 | /** | ||
| 365 | * The Component associated with this DragGestureEvent. | ||
| 366 | * | ||
| 367 | * @serial | ||
| 368 | */ | ||
| 369 | private Component component; | ||
| 370 | |||
| 371 | /** | ||
| 372 | * The origin of the drag. | ||
| 373 | * | ||
| 374 | * @serial | ||
| 375 | */ | ||
| 376 | private Point origin; | ||
| 377 | |||
| 378 | /** | ||
| 379 | * The user's preferred action. | ||
| 380 | * | ||
| 381 | * @serial | ||
| 382 | */ | ||
| 383 | private int action; | ||
| 384 | } | ||
Binary file not shown.
| @@ -0,0 +1,64 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | |||
| 27 | |||
| 28 | package java.awt.dnd; | ||
| 29 | |||
| 30 | import java.util.EventListener; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * The listener interface for receiving drag gesture events. | ||
| 34 | * This interface is intended for a drag gesture recognition | ||
| 35 | * implementation. See a specification for {@code DragGestureRecognizer} | ||
| 36 | * for details on how to register the listener interface. | ||
| 37 | * Upon recognition of a drag gesture the {@code | ||
| 38 | * DragGestureRecognizer} calls this interface's | ||
| 39 | * {@link #dragGestureRecognized dragGestureRecognized()} | ||
| 40 | * method and passes a {@code DragGestureEvent}. | ||
| 41 | |||
| 42 | * | ||
| 43 | * @see java.awt.dnd.DragGestureRecognizer | ||
| 44 | * @see java.awt.dnd.DragGestureEvent | ||
| 45 | * @see java.awt.dnd.DragSource | ||
| 46 | */ | ||
| 47 | |||
| 48 | public interface DragGestureListener extends EventListener { | ||
| 49 | |||
| 50 | /** | ||
| 51 | * This method is invoked by the {@code DragGestureRecognizer} | ||
| 52 | * when the {@code DragGestureRecognizer} detects a platform-dependent | ||
| 53 | * drag initiating gesture. To intiate the drag and drop operation, | ||
| 54 | * if approtiate, {@link DragGestureEvent#startDrag startDrag()} method on | ||
| 55 | * the {@code DragGestureEvent} has to be invoked. | ||
| 56 | * <P> | ||
| 57 | * @see java.awt.dnd.DragGestureRecognizer | ||
| 58 | * @see java.awt.dnd.DragGestureEvent | ||
| 59 | * @param dge the <code>DragGestureEvent</code> describing | ||
| 60 | * the gesture that has just occurred | ||
| 61 | */ | ||
| 62 | |||
| 63 | void dragGestureRecognized(DragGestureEvent dge); | ||
| 64 | } | ||
Binary file not shown.
| @@ -0,0 +1,466 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.event.InputEvent; | ||
| 29 | import java.awt.Component; | ||
| 30 | import java.awt.Point; | ||
| 31 | |||
| 32 | import java.util.TooManyListenersException; | ||
| 33 | import java.util.ArrayList; | ||
| 34 | |||
| 35 | import java.io.IOException; | ||
| 36 | import java.io.ObjectInputStream; | ||
| 37 | import java.io.ObjectOutputStream; | ||
| 38 | import java.io.Serializable; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * The <code>DragGestureRecognizer</code> is an | ||
| 42 | * abstract base class for the specification | ||
| 43 | * of a platform-dependent listener that can be associated with a particular | ||
| 44 | * <code>Component</code> in order to | ||
| 45 | * identify platform-dependent drag initiating gestures. | ||
| 46 | * <p> | ||
| 47 | * The appropriate <code>DragGestureRecognizer</code> | ||
| 48 | * subclass instance is obtained from the | ||
| 49 | * {@link DragSource} asssociated with | ||
| 50 | * a particular <code>Component</code>, or from the <code>Toolkit</code> object via its | ||
| 51 | * {@link java.awt.Toolkit#createDragGestureRecognizer createDragGestureRecognizer()} | ||
| 52 | * method. | ||
| 53 | * <p> | ||
| 54 | * Once the <code>DragGestureRecognizer</code> | ||
| 55 | * is associated with a particular <code>Component</code> | ||
| 56 | * it will register the appropriate listener interfaces on that | ||
| 57 | * <code>Component</code> | ||
| 58 | * in order to track the input events delivered to the <code>Component</code>. | ||
| 59 | * <p> | ||
| 60 | * Once the <code>DragGestureRecognizer</code> identifies a sequence of events | ||
| 61 | * on the <code>Component</code> as a drag initiating gesture, it will notify | ||
| 62 | * its unicast <code>DragGestureListener</code> by | ||
| 63 | * invoking its | ||
| 64 | * {@link java.awt.dnd.DragGestureListener#dragGestureRecognized gestureRecognized()} | ||
| 65 | * method. | ||
| 66 | * <P> | ||
| 67 | * When a concrete <code>DragGestureRecognizer</code> | ||
| 68 | * instance detects a drag initiating | ||
| 69 | * gesture on the <code>Component</code> it is associated with, | ||
| 70 | * it fires a {@link DragGestureEvent} to | ||
| 71 | * the <code>DragGestureListener</code> registered on | ||
| 72 | * its unicast event source for <code>DragGestureListener</code> | ||
| 73 | * events. This <code>DragGestureListener</code> is responsible | ||
| 74 | * for causing the associated | ||
| 75 | * <code>DragSource</code> to start the Drag and Drop operation (if | ||
| 76 | * appropriate). | ||
| 77 | * <P> | ||
| 78 | * @author Laurence P. G. Cable | ||
| 79 | * @see java.awt.dnd.DragGestureListener | ||
| 80 | * @see java.awt.dnd.DragGestureEvent | ||
| 81 | * @see java.awt.dnd.DragSource | ||
| 82 | */ | ||
| 83 | |||
| 84 | public abstract class DragGestureRecognizer implements Serializable { | ||
| 85 | |||
| 86 | private static final long serialVersionUID = 8996673345831063337L; | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Construct a new <code>DragGestureRecognizer</code> | ||
| 90 | * given the <code>DragSource</code> to be used | ||
| 91 | * in this Drag and Drop operation, the <code>Component</code> | ||
| 92 | * this <code>DragGestureRecognizer</code> should "observe" | ||
| 93 | * for drag initiating gestures, the action(s) supported | ||
| 94 | * for this Drag and Drop operation, and the | ||
| 95 | * <code>DragGestureListener</code> to notify | ||
| 96 | * once a drag initiating gesture has been detected. | ||
| 97 | * <P> | ||
| 98 | * @param ds the <code>DragSource</code> this | ||
| 99 | * <code>DragGestureRecognizer</code> | ||
| 100 | * will use to process the Drag and Drop operation | ||
| 101 | * | ||
| 102 | * @param c the <code>Component</code> | ||
| 103 | * this <code>DragGestureRecognizer</code> | ||
| 104 | * should "observe" the event stream to, | ||
| 105 | * in order to detect a drag initiating gesture. | ||
| 106 | * If this value is <code>null</code>, the | ||
| 107 | * <code>DragGestureRecognizer</code> | ||
| 108 | * is not associated with any <code>Component</code>. | ||
| 109 | * | ||
| 110 | * @param sa the set (logical OR) of the | ||
| 111 | * <code>DnDConstants</code> | ||
| 112 | * that this Drag and Drop operation will support | ||
| 113 | * | ||
| 114 | * @param dgl the <code>DragGestureRecognizer</code> | ||
| 115 | * to notify when a drag gesture is detected | ||
| 116 | * <P> | ||
| 117 | * @throws <code>IllegalArgumentException</code> | ||
| 118 | * if ds is <code>null</code>. | ||
| 119 | */ | ||
| 120 | |||
| 121 | protected DragGestureRecognizer(DragSource ds, Component c, int sa, DragGestureListener dgl) { | ||
| 122 | super(); | ||
| 123 | |||
| 124 | if (ds == null) throw new IllegalArgumentException("null DragSource"); | ||
| 125 | |||
| 126 | dragSource = ds; | ||
| 127 | component = c; | ||
| 128 | sourceActions = sa & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK); | ||
| 129 | |||
| 130 | try { | ||
| 131 | if (dgl != null) addDragGestureListener(dgl); | ||
| 132 | } catch (TooManyListenersException tmle) { | ||
| 133 | // cant happen ... | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | /** | ||
| 138 | * Construct a new <code>DragGestureRecognizer</code> | ||
| 139 | * given the <code>DragSource</code> to be used in this | ||
| 140 | * Drag and Drop | ||
| 141 | * operation, the <code>Component</code> this | ||
| 142 | * <code>DragGestureRecognizer</code> should "observe" | ||
| 143 | * for drag initiating gestures, and the action(s) | ||
| 144 | * supported for this Drag and Drop operation. | ||
| 145 | * <P> | ||
| 146 | * @param ds the <code>DragSource</code> this | ||
| 147 | * <code>DragGestureRecognizer</code> will use to | ||
| 148 | * process the Drag and Drop operation | ||
| 149 | * | ||
| 150 | * @param c the <code>Component</code> this | ||
| 151 | * <code>DragGestureRecognizer</code> should "observe" the event | ||
| 152 | * stream to, in order to detect a drag initiating gesture. | ||
| 153 | * If this value is <code>null</code>, the | ||
| 154 | * <code>DragGestureRecognizer</code> | ||
| 155 | * is not associated with any <code>Component</code>. | ||
| 156 | * | ||
| 157 | * @param sa the set (logical OR) of the <code>DnDConstants</code> | ||
| 158 | * that this Drag and Drop operation will support | ||
| 159 | * <P> | ||
| 160 | * @throws <code>IllegalArgumentException</code> | ||
| 161 | * if ds is <code>null</code>. | ||
| 162 | */ | ||
| 163 | |||
| 164 | protected DragGestureRecognizer(DragSource ds, Component c, int sa) { | ||
| 165 | this(ds, c, sa, null); | ||
| 166 | } | ||
| 167 | |||
| 168 | /** | ||
| 169 | * Construct a new <code>DragGestureRecognizer</code> | ||
| 170 | * given the <code>DragSource</code> to be used | ||
| 171 | * in this Drag and Drop operation, and | ||
| 172 | * the <code>Component</code> this | ||
| 173 | * <code>DragGestureRecognizer</code> | ||
| 174 | * should "observe" for drag initiating gestures. | ||
| 175 | * <P> | ||
| 176 | * @param ds the <code>DragSource</code> this | ||
| 177 | * <code>DragGestureRecognizer</code> | ||
| 178 | * will use to process the Drag and Drop operation | ||
| 179 | * | ||
| 180 | * @param c the <code>Component</code> | ||
| 181 | * this <code>DragGestureRecognizer</code> | ||
| 182 | * should "observe" the event stream to, | ||
| 183 | * in order to detect a drag initiating gesture. | ||
| 184 | * If this value is <code>null</code>, | ||
| 185 | * the <code>DragGestureRecognizer</code> | ||
| 186 | * is not associated with any <code>Component</code>. | ||
| 187 | * <P> | ||
| 188 | * @throws <code>IllegalArgumentException</code> | ||
| 189 | * if ds is <code>null</code>. | ||
| 190 | */ | ||
| 191 | |||
| 192 | protected DragGestureRecognizer(DragSource ds, Component c) { | ||
| 193 | this(ds, c, DnDConstants.ACTION_NONE); | ||
| 194 | } | ||
| 195 | |||
| 196 | /** | ||
| 197 | * Construct a new <code>DragGestureRecognizer</code> | ||
| 198 | * given the <code>DragSource</code> to be used in this | ||
| 199 | * Drag and Drop operation. | ||
| 200 | * <P> | ||
| 201 | * @param ds the <code>DragSource</code> this | ||
| 202 | * <code>DragGestureRecognizer</code> will | ||
| 203 | * use to process the Drag and Drop operation | ||
| 204 | * <P> | ||
| 205 | * @throws <code>IllegalArgumentException</code> | ||
| 206 | * if ds is <code>null</code>. | ||
| 207 | */ | ||
| 208 | |||
| 209 | protected DragGestureRecognizer(DragSource ds) { | ||
| 210 | this(ds, null); | ||
| 211 | } | ||
| 212 | |||
| 213 | /** | ||
| 214 | * register this DragGestureRecognizer's Listeners with the Component | ||
| 215 | * | ||
| 216 | * subclasses must override this method | ||
| 217 | */ | ||
| 218 | |||
| 219 | protected abstract void registerListeners(); | ||
| 220 | |||
| 221 | /** | ||
| 222 | * unregister this DragGestureRecognizer's Listeners with the Component | ||
| 223 | * | ||
| 224 | * subclasses must override this method | ||
| 225 | */ | ||
| 226 | |||
| 227 | protected abstract void unregisterListeners(); | ||
| 228 | |||
| 229 | /** | ||
| 230 | * This method returns the <code>DragSource</code> | ||
| 231 | * this <code>DragGestureRecognizer</code> | ||
| 232 | * will use in order to process the Drag and Drop | ||
| 233 | * operation. | ||
| 234 | * <P> | ||
| 235 | * @return the DragSource | ||
| 236 | */ | ||
| 237 | |||
| 238 | public DragSource getDragSource() { return dragSource; } | ||
| 239 | |||
| 240 | /** | ||
| 241 | * This method returns the <code>Component</code> | ||
| 242 | * that is to be "observed" by the | ||
| 243 | * <code>DragGestureRecognizer</code> | ||
| 244 | * for drag initiating gestures. | ||
| 245 | * <P> | ||
| 246 | * @return The Component this DragGestureRecognizer | ||
| 247 | * is associated with | ||
| 248 | */ | ||
| 249 | |||
| 250 | public synchronized Component getComponent() { return component; } | ||
| 251 | |||
| 252 | /** | ||
| 253 | * set the Component that the DragGestureRecognizer is associated with | ||
| 254 | * | ||
| 255 | * registerListeners() and unregisterListeners() are called as a side | ||
| 256 | * effect as appropriate. | ||
| 257 | * <P> | ||
| 258 | * @param c The <code>Component</code> or <code>null</code> | ||
| 259 | */ | ||
| 260 | |||
| 261 | public synchronized void setComponent(Component c) { | ||
| 262 | if (component != null && dragGestureListener != null) | ||
| 263 | unregisterListeners(); | ||
| 264 | |||
| 265 | component = c; | ||
| 266 | |||
| 267 | if (component != null && dragGestureListener != null) | ||
| 268 | registerListeners(); | ||
| 269 | } | ||
| 270 | |||
| 271 | /** | ||
| 272 | * This method returns an int representing the | ||
| 273 | * type of action(s) this Drag and Drop | ||
| 274 | * operation will support. | ||
| 275 | * <P> | ||
| 276 | * @return the currently permitted source action(s) | ||
| 277 | */ | ||
| 278 | |||
| 279 | public synchronized int getSourceActions() { return sourceActions; } | ||
| 280 | |||
| 281 | /** | ||
| 282 | * This method sets the permitted source drag action(s) | ||
| 283 | * for this Drag and Drop operation. | ||
| 284 | * <P> | ||
| 285 | * @param actions the permitted source drag action(s) | ||
| 286 | */ | ||
| 287 | |||
| 288 | public synchronized void setSourceActions(int actions) { | ||
| 289 | sourceActions = actions & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK); | ||
| 290 | } | ||
| 291 | |||
| 292 | /** | ||
| 293 | * This method returns the first event in the | ||
| 294 | * series of events that initiated | ||
| 295 | * the Drag and Drop operation. | ||
| 296 | * <P> | ||
| 297 | * @return the initial event that triggered the drag gesture | ||
| 298 | */ | ||
| 299 | |||
| 300 | public InputEvent getTriggerEvent() { return events.isEmpty() ? null : (InputEvent)events.get(0); } | ||
| 301 | |||
| 302 | /** | ||
| 303 | * Reset the Recognizer, if its currently recognizing a gesture, ignore | ||
| 304 | * it. | ||
| 305 | */ | ||
| 306 | |||
| 307 | public void resetRecognizer() { events.clear(); } | ||
| 308 | |||
| 309 | /** | ||
| 310 | * Register a new <code>DragGestureListener</code>. | ||
| 311 | * <P> | ||
| 312 | * @param dgl the <code>DragGestureListener</code> to register | ||
| 313 | * with this <code>DragGestureRecognizer</code>. | ||
| 314 | * <P> | ||
| 315 | * @throws java.util.TooManyListenersException if a | ||
| 316 | * <code>DragGestureListener</code> has already been added. | ||
| 317 | */ | ||
| 318 | |||
| 319 | public synchronized void addDragGestureListener(DragGestureListener dgl) throws TooManyListenersException { | ||
| 320 | if (dragGestureListener != null) | ||
| 321 | throw new TooManyListenersException(); | ||
| 322 | else { | ||
| 323 | dragGestureListener = dgl; | ||
| 324 | |||
| 325 | if (component != null) registerListeners(); | ||
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | /** | ||
| 330 | * unregister the current DragGestureListener | ||
| 331 | * <P> | ||
| 332 | * @param dgl the <code>DragGestureListener</code> to unregister | ||
| 333 | * from this <code>DragGestureRecognizer</code> | ||
| 334 | * <P> | ||
| 335 | * @throws <code>IllegalArgumentException</code> if | ||
| 336 | * dgl is not (equal to) the currently registered <code>DragGestureListener</code>. | ||
| 337 | */ | ||
| 338 | |||
| 339 | public synchronized void removeDragGestureListener(DragGestureListener dgl) { | ||
| 340 | if (dragGestureListener == null || !dragGestureListener.equals(dgl)) | ||
| 341 | throw new IllegalArgumentException(); | ||
| 342 | else { | ||
| 343 | dragGestureListener = null; | ||
| 344 | |||
| 345 | if (component != null) unregisterListeners(); | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | /** | ||
| 350 | * Notify the DragGestureListener that a Drag and Drop initiating | ||
| 351 | * gesture has occurred. Then reset the state of the Recognizer. | ||
| 352 | * <P> | ||
| 353 | * @param dragAction The action initially selected by the users gesture | ||
| 354 | * @param p The point (in Component coords) where the gesture originated | ||
| 355 | */ | ||
| 356 | protected synchronized void fireDragGestureRecognized(int dragAction, Point p) { | ||
| 357 | try { | ||
| 358 | if (dragGestureListener != null) { | ||
| 359 | dragGestureListener.dragGestureRecognized(new DragGestureEvent(this, dragAction, p, events)); | ||
| 360 | } | ||
| 361 | } finally { | ||
| 362 | events.clear(); | ||
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 | /** | ||
| 367 | * Listeners registered on the Component by this Recognizer shall record | ||
| 368 | * all Events that are recognized as part of the series of Events that go | ||
| 369 | * to comprise a Drag and Drop initiating gesture via this API. | ||
| 370 | *<P> | ||
| 371 | * This method is used by a <code>DragGestureRecognizer</code> | ||
| 372 | * implementation to add an <code>InputEvent</code> | ||
| 373 | * subclass (that it believes is one in a series | ||
| 374 | * of events that comprise a Drag and Drop operation) | ||
| 375 | * to the array of events that this | ||
| 376 | * <code>DragGestureRecognizer</code> maintains internally. | ||
| 377 | * <P> | ||
| 378 | * @param awtie the <code>InputEvent</code> | ||
| 379 | * to add to this <code>DragGestureRecognizer</code>'s | ||
| 380 | * internal array of events. Note that <code>null</code> | ||
| 381 | * is not a valid value, and will be ignored. | ||
| 382 | */ | ||
| 383 | |||
| 384 | protected synchronized void appendEvent(InputEvent awtie) { | ||
| 385 | events.add(awtie); | ||
| 386 | } | ||
| 387 | |||
| 388 | /** | ||
| 389 | * Serializes this <code>DragGestureRecognizer</code>. This method first | ||
| 390 | * performs default serialization. Then, this object's | ||
| 391 | * <code>DragGestureListener</code> is written out if and only if it can be | ||
| 392 | * serialized. If not, <code>null</code> is written instead. | ||
| 393 | * | ||
| 394 | * @serialData The default serializable fields, in alphabetical order, | ||
| 395 | * followed by either a <code>DragGestureListener</code>, or | ||
| 396 | * <code>null</code>. | ||
| 397 | * @since 1.4 | ||
| 398 | */ | ||
| 399 | private void writeObject(ObjectOutputStream s) throws IOException { | ||
| 400 | s.defaultWriteObject(); | ||
| 401 | |||
| 402 | s.writeObject(SerializationTester.test(dragGestureListener) | ||
| 403 | ? dragGestureListener : null); | ||
| 404 | } | ||
| 405 | |||
| 406 | /** | ||
| 407 | * Deserializes this <code>DragGestureRecognizer</code>. This method first | ||
| 408 | * performs default deserialization for all non-<code>transient</code> | ||
| 409 | * fields. This object's <code>DragGestureListener</code> is then | ||
| 410 | * deserialized as well by using the next object in the stream. | ||
| 411 | * | ||
| 412 | * @since 1.4 | ||
| 413 | */ | ||
| 414 | private void readObject(ObjectInputStream s) | ||
| 415 | throws ClassNotFoundException, IOException | ||
| 416 | { | ||
| 417 | s.defaultReadObject(); | ||
| 418 | |||
| 419 | dragGestureListener = (DragGestureListener)s.readObject(); | ||
| 420 | } | ||
| 421 | |||
| 422 | /* | ||
| 423 | * fields | ||
| 424 | */ | ||
| 425 | |||
| 426 | /** | ||
| 427 | * The <code>DragSource</code> | ||
| 428 | * associated with this | ||
| 429 | * <code>DragGestureRecognizer</code>. | ||
| 430 | * | ||
| 431 | * @serial | ||
| 432 | */ | ||
| 433 | protected DragSource dragSource; | ||
| 434 | |||
| 435 | /** | ||
| 436 | * The <code>Component</code> | ||
| 437 | * associated with this <code>DragGestureRecognizer</code>. | ||
| 438 | * | ||
| 439 | * @serial | ||
| 440 | */ | ||
| 441 | protected Component component; | ||
| 442 | |||
| 443 | /** | ||
| 444 | * The <code>DragGestureListener</code> | ||
| 445 | * associated with this <code>DragGestureRecognizer</code>. | ||
| 446 | */ | ||
| 447 | protected transient DragGestureListener dragGestureListener; | ||
| 448 | |||
| 449 | /** | ||
| 450 | * An <code>int</code> representing | ||
| 451 | * the type(s) of action(s) used | ||
| 452 | * in this Drag and Drop operation. | ||
| 453 | * | ||
| 454 | * @serial | ||
| 455 | */ | ||
| 456 | protected int sourceActions; | ||
| 457 | |||
| 458 | /** | ||
| 459 | * The list of events (in order) that | ||
| 460 | * the <code>DragGestureRecognizer</code> | ||
| 461 | * "recognized" as a "gesture" that triggers a drag. | ||
| 462 | * | ||
| 463 | * @serial | ||
| 464 | */ | ||
| 465 | protected ArrayList<InputEvent> events = new ArrayList<InputEvent>(1); | ||
| 466 | } | ||
Binary file not shown.
| @@ -0,0 +1,922 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.Component; | ||
| 29 | import java.awt.Cursor; | ||
| 30 | import java.awt.GraphicsEnvironment; | ||
| 31 | import java.awt.HeadlessException; | ||
| 32 | import java.awt.Image; | ||
| 33 | import java.awt.Point; | ||
| 34 | import java.awt.Toolkit; | ||
| 35 | import java.awt.datatransfer.FlavorMap; | ||
| 36 | import java.awt.datatransfer.SystemFlavorMap; | ||
| 37 | import java.awt.datatransfer.Transferable; | ||
| 38 | import java.awt.dnd.peer.DragSourceContextPeer; | ||
| 39 | import java.io.IOException; | ||
| 40 | import java.io.ObjectInputStream; | ||
| 41 | import java.io.ObjectOutputStream; | ||
| 42 | import java.io.Serializable; | ||
| 43 | import java.security.AccessController; | ||
| 44 | import java.util.EventListener; | ||
| 45 | import sun.awt.dnd.SunDragSourceContextPeer; | ||
| 46 | import sun.security.action.GetIntegerAction; | ||
| 47 | |||
| 48 | |||
| 49 | /** | ||
| 50 | * The <code>DragSource</code> is the entity responsible | ||
| 51 | * for the initiation of the Drag | ||
| 52 | * and Drop operation, and may be used in a number of scenarios: | ||
| 53 | * <UL> | ||
| 54 | * <LI>1 default instance per JVM for the lifetime of that JVM. | ||
| 55 | * <LI>1 instance per class of potential Drag Initiator object (e.g | ||
| 56 | * TextField). [implementation dependent] | ||
| 57 | * <LI>1 per instance of a particular | ||
| 58 | * <code>Component</code>, or application specific | ||
| 59 | * object associated with a <code>Component</code> | ||
| 60 | * instance in the GUI. [implementation dependent] | ||
| 61 | * <LI>Some other arbitrary association. [implementation dependent] | ||
| 62 | *</UL> | ||
| 63 | * | ||
| 64 | * Once the <code>DragSource</code> is | ||
| 65 | * obtained, a <code>DragGestureRecognizer</code> should | ||
| 66 | * also be obtained to associate the <code>DragSource</code> | ||
| 67 | * with a particular | ||
| 68 | * <code>Component</code>. | ||
| 69 | * <P> | ||
| 70 | * The initial interpretation of the user's gesture, | ||
| 71 | * and the subsequent starting of the drag operation | ||
| 72 | * are the responsibility of the implementing | ||
| 73 | * <code>Component</code>, which is usually | ||
| 74 | * implemented by a <code>DragGestureRecognizer</code>. | ||
| 75 | *<P> | ||
| 76 | * When a drag gesture occurs, the | ||
| 77 | * <code>DragSource</code>'s | ||
| 78 | * startDrag() method shall be | ||
| 79 | * invoked in order to cause processing | ||
| 80 | * of the user's navigational | ||
| 81 | * gestures and delivery of Drag and Drop | ||
| 82 | * protocol notifications. A | ||
| 83 | * <code>DragSource</code> shall only | ||
| 84 | * permit a single Drag and Drop operation to be | ||
| 85 | * current at any one time, and shall | ||
| 86 | * reject any further startDrag() requests | ||
| 87 | * by throwing an <code>IllegalDnDOperationException</code> | ||
| 88 | * until such time as the extant operation is complete. | ||
| 89 | * <P> | ||
| 90 | * The startDrag() method invokes the | ||
| 91 | * createDragSourceContext() method to | ||
| 92 | * instantiate an appropriate | ||
| 93 | * <code>DragSourceContext</code> | ||
| 94 | * and associate the <code>DragSourceContextPeer</code> | ||
| 95 | * with that. | ||
| 96 | * <P> | ||
| 97 | * If the Drag and Drop System is | ||
| 98 | * unable to initiate a drag operation for | ||
| 99 | * some reason, the startDrag() method throws | ||
| 100 | * a <code>java.awt.dnd.InvalidDnDOperationException</code> | ||
| 101 | * to signal such a condition. Typically this | ||
| 102 | * exception is thrown when the underlying platform | ||
| 103 | * system is either not in a state to | ||
| 104 | * initiate a drag, or the parameters specified are invalid. | ||
| 105 | * <P> | ||
| 106 | * Note that during the drag, the | ||
| 107 | * set of operations exposed by the source | ||
| 108 | * at the start of the drag operation may not change | ||
| 109 | * until the operation is complete. | ||
| 110 | * The operation(s) are constant for the | ||
| 111 | * duration of the operation with respect to the | ||
| 112 | * <code>DragSource</code>. | ||
| 113 | * | ||
| 114 | * @since 1.2 | ||
| 115 | */ | ||
| 116 | |||
| 117 | public class DragSource implements Serializable { | ||
| 118 | |||
| 119 | private static final long serialVersionUID = 6236096958971414066L; | ||
| 120 | |||
| 121 | /* | ||
| 122 | * load a system default cursor | ||
| 123 | */ | ||
| 124 | |||
| 125 | private static Cursor load(String name) { | ||
| 126 | if (GraphicsEnvironment.isHeadless()) { | ||
| 127 | return null; | ||
| 128 | } | ||
| 129 | |||
| 130 | try { | ||
| 131 | return (Cursor)Toolkit.getDefaultToolkit().getDesktopProperty(name); | ||
| 132 | } catch (Exception e) { | ||
| 133 | e.printStackTrace(); | ||
| 134 | |||
| 135 | throw new RuntimeException("failed to load system cursor: " + name + " : " + e.getMessage()); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | /** | ||
| 141 | * The default <code>Cursor</code> to use with a copy operation indicating | ||
| 142 | * that a drop is currently allowed. <code>null</code> if | ||
| 143 | * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>. | ||
| 144 | * | ||
| 145 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 146 | */ | ||
| 147 | public static final Cursor DefaultCopyDrop = | ||
| 148 | load("DnD.Cursor.CopyDrop"); | ||
| 149 | |||
| 150 | /** | ||
| 151 | * The default <code>Cursor</code> to use with a move operation indicating | ||
| 152 | * that a drop is currently allowed. <code>null</code> if | ||
| 153 | * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>. | ||
| 154 | * | ||
| 155 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 156 | */ | ||
| 157 | public static final Cursor DefaultMoveDrop = | ||
| 158 | load("DnD.Cursor.MoveDrop"); | ||
| 159 | |||
| 160 | /** | ||
| 161 | * The default <code>Cursor</code> to use with a link operation indicating | ||
| 162 | * that a drop is currently allowed. <code>null</code> if | ||
| 163 | * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>. | ||
| 164 | * | ||
| 165 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 166 | */ | ||
| 167 | public static final Cursor DefaultLinkDrop = | ||
| 168 | load("DnD.Cursor.LinkDrop"); | ||
| 169 | |||
| 170 | /** | ||
| 171 | * The default <code>Cursor</code> to use with a copy operation indicating | ||
| 172 | * that a drop is currently not allowed. <code>null</code> if | ||
| 173 | * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>. | ||
| 174 | * | ||
| 175 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 176 | */ | ||
| 177 | public static final Cursor DefaultCopyNoDrop = | ||
| 178 | load("DnD.Cursor.CopyNoDrop"); | ||
| 179 | |||
| 180 | /** | ||
| 181 | * The default <code>Cursor</code> to use with a move operation indicating | ||
| 182 | * that a drop is currently not allowed. <code>null</code> if | ||
| 183 | * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>. | ||
| 184 | * | ||
| 185 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 186 | */ | ||
| 187 | public static final Cursor DefaultMoveNoDrop = | ||
| 188 | load("DnD.Cursor.MoveNoDrop"); | ||
| 189 | |||
| 190 | /** | ||
| 191 | * The default <code>Cursor</code> to use with a link operation indicating | ||
| 192 | * that a drop is currently not allowed. <code>null</code> if | ||
| 193 | * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>. | ||
| 194 | * | ||
| 195 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 196 | */ | ||
| 197 | public static final Cursor DefaultLinkNoDrop = | ||
| 198 | load("DnD.Cursor.LinkNoDrop"); | ||
| 199 | |||
| 200 | private static final DragSource dflt = | ||
| 201 | (GraphicsEnvironment.isHeadless()) ? null : new DragSource(); | ||
| 202 | |||
| 203 | /** | ||
| 204 | * Internal constants for serialization. | ||
| 205 | */ | ||
| 206 | static final String dragSourceListenerK = "dragSourceL"; | ||
| 207 | static final String dragSourceMotionListenerK = "dragSourceMotionL"; | ||
| 208 | |||
| 209 | /** | ||
| 210 | * Gets the <code>DragSource</code> object associated with | ||
| 211 | * the underlying platform. | ||
| 212 | * | ||
| 213 | * @return the platform DragSource | ||
| 214 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 215 | * returns true | ||
| 216 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 217 | */ | ||
| 218 | public static DragSource getDefaultDragSource() { | ||
| 219 | if (GraphicsEnvironment.isHeadless()) { | ||
| 220 | throw new HeadlessException(); | ||
| 221 | } else { | ||
| 222 | return dflt; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 226 | /** | ||
| 227 | * Reports | ||
| 228 | * whether or not drag | ||
| 229 | * <code>Image</code> support | ||
| 230 | * is available on the underlying platform. | ||
| 231 | * <P> | ||
| 232 | * @return if the Drag Image support is available on this platform | ||
| 233 | */ | ||
| 234 | |||
| 235 | public static boolean isDragImageSupported() { | ||
| 236 | Toolkit t = Toolkit.getDefaultToolkit(); | ||
| 237 | |||
| 238 | Boolean supported; | ||
| 239 | |||
| 240 | try { | ||
| 241 | supported = (Boolean)Toolkit.getDefaultToolkit().getDesktopProperty("DnD.isDragImageSupported"); | ||
| 242 | |||
| 243 | return supported.booleanValue(); | ||
| 244 | } catch (Exception e) { | ||
| 245 | return false; | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
| 249 | /** | ||
| 250 | * Creates a new <code>DragSource</code>. | ||
| 251 | * | ||
| 252 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 253 | * returns true | ||
| 254 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 255 | */ | ||
| 256 | public DragSource() throws HeadlessException { | ||
| 257 | if (GraphicsEnvironment.isHeadless()) { | ||
| 258 | throw new HeadlessException(); | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | /** | ||
| 263 | * Start a drag, given the <code>DragGestureEvent</code> | ||
| 264 | * that initiated the drag, the initial | ||
| 265 | * <code>Cursor</code> to use, | ||
| 266 | * the <code>Image</code> to drag, | ||
| 267 | * the offset of the <code>Image</code> origin | ||
| 268 | * from the hotspot of the <code>Cursor</code> at | ||
| 269 | * the instant of the trigger, | ||
| 270 | * the <code>Transferable</code> subject data | ||
| 271 | * of the drag, the <code>DragSourceListener</code>, | ||
| 272 | * and the <code>FlavorMap</code>. | ||
| 273 | * <P> | ||
| 274 | * @param trigger the <code>DragGestureEvent</code> that initiated the drag | ||
| 275 | * @param dragCursor the initial {@code Cursor} for this drag operation | ||
| 276 | * or {@code null} for the default cursor handling; | ||
| 277 | * see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> | ||
| 278 | * for more details on the cursor handling mechanism during drag and drop | ||
| 279 | * @param dragImage the image to drag or {@code null} | ||
| 280 | * @param imageOffset the offset of the <code>Image</code> origin from the hotspot | ||
| 281 | * of the <code>Cursor</code> at the instant of the trigger | ||
| 282 | * @param transferable the subject data of the drag | ||
| 283 | * @param dsl the <code>DragSourceListener</code> | ||
| 284 | * @param flavorMap the <code>FlavorMap</code> to use, or <code>null</code> | ||
| 285 | * <P> | ||
| 286 | * @throws java.awt.dnd.InvalidDnDOperationException | ||
| 287 | * if the Drag and Drop | ||
| 288 | * system is unable to initiate a drag operation, or if the user | ||
| 289 | * attempts to start a drag while an existing drag operation | ||
| 290 | * is still executing | ||
| 291 | */ | ||
| 292 | |||
| 293 | public void startDrag(DragGestureEvent trigger, | ||
| 294 | Cursor dragCursor, | ||
| 295 | Image dragImage, | ||
| 296 | Point imageOffset, | ||
| 297 | Transferable transferable, | ||
| 298 | DragSourceListener dsl, | ||
| 299 | FlavorMap flavorMap) throws InvalidDnDOperationException { | ||
| 300 | |||
| 301 | SunDragSourceContextPeer.setDragDropInProgress(true); | ||
| 302 | |||
| 303 | try { | ||
| 304 | if (flavorMap != null) this.flavorMap = flavorMap; | ||
| 305 | |||
| 306 | DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger); | ||
| 307 | |||
| 308 | DragSourceContext dsc = createDragSourceContext(dscp, | ||
| 309 | trigger, | ||
| 310 | dragCursor, | ||
| 311 | dragImage, | ||
| 312 | imageOffset, | ||
| 313 | transferable, | ||
| 314 | dsl | ||
| 315 | ); | ||
| 316 | |||
| 317 | if (dsc == null) { | ||
| 318 | throw new InvalidDnDOperationException(); | ||
| 319 | } | ||
| 320 | |||
| 321 | dscp.startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw | ||
| 322 | } catch (RuntimeException e) { | ||
| 323 | SunDragSourceContextPeer.setDragDropInProgress(false); | ||
| 324 | throw e; | ||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 328 | /** | ||
| 329 | * Start a drag, given the <code>DragGestureEvent</code> | ||
| 330 | * that initiated the drag, the initial | ||
| 331 | * <code>Cursor</code> to use, | ||
| 332 | * the <code>Transferable</code> subject data | ||
| 333 | * of the drag, the <code>DragSourceListener</code>, | ||
| 334 | * and the <code>FlavorMap</code>. | ||
| 335 | * <P> | ||
| 336 | * @param trigger the <code>DragGestureEvent</code> that | ||
| 337 | * initiated the drag | ||
| 338 | * @param dragCursor the initial {@code Cursor} for this drag operation | ||
| 339 | * or {@code null} for the default cursor handling; | ||
| 340 | * see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> | ||
| 341 | * for more details on the cursor handling mechanism during drag and drop | ||
| 342 | * @param transferable the subject data of the drag | ||
| 343 | * @param dsl the <code>DragSourceListener</code> | ||
| 344 | * @param flavorMap the <code>FlavorMap</code> to use or <code>null</code> | ||
| 345 | * <P> | ||
| 346 | * @throws java.awt.dnd.InvalidDnDOperationException | ||
| 347 | * if the Drag and Drop | ||
| 348 | * system is unable to initiate a drag operation, or if the user | ||
| 349 | * attempts to start a drag while an existing drag operation | ||
| 350 | * is still executing | ||
| 351 | */ | ||
| 352 | |||
| 353 | public void startDrag(DragGestureEvent trigger, | ||
| 354 | Cursor dragCursor, | ||
| 355 | Transferable transferable, | ||
| 356 | DragSourceListener dsl, | ||
| 357 | FlavorMap flavorMap) throws InvalidDnDOperationException { | ||
| 358 | startDrag(trigger, dragCursor, null, null, transferable, dsl, flavorMap); | ||
| 359 | } | ||
| 360 | |||
| 361 | /** | ||
| 362 | * Start a drag, given the <code>DragGestureEvent</code> | ||
| 363 | * that initiated the drag, the initial <code>Cursor</code> | ||
| 364 | * to use, | ||
| 365 | * the <code>Image</code> to drag, | ||
| 366 | * the offset of the <code>Image</code> origin | ||
| 367 | * from the hotspot of the <code>Cursor</code> | ||
| 368 | * at the instant of the trigger, | ||
| 369 | * the subject data of the drag, and | ||
| 370 | * the <code>DragSourceListener</code>. | ||
| 371 | * <P> | ||
| 372 | * @param trigger the <code>DragGestureEvent</code> that initiated the drag | ||
| 373 | * @param dragCursor the initial {@code Cursor} for this drag operation | ||
| 374 | * or {@code null} for the default cursor handling; | ||
| 375 | * see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> | ||
| 376 | * for more details on the cursor handling mechanism during drag and drop | ||
| 377 | * @param dragImage the <code>Image</code> to drag or <code>null</code> | ||
| 378 | * @param dragOffset the offset of the <code>Image</code> origin from the hotspot | ||
| 379 | * of the <code>Cursor</code> at the instant of the trigger | ||
| 380 | * @param transferable the subject data of the drag | ||
| 381 | * @param dsl the <code>DragSourceListener</code> | ||
| 382 | * <P> | ||
| 383 | * @throws java.awt.dnd.InvalidDnDOperationException | ||
| 384 | * if the Drag and Drop | ||
| 385 | * system is unable to initiate a drag operation, or if the user | ||
| 386 | * attempts to start a drag while an existing drag operation | ||
| 387 | * is still executing | ||
| 388 | */ | ||
| 389 | |||
| 390 | public void startDrag(DragGestureEvent trigger, | ||
| 391 | Cursor dragCursor, | ||
| 392 | Image dragImage, | ||
| 393 | Point dragOffset, | ||
| 394 | Transferable transferable, | ||
| 395 | DragSourceListener dsl) throws InvalidDnDOperationException { | ||
| 396 | startDrag(trigger, dragCursor, dragImage, dragOffset, transferable, dsl, null); | ||
| 397 | } | ||
| 398 | |||
| 399 | /** | ||
| 400 | * Start a drag, given the <code>DragGestureEvent</code> | ||
| 401 | * that initiated the drag, the initial | ||
| 402 | * <code>Cursor</code> to | ||
| 403 | * use, | ||
| 404 | * the <code>Transferable</code> subject data | ||
| 405 | * of the drag, and the <code>DragSourceListener</code>. | ||
| 406 | * <P> | ||
| 407 | * @param trigger the <code>DragGestureEvent</code> that initiated the drag | ||
| 408 | * @param dragCursor the initial {@code Cursor} for this drag operation | ||
| 409 | * or {@code null} for the default cursor handling; | ||
| 410 | * see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> class | ||
| 411 | * for more details on the cursor handling mechanism during drag and drop | ||
| 412 | * @param transferable the subject data of the drag | ||
| 413 | * @param dsl the <code>DragSourceListener</code> | ||
| 414 | * <P> | ||
| 415 | * @throws java.awt.dnd.InvalidDnDOperationException | ||
| 416 | * if the Drag and Drop | ||
| 417 | * system is unable to initiate a drag operation, or if the user | ||
| 418 | * attempts to start a drag while an existing drag operation | ||
| 419 | * is still executing | ||
| 420 | */ | ||
| 421 | |||
| 422 | public void startDrag(DragGestureEvent trigger, | ||
| 423 | Cursor dragCursor, | ||
| 424 | Transferable transferable, | ||
| 425 | DragSourceListener dsl) throws InvalidDnDOperationException { | ||
| 426 | startDrag(trigger, dragCursor, null, null, transferable, dsl, null); | ||
| 427 | } | ||
| 428 | |||
| 429 | /** | ||
| 430 | * Creates the {@code DragSourceContext} to handle the current drag | ||
| 431 | * operation. | ||
| 432 | * <p> | ||
| 433 | * To incorporate a new <code>DragSourceContext</code> | ||
| 434 | * subclass, subclass <code>DragSource</code> and | ||
| 435 | * override this method. | ||
| 436 | * <p> | ||
| 437 | * If <code>dragImage</code> is <code>null</code>, no image is used | ||
| 438 | * to represent the drag over feedback for this drag operation, but | ||
| 439 | * <code>NullPointerException</code> is not thrown. | ||
| 440 | * <p> | ||
| 441 | * If <code>dsl</code> is <code>null</code>, no drag source listener | ||
| 442 | * is registered with the created <code>DragSourceContext</code>, | ||
| 443 | * but <code>NullPointerException</code> is not thrown. | ||
| 444 | * | ||
| 445 | * @param dscp The <code>DragSourceContextPeer</code> for this drag | ||
| 446 | * @param dgl The <code>DragGestureEvent</code> that triggered the | ||
| 447 | * drag | ||
| 448 | * @param dragCursor The initial {@code Cursor} for this drag operation | ||
| 449 | * or {@code null} for the default cursor handling; | ||
| 450 | * see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> class | ||
| 451 | * for more details on the cursor handling mechanism during drag and drop | ||
| 452 | * @param dragImage The <code>Image</code> to drag or <code>null</code> | ||
| 453 | * @param imageOffset The offset of the <code>Image</code> origin from the | ||
| 454 | * hotspot of the cursor at the instant of the trigger | ||
| 455 | * @param t The subject data of the drag | ||
| 456 | * @param dsl The <code>DragSourceListener</code> | ||
| 457 | * | ||
| 458 | * @return the <code>DragSourceContext</code> | ||
| 459 | * | ||
| 460 | * @throws NullPointerException if <code>dscp</code> is <code>null</code> | ||
| 461 | * @throws NullPointerException if <code>dgl</code> is <code>null</code> | ||
| 462 | * @throws NullPointerException if <code>dragImage</code> is not | ||
| 463 | * <code>null</code> and <code>imageOffset</code> is <code>null</code> | ||
| 464 | * @throws NullPointerException if <code>t</code> is <code>null</code> | ||
| 465 | * @throws IllegalArgumentException if the <code>Component</code> | ||
| 466 | * associated with the trigger event is <code>null</code>. | ||
| 467 | * @throws IllegalArgumentException if the <code>DragSource</code> for the | ||
| 468 | * trigger event is <code>null</code>. | ||
| 469 | * @throws IllegalArgumentException if the drag action for the | ||
| 470 | * trigger event is <code>DnDConstants.ACTION_NONE</code>. | ||
| 471 | * @throws IllegalArgumentException if the source actions for the | ||
| 472 | * <code>DragGestureRecognizer</code> associated with the trigger | ||
| 473 | * event are equal to <code>DnDConstants.ACTION_NONE</code>. | ||
| 474 | */ | ||
| 475 | |||
| 476 | protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl) { | ||
| 477 | return new DragSourceContext(dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl); | ||
| 478 | } | ||
| 479 | |||
| 480 | /** | ||
| 481 | * This method returns the | ||
| 482 | * <code>FlavorMap</code> for this <code>DragSource</code>. | ||
| 483 | * <P> | ||
| 484 | * @return the <code>FlavorMap</code> for this <code>DragSource</code> | ||
| 485 | */ | ||
| 486 | |||
| 487 | public FlavorMap getFlavorMap() { return flavorMap; } | ||
| 488 | |||
| 489 | /** | ||
| 490 | * Creates a new <code>DragGestureRecognizer</code> | ||
| 491 | * that implements the specified | ||
| 492 | * abstract subclass of | ||
| 493 | * <code>DragGestureRecognizer</code>, and | ||
| 494 | * sets the specified <code>Component</code> | ||
| 495 | * and <code>DragGestureListener</code> on | ||
| 496 | * the newly created object. | ||
| 497 | * <P> | ||
| 498 | * @param recognizerAbstractClass the requested abstract type | ||
| 499 | * @param actions the permitted source drag actions | ||
| 500 | * @param c the <code>Component</code> target | ||
| 501 | * @param dgl the <code>DragGestureListener</code> to notify | ||
| 502 | * <P> | ||
| 503 | * @return the new <code>DragGestureRecognizer</code> or <code>null</code> | ||
| 504 | * if the <code>Toolkit.createDragGestureRecognizer</code> method | ||
| 505 | * has no implementation available for | ||
| 506 | * the requested <code>DragGestureRecognizer</code> | ||
| 507 | * subclass and returns <code>null</code> | ||
| 508 | */ | ||
| 509 | |||
| 510 | public <T extends DragGestureRecognizer> T | ||
| 511 | createDragGestureRecognizer(Class<T> recognizerAbstractClass, | ||
| 512 | Component c, int actions, | ||
| 513 | DragGestureListener dgl) | ||
| 514 | { | ||
| 515 | return Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizerAbstractClass, this, c, actions, dgl); | ||
| 516 | } | ||
| 517 | |||
| 518 | |||
| 519 | /** | ||
| 520 | * Creates a new <code>DragGestureRecognizer</code> | ||
| 521 | * that implements the default | ||
| 522 | * abstract subclass of <code>DragGestureRecognizer</code> | ||
| 523 | * for this <code>DragSource</code>, | ||
| 524 | * and sets the specified <code>Component</code> | ||
| 525 | * and <code>DragGestureListener</code> on the | ||
| 526 | * newly created object. | ||
| 527 | * | ||
| 528 | * For this <code>DragSource</code> | ||
| 529 | * the default is <code>MouseDragGestureRecognizer</code>. | ||
| 530 | * <P> | ||
| 531 | * @param c the <code>Component</code> target for the recognizer | ||
| 532 | * @param actions the permitted source actions | ||
| 533 | * @param dgl the <code>DragGestureListener</code> to notify | ||
| 534 | * <P> | ||
| 535 | * @return the new <code>DragGestureRecognizer</code> or <code>null</code> | ||
| 536 | * if the <code>Toolkit.createDragGestureRecognizer</code> method | ||
| 537 | * has no implementation available for | ||
| 538 | * the requested <code>DragGestureRecognizer</code> | ||
| 539 | * subclass and returns <code>null</code> | ||
| 540 | */ | ||
| 541 | |||
| 542 | public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c, int actions, DragGestureListener dgl) { | ||
| 543 | return Toolkit.getDefaultToolkit().createDragGestureRecognizer(MouseDragGestureRecognizer.class, this, c, actions, dgl); | ||
| 544 | } | ||
| 545 | |||
| 546 | /** | ||
| 547 | * Adds the specified <code>DragSourceListener</code> to this | ||
| 548 | * <code>DragSource</code> to receive drag source events during drag | ||
| 549 | * operations intiated with this <code>DragSource</code>. | ||
| 550 | * If a <code>null</code> listener is specified, no action is taken and no | ||
| 551 | * exception is thrown. | ||
| 552 | * | ||
| 553 | * @param dsl the <code>DragSourceListener</code> to add | ||
| 554 | * | ||
| 555 | * @see #removeDragSourceListener | ||
| 556 | * @see #getDragSourceListeners | ||
| 557 | * @since 1.4 | ||
| 558 | */ | ||
| 559 | public void addDragSourceListener(DragSourceListener dsl) { | ||
| 560 | if (dsl != null) { | ||
| 561 | synchronized (this) { | ||
| 562 | listener = DnDEventMulticaster.add(listener, dsl); | ||
| 563 | } | ||
| 564 | } | ||
| 565 | } | ||
| 566 | |||
| 567 | /** | ||
| 568 | * Removes the specified <code>DragSourceListener</code> from this | ||
| 569 | * <code>DragSource</code>. | ||
| 570 | * If a <code>null</code> listener is specified, no action is taken and no | ||
| 571 | * exception is thrown. | ||
| 572 | * If the listener specified by the argument was not previously added to | ||
| 573 | * this <code>DragSource</code>, no action is taken and no exception | ||
| 574 | * is thrown. | ||
| 575 | * | ||
| 576 | * @param dsl the <code>DragSourceListener</code> to remove | ||
| 577 | * | ||
| 578 | * @see #addDragSourceListener | ||
| 579 | * @see #getDragSourceListeners | ||
| 580 | * @since 1.4 | ||
| 581 | */ | ||
| 582 | public void removeDragSourceListener(DragSourceListener dsl) { | ||
| 583 | if (dsl != null) { | ||
| 584 | synchronized (this) { | ||
| 585 | listener = DnDEventMulticaster.remove(listener, dsl); | ||
| 586 | } | ||
| 587 | } | ||
| 588 | } | ||
| 589 | |||
| 590 | /** | ||
| 591 | * Gets all the <code>DragSourceListener</code>s | ||
| 592 | * registered with this <code>DragSource</code>. | ||
| 593 | * | ||
| 594 | * @return all of this <code>DragSource</code>'s | ||
| 595 | * <code>DragSourceListener</code>s or an empty array if no | ||
| 596 | * such listeners are currently registered | ||
| 597 | * | ||
| 598 | * @see #addDragSourceListener | ||
| 599 | * @see #removeDragSourceListener | ||
| 600 | * @since 1.4 | ||
| 601 | */ | ||
| 602 | public DragSourceListener[] getDragSourceListeners() { | ||
| 603 | return (DragSourceListener[])getListeners(DragSourceListener.class); | ||
| 604 | } | ||
| 605 | |||
| 606 | /** | ||
| 607 | * Adds the specified <code>DragSourceMotionListener</code> to this | ||
| 608 | * <code>DragSource</code> to receive drag motion events during drag | ||
| 609 | * operations intiated with this <code>DragSource</code>. | ||
| 610 | * If a <code>null</code> listener is specified, no action is taken and no | ||
| 611 | * exception is thrown. | ||
| 612 | * | ||
| 613 | * @param dsml the <code>DragSourceMotionListener</code> to add | ||
| 614 | * | ||
| 615 | * @see #removeDragSourceMotionListener | ||
| 616 | * @see #getDragSourceMotionListeners | ||
| 617 | * @since 1.4 | ||
| 618 | */ | ||
| 619 | public void addDragSourceMotionListener(DragSourceMotionListener dsml) { | ||
| 620 | if (dsml != null) { | ||
| 621 | synchronized (this) { | ||
| 622 | motionListener = DnDEventMulticaster.add(motionListener, dsml); | ||
| 623 | } | ||
| 624 | } | ||
| 625 | } | ||
| 626 | |||
| 627 | /** | ||
| 628 | * Removes the specified <code>DragSourceMotionListener</code> from this | ||
| 629 | * <code>DragSource</code>. | ||
| 630 | * If a <code>null</code> listener is specified, no action is taken and no | ||
| 631 | * exception is thrown. | ||
| 632 | * If the listener specified by the argument was not previously added to | ||
| 633 | * this <code>DragSource</code>, no action is taken and no exception | ||
| 634 | * is thrown. | ||
| 635 | * | ||
| 636 | * @param dsml the <code>DragSourceMotionListener</code> to remove | ||
| 637 | * | ||
| 638 | * @see #addDragSourceMotionListener | ||
| 639 | * @see #getDragSourceMotionListeners | ||
| 640 | * @since 1.4 | ||
| 641 | */ | ||
| 642 | public void removeDragSourceMotionListener(DragSourceMotionListener dsml) { | ||
| 643 | if (dsml != null) { | ||
| 644 | synchronized (this) { | ||
| 645 | motionListener = DnDEventMulticaster.remove(motionListener, dsml); | ||
| 646 | } | ||
| 647 | } | ||
| 648 | } | ||
| 649 | |||
| 650 | /** | ||
| 651 | * Gets all of the <code>DragSourceMotionListener</code>s | ||
| 652 | * registered with this <code>DragSource</code>. | ||
| 653 | * | ||
| 654 | * @return all of this <code>DragSource</code>'s | ||
| 655 | * <code>DragSourceMotionListener</code>s or an empty array if no | ||
| 656 | * such listeners are currently registered | ||
| 657 | * | ||
| 658 | * @see #addDragSourceMotionListener | ||
| 659 | * @see #removeDragSourceMotionListener | ||
| 660 | * @since 1.4 | ||
| 661 | */ | ||
| 662 | public DragSourceMotionListener[] getDragSourceMotionListeners() { | ||
| 663 | return (DragSourceMotionListener[]) | ||
| 664 | getListeners(DragSourceMotionListener.class); | ||
| 665 | } | ||
| 666 | |||
| 667 | /** | ||
| 668 | * Gets all the objects currently registered as | ||
| 669 | * <code><em>Foo</em>Listener</code>s upon this <code>DragSource</code>. | ||
| 670 | * <code><em>Foo</em>Listener</code>s are registered using the | ||
| 671 | * <code>add<em>Foo</em>Listener</code> method. | ||
| 672 | * | ||
| 673 | * @param listenerType the type of listeners requested; this parameter | ||
| 674 | * should specify an interface that descends from | ||
| 675 | * <code>java.util.EventListener</code> | ||
| 676 | * @return an array of all objects registered as | ||
| 677 | * <code><em>Foo</em>Listener</code>s on this | ||
| 678 | * <code>DragSource</code>, or an empty array if no such listeners | ||
| 679 | * have been added | ||
| 680 | * @exception <code>ClassCastException</code> if <code>listenerType</code> | ||
| 681 | * doesn't specify a class or interface that implements | ||
| 682 | * <code>java.util.EventListener</code> | ||
| 683 | * | ||
| 684 | * @see #getDragSourceListeners | ||
| 685 | * @see #getDragSourceMotionListeners | ||
| 686 | * @since 1.4 | ||
| 687 | */ | ||
| 688 | public <T extends EventListener> T[] getListeners(Class<T> listenerType) { | ||
| 689 | EventListener l = null; | ||
| 690 | if (listenerType == DragSourceListener.class) { | ||
| 691 | l = listener; | ||
| 692 | } else if (listenerType == DragSourceMotionListener.class) { | ||
| 693 | l = motionListener; | ||
| 694 | } | ||
| 695 | return DnDEventMulticaster.getListeners(l, listenerType); | ||
| 696 | } | ||
| 697 | |||
| 698 | /** | ||
| 699 | * This method calls <code>dragEnter</code> on the | ||
| 700 | * <code>DragSourceListener</code>s registered with this | ||
| 701 | * <code>DragSource</code>, and passes them the specified | ||
| 702 | * <code>DragSourceDragEvent</code>. | ||
| 703 | * | ||
| 704 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 705 | */ | ||
| 706 | void processDragEnter(DragSourceDragEvent dsde) { | ||
| 707 | DragSourceListener dsl = listener; | ||
| 708 | if (dsl != null) { | ||
| 709 | dsl.dragEnter(dsde); | ||
| 710 | } | ||
| 711 | } | ||
| 712 | |||
| 713 | /** | ||
| 714 | * This method calls <code>dragOver</code> on the | ||
| 715 | * <code>DragSourceListener</code>s registered with this | ||
| 716 | * <code>DragSource</code>, and passes them the specified | ||
| 717 | * <code>DragSourceDragEvent</code>. | ||
| 718 | * | ||
| 719 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 720 | */ | ||
| 721 | void processDragOver(DragSourceDragEvent dsde) { | ||
| 722 | DragSourceListener dsl = listener; | ||
| 723 | if (dsl != null) { | ||
| 724 | dsl.dragOver(dsde); | ||
| 725 | } | ||
| 726 | } | ||
| 727 | |||
| 728 | /** | ||
| 729 | * This method calls <code>dropActionChanged</code> on the | ||
| 730 | * <code>DragSourceListener</code>s registered with this | ||
| 731 | * <code>DragSource</code>, and passes them the specified | ||
| 732 | * <code>DragSourceDragEvent</code>. | ||
| 733 | * | ||
| 734 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 735 | */ | ||
| 736 | void processDropActionChanged(DragSourceDragEvent dsde) { | ||
| 737 | DragSourceListener dsl = listener; | ||
| 738 | if (dsl != null) { | ||
| 739 | dsl.dropActionChanged(dsde); | ||
| 740 | } | ||
| 741 | } | ||
| 742 | |||
| 743 | /** | ||
| 744 | * This method calls <code>dragExit</code> on the | ||
| 745 | * <code>DragSourceListener</code>s registered with this | ||
| 746 | * <code>DragSource</code>, and passes them the specified | ||
| 747 | * <code>DragSourceEvent</code>. | ||
| 748 | * | ||
| 749 | * @param dse the <code>DragSourceEvent</code> | ||
| 750 | */ | ||
| 751 | void processDragExit(DragSourceEvent dse) { | ||
| 752 | DragSourceListener dsl = listener; | ||
| 753 | if (dsl != null) { | ||
| 754 | dsl.dragExit(dse); | ||
| 755 | } | ||
| 756 | } | ||
| 757 | |||
| 758 | /** | ||
| 759 | * This method calls <code>dragDropEnd</code> on the | ||
| 760 | * <code>DragSourceListener</code>s registered with this | ||
| 761 | * <code>DragSource</code>, and passes them the specified | ||
| 762 | * <code>DragSourceDropEvent</code>. | ||
| 763 | * | ||
| 764 | * @param dsde the <code>DragSourceEvent</code> | ||
| 765 | */ | ||
| 766 | void processDragDropEnd(DragSourceDropEvent dsde) { | ||
| 767 | DragSourceListener dsl = listener; | ||
| 768 | if (dsl != null) { | ||
| 769 | dsl.dragDropEnd(dsde); | ||
| 770 | } | ||
| 771 | } | ||
| 772 | |||
| 773 | /** | ||
| 774 | * This method calls <code>dragMouseMoved</code> on the | ||
| 775 | * <code>DragSourceMotionListener</code>s registered with this | ||
| 776 | * <code>DragSource</code>, and passes them the specified | ||
| 777 | * <code>DragSourceDragEvent</code>. | ||
| 778 | * | ||
| 779 | * @param dsde the <code>DragSourceEvent</code> | ||
| 780 | */ | ||
| 781 | void processDragMouseMoved(DragSourceDragEvent dsde) { | ||
| 782 | DragSourceMotionListener dsml = motionListener; | ||
| 783 | if (dsml != null) { | ||
| 784 | dsml.dragMouseMoved(dsde); | ||
| 785 | } | ||
| 786 | } | ||
| 787 | |||
| 788 | /** | ||
| 789 | * Serializes this <code>DragSource</code>. This method first performs | ||
| 790 | * default serialization. Next, it writes out this object's | ||
| 791 | * <code>FlavorMap</code> if and only if it can be serialized. If not, | ||
| 792 | * <code>null</code> is written instead. Next, it writes out | ||
| 793 | * <code>Serializable</code> listeners registered with this | ||
| 794 | * object. Listeners are written in a <code>null</code>-terminated sequence | ||
| 795 | * of 0 or more pairs. The pair consists of a <code>String</code> and an | ||
| 796 | * <code>Object</code>; the <code>String</code> indicates the type of the | ||
| 797 | * <code>Object</code> and is one of the following: | ||
| 798 | * <ul> | ||
| 799 | * <li><code>dragSourceListenerK</code> indicating a | ||
| 800 | * <code>DragSourceListener</code> object; | ||
| 801 | * <li><code>dragSourceMotionListenerK</code> indicating a | ||
| 802 | * <code>DragSourceMotionListener</code> object. | ||
| 803 | * </ul> | ||
| 804 | * | ||
| 805 | * @serialData Either a <code>FlavorMap</code> instance, or | ||
| 806 | * <code>null</code>, followed by a <code>null</code>-terminated | ||
| 807 | * sequence of 0 or more pairs; the pair consists of a | ||
| 808 | * <code>String</code> and an <code>Object</code>; the | ||
| 809 | * <code>String</code> indicates the type of the <code>Object</code> | ||
| 810 | * and is one of the following: | ||
| 811 | * <ul> | ||
| 812 | * <li><code>dragSourceListenerK</code> indicating a | ||
| 813 | * <code>DragSourceListener</code> object; | ||
| 814 | * <li><code>dragSourceMotionListenerK</code> indicating a | ||
| 815 | * <code>DragSourceMotionListener</code> object. | ||
| 816 | * </ul>. | ||
| 817 | * @since 1.4 | ||
| 818 | */ | ||
| 819 | private void writeObject(ObjectOutputStream s) throws IOException { | ||
| 820 | s.defaultWriteObject(); | ||
| 821 | |||
| 822 | s.writeObject(SerializationTester.test(flavorMap) ? flavorMap : null); | ||
| 823 | |||
| 824 | DnDEventMulticaster.save(s, dragSourceListenerK, listener); | ||
| 825 | DnDEventMulticaster.save(s, dragSourceMotionListenerK, motionListener); | ||
| 826 | s.writeObject(null); | ||
| 827 | } | ||
| 828 | |||
| 829 | /** | ||
| 830 | * Deserializes this <code>DragSource</code>. This method first performs | ||
| 831 | * default deserialization. Next, this object's <code>FlavorMap</code> is | ||
| 832 | * deserialized by using the next object in the stream. | ||
| 833 | * If the resulting <code>FlavorMap</code> is <code>null</code>, this | ||
| 834 | * object's <code>FlavorMap</code> is set to the default FlavorMap for | ||
| 835 | * this thread's <code>ClassLoader</code>. | ||
| 836 | * Next, this object's listeners are deserialized by reading a | ||
| 837 | * <code>null</code>-terminated sequence of 0 or more key/value pairs | ||
| 838 | * from the stream: | ||
| 839 | * <ul> | ||
| 840 | * <li>If a key object is a <code>String</code> equal to | ||
| 841 | * <code>dragSourceListenerK</code>, a <code>DragSourceListener</code> is | ||
| 842 | * deserialized using the corresponding value object and added to this | ||
| 843 | * <code>DragSource</code>. | ||
| 844 | * <li>If a key object is a <code>String</code> equal to | ||
| 845 | * <code>dragSourceMotionListenerK</code>, a | ||
| 846 | * <code>DragSourceMotionListener</code> is deserialized using the | ||
| 847 | * corresponding value object and added to this <code>DragSource</code>. | ||
| 848 | * <li>Otherwise, the key/value pair is skipped. | ||
| 849 | * </ul> | ||
| 850 | * | ||
| 851 | * @see java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap | ||
| 852 | * @since 1.4 | ||
| 853 | */ | ||
| 854 | private void readObject(ObjectInputStream s) | ||
| 855 | throws ClassNotFoundException, IOException { | ||
| 856 | s.defaultReadObject(); | ||
| 857 | |||
| 858 | // 'flavorMap' was written explicitly | ||
| 859 | flavorMap = (FlavorMap)s.readObject(); | ||
| 860 | |||
| 861 | // Implementation assumes 'flavorMap' is never null. | ||
| 862 | if (flavorMap == null) { | ||
| 863 | flavorMap = SystemFlavorMap.getDefaultFlavorMap(); | ||
| 864 | } | ||
| 865 | |||
| 866 | Object keyOrNull; | ||
| 867 | while (null != (keyOrNull = s.readObject())) { | ||
| 868 | String key = ((String)keyOrNull).intern(); | ||
| 869 | |||
| 870 | if (dragSourceListenerK == key) { | ||
| 871 | addDragSourceListener((DragSourceListener)(s.readObject())); | ||
| 872 | } else if (dragSourceMotionListenerK == key) { | ||
| 873 | addDragSourceMotionListener( | ||
| 874 | (DragSourceMotionListener)(s.readObject())); | ||
| 875 | } else { | ||
| 876 | // skip value for unrecognized key | ||
| 877 | s.readObject(); | ||
| 878 | } | ||
| 879 | } | ||
| 880 | } | ||
| 881 | |||
| 882 | /** | ||
| 883 | * Returns the drag gesture motion threshold. The drag gesture motion threshold | ||
| 884 | * defines the recommended behavior for {@link MouseDragGestureRecognizer}s. | ||
| 885 | * <p> | ||
| 886 | * If the system property <code>awt.dnd.drag.threshold</code> is set to | ||
| 887 | * a positive integer, this method returns the value of the system property; | ||
| 888 | * otherwise if a pertinent desktop property is available and supported by | ||
| 889 | * the implementation of the Java platform, this method returns the value of | ||
| 890 | * that property; otherwise this method returns some default value. | ||
| 891 | * The pertinent desktop property can be queried using | ||
| 892 | * <code>java.awt.Toolkit.getDesktopProperty("DnD.gestureMotionThreshold")</code>. | ||
| 893 | * | ||
| 894 | * @return the drag gesture motion threshold | ||
| 895 | * @see MouseDragGestureRecognizer | ||
| 896 | * @since 1.5 | ||
| 897 | */ | ||
| 898 | public static int getDragThreshold() { | ||
| 899 | int ts = ((Integer)AccessController.doPrivileged( | ||
| 900 | new GetIntegerAction("awt.dnd.drag.threshold", 0))).intValue(); | ||
| 901 | if (ts > 0) { | ||
| 902 | return ts; | ||
| 903 | } else { | ||
| 904 | Integer td = (Integer)Toolkit.getDefaultToolkit(). | ||
| 905 | getDesktopProperty("DnD.gestureMotionThreshold"); | ||
| 906 | if (td != null) { | ||
| 907 | return td.intValue(); | ||
| 908 | } | ||
| 909 | } | ||
| 910 | return 5; | ||
| 911 | } | ||
| 912 | |||
| 913 | /* | ||
| 914 | * fields | ||
| 915 | */ | ||
| 916 | |||
| 917 | private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap(); | ||
| 918 | |||
| 919 | private transient DragSourceListener listener; | ||
| 920 | |||
| 921 | private transient DragSourceMotionListener motionListener; | ||
| 922 | } | ||
Binary file not shown.
| @@ -0,0 +1,142 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | /** | ||
| 29 | * An abstract adapter class for receiving drag source events. The methods in | ||
| 30 | * this class are empty. This class exists only as a convenience for creating | ||
| 31 | * listener objects. | ||
| 32 | * <p> | ||
| 33 | * Extend this class to create a <code>DragSourceEvent</code> listener | ||
| 34 | * and override the methods for the events of interest. (If you implement the | ||
| 35 | * <code>DragSourceListener</code> interface, you have to define all of | ||
| 36 | * the methods in it. This abstract class defines null methods for them | ||
| 37 | * all, so you only have to define methods for events you care about.) | ||
| 38 | * <p> | ||
| 39 | * Create a listener object using the extended class and then register it with | ||
| 40 | * a <code>DragSource</code>. When the drag enters, moves over, or exits | ||
| 41 | * a drop site, when the drop action changes, and when the drag ends, the | ||
| 42 | * relevant method in the listener object is invoked, and the | ||
| 43 | * <code>DragSourceEvent</code> is passed to it. | ||
| 44 | * <p> | ||
| 45 | * The drop site is <i>associated with the previous <code>dragEnter()</code> | ||
| 46 | * invocation</i> if the latest invocation of <code>dragEnter()</code> on this | ||
| 47 | * adapter corresponds to that drop site and is not followed by a | ||
| 48 | * <code>dragExit()</code> invocation on this adapter. | ||
| 49 | * | ||
| 50 | * @see DragSourceEvent | ||
| 51 | * @see DragSourceListener | ||
| 52 | * @see DragSourceMotionListener | ||
| 53 | * | ||
| 54 | * @author David Mendenhall | ||
| 55 | * @since 1.4 | ||
| 56 | */ | ||
| 57 | public abstract class DragSourceAdapter | ||
| 58 | implements DragSourceListener, DragSourceMotionListener { | ||
| 59 | |||
| 60 | /** | ||
| 61 | * Called as the cursor's hotspot enters a platform-dependent drop site. | ||
| 62 | * This method is invoked when all the following conditions are true: | ||
| 63 | * <UL> | ||
| 64 | * <LI>The cursor's hotspot enters the operable part of | ||
| 65 | * a platform-dependent drop site. | ||
| 66 | * <LI>The drop site is active. | ||
| 67 | * <LI>The drop site accepts the drag. | ||
| 68 | * </UL> | ||
| 69 | * | ||
| 70 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 71 | */ | ||
| 72 | public void dragEnter(DragSourceDragEvent dsde) {} | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Called as the cursor's hotspot moves over a platform-dependent drop site. | ||
| 76 | * This method is invoked when all the following conditions are true: | ||
| 77 | * <UL> | ||
| 78 | * <LI>The cursor's hotspot has moved, but still intersects the | ||
| 79 | * operable part of the drop site associated with the previous | ||
| 80 | * dragEnter() invocation. | ||
| 81 | * <LI>The drop site is still active. | ||
| 82 | * <LI>The drop site accepts the drag. | ||
| 83 | * </UL> | ||
| 84 | * | ||
| 85 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 86 | */ | ||
| 87 | public void dragOver(DragSourceDragEvent dsde) {} | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Called whenever the mouse is moved during a drag operation. | ||
| 91 | * | ||
| 92 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 93 | */ | ||
| 94 | public void dragMouseMoved(DragSourceDragEvent dsde) {} | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Called when the user has modified the drop gesture. | ||
| 98 | * This method is invoked when the state of the input | ||
| 99 | * device(s) that the user is interacting with changes. | ||
| 100 | * Such devices are typically the mouse buttons or keyboard | ||
| 101 | * modifiers that the user is interacting with. | ||
| 102 | * | ||
| 103 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 104 | */ | ||
| 105 | public void dropActionChanged(DragSourceDragEvent dsde) {} | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Called as the cursor's hotspot exits a platform-dependent drop site. | ||
| 109 | * This method is invoked when any of the following conditions are true: | ||
| 110 | * <UL> | ||
| 111 | * <LI>The cursor's hotspot no longer intersects the operable part | ||
| 112 | * of the drop site associated with the previous dragEnter() invocation. | ||
| 113 | * </UL> | ||
| 114 | * OR | ||
| 115 | * <UL> | ||
| 116 | * <LI>The drop site associated with the previous dragEnter() invocation | ||
| 117 | * is no longer active. | ||
| 118 | * </UL> | ||
| 119 | * OR | ||
| 120 | * <UL> | ||
| 121 | * <LI> The drop site associated with the previous dragEnter() invocation | ||
| 122 | * has rejected the drag. | ||
| 123 | * </UL> | ||
| 124 | * | ||
| 125 | * @param dse the <code>DragSourceEvent</code> | ||
| 126 | */ | ||
| 127 | public void dragExit(DragSourceEvent dse) {} | ||
| 128 | |||
| 129 | /** | ||
| 130 | * This method is invoked to signify that the Drag and Drop | ||
| 131 | * operation is complete. The getDropSuccess() method of | ||
| 132 | * the <code>DragSourceDropEvent</code> can be used to | ||
| 133 | * determine the termination state. The getDropAction() method | ||
| 134 | * returns the operation that the drop site selected | ||
| 135 | * to apply to the Drop operation. Once this method is complete, the | ||
| 136 | * current <code>DragSourceContext</code> and | ||
| 137 | * associated resources become invalid. | ||
| 138 | * | ||
| 139 | * @param dsde the <code>DragSourceDropEvent</code> | ||
| 140 | */ | ||
| 141 | public void dragDropEnd(DragSourceDropEvent dsde) {} | ||
| 142 | } | ||
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,634 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.Component; | ||
| 29 | import java.awt.Cursor; | ||
| 30 | import java.awt.Image; | ||
| 31 | import java.awt.Point; | ||
| 32 | |||
| 33 | import java.awt.datatransfer.DataFlavor; | ||
| 34 | import java.awt.datatransfer.Transferable; | ||
| 35 | import java.awt.datatransfer.UnsupportedFlavorException; | ||
| 36 | |||
| 37 | import java.awt.dnd.peer.DragSourceContextPeer; | ||
| 38 | |||
| 39 | import java.io.IOException; | ||
| 40 | import java.io.ObjectOutputStream; | ||
| 41 | import java.io.ObjectInputStream; | ||
| 42 | import java.io.Serializable; | ||
| 43 | |||
| 44 | import java.util.TooManyListenersException; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * The <code>DragSourceContext</code> class is responsible for managing the | ||
| 48 | * initiator side of the Drag and Drop protocol. In particular, it is responsible | ||
| 49 | * for managing drag event notifications to the | ||
| 50 | * {@linkplain DragSourceListener DragSourceListeners} | ||
| 51 | * and {@linkplain DragSourceMotionListener DragSourceMotionListeners}, and providing the | ||
| 52 | * {@link Transferable} representing the source data for the drag operation. | ||
| 53 | * <p> | ||
| 54 | * Note that the <code>DragSourceContext</code> itself | ||
| 55 | * implements the <code>DragSourceListener</code> and | ||
| 56 | * <code>DragSourceMotionListener</code> interfaces. | ||
| 57 | * This is to allow the platform peer | ||
| 58 | * (the {@link DragSourceContextPeer} instance) | ||
| 59 | * created by the {@link DragSource} to notify | ||
| 60 | * the <code>DragSourceContext</code> of | ||
| 61 | * state changes in the ongoing operation. This allows the | ||
| 62 | * <code>DragSourceContext</code> object to interpose | ||
| 63 | * itself between the platform and the | ||
| 64 | * listeners provided by the initiator of the drag operation. | ||
| 65 | * <p> | ||
| 66 | * <a name="defaultCursor" /> | ||
| 67 | * By default, {@code DragSourceContext} sets the cursor as appropriate | ||
| 68 | * for the current state of the drag and drop operation. For example, if | ||
| 69 | * the user has chosen {@linkplain DnDConstants#ACTION_MOVE the move action}, | ||
| 70 | * and the pointer is over a target that accepts | ||
| 71 | * the move action, the default move cursor is shown. When | ||
| 72 | * the pointer is over an area that does not accept the transfer, | ||
| 73 | * the default "no drop" cursor is shown. | ||
| 74 | * <p> | ||
| 75 | * This default handling mechanism is disabled when a custom cursor is set | ||
| 76 | * by the {@link #setCursor} method. When the default handling is disabled, | ||
| 77 | * it becomes the responsibility | ||
| 78 | * of the developer to keep the cursor up to date, by listening | ||
| 79 | * to the {@code DragSource} events and calling the {@code setCursor()} method. | ||
| 80 | * Alternatively, you can provide custom cursor behavior by providing | ||
| 81 | * custom implementations of the {@code DragSource} | ||
| 82 | * and the {@code DragSourceContext} classes. | ||
| 83 | * | ||
| 84 | * @see DragSourceListener | ||
| 85 | * @see DragSourceMotionListener | ||
| 86 | * @see DnDConstants | ||
| 87 | * @since 1.2 | ||
| 88 | */ | ||
| 89 | |||
| 90 | public class DragSourceContext | ||
| 91 | implements DragSourceListener, DragSourceMotionListener, Serializable { | ||
| 92 | |||
| 93 | private static final long serialVersionUID = -115407898692194719L; | ||
| 94 | |||
| 95 | // used by updateCurrentCursor | ||
| 96 | |||
| 97 | /** | ||
| 98 | * An <code>int</code> used by updateCurrentCursor() | ||
| 99 | * indicating that the <code>Cursor</code> should change | ||
| 100 | * to the default (no drop) <code>Cursor</code>. | ||
| 101 | */ | ||
| 102 | protected static final int DEFAULT = 0; | ||
| 103 | |||
| 104 | /** | ||
| 105 | * An <code>int</code> used by updateCurrentCursor() | ||
| 106 | * indicating that the <code>Cursor</code> | ||
| 107 | * has entered a <code>DropTarget</code>. | ||
| 108 | */ | ||
| 109 | protected static final int ENTER = 1; | ||
| 110 | |||
| 111 | /** | ||
| 112 | * An <code>int</code> used by updateCurrentCursor() | ||
| 113 | * indicating that the <code>Cursor</code> is | ||
| 114 | * over a <code>DropTarget</code>. | ||
| 115 | */ | ||
| 116 | protected static final int OVER = 2; | ||
| 117 | |||
| 118 | /** | ||
| 119 | * An <code>int</code> used by updateCurrentCursor() | ||
| 120 | * indicating that the user operation has changed. | ||
| 121 | */ | ||
| 122 | |||
| 123 | protected static final int CHANGED = 3; | ||
| 124 | |||
| 125 | /** | ||
| 126 | * Called from <code>DragSource</code>, this constructor creates a new | ||
| 127 | * <code>DragSourceContext</code> given the | ||
| 128 | * <code>DragSourceContextPeer</code> for this Drag, the | ||
| 129 | * <code>DragGestureEvent</code> that triggered the Drag, the initial | ||
| 130 | * <code>Cursor</code> to use for the Drag, an (optional) | ||
| 131 | * <code>Image</code> to display while the Drag is taking place, the offset | ||
| 132 | * of the <code>Image</code> origin from the hotspot at the instant of the | ||
| 133 | * triggering event, the <code>Transferable</code> subject data, and the | ||
| 134 | * <code>DragSourceListener</code> to use during the Drag and Drop | ||
| 135 | * operation. | ||
| 136 | * <br> | ||
| 137 | * If <code>DragSourceContextPeer</code> is <code>null</code> | ||
| 138 | * <code>NullPointerException</code> is thrown. | ||
| 139 | * <br> | ||
| 140 | * If <code>DragGestureEvent</code> is <code>null</code> | ||
| 141 | * <code>NullPointerException</code> is thrown. | ||
| 142 | * <br> | ||
| 143 | * If <code>Cursor</code> is <code>null</code> no exception is thrown and | ||
| 144 | * the default drag cursor behavior is activated for this drag operation. | ||
| 145 | * <br> | ||
| 146 | * If <code>Image</code> is <code>null</code> no exception is thrown. | ||
| 147 | * <br> | ||
| 148 | * If <code>Image</code> is not <code>null</code> and the offset is | ||
| 149 | * <code>null</code> <code>NullPointerException</code> is thrown. | ||
| 150 | * <br> | ||
| 151 | * If <code>Transferable</code> is <code>null</code> | ||
| 152 | * <code>NullPointerException</code> is thrown. | ||
| 153 | * <br> | ||
| 154 | * If <code>DragSourceListener</code> is <code>null</code> no exception | ||
| 155 | * is thrown. | ||
| 156 | * | ||
| 157 | * @param dscp the <code>DragSourceContextPeer</code> for this drag | ||
| 158 | * @param trigger the triggering event | ||
| 159 | * @param dragCursor the initial {@code Cursor} for this drag operation | ||
| 160 | * or {@code null} for the default cursor handling; | ||
| 161 | * see <a href="DragSourceContext.html#defaultCursor">class level documentation</a> | ||
| 162 | * for more details on the cursor handling mechanism during drag and drop | ||
| 163 | * @param dragImage the <code>Image</code> to drag (or <code>null</code>) | ||
| 164 | * @param offset the offset of the image origin from the hotspot at the | ||
| 165 | * instant of the triggering event | ||
| 166 | * @param t the <code>Transferable</code> | ||
| 167 | * @param dsl the <code>DragSourceListener</code> | ||
| 168 | * | ||
| 169 | * @throws IllegalArgumentException if the <code>Component</code> associated | ||
| 170 | * with the trigger event is <code>null</code>. | ||
| 171 | * @throws IllegalArgumentException if the <code>DragSource</code> for the | ||
| 172 | * trigger event is <code>null</code>. | ||
| 173 | * @throws IllegalArgumentException if the drag action for the | ||
| 174 | * trigger event is <code>DnDConstants.ACTION_NONE</code>. | ||
| 175 | * @throws IllegalArgumentException if the source actions for the | ||
| 176 | * <code>DragGestureRecognizer</code> associated with the trigger | ||
| 177 | * event are equal to <code>DnDConstants.ACTION_NONE</code>. | ||
| 178 | * @throws NullPointerException if dscp, trigger, or t are null, or | ||
| 179 | * if dragImage is non-null and offset is null | ||
| 180 | */ | ||
| 181 | public DragSourceContext(DragSourceContextPeer dscp, | ||
| 182 | DragGestureEvent trigger, Cursor dragCursor, | ||
| 183 | Image dragImage, Point offset, Transferable t, | ||
| 184 | DragSourceListener dsl) { | ||
| 185 | if (dscp == null) { | ||
| 186 | throw new NullPointerException("DragSourceContextPeer"); | ||
| 187 | } | ||
| 188 | |||
| 189 | if (trigger == null) { | ||
| 190 | throw new NullPointerException("Trigger"); | ||
| 191 | } | ||
| 192 | |||
| 193 | if (trigger.getDragSource() == null) { | ||
| 194 | throw new IllegalArgumentException("DragSource"); | ||
| 195 | } | ||
| 196 | |||
| 197 | if (trigger.getComponent() == null) { | ||
| 198 | throw new IllegalArgumentException("Component"); | ||
| 199 | } | ||
| 200 | |||
| 201 | if (trigger.getSourceAsDragGestureRecognizer().getSourceActions() == | ||
| 202 | DnDConstants.ACTION_NONE) { | ||
| 203 | throw new IllegalArgumentException("source actions"); | ||
| 204 | } | ||
| 205 | |||
| 206 | if (trigger.getDragAction() == DnDConstants.ACTION_NONE) { | ||
| 207 | throw new IllegalArgumentException("no drag action"); | ||
| 208 | } | ||
| 209 | |||
| 210 | if (t == null) { | ||
| 211 | throw new NullPointerException("Transferable"); | ||
| 212 | } | ||
| 213 | |||
| 214 | if (dragImage != null && offset == null) { | ||
| 215 | throw new NullPointerException("offset"); | ||
| 216 | } | ||
| 217 | |||
| 218 | peer = dscp; | ||
| 219 | this.trigger = trigger; | ||
| 220 | cursor = dragCursor; | ||
| 221 | transferable = t; | ||
| 222 | listener = dsl; | ||
| 223 | sourceActions = | ||
| 224 | trigger.getSourceAsDragGestureRecognizer().getSourceActions(); | ||
| 225 | |||
| 226 | useCustomCursor = (dragCursor != null); | ||
| 227 | |||
| 228 | updateCurrentCursor(trigger.getDragAction(), getSourceActions(), DEFAULT); | ||
| 229 | } | ||
| 230 | |||
| 231 | /** | ||
| 232 | * Returns the <code>DragSource</code> | ||
| 233 | * that instantiated this <code>DragSourceContext</code>. | ||
| 234 | * | ||
| 235 | * @return the <code>DragSource</code> that | ||
| 236 | * instantiated this <code>DragSourceContext</code> | ||
| 237 | */ | ||
| 238 | |||
| 239 | public DragSource getDragSource() { return trigger.getDragSource(); } | ||
| 240 | |||
| 241 | /** | ||
| 242 | * Returns the <code>Component</code> associated with this | ||
| 243 | * <code>DragSourceContext</code>. | ||
| 244 | * | ||
| 245 | * @return the <code>Component</code> that started the drag | ||
| 246 | */ | ||
| 247 | |||
| 248 | public Component getComponent() { return trigger.getComponent(); } | ||
| 249 | |||
| 250 | /** | ||
| 251 | * Returns the <code>DragGestureEvent</code> | ||
| 252 | * that initially triggered the drag. | ||
| 253 | * | ||
| 254 | * @return the Event that triggered the drag | ||
| 255 | */ | ||
| 256 | |||
| 257 | public DragGestureEvent getTrigger() { return trigger; } | ||
| 258 | |||
| 259 | /** | ||
| 260 | * Returns a bitwise mask of <code>DnDConstants</code> that | ||
| 261 | * represent the set of drop actions supported by the drag source for the | ||
| 262 | * drag operation associated with this <code>DragSourceContext</code>. | ||
| 263 | * | ||
| 264 | * @return the drop actions supported by the drag source | ||
| 265 | */ | ||
| 266 | public int getSourceActions() { | ||
| 267 | return sourceActions; | ||
| 268 | } | ||
| 269 | |||
| 270 | /** | ||
| 271 | * Sets the cursor for this drag operation to the specified | ||
| 272 | * <code>Cursor</code>. If the specified <code>Cursor</code> | ||
| 273 | * is <code>null</code>, the default drag cursor behavior is | ||
| 274 | * activated for this drag operation, otherwise it is deactivated. | ||
| 275 | * | ||
| 276 | * @param c the initial {@code Cursor} for this drag operation, | ||
| 277 | * or {@code null} for the default cursor handling; | ||
| 278 | * see {@linkplain Cursor class | ||
| 279 | * level documentation} for more details | ||
| 280 | * on the cursor handling during drag and drop | ||
| 281 | * | ||
| 282 | */ | ||
| 283 | |||
| 284 | public synchronized void setCursor(Cursor c) { | ||
| 285 | useCustomCursor = (c != null); | ||
| 286 | setCursorImpl(c); | ||
| 287 | } | ||
| 288 | |||
| 289 | /** | ||
| 290 | * Returns the current drag <code>Cursor</code>. | ||
| 291 | * <P> | ||
| 292 | * @return the current drag <code>Cursor</code> | ||
| 293 | */ | ||
| 294 | |||
| 295 | public Cursor getCursor() { return cursor; } | ||
| 296 | |||
| 297 | /** | ||
| 298 | * Add a <code>DragSourceListener</code> to this | ||
| 299 | * <code>DragSourceContext</code> if one has not already been added. | ||
| 300 | * If a <code>DragSourceListener</code> already exists, | ||
| 301 | * this method throws a <code>TooManyListenersException</code>. | ||
| 302 | * <P> | ||
| 303 | * @param dsl the <code>DragSourceListener</code> to add. | ||
| 304 | * Note that while <code>null</code> is not prohibited, | ||
| 305 | * it is not acceptable as a parameter. | ||
| 306 | * <P> | ||
| 307 | * @throws TooManyListenersException if | ||
| 308 | * a <code>DragSourceListener</code> has already been added | ||
| 309 | */ | ||
| 310 | |||
| 311 | public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException { | ||
| 312 | if (dsl == null) return; | ||
| 313 | |||
| 314 | if (equals(dsl)) throw new IllegalArgumentException("DragSourceContext may not be its own listener"); | ||
| 315 | |||
| 316 | if (listener != null) | ||
| 317 | throw new TooManyListenersException(); | ||
| 318 | else | ||
| 319 | listener = dsl; | ||
| 320 | } | ||
| 321 | |||
| 322 | /** | ||
| 323 | * Removes the specified <code>DragSourceListener</code> | ||
| 324 | * from this <code>DragSourceContext</code>. | ||
| 325 | * | ||
| 326 | * @param dsl the <code>DragSourceListener</code> to remove; | ||
| 327 | * note that while <code>null</code> is not prohibited, | ||
| 328 | * it is not acceptable as a parameter | ||
| 329 | */ | ||
| 330 | |||
| 331 | public synchronized void removeDragSourceListener(DragSourceListener dsl) { | ||
| 332 | if (listener != null && listener.equals(dsl)) { | ||
| 333 | listener = null; | ||
| 334 | } else | ||
| 335 | throw new IllegalArgumentException(); | ||
| 336 | } | ||
| 337 | |||
| 338 | /** | ||
| 339 | * Notifies the peer that the <code>Transferable</code>'s | ||
| 340 | * <code>DataFlavor</code>s have changed. | ||
| 341 | */ | ||
| 342 | |||
| 343 | public void transferablesFlavorsChanged() { | ||
| 344 | if (peer != null) peer.transferablesFlavorsChanged(); | ||
| 345 | } | ||
| 346 | |||
| 347 | /** | ||
| 348 | * Calls <code>dragEnter</code> on the | ||
| 349 | * <code>DragSourceListener</code>s registered with this | ||
| 350 | * <code>DragSourceContext</code> and with the associated | ||
| 351 | * <code>DragSource</code>, and passes them the specified | ||
| 352 | * <code>DragSourceDragEvent</code>. | ||
| 353 | * | ||
| 354 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 355 | */ | ||
| 356 | public void dragEnter(DragSourceDragEvent dsde) { | ||
| 357 | DragSourceListener dsl = listener; | ||
| 358 | if (dsl != null) { | ||
| 359 | dsl.dragEnter(dsde); | ||
| 360 | } | ||
| 361 | getDragSource().processDragEnter(dsde); | ||
| 362 | |||
| 363 | updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), ENTER); | ||
| 364 | } | ||
| 365 | |||
| 366 | /** | ||
| 367 | * Calls <code>dragOver</code> on the | ||
| 368 | * <code>DragSourceListener</code>s registered with this | ||
| 369 | * <code>DragSourceContext</code> and with the associated | ||
| 370 | * <code>DragSource</code>, and passes them the specified | ||
| 371 | * <code>DragSourceDragEvent</code>. | ||
| 372 | * | ||
| 373 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 374 | */ | ||
| 375 | public void dragOver(DragSourceDragEvent dsde) { | ||
| 376 | DragSourceListener dsl = listener; | ||
| 377 | if (dsl != null) { | ||
| 378 | dsl.dragOver(dsde); | ||
| 379 | } | ||
| 380 | getDragSource().processDragOver(dsde); | ||
| 381 | |||
| 382 | updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), OVER); | ||
| 383 | } | ||
| 384 | |||
| 385 | /** | ||
| 386 | * Calls <code>dragExit</code> on the | ||
| 387 | * <code>DragSourceListener</code>s registered with this | ||
| 388 | * <code>DragSourceContext</code> and with the associated | ||
| 389 | * <code>DragSource</code>, and passes them the specified | ||
| 390 | * <code>DragSourceEvent</code>. | ||
| 391 | * | ||
| 392 | * @param dse the <code>DragSourceEvent</code> | ||
| 393 | */ | ||
| 394 | public void dragExit(DragSourceEvent dse) { | ||
| 395 | DragSourceListener dsl = listener; | ||
| 396 | if (dsl != null) { | ||
| 397 | dsl.dragExit(dse); | ||
| 398 | } | ||
| 399 | getDragSource().processDragExit(dse); | ||
| 400 | |||
| 401 | updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, DEFAULT); | ||
| 402 | } | ||
| 403 | |||
| 404 | /** | ||
| 405 | * Calls <code>dropActionChanged</code> on the | ||
| 406 | * <code>DragSourceListener</code>s registered with this | ||
| 407 | * <code>DragSourceContext</code> and with the associated | ||
| 408 | * <code>DragSource</code>, and passes them the specified | ||
| 409 | * <code>DragSourceDragEvent</code>. | ||
| 410 | * | ||
| 411 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 412 | */ | ||
| 413 | public void dropActionChanged(DragSourceDragEvent dsde) { | ||
| 414 | DragSourceListener dsl = listener; | ||
| 415 | if (dsl != null) { | ||
| 416 | dsl.dropActionChanged(dsde); | ||
| 417 | } | ||
| 418 | getDragSource().processDropActionChanged(dsde); | ||
| 419 | |||
| 420 | updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), CHANGED); | ||
| 421 | } | ||
| 422 | |||
| 423 | /** | ||
| 424 | * Calls <code>dragDropEnd</code> on the | ||
| 425 | * <code>DragSourceListener</code>s registered with this | ||
| 426 | * <code>DragSourceContext</code> and with the associated | ||
| 427 | * <code>DragSource</code>, and passes them the specified | ||
| 428 | * <code>DragSourceDropEvent</code>. | ||
| 429 | * | ||
| 430 | * @param dsde the <code>DragSourceDropEvent</code> | ||
| 431 | */ | ||
| 432 | public void dragDropEnd(DragSourceDropEvent dsde) { | ||
| 433 | DragSourceListener dsl = listener; | ||
| 434 | if (dsl != null) { | ||
| 435 | dsl.dragDropEnd(dsde); | ||
| 436 | } | ||
| 437 | getDragSource().processDragDropEnd(dsde); | ||
| 438 | } | ||
| 439 | |||
| 440 | /** | ||
| 441 | * Calls <code>dragMouseMoved</code> on the | ||
| 442 | * <code>DragSourceMotionListener</code>s registered with the | ||
| 443 | * <code>DragSource</code> associated with this | ||
| 444 | * <code>DragSourceContext</code>, and them passes the specified | ||
| 445 | * <code>DragSourceDragEvent</code>. | ||
| 446 | * | ||
| 447 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 448 | * @since 1.4 | ||
| 449 | */ | ||
| 450 | public void dragMouseMoved(DragSourceDragEvent dsde) { | ||
| 451 | getDragSource().processDragMouseMoved(dsde); | ||
| 452 | } | ||
| 453 | |||
| 454 | /** | ||
| 455 | * Returns the <code>Transferable</code> associated with | ||
| 456 | * this <code>DragSourceContext</code>. | ||
| 457 | * | ||
| 458 | * @return the <code>Transferable</code> | ||
| 459 | */ | ||
| 460 | public Transferable getTransferable() { return transferable; } | ||
| 461 | |||
| 462 | /** | ||
| 463 | * If the default drag cursor behavior is active, this method | ||
| 464 | * sets the default drag cursor for the specified actions | ||
| 465 | * supported by the drag source, the drop target action, | ||
| 466 | * and status, otherwise this method does nothing. | ||
| 467 | * | ||
| 468 | * @param sourceAct the actions supported by the drag source | ||
| 469 | * @param targetAct the drop target action | ||
| 470 | * @param status one of the fields <code>DEFAULT</code>, | ||
| 471 | * <code>ENTER</code>, <code>OVER</code>, | ||
| 472 | * <code>CHANGED</code> | ||
| 473 | */ | ||
| 474 | |||
| 475 | protected synchronized void updateCurrentCursor(int sourceAct, int targetAct, int status) { | ||
| 476 | |||
| 477 | // if the cursor has been previously set then dont do any defaults | ||
| 478 | // processing. | ||
| 479 | |||
| 480 | if (useCustomCursor) { | ||
| 481 | return; | ||
| 482 | } | ||
| 483 | |||
| 484 | // do defaults processing | ||
| 485 | |||
| 486 | Cursor c = null; | ||
| 487 | |||
| 488 | switch (status) { | ||
| 489 | default: | ||
| 490 | targetAct = DnDConstants.ACTION_NONE; | ||
| 491 | case ENTER: | ||
| 492 | case OVER: | ||
| 493 | case CHANGED: | ||
| 494 | int ra = sourceAct & targetAct; | ||
| 495 | |||
| 496 | if (ra == DnDConstants.ACTION_NONE) { // no drop possible | ||
| 497 | if ((sourceAct & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK) | ||
| 498 | c = DragSource.DefaultLinkNoDrop; | ||
| 499 | else if ((sourceAct & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) | ||
| 500 | c = DragSource.DefaultMoveNoDrop; | ||
| 501 | else | ||
| 502 | c = DragSource.DefaultCopyNoDrop; | ||
| 503 | } else { // drop possible | ||
| 504 | if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK) | ||
| 505 | c = DragSource.DefaultLinkDrop; | ||
| 506 | else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) | ||
| 507 | c = DragSource.DefaultMoveDrop; | ||
| 508 | else | ||
| 509 | c = DragSource.DefaultCopyDrop; | ||
| 510 | } | ||
| 511 | } | ||
| 512 | |||
| 513 | setCursorImpl(c); | ||
| 514 | } | ||
| 515 | |||
| 516 | private void setCursorImpl(Cursor c) { | ||
| 517 | if (cursor == null || !cursor.equals(c)) { | ||
| 518 | cursor = c; | ||
| 519 | if (peer != null) peer.setCursor(cursor); | ||
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 | /** | ||
| 524 | * Serializes this <code>DragSourceContext</code>. This method first | ||
| 525 | * performs default serialization. Next, this object's | ||
| 526 | * <code>Transferable</code> is written out if and only if it can be | ||
| 527 | * serialized. If not, <code>null</code> is written instead. In this case, | ||
| 528 | * a <code>DragSourceContext</code> created from the resulting deserialized | ||
| 529 | * stream will contain a dummy <code>Transferable</code> which supports no | ||
| 530 | * <code>DataFlavor</code>s. Finally, this object's | ||
| 531 | * <code>DragSourceListener</code> is written out if and only if it can be | ||
| 532 | * serialized. If not, <code>null</code> is written instead. | ||
| 533 | * | ||
| 534 | * @serialData The default serializable fields, in alphabetical order, | ||
| 535 | * followed by either a <code>Transferable</code> instance, or | ||
| 536 | * <code>null</code>, followed by either a | ||
| 537 | * <code>DragSourceListener</code> instance, or | ||
| 538 | * <code>null</code>. | ||
| 539 | * @since 1.4 | ||
| 540 | */ | ||
| 541 | private void writeObject(ObjectOutputStream s) throws IOException { | ||
| 542 | s.defaultWriteObject(); | ||
| 543 | |||
| 544 | s.writeObject(SerializationTester.test(transferable) | ||
| 545 | ? transferable : null); | ||
| 546 | s.writeObject(SerializationTester.test(listener) | ||
| 547 | ? listener : null); | ||
| 548 | } | ||
| 549 | |||
| 550 | /** | ||
| 551 | * Deserializes this <code>DragSourceContext</code>. This method first | ||
| 552 | * performs default deserialization for all non-<code>transient</code> | ||
| 553 | * fields. This object's <code>Transferable</code> and | ||
| 554 | * <code>DragSourceListener</code> are then deserialized as well by using | ||
| 555 | * the next two objects in the stream. If the resulting | ||
| 556 | * <code>Transferable</code> is <code>null</code>, this object's | ||
| 557 | * <code>Transferable</code> is set to a dummy <code>Transferable</code> | ||
| 558 | * which supports no <code>DataFlavor</code>s. | ||
| 559 | * | ||
| 560 | * @since 1.4 | ||
| 561 | */ | ||
| 562 | private void readObject(ObjectInputStream s) | ||
| 563 | throws ClassNotFoundException, IOException | ||
| 564 | { | ||
| 565 | s.defaultReadObject(); | ||
| 566 | |||
| 567 | transferable = (Transferable)s.readObject(); | ||
| 568 | listener = (DragSourceListener)s.readObject(); | ||
| 569 | |||
| 570 | // Implementation assumes 'transferable' is never null. | ||
| 571 | if (transferable == null) { | ||
| 572 | if (emptyTransferable == null) { | ||
| 573 | emptyTransferable = new Transferable() { | ||
| 574 | public DataFlavor[] getTransferDataFlavors() { | ||
| 575 | return new DataFlavor[0]; | ||
| 576 | } | ||
| 577 | public boolean isDataFlavorSupported(DataFlavor flavor) | ||
| 578 | { | ||
| 579 | return false; | ||
| 580 | } | ||
| 581 | public Object getTransferData(DataFlavor flavor) | ||
| 582 | throws UnsupportedFlavorException | ||
| 583 | { | ||
| 584 | throw new UnsupportedFlavorException(flavor); | ||
| 585 | } | ||
| 586 | }; | ||
| 587 | } | ||
| 588 | transferable = emptyTransferable; | ||
| 589 | } | ||
| 590 | } | ||
| 591 | |||
| 592 | private static Transferable emptyTransferable; | ||
| 593 | |||
| 594 | /* | ||
| 595 | * fields | ||
| 596 | */ | ||
| 597 | |||
| 598 | private transient DragSourceContextPeer peer; | ||
| 599 | |||
| 600 | /** | ||
| 601 | * The event which triggered the start of the drag. | ||
| 602 | * | ||
| 603 | * @serial | ||
| 604 | */ | ||
| 605 | private DragGestureEvent trigger; | ||
| 606 | |||
| 607 | /** | ||
| 608 | * The current drag cursor. | ||
| 609 | * | ||
| 610 | * @serial | ||
| 611 | */ | ||
| 612 | private Cursor cursor; | ||
| 613 | |||
| 614 | private transient Transferable transferable; | ||
| 615 | |||
| 616 | private transient DragSourceListener listener; | ||
| 617 | |||
| 618 | /** | ||
| 619 | * <code>true</code> if the custom drag cursor is used instead of the | ||
| 620 | * default one. | ||
| 621 | * | ||
| 622 | * @serial | ||
| 623 | */ | ||
| 624 | private boolean useCustomCursor; | ||
| 625 | |||
| 626 | /** | ||
| 627 | * A bitwise mask of <code>DnDConstants</code> that represents the set of | ||
| 628 | * drop actions supported by the drag source for the drag operation associated | ||
| 629 | * with this <code>DragSourceContext.</code> | ||
| 630 | * | ||
| 631 | * @serial | ||
| 632 | */ | ||
| 633 | private final int sourceActions; | ||
| 634 | } | ||
Binary file not shown.
| @@ -0,0 +1,328 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.event.InputEvent; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * The <code>DragSourceDragEvent</code> is | ||
| 32 | * delivered from the <code>DragSourceContextPeer</code>, | ||
| 33 | * via the <code>DragSourceContext</code>, to the <code>DragSourceListener</code> | ||
| 34 | * registered with that <code>DragSourceContext</code> and with its associated | ||
| 35 | * <code>DragSource</code>. | ||
| 36 | * <p> | ||
| 37 | * The <code>DragSourceDragEvent</code> reports the <i>target drop action</i> | ||
| 38 | * and the <i>user drop action</i> that reflect the current state of | ||
| 39 | * the drag operation. | ||
| 40 | * <p> | ||
| 41 | * <i>Target drop action</i> is one of <code>DnDConstants</code> that represents | ||
| 42 | * the drop action selected by the current drop target if this drop action is | ||
| 43 | * supported by the drag source or <code>DnDConstants.ACTION_NONE</code> if this | ||
| 44 | * drop action is not supported by the drag source. | ||
| 45 | * <p> | ||
| 46 | * <i>User drop action</i> depends on the drop actions supported by the drag | ||
| 47 | * source and the drop action selected by the user. The user can select a drop | ||
| 48 | * action by pressing modifier keys during the drag operation: | ||
| 49 | * <pre> | ||
| 50 | * Ctrl + Shift -> ACTION_LINK | ||
| 51 | * Ctrl -> ACTION_COPY | ||
| 52 | * Shift -> ACTION_MOVE | ||
| 53 | * </pre> | ||
| 54 | * If the user selects a drop action, the <i>user drop action</i> is one of | ||
| 55 | * <code>DnDConstants</code> that represents the selected drop action if this | ||
| 56 | * drop action is supported by the drag source or | ||
| 57 | * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported | ||
| 58 | * by the drag source. | ||
| 59 | * <p> | ||
| 60 | * If the user doesn't select a drop action, the set of | ||
| 61 | * <code>DnDConstants</code> that represents the set of drop actions supported | ||
| 62 | * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>, | ||
| 63 | * then for <code>DnDConstants.ACTION_COPY</code>, then for | ||
| 64 | * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the | ||
| 65 | * first constant found. If no constant is found the <i>user drop action</i> | ||
| 66 | * is <code>DnDConstants.ACTION_NONE</code>. | ||
| 67 | * | ||
| 68 | * @since 1.2 | ||
| 69 | * | ||
| 70 | */ | ||
| 71 | |||
| 72 | public class DragSourceDragEvent extends DragSourceEvent { | ||
| 73 | |||
| 74 | private static final long serialVersionUID = 481346297933902471L; | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Constructs a <code>DragSourceDragEvent</code>. | ||
| 78 | * This class is typically | ||
| 79 | * instantiated by the <code>DragSourceContextPeer</code> | ||
| 80 | * rather than directly | ||
| 81 | * by client code. | ||
| 82 | * The coordinates for this <code>DragSourceDragEvent</code> | ||
| 83 | * are not specified, so <code>getLocation</code> will return | ||
| 84 | * <code>null</code> for this event. | ||
| 85 | * <p> | ||
| 86 | * The arguments <code>dropAction</code> and <code>action</code> should | ||
| 87 | * be one of <code>DnDConstants</code> that represents a single action. | ||
| 88 | * The argument <code>modifiers</code> should be either a bitwise mask | ||
| 89 | * of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a | ||
| 90 | * bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code> | ||
| 91 | * constants. | ||
| 92 | * This constructor does not throw any exception for invalid <code>dropAction</code>, | ||
| 93 | * <code>action</code> and <code>modifiers</code>. | ||
| 94 | * | ||
| 95 | * @param dsc the <code>DragSourceContext</code> that is to manage | ||
| 96 | * notifications for this event. | ||
| 97 | * @param dropAction the user drop action. | ||
| 98 | * @param action the target drop action. | ||
| 99 | * @param modifiers the modifier keys down during event (shift, ctrl, | ||
| 100 | * alt, meta) | ||
| 101 | * Either extended _DOWN_MASK or old _MASK modifiers | ||
| 102 | * should be used, but both models should not be mixed | ||
| 103 | * in one event. Use of the extended modifiers is | ||
| 104 | * preferred. | ||
| 105 | * | ||
| 106 | * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>. | ||
| 107 | * | ||
| 108 | * @see java.awt.event.InputEvent | ||
| 109 | * @see DragSourceEvent#getLocation | ||
| 110 | */ | ||
| 111 | |||
| 112 | public DragSourceDragEvent(DragSourceContext dsc, int dropAction, | ||
| 113 | int action, int modifiers) { | ||
| 114 | super(dsc); | ||
| 115 | |||
| 116 | targetActions = action; | ||
| 117 | gestureModifiers = modifiers; | ||
| 118 | this.dropAction = dropAction; | ||
| 119 | if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) { | ||
| 120 | invalidModifiers = true; | ||
| 121 | } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) { | ||
| 122 | setNewModifiers(); | ||
| 123 | } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) { | ||
| 124 | setOldModifiers(); | ||
| 125 | } else { | ||
| 126 | invalidModifiers = true; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Constructs a <code>DragSourceDragEvent</code> given the specified | ||
| 132 | * <code>DragSourceContext</code>, user drop action, target drop action, | ||
| 133 | * modifiers and coordinates. | ||
| 134 | * <p> | ||
| 135 | * The arguments <code>dropAction</code> and <code>action</code> should | ||
| 136 | * be one of <code>DnDConstants</code> that represents a single action. | ||
| 137 | * The argument <code>modifiers</code> should be either a bitwise mask | ||
| 138 | * of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a | ||
| 139 | * bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code> | ||
| 140 | * constants. | ||
| 141 | * This constructor does not throw any exception for invalid <code>dropAction</code>, | ||
| 142 | * <code>action</code> and <code>modifiers</code>. | ||
| 143 | * | ||
| 144 | * @param dsc the <code>DragSourceContext</code> associated with this | ||
| 145 | * event. | ||
| 146 | * @param dropAction the user drop action. | ||
| 147 | * @param action the target drop action. | ||
| 148 | * @param modifiers the modifier keys down during event (shift, ctrl, | ||
| 149 | * alt, meta) | ||
| 150 | * Either extended _DOWN_MASK or old _MASK modifiers | ||
| 151 | * should be used, but both models should not be mixed | ||
| 152 | * in one event. Use of the extended modifiers is | ||
| 153 | * preferred. | ||
| 154 | * @param x the horizontal coordinate for the cursor location | ||
| 155 | * @param y the vertical coordinate for the cursor location | ||
| 156 | * | ||
| 157 | * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>. | ||
| 158 | * | ||
| 159 | * @see java.awt.event.InputEvent | ||
| 160 | * @since 1.4 | ||
| 161 | */ | ||
| 162 | public DragSourceDragEvent(DragSourceContext dsc, int dropAction, | ||
| 163 | int action, int modifiers, int x, int y) { | ||
| 164 | super(dsc, x, y); | ||
| 165 | |||
| 166 | targetActions = action; | ||
| 167 | gestureModifiers = modifiers; | ||
| 168 | this.dropAction = dropAction; | ||
| 169 | if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) { | ||
| 170 | invalidModifiers = true; | ||
| 171 | } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) { | ||
| 172 | setNewModifiers(); | ||
| 173 | } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) { | ||
| 174 | setOldModifiers(); | ||
| 175 | } else { | ||
| 176 | invalidModifiers = true; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | /** | ||
| 181 | * This method returns the target drop action. | ||
| 182 | * | ||
| 183 | * @return the target drop action. | ||
| 184 | */ | ||
| 185 | public int getTargetActions() { | ||
| 186 | return targetActions; | ||
| 187 | } | ||
| 188 | |||
| 189 | |||
| 190 | private static final int JDK_1_3_MODIFIERS = InputEvent.SHIFT_DOWN_MASK - 1; | ||
| 191 | private static final int JDK_1_4_MODIFIERS = | ||
| 192 | ((InputEvent.ALT_GRAPH_DOWN_MASK << 1) - 1) & ~JDK_1_3_MODIFIERS; | ||
| 193 | |||
| 194 | /** | ||
| 195 | * This method returns an <code>int</code> representing | ||
| 196 | * the current state of the input device modifiers | ||
| 197 | * associated with the user's gesture. Typically these | ||
| 198 | * would be mouse buttons or keyboard modifiers. | ||
| 199 | * <P> | ||
| 200 | * If the <code>modifiers</code> passed to the constructor | ||
| 201 | * are invalid, this method returns them unchanged. | ||
| 202 | * | ||
| 203 | * @return the current state of the input device modifiers | ||
| 204 | */ | ||
| 205 | |||
| 206 | public int getGestureModifiers() { | ||
| 207 | return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_3_MODIFIERS; | ||
| 208 | } | ||
| 209 | |||
| 210 | /** | ||
| 211 | * This method returns an <code>int</code> representing | ||
| 212 | * the current state of the input device extended modifiers | ||
| 213 | * associated with the user's gesture. | ||
| 214 | * See {@link InputEvent#getModifiersEx} | ||
| 215 | * <P> | ||
| 216 | * If the <code>modifiers</code> passed to the constructor | ||
| 217 | * are invalid, this method returns them unchanged. | ||
| 218 | * | ||
| 219 | * @return the current state of the input device extended modifiers | ||
| 220 | * @since 1.4 | ||
| 221 | */ | ||
| 222 | |||
| 223 | public int getGestureModifiersEx() { | ||
| 224 | return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_4_MODIFIERS; | ||
| 225 | } | ||
| 226 | |||
| 227 | /** | ||
| 228 | * This method returns the user drop action. | ||
| 229 | * | ||
| 230 | * @return the user drop action. | ||
| 231 | */ | ||
| 232 | public int getUserAction() { return dropAction; } | ||
| 233 | |||
| 234 | /** | ||
| 235 | * This method returns the logical intersection of | ||
| 236 | * the target drop action and the set of drop actions supported by | ||
| 237 | * the drag source. | ||
| 238 | * | ||
| 239 | * @return the logical intersection of the target drop action and | ||
| 240 | * the set of drop actions supported by the drag source. | ||
| 241 | */ | ||
| 242 | public int getDropAction() { | ||
| 243 | return targetActions & getDragSourceContext().getSourceActions(); | ||
| 244 | } | ||
| 245 | |||
| 246 | /* | ||
| 247 | * fields | ||
| 248 | */ | ||
| 249 | |||
| 250 | /** | ||
| 251 | * The target drop action. | ||
| 252 | * | ||
| 253 | * @serial | ||
| 254 | */ | ||
| 255 | private int targetActions = DnDConstants.ACTION_NONE; | ||
| 256 | |||
| 257 | /** | ||
| 258 | * The user drop action. | ||
| 259 | * | ||
| 260 | * @serial | ||
| 261 | */ | ||
| 262 | private int dropAction = DnDConstants.ACTION_NONE; | ||
| 263 | |||
| 264 | /** | ||
| 265 | * The state of the input device modifiers associated with the user | ||
| 266 | * gesture. | ||
| 267 | * | ||
| 268 | * @serial | ||
| 269 | */ | ||
| 270 | private int gestureModifiers = 0; | ||
| 271 | |||
| 272 | /** | ||
| 273 | * Indicates whether the <code>gestureModifiers</code> are invalid. | ||
| 274 | * | ||
| 275 | * @serial | ||
| 276 | */ | ||
| 277 | private boolean invalidModifiers; | ||
| 278 | |||
| 279 | /** | ||
| 280 | * Sets new modifiers by the old ones. | ||
| 281 | * The mouse modifiers have higher priority than overlaying key | ||
| 282 | * modifiers. | ||
| 283 | */ | ||
| 284 | private void setNewModifiers() { | ||
| 285 | if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) { | ||
| 286 | gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK; | ||
| 287 | } | ||
| 288 | if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) { | ||
| 289 | gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK; | ||
| 290 | } | ||
| 291 | if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) { | ||
| 292 | gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK; | ||
| 293 | } | ||
| 294 | if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) { | ||
| 295 | gestureModifiers |= InputEvent.SHIFT_DOWN_MASK; | ||
| 296 | } | ||
| 297 | if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) { | ||
| 298 | gestureModifiers |= InputEvent.CTRL_DOWN_MASK; | ||
| 299 | } | ||
| 300 | if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) { | ||
| 301 | gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK; | ||
| 302 | } | ||
| 303 | } | ||
| 304 | |||
| 305 | /** | ||
| 306 | * Sets old modifiers by the new ones. | ||
| 307 | */ | ||
| 308 | private void setOldModifiers() { | ||
| 309 | if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) { | ||
| 310 | gestureModifiers |= InputEvent.BUTTON1_MASK; | ||
| 311 | } | ||
| 312 | if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) { | ||
| 313 | gestureModifiers |= InputEvent.BUTTON2_MASK; | ||
| 314 | } | ||
| 315 | if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) { | ||
| 316 | gestureModifiers |= InputEvent.BUTTON3_MASK; | ||
| 317 | } | ||
| 318 | if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) { | ||
| 319 | gestureModifiers |= InputEvent.SHIFT_MASK; | ||
| 320 | } | ||
| 321 | if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) { | ||
| 322 | gestureModifiers |= InputEvent.CTRL_MASK; | ||
| 323 | } | ||
| 324 | if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) { | ||
| 325 | gestureModifiers |= InputEvent.ALT_GRAPH_MASK; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | } | ||
Binary file not shown.
| @@ -0,0 +1,168 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | /** | ||
| 29 | * The <code>DragSourceDropEvent</code> is delivered | ||
| 30 | * from the <code>DragSourceContextPeer</code>, | ||
| 31 | * via the <code>DragSourceContext</code>, to the <code>dragDropEnd</code> | ||
| 32 | * method of <code>DragSourceListener</code>s registered with that | ||
| 33 | * <code>DragSourceContext</code> and with its associated | ||
| 34 | * <code>DragSource</code>. | ||
| 35 | * It contains sufficient information for the | ||
| 36 | * originator of the operation | ||
| 37 | * to provide appropriate feedback to the end user | ||
| 38 | * when the operation completes. | ||
| 39 | * <P> | ||
| 40 | * <P> | ||
| 41 | * @since 1.2 | ||
| 42 | */ | ||
| 43 | |||
| 44 | public class DragSourceDropEvent extends DragSourceEvent { | ||
| 45 | |||
| 46 | private static final long serialVersionUID = -5571321229470821891L; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Construct a <code>DragSourceDropEvent</code> for a drop, | ||
| 50 | * given the | ||
| 51 | * <code>DragSourceContext</code>, the drop action, | ||
| 52 | * and a <code>boolean</code> indicating if the drop was successful. | ||
| 53 | * The coordinates for this <code>DragSourceDropEvent</code> | ||
| 54 | * are not specified, so <code>getLocation</code> will return | ||
| 55 | * <code>null</code> for this event. | ||
| 56 | * <p> | ||
| 57 | * The argument <code>action</code> should be one of <code>DnDConstants</code> | ||
| 58 | * that represents a single action. | ||
| 59 | * This constructor does not throw any exception for invalid <code>action</code>. | ||
| 60 | * | ||
| 61 | * @param dsc the <code>DragSourceContext</code> | ||
| 62 | * associated with this <code>DragSourceDropEvent</code> | ||
| 63 | * @param action the drop action | ||
| 64 | * @param success a boolean indicating if the drop was successful | ||
| 65 | * | ||
| 66 | * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>. | ||
| 67 | * | ||
| 68 | * @see DragSourceEvent#getLocation | ||
| 69 | */ | ||
| 70 | |||
| 71 | public DragSourceDropEvent(DragSourceContext dsc, int action, boolean success) { | ||
| 72 | super(dsc); | ||
| 73 | |||
| 74 | dropSuccess = success; | ||
| 75 | dropAction = action; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Construct a <code>DragSourceDropEvent</code> for a drop, given the | ||
| 80 | * <code>DragSourceContext</code>, the drop action, a <code>boolean</code> | ||
| 81 | * indicating if the drop was successful, and coordinates. | ||
| 82 | * <p> | ||
| 83 | * The argument <code>action</code> should be one of <code>DnDConstants</code> | ||
| 84 | * that represents a single action. | ||
| 85 | * This constructor does not throw any exception for invalid <code>action</code>. | ||
| 86 | * | ||
| 87 | * @param dsc the <code>DragSourceContext</code> | ||
| 88 | * associated with this <code>DragSourceDropEvent</code> | ||
| 89 | * @param action the drop action | ||
| 90 | * @param success a boolean indicating if the drop was successful | ||
| 91 | * @param x the horizontal coordinate for the cursor location | ||
| 92 | * @param y the vertical coordinate for the cursor location | ||
| 93 | * | ||
| 94 | * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>. | ||
| 95 | * | ||
| 96 | * @since 1.4 | ||
| 97 | */ | ||
| 98 | public DragSourceDropEvent(DragSourceContext dsc, int action, | ||
| 99 | boolean success, int x, int y) { | ||
| 100 | super(dsc, x, y); | ||
| 101 | |||
| 102 | dropSuccess = success; | ||
| 103 | dropAction = action; | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Construct a <code>DragSourceDropEvent</code> | ||
| 108 | * for a drag that does not result in a drop. | ||
| 109 | * The coordinates for this <code>DragSourceDropEvent</code> | ||
| 110 | * are not specified, so <code>getLocation</code> will return | ||
| 111 | * <code>null</code> for this event. | ||
| 112 | * | ||
| 113 | * @param dsc the <code>DragSourceContext</code> | ||
| 114 | * | ||
| 115 | * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>. | ||
| 116 | * | ||
| 117 | * @see DragSourceEvent#getLocation | ||
| 118 | */ | ||
| 119 | |||
| 120 | public DragSourceDropEvent(DragSourceContext dsc) { | ||
| 121 | super(dsc); | ||
| 122 | |||
| 123 | dropSuccess = false; | ||
| 124 | } | ||
| 125 | |||
| 126 | /** | ||
| 127 | * This method returns a <code>boolean</code> indicating | ||
| 128 | * if the drop was successful. | ||
| 129 | * | ||
| 130 | * @return <code>true</code> if the drop target accepted the drop and | ||
| 131 | * successfully performed a drop action; | ||
| 132 | * <code>false</code> if the drop target rejected the drop or | ||
| 133 | * if the drop target accepted the drop, but failed to perform | ||
| 134 | * a drop action. | ||
| 135 | */ | ||
| 136 | |||
| 137 | public boolean getDropSuccess() { return dropSuccess; } | ||
| 138 | |||
| 139 | /** | ||
| 140 | * This method returns an <code>int</code> representing | ||
| 141 | * the action performed by the target on the subject of the drop. | ||
| 142 | * | ||
| 143 | * @return the action performed by the target on the subject of the drop | ||
| 144 | * if the drop target accepted the drop and the target drop action | ||
| 145 | * is supported by the drag source; otherwise, | ||
| 146 | * <code>DnDConstants.ACTION_NONE</code>. | ||
| 147 | */ | ||
| 148 | |||
| 149 | public int getDropAction() { return dropAction; } | ||
| 150 | |||
| 151 | /* | ||
| 152 | * fields | ||
| 153 | */ | ||
| 154 | |||
| 155 | /** | ||
| 156 | * <code>true</code> if the drop was successful. | ||
| 157 | * | ||
| 158 | * @serial | ||
| 159 | */ | ||
| 160 | private boolean dropSuccess; | ||
| 161 | |||
| 162 | /** | ||
| 163 | * The drop action. | ||
| 164 | * | ||
| 165 | * @serial | ||
| 166 | */ | ||
| 167 | private int dropAction = DnDConstants.ACTION_NONE; | ||
| 168 | } | ||
Binary file not shown.
| @@ -0,0 +1,185 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | * occured. | ||
| 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 occured 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 | * occured 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 <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 | } | ||
Binary file not shown.
| @@ -0,0 +1,126 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.util.EventListener; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * The <code>DragSourceListener</code> defines the | ||
| 32 | * event interface for originators of | ||
| 33 | * Drag and Drop operations to track the state of the user's gesture, and to | ||
| 34 | * provide appropriate "drag over" | ||
| 35 | * feedback to the user throughout the | ||
| 36 | * Drag and Drop operation. | ||
| 37 | * <p> | ||
| 38 | * The drop site is <i>associated with the previous <code>dragEnter()</code> | ||
| 39 | * invocation</i> if the latest invocation of <code>dragEnter()</code> on this | ||
| 40 | * listener: | ||
| 41 | * <ul> | ||
| 42 | * <li>corresponds to that drop site and | ||
| 43 | * <li> is not followed by a <code>dragExit()</code> invocation on this listener. | ||
| 44 | * </ul> | ||
| 45 | * | ||
| 46 | * @since 1.2 | ||
| 47 | */ | ||
| 48 | |||
| 49 | public interface DragSourceListener extends EventListener { | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Called as the cursor's hotspot enters a platform-dependent drop site. | ||
| 53 | * This method is invoked when all the following conditions are true: | ||
| 54 | * <UL> | ||
| 55 | * <LI>The cursor's hotspot enters the operable part of a platform- | ||
| 56 | * dependent drop site. | ||
| 57 | * <LI>The drop site is active. | ||
| 58 | * <LI>The drop site accepts the drag. | ||
| 59 | * </UL> | ||
| 60 | * | ||
| 61 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 62 | */ | ||
| 63 | void dragEnter(DragSourceDragEvent dsde); | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Called as the cursor's hotspot moves over a platform-dependent drop site. | ||
| 67 | * This method is invoked when all the following conditions are true: | ||
| 68 | * <UL> | ||
| 69 | * <LI>The cursor's hotspot has moved, but still intersects the | ||
| 70 | * operable part of the drop site associated with the previous | ||
| 71 | * dragEnter() invocation. | ||
| 72 | * <LI>The drop site is still active. | ||
| 73 | * <LI>The drop site accepts the drag. | ||
| 74 | * </UL> | ||
| 75 | * | ||
| 76 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 77 | */ | ||
| 78 | void dragOver(DragSourceDragEvent dsde); | ||
| 79 | |||
| 80 | /** | ||
| 81 | * Called when the user has modified the drop gesture. | ||
| 82 | * This method is invoked when the state of the input | ||
| 83 | * device(s) that the user is interacting with changes. | ||
| 84 | * Such devices are typically the mouse buttons or keyboard | ||
| 85 | * modifiers that the user is interacting with. | ||
| 86 | * | ||
| 87 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 88 | */ | ||
| 89 | void dropActionChanged(DragSourceDragEvent dsde); | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Called as the cursor's hotspot exits a platform-dependent drop site. | ||
| 93 | * This method is invoked when any of the following conditions are true: | ||
| 94 | * <UL> | ||
| 95 | * <LI>The cursor's hotspot no longer intersects the operable part | ||
| 96 | * of the drop site associated with the previous dragEnter() invocation. | ||
| 97 | * </UL> | ||
| 98 | * OR | ||
| 99 | * <UL> | ||
| 100 | * <LI>The drop site associated with the previous dragEnter() invocation | ||
| 101 | * is no longer active. | ||
| 102 | * </UL> | ||
| 103 | * OR | ||
| 104 | * <UL> | ||
| 105 | * <LI> The drop site associated with the previous dragEnter() invocation | ||
| 106 | * has rejected the drag. | ||
| 107 | * </UL> | ||
| 108 | * | ||
| 109 | * @param dse the <code>DragSourceEvent</code> | ||
| 110 | */ | ||
| 111 | void dragExit(DragSourceEvent dse); | ||
| 112 | |||
| 113 | /** | ||
| 114 | * This method is invoked to signify that the Drag and Drop | ||
| 115 | * operation is complete. The getDropSuccess() method of | ||
| 116 | * the <code>DragSourceDropEvent</code> can be used to | ||
| 117 | * determine the termination state. The getDropAction() method | ||
| 118 | * returns the operation that the drop site selected | ||
| 119 | * to apply to the Drop operation. Once this method is complete, the | ||
| 120 | * current <code>DragSourceContext</code> and | ||
| 121 | * associated resources become invalid. | ||
| 122 | * | ||
| 123 | * @param dsde the <code>DragSourceDropEvent</code> | ||
| 124 | */ | ||
| 125 | void dragDropEnd(DragSourceDropEvent dsde); | ||
| 126 | } | ||
Binary file not shown.
| @@ -0,0 +1,61 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.util.EventListener; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * A listener interface for receiving mouse motion events during a drag | ||
| 32 | * operation. | ||
| 33 | * <p> | ||
| 34 | * The class that is interested in processing mouse motion events during | ||
| 35 | * a drag operation either implements this interface or extends the abstract | ||
| 36 | * <code>DragSourceAdapter</code> class (overriding only the methods of | ||
| 37 | * interest). | ||
| 38 | * <p> | ||
| 39 | * Create a listener object using that class and then register it with | ||
| 40 | * a <code>DragSource</code>. Whenever the mouse moves during a drag | ||
| 41 | * operation initiated with this <code>DragSource</code>, that object's | ||
| 42 | * <code>dragMouseMoved</code> method is invoked, and the | ||
| 43 | * <code>DragSourceDragEvent</code> is passed to it. | ||
| 44 | * | ||
| 45 | * @see DragSourceDragEvent | ||
| 46 | * @see DragSource | ||
| 47 | * @see DragSourceListener | ||
| 48 | * @see DragSourceAdapter | ||
| 49 | * | ||
| 50 | * @since 1.4 | ||
| 51 | */ | ||
| 52 | |||
| 53 | public interface DragSourceMotionListener extends EventListener { | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Called whenever the mouse is moved during a drag operation. | ||
| 57 | * | ||
| 58 | * @param dsde the <code>DragSourceDragEvent</code> | ||
| 59 | */ | ||
| 60 | void dragMouseMoved(DragSourceDragEvent dsde); | ||
| 61 | } | ||
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,858 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.util.TooManyListenersException; | ||
| 29 | |||
| 30 | import java.io.IOException; | ||
| 31 | import java.io.ObjectInputStream; | ||
| 32 | import java.io.ObjectOutputStream; | ||
| 33 | import java.io.Serializable; | ||
| 34 | |||
| 35 | import java.awt.Component; | ||
| 36 | import java.awt.Dimension; | ||
| 37 | import java.awt.GraphicsEnvironment; | ||
| 38 | import java.awt.HeadlessException; | ||
| 39 | import java.awt.Insets; | ||
| 40 | import java.awt.Point; | ||
| 41 | import java.awt.Rectangle; | ||
| 42 | import java.awt.Toolkit; | ||
| 43 | import java.awt.event.ActionEvent; | ||
| 44 | import java.awt.event.ActionListener; | ||
| 45 | import java.awt.datatransfer.FlavorMap; | ||
| 46 | import java.awt.datatransfer.SystemFlavorMap; | ||
| 47 | import javax.swing.Timer; | ||
| 48 | import java.awt.peer.ComponentPeer; | ||
| 49 | import java.awt.peer.LightweightPeer; | ||
| 50 | import java.awt.dnd.peer.DropTargetPeer; | ||
| 51 | |||
| 52 | |||
| 53 | /** | ||
| 54 | * The <code>DropTarget</code> is associated | ||
| 55 | * with a <code>Component</code> when that <code>Component</code> | ||
| 56 | * wishes | ||
| 57 | * to accept drops during Drag and Drop operations. | ||
| 58 | * <P> | ||
| 59 | * Each | ||
| 60 | * <code>DropTarget</code> is associated with a <code>FlavorMap</code>. | ||
| 61 | * The default <code>FlavorMap</code> hereafter designates the | ||
| 62 | * <code>FlavorMap</code> returned by <code>SystemFlavorMap.getDefaultFlavorMap()</code>. | ||
| 63 | * | ||
| 64 | * @since 1.2 | ||
| 65 | */ | ||
| 66 | |||
| 67 | public class DropTarget implements DropTargetListener, Serializable { | ||
| 68 | |||
| 69 | private static final long serialVersionUID = -6283860791671019047L; | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Creates a new DropTarget given the <code>Component</code> | ||
| 73 | * to associate itself with, an <code>int</code> representing | ||
| 74 | * the default acceptable action(s) to | ||
| 75 | * support, a <code>DropTargetListener</code> | ||
| 76 | * to handle event processing, a <code>boolean</code> indicating | ||
| 77 | * if the <code>DropTarget</code> is currently accepting drops, and | ||
| 78 | * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>). | ||
| 79 | * <P> | ||
| 80 | * The Component will receive drops only if it is enabled. | ||
| 81 | * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated | ||
| 82 | * @param ops The default acceptable actions for this <code>DropTarget</code> | ||
| 83 | * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code> | ||
| 84 | * @param act Is the <code>DropTarget</code> accepting drops. | ||
| 85 | * @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE> | ||
| 86 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 87 | * returns true | ||
| 88 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 89 | */ | ||
| 90 | public DropTarget(Component c, int ops, DropTargetListener dtl, | ||
| 91 | boolean act, FlavorMap fm) | ||
| 92 | throws HeadlessException | ||
| 93 | { | ||
| 94 | if (GraphicsEnvironment.isHeadless()) { | ||
| 95 | throw new HeadlessException(); | ||
| 96 | } | ||
| 97 | |||
| 98 | component = c; | ||
| 99 | |||
| 100 | setDefaultActions(ops); | ||
| 101 | |||
| 102 | if (dtl != null) try { | ||
| 103 | addDropTargetListener(dtl); | ||
| 104 | } catch (TooManyListenersException tmle) { | ||
| 105 | // do nothing! | ||
| 106 | } | ||
| 107 | |||
| 108 | if (c != null) { | ||
| 109 | c.setDropTarget(this); | ||
| 110 | setActive(act); | ||
| 111 | } | ||
| 112 | |||
| 113 | if (fm != null) { | ||
| 114 | flavorMap = fm; | ||
| 115 | } else { | ||
| 116 | flavorMap = SystemFlavorMap.getDefaultFlavorMap(); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Creates a <code>DropTarget</code> given the <code>Component</code> | ||
| 122 | * to associate itself with, an <code>int</code> representing | ||
| 123 | * the default acceptable action(s) | ||
| 124 | * to support, a <code>DropTargetListener</code> | ||
| 125 | * to handle event processing, and a <code>boolean</code> indicating | ||
| 126 | * if the <code>DropTarget</code> is currently accepting drops. | ||
| 127 | * <P> | ||
| 128 | * The Component will receive drops only if it is enabled. | ||
| 129 | * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated | ||
| 130 | * @param ops The default acceptable actions for this <code>DropTarget</code> | ||
| 131 | * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code> | ||
| 132 | * @param act Is the <code>DropTarget</code> accepting drops. | ||
| 133 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 134 | * returns true | ||
| 135 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 136 | */ | ||
| 137 | public DropTarget(Component c, int ops, DropTargetListener dtl, | ||
| 138 | boolean act) | ||
| 139 | throws HeadlessException | ||
| 140 | { | ||
| 141 | this(c, ops, dtl, act, null); | ||
| 142 | } | ||
| 143 | |||
| 144 | /** | ||
| 145 | * Creates a <code>DropTarget</code>. | ||
| 146 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 147 | * returns true | ||
| 148 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 149 | */ | ||
| 150 | public DropTarget() throws HeadlessException { | ||
| 151 | this(null, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null); | ||
| 152 | } | ||
| 153 | |||
| 154 | /** | ||
| 155 | * Creates a <code>DropTarget</code> given the <code>Component</code> | ||
| 156 | * to associate itself with, and the <code>DropTargetListener</code> | ||
| 157 | * to handle event processing. | ||
| 158 | * <P> | ||
| 159 | * The Component will receive drops only if it is enabled. | ||
| 160 | * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated | ||
| 161 | * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code> | ||
| 162 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 163 | * returns true | ||
| 164 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 165 | */ | ||
| 166 | public DropTarget(Component c, DropTargetListener dtl) | ||
| 167 | throws HeadlessException | ||
| 168 | { | ||
| 169 | this(c, DnDConstants.ACTION_COPY_OR_MOVE, dtl, true, null); | ||
| 170 | } | ||
| 171 | |||
| 172 | /** | ||
| 173 | * Creates a <code>DropTarget</code> given the <code>Component</code> | ||
| 174 | * to associate itself with, an <code>int</code> representing | ||
| 175 | * the default acceptable action(s) to support, and a | ||
| 176 | * <code>DropTargetListener</code> to handle event processing. | ||
| 177 | * <P> | ||
| 178 | * The Component will receive drops only if it is enabled. | ||
| 179 | * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated | ||
| 180 | * @param ops The default acceptable actions for this <code>DropTarget</code> | ||
| 181 | * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code> | ||
| 182 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 183 | * returns true | ||
| 184 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 185 | */ | ||
| 186 | public DropTarget(Component c, int ops, DropTargetListener dtl) | ||
| 187 | throws HeadlessException | ||
| 188 | { | ||
| 189 | this(c, ops, dtl, true); | ||
| 190 | } | ||
| 191 | |||
| 192 | /** | ||
| 193 | * Note: this interface is required to permit the safe association | ||
| 194 | * of a DropTarget with a Component in one of two ways, either: | ||
| 195 | * <code> component.setDropTarget(droptarget); </code> | ||
| 196 | * or <code> droptarget.setComponent(component); </code> | ||
| 197 | * <P> | ||
| 198 | * The Component will receive drops only if it is enabled. | ||
| 199 | * @param c The new <code>Component</code> this <code>DropTarget</code> | ||
| 200 | * is to be associated with.<P> | ||
| 201 | */ | ||
| 202 | |||
| 203 | public synchronized void setComponent(Component c) { | ||
| 204 | if (component == c || component != null && component.equals(c)) | ||
| 205 | return; | ||
| 206 | |||
| 207 | Component old; | ||
| 208 | ComponentPeer oldPeer = null; | ||
| 209 | |||
| 210 | if ((old = component) != null) { | ||
| 211 | clearAutoscroll(); | ||
| 212 | |||
| 213 | component = null; | ||
| 214 | |||
| 215 | if (componentPeer != null) { | ||
| 216 | oldPeer = componentPeer; | ||
| 217 | removeNotify(componentPeer); | ||
| 218 | } | ||
| 219 | |||
| 220 | old.setDropTarget(null); | ||
| 221 | |||
| 222 | } | ||
| 223 | |||
| 224 | if ((component = c) != null) try { | ||
| 225 | c.setDropTarget(this); | ||
| 226 | } catch (Exception e) { // undo the change | ||
| 227 | if (old != null) { | ||
| 228 | old.setDropTarget(this); | ||
| 229 | addNotify(oldPeer); | ||
| 230 | } | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | /** | ||
| 235 | * Gets the <code>Component</code> associated | ||
| 236 | * with this <code>DropTarget</code>. | ||
| 237 | * <P> | ||
| 238 | * @return the current <code>Component</code> | ||
| 239 | */ | ||
| 240 | |||
| 241 | public synchronized Component getComponent() { | ||
| 242 | return component; | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * Sets the default acceptable actions for this <code>DropTarget</code> | ||
| 247 | * <P> | ||
| 248 | * @param ops the default actions | ||
| 249 | * <P> | ||
| 250 | * @see java.awt.dnd.DnDConstants | ||
| 251 | */ | ||
| 252 | |||
| 253 | public void setDefaultActions(int ops) { | ||
| 254 | getDropTargetContext().setTargetActions(ops & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE)); | ||
| 255 | } | ||
| 256 | |||
| 257 | /* | ||
| 258 | * Called by DropTargetContext.setTargetActions() | ||
| 259 | * with appropriate synchronization. | ||
| 260 | */ | ||
| 261 | void doSetDefaultActions(int ops) { | ||
| 262 | actions = ops; | ||
| 263 | } | ||
| 264 | |||
| 265 | /** | ||
| 266 | * Gets an <code>int</code> representing the | ||
| 267 | * current action(s) supported by this <code>DropTarget</code>. | ||
| 268 | * <P> | ||
| 269 | * @return the current default actions | ||
| 270 | */ | ||
| 271 | |||
| 272 | public int getDefaultActions() { | ||
| 273 | return actions; | ||
| 274 | } | ||
| 275 | |||
| 276 | /** | ||
| 277 | * Sets the DropTarget active if <code>true</code>, | ||
| 278 | * inactive if <code>false</code>. | ||
| 279 | * <P> | ||
| 280 | * @param isActive sets the <code>DropTarget</code> (in)active. | ||
| 281 | */ | ||
| 282 | |||
| 283 | public synchronized void setActive(boolean isActive) { | ||
| 284 | if (isActive != active) { | ||
| 285 | active = isActive; | ||
| 286 | } | ||
| 287 | |||
| 288 | if (!active) clearAutoscroll(); | ||
| 289 | } | ||
| 290 | |||
| 291 | /** | ||
| 292 | * Reports whether or not | ||
| 293 | * this <code>DropTarget</code> | ||
| 294 | * is currently active (ready to accept drops). | ||
| 295 | * <P> | ||
| 296 | * @return <CODE>true</CODE> if active, <CODE>false</CODE> if not | ||
| 297 | */ | ||
| 298 | |||
| 299 | public boolean isActive() { | ||
| 300 | return active; | ||
| 301 | } | ||
| 302 | |||
| 303 | /** | ||
| 304 | * Adds a new <code>DropTargetListener</code> (UNICAST SOURCE). | ||
| 305 | * <P> | ||
| 306 | * @param dtl The new <code>DropTargetListener</code> | ||
| 307 | * <P> | ||
| 308 | * @throws <code>TooManyListenersException</code> if a | ||
| 309 | * <code>DropTargetListener</code> is already added to this | ||
| 310 | * <code>DropTarget</code>. | ||
| 311 | */ | ||
| 312 | |||
| 313 | public synchronized void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException { | ||
| 314 | if (dtl == null) return; | ||
| 315 | |||
| 316 | if (equals(dtl)) throw new IllegalArgumentException("DropTarget may not be its own Listener"); | ||
| 317 | |||
| 318 | if (dtListener == null) | ||
| 319 | dtListener = dtl; | ||
| 320 | else | ||
| 321 | throw new TooManyListenersException(); | ||
| 322 | } | ||
| 323 | |||
| 324 | /** | ||
| 325 | * Removes the current <code>DropTargetListener</code> (UNICAST SOURCE). | ||
| 326 | * <P> | ||
| 327 | * @param dtl the DropTargetListener to deregister. | ||
| 328 | */ | ||
| 329 | |||
| 330 | public synchronized void removeDropTargetListener(DropTargetListener dtl) { | ||
| 331 | if (dtl != null && dtListener != null) { | ||
| 332 | if(dtListener.equals(dtl)) | ||
| 333 | dtListener = null; | ||
| 334 | else | ||
| 335 | throw new IllegalArgumentException("listener mismatch"); | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | /** | ||
| 340 | * Calls <code>dragEnter</code> on the registered | ||
| 341 | * <code>DropTargetListener</code> and passes it | ||
| 342 | * the specified <code>DropTargetDragEvent</code>. | ||
| 343 | * Has no effect if this <code>DropTarget</code> | ||
| 344 | * is not active. | ||
| 345 | * | ||
| 346 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 347 | * | ||
| 348 | * @throws NullPointerException if this <code>DropTarget</code> | ||
| 349 | * is active and <code>dtde</code> is <code>null</code> | ||
| 350 | * | ||
| 351 | * @see #isActive | ||
| 352 | */ | ||
| 353 | public synchronized void dragEnter(DropTargetDragEvent dtde) { | ||
| 354 | if (!active) return; | ||
| 355 | |||
| 356 | if (dtListener != null) { | ||
| 357 | dtListener.dragEnter(dtde); | ||
| 358 | } else | ||
| 359 | dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE); | ||
| 360 | |||
| 361 | initializeAutoscrolling(dtde.getLocation()); | ||
| 362 | } | ||
| 363 | |||
| 364 | /** | ||
| 365 | * Calls <code>dragOver</code> on the registered | ||
| 366 | * <code>DropTargetListener</code> and passes it | ||
| 367 | * the specified <code>DropTargetDragEvent</code>. | ||
| 368 | * Has no effect if this <code>DropTarget</code> | ||
| 369 | * is not active. | ||
| 370 | * | ||
| 371 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 372 | * | ||
| 373 | * @throws NullPointerException if this <code>DropTarget</code> | ||
| 374 | * is active and <code>dtde</code> is <code>null</code> | ||
| 375 | * | ||
| 376 | * @see #isActive | ||
| 377 | */ | ||
| 378 | public synchronized void dragOver(DropTargetDragEvent dtde) { | ||
| 379 | if (!active) return; | ||
| 380 | |||
| 381 | if (dtListener != null && active) dtListener.dragOver(dtde); | ||
| 382 | |||
| 383 | updateAutoscroll(dtde.getLocation()); | ||
| 384 | } | ||
| 385 | |||
| 386 | /** | ||
| 387 | * Calls <code>dropActionChanged</code> on the registered | ||
| 388 | * <code>DropTargetListener</code> and passes it | ||
| 389 | * the specified <code>DropTargetDragEvent</code>. | ||
| 390 | * Has no effect if this <code>DropTarget</code> | ||
| 391 | * is not active. | ||
| 392 | * | ||
| 393 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 394 | * | ||
| 395 | * @throws NullPointerException if this <code>DropTarget</code> | ||
| 396 | * is active and <code>dtde</code> is <code>null</code> | ||
| 397 | * | ||
| 398 | * @see #isActive | ||
| 399 | */ | ||
| 400 | public synchronized void dropActionChanged(DropTargetDragEvent dtde) { | ||
| 401 | if (!active) return; | ||
| 402 | |||
| 403 | if (dtListener != null) dtListener.dropActionChanged(dtde); | ||
| 404 | |||
| 405 | updateAutoscroll(dtde.getLocation()); | ||
| 406 | } | ||
| 407 | |||
| 408 | /** | ||
| 409 | * Calls <code>dragExit</code> on the registered | ||
| 410 | * <code>DropTargetListener</code> and passes it | ||
| 411 | * the specified <code>DropTargetEvent</code>. | ||
| 412 | * Has no effect if this <code>DropTarget</code> | ||
| 413 | * is not active. | ||
| 414 | * <p> | ||
| 415 | * This method itself does not throw any exception | ||
| 416 | * for null parameter but for exceptions thrown by | ||
| 417 | * the respective method of the listener. | ||
| 418 | * | ||
| 419 | * @param dte the <code>DropTargetEvent</code> | ||
| 420 | * | ||
| 421 | * @see #isActive | ||
| 422 | */ | ||
| 423 | public synchronized void dragExit(DropTargetEvent dte) { | ||
| 424 | if (!active) return; | ||
| 425 | |||
| 426 | if (dtListener != null && active) dtListener.dragExit(dte); | ||
| 427 | |||
| 428 | clearAutoscroll(); | ||
| 429 | } | ||
| 430 | |||
| 431 | /** | ||
| 432 | * Calls <code>drop</code> on the registered | ||
| 433 | * <code>DropTargetListener</code> and passes it | ||
| 434 | * the specified <code>DropTargetDropEvent</code> | ||
| 435 | * if this <code>DropTarget</code> is active. | ||
| 436 | * | ||
| 437 | * @param dtde the <code>DropTargetDropEvent</code> | ||
| 438 | * | ||
| 439 | * @throws NullPointerException if <code>dtde</code> is null | ||
| 440 | * and at least one of the following is true: this | ||
| 441 | * <code>DropTarget</code> is not active, or there is | ||
| 442 | * no a <code>DropTargetListener</code> registered. | ||
| 443 | * | ||
| 444 | * @see #isActive | ||
| 445 | */ | ||
| 446 | public synchronized void drop(DropTargetDropEvent dtde) { | ||
| 447 | clearAutoscroll(); | ||
| 448 | |||
| 449 | if (dtListener != null && active) | ||
| 450 | dtListener.drop(dtde); | ||
| 451 | else { // we should'nt get here ... | ||
| 452 | dtde.rejectDrop(); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | /** | ||
| 457 | * Gets the <code>FlavorMap</code> | ||
| 458 | * associated with this <code>DropTarget</code>. | ||
| 459 | * If no <code>FlavorMap</code> has been set for this | ||
| 460 | * <code>DropTarget</code>, it is associated with the default | ||
| 461 | * <code>FlavorMap</code>. | ||
| 462 | * <P> | ||
| 463 | * @return the FlavorMap for this DropTarget | ||
| 464 | */ | ||
| 465 | |||
| 466 | public FlavorMap getFlavorMap() { return flavorMap; } | ||
| 467 | |||
| 468 | /** | ||
| 469 | * Sets the <code>FlavorMap</code> associated | ||
| 470 | * with this <code>DropTarget</code>. | ||
| 471 | * <P> | ||
| 472 | * @param fm the new <code>FlavorMap</code>, or null to | ||
| 473 | * associate the default FlavorMap with this DropTarget. | ||
| 474 | */ | ||
| 475 | |||
| 476 | public void setFlavorMap(FlavorMap fm) { | ||
| 477 | flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm; | ||
| 478 | } | ||
| 479 | |||
| 480 | /** | ||
| 481 | * Notify the DropTarget that it has been associated with a Component | ||
| 482 | * | ||
| 483 | ********************************************************************** | ||
| 484 | * This method is usually called from java.awt.Component.addNotify() of | ||
| 485 | * the Component associated with this DropTarget to notify the DropTarget | ||
| 486 | * that a ComponentPeer has been associated with that Component. | ||
| 487 | * | ||
| 488 | * Calling this method, other than to notify this DropTarget of the | ||
| 489 | * association of the ComponentPeer with the Component may result in | ||
| 490 | * a malfunction of the DnD system. | ||
| 491 | ********************************************************************** | ||
| 492 | * <P> | ||
| 493 | * @param peer The Peer of the Component we are associated with! | ||
| 494 | * | ||
| 495 | */ | ||
| 496 | |||
| 497 | public void addNotify(ComponentPeer peer) { | ||
| 498 | if (peer == componentPeer) return; | ||
| 499 | |||
| 500 | componentPeer = peer; | ||
| 501 | |||
| 502 | for (Component c = component; | ||
| 503 | c != null && peer instanceof LightweightPeer; c = c.getParent()) { | ||
| 504 | peer = c.getPeer(); | ||
| 505 | } | ||
| 506 | |||
| 507 | if (peer instanceof DropTargetPeer) { | ||
| 508 | nativePeer = peer; | ||
| 509 | ((DropTargetPeer)peer).addDropTarget(this); | ||
| 510 | } else { | ||
| 511 | nativePeer = null; | ||
| 512 | } | ||
| 513 | } | ||
| 514 | |||
| 515 | /** | ||
| 516 | * Notify the DropTarget that it has been disassociated from a Component | ||
| 517 | * | ||
| 518 | ********************************************************************** | ||
| 519 | * This method is usually called from java.awt.Component.removeNotify() of | ||
| 520 | * the Component associated with this DropTarget to notify the DropTarget | ||
| 521 | * that a ComponentPeer has been disassociated with that Component. | ||
| 522 | * | ||
| 523 | * Calling this method, other than to notify this DropTarget of the | ||
| 524 | * disassociation of the ComponentPeer from the Component may result in | ||
| 525 | * a malfunction of the DnD system. | ||
| 526 | ********************************************************************** | ||
| 527 | * <P> | ||
| 528 | * @param peer The Peer of the Component we are being disassociated from! | ||
| 529 | */ | ||
| 530 | |||
| 531 | public void removeNotify(ComponentPeer peer) { | ||
| 532 | if (nativePeer != null) | ||
| 533 | ((DropTargetPeer)nativePeer).removeDropTarget(this); | ||
| 534 | |||
| 535 | componentPeer = nativePeer = null; | ||
| 536 | } | ||
| 537 | |||
| 538 | /** | ||
| 539 | * Gets the <code>DropTargetContext</code> associated | ||
| 540 | * with this <code>DropTarget</code>. | ||
| 541 | * <P> | ||
| 542 | * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>. | ||
| 543 | */ | ||
| 544 | |||
| 545 | public DropTargetContext getDropTargetContext() { | ||
| 546 | return dropTargetContext; | ||
| 547 | } | ||
| 548 | |||
| 549 | /** | ||
| 550 | * Creates the DropTargetContext associated with this DropTarget. | ||
| 551 | * Subclasses may override this method to instantiate their own | ||
| 552 | * DropTargetContext subclass. | ||
| 553 | * | ||
| 554 | * This call is typically *only* called by the platform's | ||
| 555 | * DropTargetContextPeer as a drag operation encounters this | ||
| 556 | * DropTarget. Accessing the Context while no Drag is current | ||
| 557 | * has undefined results. | ||
| 558 | */ | ||
| 559 | |||
| 560 | protected DropTargetContext createDropTargetContext() { | ||
| 561 | return new DropTargetContext(this); | ||
| 562 | } | ||
| 563 | |||
| 564 | /** | ||
| 565 | * Serializes this <code>DropTarget</code>. Performs default serialization, | ||
| 566 | * and then writes out this object's <code>DropTargetListener</code> if and | ||
| 567 | * only if it can be serialized. If not, <code>null</code> is written | ||
| 568 | * instead. | ||
| 569 | * | ||
| 570 | * @serialData The default serializable fields, in alphabetical order, | ||
| 571 | * followed by either a <code>DropTargetListener</code> | ||
| 572 | * instance, or <code>null</code>. | ||
| 573 | * @since 1.4 | ||
| 574 | */ | ||
| 575 | private void writeObject(ObjectOutputStream s) throws IOException { | ||
| 576 | s.defaultWriteObject(); | ||
| 577 | |||
| 578 | s.writeObject(SerializationTester.test(dtListener) | ||
| 579 | ? dtListener : null); | ||
| 580 | } | ||
| 581 | |||
| 582 | /** | ||
| 583 | * Deserializes this <code>DropTarget</code>. This method first performs | ||
| 584 | * default deserialization for all non-<code>transient</code> fields. An | ||
| 585 | * attempt is then made to deserialize this object's | ||
| 586 | * <code>DropTargetListener</code> as well. This is first attempted by | ||
| 587 | * deserializing the field <code>dtListener</code>, because, in releases | ||
| 588 | * prior to 1.4, a non-<code>transient</code> field of this name stored the | ||
| 589 | * <code>DropTargetListener</code>. If this fails, the next object in the | ||
| 590 | * stream is used instead. | ||
| 591 | * | ||
| 592 | * @since 1.4 | ||
| 593 | */ | ||
| 594 | private void readObject(ObjectInputStream s) | ||
| 595 | throws ClassNotFoundException, IOException | ||
| 596 | { | ||
| 597 | ObjectInputStream.GetField f = s.readFields(); | ||
| 598 | |||
| 599 | try { | ||
| 600 | dropTargetContext = | ||
| 601 | (DropTargetContext)f.get("dropTargetContext", null); | ||
| 602 | } catch (IllegalArgumentException e) { | ||
| 603 | // Pre-1.4 support. 'dropTargetContext' was previoulsy transient | ||
| 604 | } | ||
| 605 | if (dropTargetContext == null) { | ||
| 606 | dropTargetContext = createDropTargetContext(); | ||
| 607 | } | ||
| 608 | |||
| 609 | component = (Component)f.get("component", null); | ||
| 610 | actions = f.get("actions", DnDConstants.ACTION_COPY_OR_MOVE); | ||
| 611 | active = f.get("active", true); | ||
| 612 | |||
| 613 | // Pre-1.4 support. 'dtListener' was previously non-transient | ||
| 614 | try { | ||
| 615 | dtListener = (DropTargetListener)f.get("dtListener", null); | ||
| 616 | } catch (IllegalArgumentException e) { | ||
| 617 | // 1.4-compatible byte stream. 'dtListener' was written explicitly | ||
| 618 | dtListener = (DropTargetListener)s.readObject(); | ||
| 619 | } | ||
| 620 | } | ||
| 621 | |||
| 622 | /*********************************************************************/ | ||
| 623 | |||
| 624 | /** | ||
| 625 | * this protected nested class implements autoscrolling | ||
| 626 | */ | ||
| 627 | |||
| 628 | protected static class DropTargetAutoScroller implements ActionListener { | ||
| 629 | |||
| 630 | /** | ||
| 631 | * construct a DropTargetAutoScroller | ||
| 632 | * <P> | ||
| 633 | * @param c the <code>Component</code> | ||
| 634 | * @param p the <code>Point</code> | ||
| 635 | */ | ||
| 636 | |||
| 637 | protected DropTargetAutoScroller(Component c, Point p) { | ||
| 638 | super(); | ||
| 639 | |||
| 640 | component = c; | ||
| 641 | autoScroll = (Autoscroll)component; | ||
| 642 | |||
| 643 | Toolkit t = Toolkit.getDefaultToolkit(); | ||
| 644 | |||
| 645 | Integer initial = Integer.valueOf(100); | ||
| 646 | Integer interval = Integer.valueOf(100); | ||
| 647 | |||
| 648 | try { | ||
| 649 | initial = (Integer)t.getDesktopProperty("DnD.Autoscroll.initialDelay"); | ||
| 650 | } catch (Exception e) { | ||
| 651 | // ignore | ||
| 652 | } | ||
| 653 | |||
| 654 | try { | ||
| 655 | interval = (Integer)t.getDesktopProperty("DnD.Autoscroll.interval"); | ||
| 656 | } catch (Exception e) { | ||
| 657 | // ignore | ||
| 658 | } | ||
| 659 | |||
| 660 | timer = new Timer(interval.intValue(), this); | ||
| 661 | |||
| 662 | timer.setCoalesce(true); | ||
| 663 | timer.setInitialDelay(initial.intValue()); | ||
| 664 | |||
| 665 | locn = p; | ||
| 666 | prev = p; | ||
| 667 | |||
| 668 | try { | ||
| 669 | hysteresis = ((Integer)t.getDesktopProperty("DnD.Autoscroll.cursorHysteresis")).intValue(); | ||
| 670 | } catch (Exception e) { | ||
| 671 | // ignore | ||
| 672 | } | ||
| 673 | |||
| 674 | timer.start(); | ||
| 675 | } | ||
| 676 | |||
| 677 | /** | ||
| 678 | * update the geometry of the autoscroll region | ||
| 679 | */ | ||
| 680 | |||
| 681 | private void updateRegion() { | ||
| 682 | Insets i = autoScroll.getAutoscrollInsets(); | ||
| 683 | Dimension size = component.getSize(); | ||
| 684 | |||
| 685 | if (size.width != outer.width || size.height != outer.height) | ||
| 686 | outer.reshape(0, 0, size.width, size.height); | ||
| 687 | |||
| 688 | if (inner.x != i.left || inner.y != i.top) | ||
| 689 | inner.setLocation(i.left, i.top); | ||
| 690 | |||
| 691 | int newWidth = size.width - (i.left + i.right); | ||
| 692 | int newHeight = size.height - (i.top + i.bottom); | ||
| 693 | |||
| 694 | if (newWidth != inner.width || newHeight != inner.height) | ||
| 695 | inner.setSize(newWidth, newHeight); | ||
| 696 | |||
| 697 | } | ||
| 698 | |||
| 699 | /** | ||
| 700 | * cause autoscroll to occur | ||
| 701 | * <P> | ||
| 702 | * @param newLocn the <code>Point</code> | ||
| 703 | */ | ||
| 704 | |||
| 705 | protected synchronized void updateLocation(Point newLocn) { | ||
| 706 | prev = locn; | ||
| 707 | locn = newLocn; | ||
| 708 | |||
| 709 | if (Math.abs(locn.x - prev.x) > hysteresis || | ||
| 710 | Math.abs(locn.y - prev.y) > hysteresis) { | ||
| 711 | if (timer.isRunning()) timer.stop(); | ||
| 712 | } else { | ||
| 713 | if (!timer.isRunning()) timer.start(); | ||
| 714 | } | ||
| 715 | } | ||
| 716 | |||
| 717 | /** | ||
| 718 | * cause autoscrolling to stop | ||
| 719 | */ | ||
| 720 | |||
| 721 | protected void stop() { timer.stop(); } | ||
| 722 | |||
| 723 | /** | ||
| 724 | * cause autoscroll to occur | ||
| 725 | * <P> | ||
| 726 | * @param e the <code>ActionEvent</code> | ||
| 727 | */ | ||
| 728 | |||
| 729 | public synchronized void actionPerformed(ActionEvent e) { | ||
| 730 | updateRegion(); | ||
| 731 | |||
| 732 | if (outer.contains(locn) && !inner.contains(locn)) | ||
| 733 | autoScroll.autoscroll(locn); | ||
| 734 | } | ||
| 735 | |||
| 736 | /* | ||
| 737 | * fields | ||
| 738 | */ | ||
| 739 | |||
| 740 | private Component component; | ||
| 741 | private Autoscroll autoScroll; | ||
| 742 | |||
| 743 | private Timer timer; | ||
| 744 | |||
| 745 | private Point locn; | ||
| 746 | private Point prev; | ||
| 747 | |||
| 748 | private Rectangle outer = new Rectangle(); | ||
| 749 | private Rectangle inner = new Rectangle(); | ||
| 750 | |||
| 751 | private int hysteresis = 10; | ||
| 752 | } | ||
| 753 | |||
| 754 | /*********************************************************************/ | ||
| 755 | |||
| 756 | /** | ||
| 757 | * create an embedded autoscroller | ||
| 758 | * <P> | ||
| 759 | * @param c the <code>Component</code> | ||
| 760 | * @param p the <code>Point</code> | ||
| 761 | */ | ||
| 762 | |||
| 763 | protected DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p) { | ||
| 764 | return new DropTargetAutoScroller(c, p); | ||
| 765 | } | ||
| 766 | |||
| 767 | /** | ||
| 768 | * initialize autoscrolling | ||
| 769 | * <P> | ||
| 770 | * @param p the <code>Point</code> | ||
| 771 | */ | ||
| 772 | |||
| 773 | protected void initializeAutoscrolling(Point p) { | ||
| 774 | if (component == null || !(component instanceof Autoscroll)) return; | ||
| 775 | |||
| 776 | autoScroller = createDropTargetAutoScroller(component, p); | ||
| 777 | } | ||
| 778 | |||
| 779 | /** | ||
| 780 | * update autoscrolling with current cursor locn | ||
| 781 | * <P> | ||
| 782 | * @param dragCursorLocn the <code>Point</code> | ||
| 783 | */ | ||
| 784 | |||
| 785 | protected void updateAutoscroll(Point dragCursorLocn) { | ||
| 786 | if (autoScroller != null) autoScroller.updateLocation(dragCursorLocn); | ||
| 787 | } | ||
| 788 | |||
| 789 | /** | ||
| 790 | * clear autoscrolling | ||
| 791 | */ | ||
| 792 | |||
| 793 | protected void clearAutoscroll() { | ||
| 794 | if (autoScroller != null) { | ||
| 795 | autoScroller.stop(); | ||
| 796 | autoScroller = null; | ||
| 797 | } | ||
| 798 | } | ||
| 799 | |||
| 800 | /** | ||
| 801 | * The DropTargetContext associated with this DropTarget. | ||
| 802 | * | ||
| 803 | * @serial | ||
| 804 | */ | ||
| 805 | private DropTargetContext dropTargetContext = createDropTargetContext(); | ||
| 806 | |||
| 807 | /** | ||
| 808 | * The Component associated with this DropTarget. | ||
| 809 | * | ||
| 810 | * @serial | ||
| 811 | */ | ||
| 812 | private Component component; | ||
| 813 | |||
| 814 | /* | ||
| 815 | * That Component's Peer | ||
| 816 | */ | ||
| 817 | private transient ComponentPeer componentPeer; | ||
| 818 | |||
| 819 | /* | ||
| 820 | * That Component's "native" Peer | ||
| 821 | */ | ||
| 822 | private transient ComponentPeer nativePeer; | ||
| 823 | |||
| 824 | |||
| 825 | /** | ||
| 826 | * Default permissible actions supported by this DropTarget. | ||
| 827 | * | ||
| 828 | * @see #setDefaultActions | ||
| 829 | * @see #getDefaultActions | ||
| 830 | * @serial | ||
| 831 | */ | ||
| 832 | int actions = DnDConstants.ACTION_COPY_OR_MOVE; | ||
| 833 | |||
| 834 | /** | ||
| 835 | * <code>true</code> if the DropTarget is accepting Drag & Drop operations. | ||
| 836 | * | ||
| 837 | * @serial | ||
| 838 | */ | ||
| 839 | boolean active = true; | ||
| 840 | |||
| 841 | /* | ||
| 842 | * the auto scrolling object | ||
| 843 | */ | ||
| 844 | |||
| 845 | private transient DropTargetAutoScroller autoScroller; | ||
| 846 | |||
| 847 | /* | ||
| 848 | * The delegate | ||
| 849 | */ | ||
| 850 | |||
| 851 | private transient DropTargetListener dtListener; | ||
| 852 | |||
| 853 | /* | ||
| 854 | * The FlavorMap | ||
| 855 | */ | ||
| 856 | |||
| 857 | private transient FlavorMap flavorMap; | ||
| 858 | } | ||
Binary file not shown.
| @@ -0,0 +1,109 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | /** | ||
| 29 | * An abstract adapter class for receiving drop target events. The methods in | ||
| 30 | * this class are empty. This class exists only as a convenience for creating | ||
| 31 | * listener objects. | ||
| 32 | * <p> | ||
| 33 | * Extend this class to create a <code>DropTargetEvent</code> listener | ||
| 34 | * and override the methods for the events of interest. (If you implement the | ||
| 35 | * <code>DropTargetListener</code> interface, you have to define all of | ||
| 36 | * the methods in it. This abstract class defines a null implementation for | ||
| 37 | * every method except <code>drop(DropTargetDropEvent)</code>, so you only have | ||
| 38 | * to define methods for events you care about.) You must provide an | ||
| 39 | * implementation for at least <code>drop(DropTargetDropEvent)</code>. This | ||
| 40 | * method cannot have a null implementation because its specification requires | ||
| 41 | * that you either accept or reject the drop, and, if accepted, indicate | ||
| 42 | * whether the drop was successful. | ||
| 43 | * <p> | ||
| 44 | * Create a listener object using the extended class and then register it with | ||
| 45 | * a <code>DropTarget</code>. When the drag enters, moves over, or exits | ||
| 46 | * the operable part of the drop site for that <code>DropTarget</code>, when | ||
| 47 | * the drop action changes, and when the drop occurs, the relevant method in | ||
| 48 | * the listener object is invoked, and the <code>DropTargetEvent</code> is | ||
| 49 | * passed to it. | ||
| 50 | * <p> | ||
| 51 | * The operable part of the drop site for the <code>DropTarget</code> is | ||
| 52 | * the part of the associated <code>Component</code>'s geometry that is not | ||
| 53 | * obscured by an overlapping top-level window or by another | ||
| 54 | * <code>Component</code> higher in the Z-order that has an associated active | ||
| 55 | * <code>DropTarget</code>. | ||
| 56 | * <p> | ||
| 57 | * During the drag, the data associated with the current drag operation can be | ||
| 58 | * retrieved by calling <code>getTransferable()</code> on | ||
| 59 | * <code>DropTargetDragEvent</code> instances passed to the listener's | ||
| 60 | * methods. | ||
| 61 | * <p> | ||
| 62 | * Note that <code>getTransferable()</code> on the | ||
| 63 | * <code>DropTargetDragEvent</code> instance should only be called within the | ||
| 64 | * respective listener's method and all the necessary data should be retrieved | ||
| 65 | * from the returned <code>Transferable</code> before that method returns. | ||
| 66 | * | ||
| 67 | * @see DropTargetEvent | ||
| 68 | * @see DropTargetListener | ||
| 69 | * | ||
| 70 | * @author David Mendenhall | ||
| 71 | * @since 1.4 | ||
| 72 | */ | ||
| 73 | public abstract class DropTargetAdapter implements DropTargetListener { | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Called while a drag operation is ongoing, when the mouse pointer enters | ||
| 77 | * the operable part of the drop site for the <code>DropTarget</code> | ||
| 78 | * registered with this listener. | ||
| 79 | * | ||
| 80 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 81 | */ | ||
| 82 | public void dragEnter(DropTargetDragEvent dtde) {} | ||
| 83 | |||
| 84 | /** | ||
| 85 | * Called when a drag operation is ongoing, while the mouse pointer is still | ||
| 86 | * over the operable part of the drop site for the <code>DropTarget</code> | ||
| 87 | * registered with this listener. | ||
| 88 | * | ||
| 89 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 90 | */ | ||
| 91 | public void dragOver(DropTargetDragEvent dtde) {} | ||
| 92 | |||
| 93 | /** | ||
| 94 | * Called if the user has modified | ||
| 95 | * the current drop gesture. | ||
| 96 | * | ||
| 97 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 98 | */ | ||
| 99 | public void dropActionChanged(DropTargetDragEvent dtde) {} | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Called while a drag operation is ongoing, when the mouse pointer has | ||
| 103 | * exited the operable part of the drop site for the | ||
| 104 | * <code>DropTarget</code> registered with this listener. | ||
| 105 | * | ||
| 106 | * @param dte the <code>DropTargetEvent</code> | ||
| 107 | */ | ||
| 108 | public void dragExit(DropTargetEvent dte) {} | ||
| 109 | } | ||
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,420 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.Component; | ||
| 29 | |||
| 30 | import java.awt.datatransfer.DataFlavor; | ||
| 31 | import java.awt.datatransfer.Transferable; | ||
| 32 | import java.awt.datatransfer.UnsupportedFlavorException; | ||
| 33 | |||
| 34 | import java.awt.dnd.peer.DropTargetContextPeer; | ||
| 35 | |||
| 36 | import java.io.IOException; | ||
| 37 | import java.io.Serializable; | ||
| 38 | |||
| 39 | import java.util.Arrays; | ||
| 40 | import java.util.List; | ||
| 41 | |||
| 42 | |||
| 43 | /** | ||
| 44 | * A <code>DropTargetContext</code> is created | ||
| 45 | * whenever the logical cursor associated | ||
| 46 | * with a Drag and Drop operation coincides with the visible geometry of | ||
| 47 | * a <code>Component</code> associated with a <code>DropTarget</code>. | ||
| 48 | * The <code>DropTargetContext</code> provides | ||
| 49 | * the mechanism for a potential receiver | ||
| 50 | * of a drop operation to both provide the end user with the appropriate | ||
| 51 | * drag under feedback, but also to effect the subsequent data transfer | ||
| 52 | * if appropriate. | ||
| 53 | * | ||
| 54 | * @since 1.2 | ||
| 55 | */ | ||
| 56 | |||
| 57 | public class DropTargetContext implements Serializable { | ||
| 58 | |||
| 59 | private static final long serialVersionUID = -634158968993743371L; | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Construct a <code>DropTargetContext</code> | ||
| 63 | * given a specified <code>DropTarget</code>. | ||
| 64 | * <P> | ||
| 65 | * @param dt the DropTarget to associate with | ||
| 66 | */ | ||
| 67 | |||
| 68 | DropTargetContext(DropTarget dt) { | ||
| 69 | super(); | ||
| 70 | |||
| 71 | dropTarget = dt; | ||
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * This method returns the <code>DropTarget</code> associated with this | ||
| 76 | * <code>DropTargetContext</code>. | ||
| 77 | * <P> | ||
| 78 | * @return the <code>DropTarget</code> associated with this <code>DropTargetContext</code> | ||
| 79 | */ | ||
| 80 | |||
| 81 | public DropTarget getDropTarget() { return dropTarget; } | ||
| 82 | |||
| 83 | /** | ||
| 84 | * This method returns the <code>Component</code> associated with | ||
| 85 | * this <code>DropTargetContext</code>. | ||
| 86 | * <P> | ||
| 87 | * @return the Component associated with this Context | ||
| 88 | */ | ||
| 89 | |||
| 90 | public Component getComponent() { return dropTarget.getComponent(); } | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Called when associated with the <code>DropTargetContextPeer</code>. | ||
| 94 | * <P> | ||
| 95 | * @param dtcp the <code>DropTargetContextPeer</code> | ||
| 96 | */ | ||
| 97 | |||
| 98 | public void addNotify(DropTargetContextPeer dtcp) { | ||
| 99 | dropTargetContextPeer = dtcp; | ||
| 100 | } | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Called when disassociated with the <code>DropTargetContextPeer</code>. | ||
| 104 | */ | ||
| 105 | |||
| 106 | public void removeNotify() { | ||
| 107 | dropTargetContextPeer = null; | ||
| 108 | transferable = null; | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * This method sets the current actions acceptable to | ||
| 113 | * this <code>DropTarget</code>. | ||
| 114 | * <P> | ||
| 115 | * @param actions an <code>int</code> representing the supported action(s) | ||
| 116 | */ | ||
| 117 | |||
| 118 | protected void setTargetActions(int actions) { | ||
| 119 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 120 | if (peer != null) { | ||
| 121 | synchronized (peer) { | ||
| 122 | peer.setTargetActions(actions); | ||
| 123 | getDropTarget().doSetDefaultActions(actions); | ||
| 124 | } | ||
| 125 | } else { | ||
| 126 | getDropTarget().doSetDefaultActions(actions); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * This method returns an <code>int</code> representing the | ||
| 132 | * current actions this <code>DropTarget</code> will accept. | ||
| 133 | * <P> | ||
| 134 | * @return the current actions acceptable to this <code>DropTarget</code> | ||
| 135 | */ | ||
| 136 | |||
| 137 | protected int getTargetActions() { | ||
| 138 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 139 | return ((peer != null) | ||
| 140 | ? peer.getTargetActions() | ||
| 141 | : dropTarget.getDefaultActions() | ||
| 142 | ); | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * This method signals that the drop is completed and | ||
| 147 | * if it was successful or not. | ||
| 148 | * <P> | ||
| 149 | * @param success true for success, false if not | ||
| 150 | * <P> | ||
| 151 | * @throws InvalidDnDOperationException if a drop is not outstanding/extant | ||
| 152 | */ | ||
| 153 | |||
| 154 | public void dropComplete(boolean success) throws InvalidDnDOperationException{ | ||
| 155 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 156 | if (peer != null) { | ||
| 157 | peer.dropComplete(success); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | /** | ||
| 162 | * accept the Drag. | ||
| 163 | * <P> | ||
| 164 | * @param dragOperation the supported action(s) | ||
| 165 | */ | ||
| 166 | |||
| 167 | protected void acceptDrag(int dragOperation) { | ||
| 168 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 169 | if (peer != null) { | ||
| 170 | peer.acceptDrag(dragOperation); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | /** | ||
| 175 | * reject the Drag. | ||
| 176 | */ | ||
| 177 | |||
| 178 | protected void rejectDrag() { | ||
| 179 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 180 | if (peer != null) { | ||
| 181 | peer.rejectDrag(); | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | /** | ||
| 186 | * called to signal that the drop is acceptable | ||
| 187 | * using the specified operation. | ||
| 188 | * must be called during DropTargetListener.drop method invocation. | ||
| 189 | * <P> | ||
| 190 | * @param dropOperation the supported action(s) | ||
| 191 | */ | ||
| 192 | |||
| 193 | protected void acceptDrop(int dropOperation) { | ||
| 194 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 195 | if (peer != null) { | ||
| 196 | peer.acceptDrop(dropOperation); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | /** | ||
| 201 | * called to signal that the drop is unacceptable. | ||
| 202 | * must be called during DropTargetListener.drop method invocation. | ||
| 203 | */ | ||
| 204 | |||
| 205 | protected void rejectDrop() { | ||
| 206 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 207 | if (peer != null) { | ||
| 208 | peer.rejectDrop(); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | /** | ||
| 213 | * get the available DataFlavors of the | ||
| 214 | * <code>Transferable</code> operand of this operation. | ||
| 215 | * <P> | ||
| 216 | * @return a <code>DataFlavor[]</code> containing the | ||
| 217 | * supported <code>DataFlavor</code>s of the | ||
| 218 | * <code>Transferable</code> operand. | ||
| 219 | */ | ||
| 220 | |||
| 221 | protected DataFlavor[] getCurrentDataFlavors() { | ||
| 222 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 223 | return peer != null ? peer.getTransferDataFlavors() : new DataFlavor[0]; | ||
| 224 | } | ||
| 225 | |||
| 226 | /** | ||
| 227 | * This method returns a the currently available DataFlavors | ||
| 228 | * of the <code>Transferable</code> operand | ||
| 229 | * as a <code>java.util.List</code>. | ||
| 230 | * <P> | ||
| 231 | * @return the currently available | ||
| 232 | * DataFlavors as a <code>java.util.List</code> | ||
| 233 | */ | ||
| 234 | |||
| 235 | protected List<DataFlavor> getCurrentDataFlavorsAsList() { | ||
| 236 | return Arrays.asList(getCurrentDataFlavors()); | ||
| 237 | } | ||
| 238 | |||
| 239 | /** | ||
| 240 | * This method returns a <code>boolean</code> | ||
| 241 | * indicating if the given <code>DataFlavor</code> is | ||
| 242 | * supported by this <code>DropTargetContext</code>. | ||
| 243 | * <P> | ||
| 244 | * @param df the <code>DataFlavor</code> | ||
| 245 | * <P> | ||
| 246 | * @return if the <code>DataFlavor</code> specified is supported | ||
| 247 | */ | ||
| 248 | |||
| 249 | protected boolean isDataFlavorSupported(DataFlavor df) { | ||
| 250 | return getCurrentDataFlavorsAsList().contains(df); | ||
| 251 | } | ||
| 252 | |||
| 253 | /** | ||
| 254 | * get the Transferable (proxy) operand of this operation | ||
| 255 | * <P> | ||
| 256 | * @throws InvalidDnDOperationException if a drag is not outstanding/extant | ||
| 257 | * <P> | ||
| 258 | * @return the <code>Transferable</code> | ||
| 259 | */ | ||
| 260 | |||
| 261 | protected Transferable getTransferable() throws InvalidDnDOperationException { | ||
| 262 | DropTargetContextPeer peer = getDropTargetContextPeer(); | ||
| 263 | if (peer == null) { | ||
| 264 | throw new InvalidDnDOperationException(); | ||
| 265 | } else { | ||
| 266 | if (transferable == null) { | ||
| 267 | Transferable t = peer.getTransferable(); | ||
| 268 | boolean isLocal = peer.isTransferableJVMLocal(); | ||
| 269 | synchronized (this) { | ||
| 270 | if (transferable == null) { | ||
| 271 | transferable = createTransferableProxy(t, isLocal); | ||
| 272 | } | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | return transferable; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | |||
| 280 | /** | ||
| 281 | * Get the <code>DropTargetContextPeer</code> | ||
| 282 | * <P> | ||
| 283 | * @return the platform peer | ||
| 284 | */ | ||
| 285 | |||
| 286 | DropTargetContextPeer getDropTargetContextPeer() { | ||
| 287 | return dropTargetContextPeer; | ||
| 288 | } | ||
| 289 | |||
| 290 | /** | ||
| 291 | * Creates a TransferableProxy to proxy for the specified | ||
| 292 | * Transferable. | ||
| 293 | * | ||
| 294 | * @param t the <tt>Transferable</tt> to be proxied | ||
| 295 | * @param local <tt>true</tt> if <tt>t</tt> represents | ||
| 296 | * the result of a local drag-n-drop operation. | ||
| 297 | * @return the new <tt>TransferableProxy</tt> instance. | ||
| 298 | */ | ||
| 299 | protected Transferable createTransferableProxy(Transferable t, boolean local) { | ||
| 300 | return new TransferableProxy(t, local); | ||
| 301 | } | ||
| 302 | |||
| 303 | /****************************************************************************/ | ||
| 304 | |||
| 305 | |||
| 306 | /** | ||
| 307 | * <code>TransferableProxy</code> is a helper inner class that implements | ||
| 308 | * <code>Transferable</code> interface and serves as a proxy for another | ||
| 309 | * <code>Transferable</code> object which represents data transfer for | ||
| 310 | * a particular drag-n-drop operation. | ||
| 311 | * <p> | ||
| 312 | * The proxy forwards all requests to the encapsulated transferable | ||
| 313 | * and automatically performs additional conversion on the data | ||
| 314 | * returned by the encapsulated transferable in case of local transfer. | ||
| 315 | */ | ||
| 316 | |||
| 317 | protected class TransferableProxy implements Transferable { | ||
| 318 | |||
| 319 | /** | ||
| 320 | * Constructs a <code>TransferableProxy</code> given | ||
| 321 | * a specified <code>Transferable</code> object representing | ||
| 322 | * data transfer for a particular drag-n-drop operation and | ||
| 323 | * a <code>boolean</code> which indicates whether the | ||
| 324 | * drag-n-drop operation is local (within the same JVM). | ||
| 325 | * <p> | ||
| 326 | * @param t the <code>Transferable</code> object | ||
| 327 | * @param local <code>true</code>, if <code>t</code> represents | ||
| 328 | * the result of local drag-n-drop operation | ||
| 329 | */ | ||
| 330 | TransferableProxy(Transferable t, boolean local) { | ||
| 331 | proxy = new sun.awt.datatransfer.TransferableProxy(t, local); | ||
| 332 | transferable = t; | ||
| 333 | isLocal = local; | ||
| 334 | } | ||
| 335 | |||
| 336 | /** | ||
| 337 | * Returns an array of DataFlavor objects indicating the flavors | ||
| 338 | * the data can be provided in by the encapsulated transferable. | ||
| 339 | * <p> | ||
| 340 | * @return an array of data flavors in which the data can be | ||
| 341 | * provided by the encapsulated transferable | ||
| 342 | */ | ||
| 343 | public DataFlavor[] getTransferDataFlavors() { | ||
| 344 | return proxy.getTransferDataFlavors(); | ||
| 345 | } | ||
| 346 | |||
| 347 | /** | ||
| 348 | * Returns whether or not the specified data flavor is supported by | ||
| 349 | * the encapsulated transferable. | ||
| 350 | * @param flavor the requested flavor for the data | ||
| 351 | * @return <code>true</code> if the data flavor is supported, | ||
| 352 | * <code>false</code> otherwise | ||
| 353 | */ | ||
| 354 | public boolean isDataFlavorSupported(DataFlavor flavor) { | ||
| 355 | return proxy.isDataFlavorSupported(flavor); | ||
| 356 | } | ||
| 357 | |||
| 358 | /** | ||
| 359 | * Returns an object which represents the data provided by | ||
| 360 | * the encapsulated transferable for the requested data flavor. | ||
| 361 | * <p> | ||
| 362 | * In case of local transfer a serialized copy of the object | ||
| 363 | * returned by the encapsulated transferable is provided when | ||
| 364 | * the data is requested in application/x-java-serialized-object | ||
| 365 | * data flavor. | ||
| 366 | * | ||
| 367 | * @param df the requested flavor for the data | ||
| 368 | * @throws IOException if the data is no longer available | ||
| 369 | * in the requested flavor. | ||
| 370 | * @throws UnsupportedFlavorException if the requested data flavor is | ||
| 371 | * not supported. | ||
| 372 | */ | ||
| 373 | public Object getTransferData(DataFlavor df) | ||
| 374 | throws UnsupportedFlavorException, IOException | ||
| 375 | { | ||
| 376 | return proxy.getTransferData(df); | ||
| 377 | } | ||
| 378 | |||
| 379 | /* | ||
| 380 | * fields | ||
| 381 | */ | ||
| 382 | |||
| 383 | // We don't need to worry about client code changing the values of | ||
| 384 | // these variables. Since TransferableProxy is a protected class, only | ||
| 385 | // subclasses of DropTargetContext can access it. And DropTargetContext | ||
| 386 | // cannot be subclassed by client code because it does not have a | ||
| 387 | // public constructor. | ||
| 388 | |||
| 389 | /** | ||
| 390 | * The encapsulated <code>Transferable</code> object. | ||
| 391 | */ | ||
| 392 | protected Transferable transferable; | ||
| 393 | |||
| 394 | /** | ||
| 395 | * A <code>boolean</code> indicating if the encapsulated | ||
| 396 | * <code>Transferable</code> object represents the result | ||
| 397 | * of local drag-n-drop operation (within the same JVM). | ||
| 398 | */ | ||
| 399 | protected boolean isLocal; | ||
| 400 | |||
| 401 | private sun.awt.datatransfer.TransferableProxy proxy; | ||
| 402 | } | ||
| 403 | |||
| 404 | /****************************************************************************/ | ||
| 405 | |||
| 406 | /* | ||
| 407 | * fields | ||
| 408 | */ | ||
| 409 | |||
| 410 | /** | ||
| 411 | * The DropTarget associated with this DropTargetContext. | ||
| 412 | * | ||
| 413 | * @serial | ||
| 414 | */ | ||
| 415 | private DropTarget dropTarget; | ||
| 416 | |||
| 417 | private transient DropTargetContextPeer dropTargetContextPeer; | ||
| 418 | |||
| 419 | private transient Transferable transferable; | ||
| 420 | } | ||
Binary file not shown.
| @@ -0,0 +1,243 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.awt.datatransfer.DataFlavor; | ||
| 31 | import java.awt.datatransfer.Transferable; | ||
| 32 | |||
| 33 | import java.util.List; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * The <code>DropTargetDragEvent</code> is delivered to a | ||
| 37 | * <code>DropTargetListener</code> via its | ||
| 38 | * dragEnter() and dragOver() methods. | ||
| 39 | * <p> | ||
| 40 | * The <code>DropTargetDragEvent</code> reports the <i>source drop actions</i> | ||
| 41 | * and the <i>user drop action</i> that reflect the current state of | ||
| 42 | * the drag operation. | ||
| 43 | * <p> | ||
| 44 | * <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code> | ||
| 45 | * that represents the set of drop actions supported by the drag source for | ||
| 46 | * this drag operation. | ||
| 47 | * <p> | ||
| 48 | * <i>User drop action</i> depends on the drop actions supported by the drag | ||
| 49 | * source and the drop action selected by the user. The user can select a drop | ||
| 50 | * action by pressing modifier keys during the drag operation: | ||
| 51 | * <pre> | ||
| 52 | * Ctrl + Shift -> ACTION_LINK | ||
| 53 | * Ctrl -> ACTION_COPY | ||
| 54 | * Shift -> ACTION_MOVE | ||
| 55 | * </pre> | ||
| 56 | * If the user selects a drop action, the <i>user drop action</i> is one of | ||
| 57 | * <code>DnDConstants</code> that represents the selected drop action if this | ||
| 58 | * drop action is supported by the drag source or | ||
| 59 | * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported | ||
| 60 | * by the drag source. | ||
| 61 | * <p> | ||
| 62 | * If the user doesn't select a drop action, the set of | ||
| 63 | * <code>DnDConstants</code> that represents the set of drop actions supported | ||
| 64 | * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>, | ||
| 65 | * then for <code>DnDConstants.ACTION_COPY</code>, then for | ||
| 66 | * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the | ||
| 67 | * first constant found. If no constant is found the <i>user drop action</i> | ||
| 68 | * is <code>DnDConstants.ACTION_NONE</code>. | ||
| 69 | * | ||
| 70 | * @since 1.2 | ||
| 71 | */ | ||
| 72 | |||
| 73 | public class DropTargetDragEvent extends DropTargetEvent { | ||
| 74 | |||
| 75 | private static final long serialVersionUID = -8422265619058953682L; | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Construct a <code>DropTargetDragEvent</code> given the | ||
| 79 | * <code>DropTargetContext</code> for this operation, | ||
| 80 | * the location of the "Drag" <code>Cursor</code>'s hotspot | ||
| 81 | * in the <code>Component</code>'s coordinates, the | ||
| 82 | * user drop action, and the source drop actions. | ||
| 83 | * <P> | ||
| 84 | * @param dtc The DropTargetContext for this operation | ||
| 85 | * @param cursorLocn The location of the "Drag" Cursor's | ||
| 86 | * hotspot in Component coordinates | ||
| 87 | * @param dropAction The user drop action | ||
| 88 | * @param srcActions The source drop actions | ||
| 89 | * | ||
| 90 | * @throws NullPointerException if cursorLocn is null | ||
| 91 | * @throws <code>IllegalArgumentException</code> if dropAction is not one of | ||
| 92 | * <code>DnDConstants</code>. | ||
| 93 | * @throws <code>IllegalArgumentException</code> if srcActions is not | ||
| 94 | * a bitwise mask of <code>DnDConstants</code>. | ||
| 95 | * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>. | ||
| 96 | */ | ||
| 97 | |||
| 98 | public DropTargetDragEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) { | ||
| 99 | super(dtc); | ||
| 100 | |||
| 101 | if (cursorLocn == null) throw new NullPointerException("cursorLocn"); | ||
| 102 | |||
| 103 | if (dropAction != DnDConstants.ACTION_NONE && | ||
| 104 | dropAction != DnDConstants.ACTION_COPY && | ||
| 105 | dropAction != DnDConstants.ACTION_MOVE && | ||
| 106 | dropAction != DnDConstants.ACTION_LINK | ||
| 107 | ) throw new IllegalArgumentException("dropAction" + dropAction); | ||
| 108 | |||
| 109 | if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions"); | ||
| 110 | |||
| 111 | location = cursorLocn; | ||
| 112 | actions = srcActions; | ||
| 113 | this.dropAction = dropAction; | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * This method returns a <code>Point</code> | ||
| 118 | * indicating the <code>Cursor</code>'s current | ||
| 119 | * location within the <code>Component'</code>s | ||
| 120 | * coordinates. | ||
| 121 | * <P> | ||
| 122 | * @return the current cursor location in | ||
| 123 | * <code>Component</code>'s coords. | ||
| 124 | */ | ||
| 125 | |||
| 126 | public Point getLocation() { | ||
| 127 | return location; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | /** | ||
| 132 | * This method returns the current <code>DataFlavor</code>s from the | ||
| 133 | * <code>DropTargetContext</code>. | ||
| 134 | * <P> | ||
| 135 | * @return current DataFlavors from the DropTargetContext | ||
| 136 | */ | ||
| 137 | |||
| 138 | public DataFlavor[] getCurrentDataFlavors() { | ||
| 139 | return getDropTargetContext().getCurrentDataFlavors(); | ||
| 140 | } | ||
| 141 | |||
| 142 | /** | ||
| 143 | * This method returns the current <code>DataFlavor</code>s | ||
| 144 | * as a <code>java.util.List</code> | ||
| 145 | * <P> | ||
| 146 | * @return a <code>java.util.List</code> of the Current <code>DataFlavor</code>s | ||
| 147 | */ | ||
| 148 | |||
| 149 | public List<DataFlavor> getCurrentDataFlavorsAsList() { | ||
| 150 | return getDropTargetContext().getCurrentDataFlavorsAsList(); | ||
| 151 | } | ||
| 152 | |||
| 153 | /** | ||
| 154 | * This method returns a <code>boolean</code> indicating | ||
| 155 | * if the specified <code>DataFlavor</code> is supported. | ||
| 156 | * <P> | ||
| 157 | * @param df the <code>DataFlavor</code> to test | ||
| 158 | * <P> | ||
| 159 | * @return if a particular DataFlavor is supported | ||
| 160 | */ | ||
| 161 | |||
| 162 | public boolean isDataFlavorSupported(DataFlavor df) { | ||
| 163 | return getDropTargetContext().isDataFlavorSupported(df); | ||
| 164 | } | ||
| 165 | |||
| 166 | /** | ||
| 167 | * This method returns the source drop actions. | ||
| 168 | * | ||
| 169 | * @return the source drop actions | ||
| 170 | */ | ||
| 171 | public int getSourceActions() { return actions; } | ||
| 172 | |||
| 173 | /** | ||
| 174 | * This method returns the user drop action. | ||
| 175 | * | ||
| 176 | * @return the user drop action | ||
| 177 | */ | ||
| 178 | public int getDropAction() { return dropAction; } | ||
| 179 | |||
| 180 | /** | ||
| 181 | * This method returns the Transferable object that represents | ||
| 182 | * the data associated with the current drag operation. | ||
| 183 | * | ||
| 184 | * @return the Transferable associated with the drag operation | ||
| 185 | * @throws InvalidDnDOperationException if the data associated with the drag | ||
| 186 | * operation is not available | ||
| 187 | * | ||
| 188 | * @since 1.5 | ||
| 189 | */ | ||
| 190 | public Transferable getTransferable() { | ||
| 191 | return getDropTargetContext().getTransferable(); | ||
| 192 | } | ||
| 193 | |||
| 194 | /** | ||
| 195 | * Accepts the drag. | ||
| 196 | * | ||
| 197 | * This method should be called from a | ||
| 198 | * <code>DropTargetListeners</code> <code>dragEnter</code>, | ||
| 199 | * <code>dragOver</code>, and <code>dropActionChanged</code> | ||
| 200 | * methods if the implementation wishes to accept an operation | ||
| 201 | * from the srcActions other than the one selected by | ||
| 202 | * the user as represented by the <code>dropAction</code>. | ||
| 203 | * | ||
| 204 | * @param dragOperation the operation accepted by the target | ||
| 205 | */ | ||
| 206 | public void acceptDrag(int dragOperation) { | ||
| 207 | getDropTargetContext().acceptDrag(dragOperation); | ||
| 208 | } | ||
| 209 | |||
| 210 | /** | ||
| 211 | * Rejects the drag as a result of examining either the | ||
| 212 | * <code>dropAction</code> or the available <code>DataFlavor</code> | ||
| 213 | * types. | ||
| 214 | */ | ||
| 215 | public void rejectDrag() { | ||
| 216 | getDropTargetContext().rejectDrag(); | ||
| 217 | } | ||
| 218 | |||
| 219 | /* | ||
| 220 | * fields | ||
| 221 | */ | ||
| 222 | |||
| 223 | /** | ||
| 224 | * The location of the drag cursor's hotspot in Component coordinates. | ||
| 225 | * | ||
| 226 | * @serial | ||
| 227 | */ | ||
| 228 | private Point location; | ||
| 229 | |||
| 230 | /** | ||
| 231 | * The source drop actions. | ||
| 232 | * | ||
| 233 | * @serial | ||
| 234 | */ | ||
| 235 | private int actions; | ||
| 236 | |||
| 237 | /** | ||
| 238 | * The user drop action. | ||
| 239 | * | ||
| 240 | * @serial | ||
| 241 | */ | ||
| 242 | private int dropAction; | ||
| 243 | } | ||
Binary file not shown.
| @@ -0,0 +1,300 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.awt.datatransfer.DataFlavor; | ||
| 31 | import java.awt.datatransfer.Transferable; | ||
| 32 | |||
| 33 | import java.util.List; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * The <code>DropTargetDropEvent</code> is delivered | ||
| 37 | * via the <code>DropTargetListener</code> drop() method. | ||
| 38 | * <p> | ||
| 39 | * The <code>DropTargetDropEvent</code> reports the <i>source drop actions</i> | ||
| 40 | * and the <i>user drop action</i> that reflect the current state of the | ||
| 41 | * drag-and-drop operation. | ||
| 42 | * <p> | ||
| 43 | * <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code> | ||
| 44 | * that represents the set of drop actions supported by the drag source for | ||
| 45 | * this drag-and-drop operation. | ||
| 46 | * <p> | ||
| 47 | * <i>User drop action</i> depends on the drop actions supported by the drag | ||
| 48 | * source and the drop action selected by the user. The user can select a drop | ||
| 49 | * action by pressing modifier keys during the drag operation: | ||
| 50 | * <pre> | ||
| 51 | * Ctrl + Shift -> ACTION_LINK | ||
| 52 | * Ctrl -> ACTION_COPY | ||
| 53 | * Shift -> ACTION_MOVE | ||
| 54 | * </pre> | ||
| 55 | * If the user selects a drop action, the <i>user drop action</i> is one of | ||
| 56 | * <code>DnDConstants</code> that represents the selected drop action if this | ||
| 57 | * drop action is supported by the drag source or | ||
| 58 | * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported | ||
| 59 | * by the drag source. | ||
| 60 | * <p> | ||
| 61 | * If the user doesn't select a drop action, the set of | ||
| 62 | * <code>DnDConstants</code> that represents the set of drop actions supported | ||
| 63 | * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>, | ||
| 64 | * then for <code>DnDConstants.ACTION_COPY</code>, then for | ||
| 65 | * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the | ||
| 66 | * first constant found. If no constant is found the <i>user drop action</i> | ||
| 67 | * is <code>DnDConstants.ACTION_NONE</code>. | ||
| 68 | * | ||
| 69 | * @since 1.2 | ||
| 70 | */ | ||
| 71 | |||
| 72 | public class DropTargetDropEvent extends DropTargetEvent { | ||
| 73 | |||
| 74 | private static final long serialVersionUID = -1721911170440459322L; | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Construct a <code>DropTargetDropEvent</code> given | ||
| 78 | * the <code>DropTargetContext</code> for this operation, | ||
| 79 | * the location of the drag <code>Cursor</code>'s | ||
| 80 | * hotspot in the <code>Component</code>'s coordinates, | ||
| 81 | * the currently | ||
| 82 | * selected user drop action, and the current set of | ||
| 83 | * actions supported by the source. | ||
| 84 | * By default, this constructor | ||
| 85 | * assumes that the target is not in the same virtual machine as | ||
| 86 | * the source; that is, {@link #isLocalTransfer()} will | ||
| 87 | * return <code>false</code>. | ||
| 88 | * <P> | ||
| 89 | * @param dtc The <code>DropTargetContext</code> for this operation | ||
| 90 | * @param cursorLocn The location of the "Drag" Cursor's | ||
| 91 | * hotspot in <code>Component</code> coordinates | ||
| 92 | * @param dropAction the user drop action. | ||
| 93 | * @param srcActions the source drop actions. | ||
| 94 | * | ||
| 95 | * @throws <code>NullPointerException</code> | ||
| 96 | * if cursorLocn is <code>null</code> | ||
| 97 | * @throws <code>IllegalArgumentException</code> if dropAction is not one of | ||
| 98 | * <code>DnDConstants</code>. | ||
| 99 | * @throws <code>IllegalArgumentException</code> if srcActions is not | ||
| 100 | * a bitwise mask of <code>DnDConstants</code>. | ||
| 101 | * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>. | ||
| 102 | */ | ||
| 103 | |||
| 104 | public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) { | ||
| 105 | super(dtc); | ||
| 106 | |||
| 107 | if (cursorLocn == null) throw new NullPointerException("cursorLocn"); | ||
| 108 | |||
| 109 | if (dropAction != DnDConstants.ACTION_NONE && | ||
| 110 | dropAction != DnDConstants.ACTION_COPY && | ||
| 111 | dropAction != DnDConstants.ACTION_MOVE && | ||
| 112 | dropAction != DnDConstants.ACTION_LINK | ||
| 113 | ) throw new IllegalArgumentException("dropAction = " + dropAction); | ||
| 114 | |||
| 115 | if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions"); | ||
| 116 | |||
| 117 | location = cursorLocn; | ||
| 118 | actions = srcActions; | ||
| 119 | this.dropAction = dropAction; | ||
| 120 | } | ||
| 121 | |||
| 122 | /** | ||
| 123 | * Construct a <code>DropTargetEvent</code> given the | ||
| 124 | * <code>DropTargetContext</code> for this operation, | ||
| 125 | * the location of the drag <code>Cursor</code>'s hotspot | ||
| 126 | * in the <code>Component</code>'s | ||
| 127 | * coordinates, the currently selected user drop action, | ||
| 128 | * the current set of actions supported by the source, | ||
| 129 | * and a <code>boolean</code> indicating if the source is in the same JVM | ||
| 130 | * as the target. | ||
| 131 | * <P> | ||
| 132 | * @param dtc The DropTargetContext for this operation | ||
| 133 | * @param cursorLocn The location of the "Drag" Cursor's | ||
| 134 | * hotspot in Component's coordinates | ||
| 135 | * @param dropAction the user drop action. | ||
| 136 | * @param srcActions the source drop actions. | ||
| 137 | * @param isLocal True if the source is in the same JVM as the target | ||
| 138 | * | ||
| 139 | * @throws <code>NullPointerException</code> if cursorLocn is | ||
| 140 | * <code>null</code> | ||
| 141 | * @throws <code>IllegalArgumentException</code> if dropAction is not one of | ||
| 142 | * <code>DnDConstants</code>. | ||
| 143 | * @throws <code>IllegalArgumentException</code> if srcActions is not | ||
| 144 | * a bitwise mask of <code>DnDConstants</code>. | ||
| 145 | * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>. | ||
| 146 | */ | ||
| 147 | |||
| 148 | public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions, boolean isLocal) { | ||
| 149 | this(dtc, cursorLocn, dropAction, srcActions); | ||
| 150 | |||
| 151 | isLocalTx = isLocal; | ||
| 152 | } | ||
| 153 | |||
| 154 | /** | ||
| 155 | * This method returns a <code>Point</code> | ||
| 156 | * indicating the <code>Cursor</code>'s current | ||
| 157 | * location in the <code>Component</code>'s coordinates. | ||
| 158 | * <P> | ||
| 159 | * @return the current <code>Cursor</code> location in Component's coords. | ||
| 160 | */ | ||
| 161 | |||
| 162 | public Point getLocation() { | ||
| 163 | return location; | ||
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | /** | ||
| 168 | * This method returns the current DataFlavors. | ||
| 169 | * <P> | ||
| 170 | * @return current DataFlavors | ||
| 171 | */ | ||
| 172 | |||
| 173 | public DataFlavor[] getCurrentDataFlavors() { | ||
| 174 | return getDropTargetContext().getCurrentDataFlavors(); | ||
| 175 | } | ||
| 176 | |||
| 177 | /** | ||
| 178 | * This method returns the currently available | ||
| 179 | * <code>DataFlavor</code>s as a <code>java.util.List</code>. | ||
| 180 | * <P> | ||
| 181 | * @return the currently available DataFlavors as a java.util.List | ||
| 182 | */ | ||
| 183 | |||
| 184 | public List<DataFlavor> getCurrentDataFlavorsAsList() { | ||
| 185 | return getDropTargetContext().getCurrentDataFlavorsAsList(); | ||
| 186 | } | ||
| 187 | |||
| 188 | /** | ||
| 189 | * This method returns a <code>boolean</code> indicating if the | ||
| 190 | * specified <code>DataFlavor</code> is available | ||
| 191 | * from the source. | ||
| 192 | * <P> | ||
| 193 | * @param df the <code>DataFlavor</code> to test | ||
| 194 | * <P> | ||
| 195 | * @return if the DataFlavor specified is available from the source | ||
| 196 | */ | ||
| 197 | |||
| 198 | public boolean isDataFlavorSupported(DataFlavor df) { | ||
| 199 | return getDropTargetContext().isDataFlavorSupported(df); | ||
| 200 | } | ||
| 201 | |||
| 202 | /** | ||
| 203 | * This method returns the source drop actions. | ||
| 204 | * | ||
| 205 | * @return the source drop actions. | ||
| 206 | */ | ||
| 207 | public int getSourceActions() { return actions; } | ||
| 208 | |||
| 209 | /** | ||
| 210 | * This method returns the user drop action. | ||
| 211 | * | ||
| 212 | * @return the user drop actions. | ||
| 213 | */ | ||
| 214 | public int getDropAction() { return dropAction; } | ||
| 215 | |||
| 216 | /** | ||
| 217 | * This method returns the <code>Transferable</code> object | ||
| 218 | * associated with the drop. | ||
| 219 | * <P> | ||
| 220 | * @return the <code>Transferable</code> associated with the drop | ||
| 221 | */ | ||
| 222 | |||
| 223 | public Transferable getTransferable() { | ||
| 224 | return getDropTargetContext().getTransferable(); | ||
| 225 | } | ||
| 226 | |||
| 227 | /** | ||
| 228 | * accept the drop, using the specified action. | ||
| 229 | * <P> | ||
| 230 | * @param dropAction the specified action | ||
| 231 | */ | ||
| 232 | |||
| 233 | public void acceptDrop(int dropAction) { | ||
| 234 | getDropTargetContext().acceptDrop(dropAction); | ||
| 235 | } | ||
| 236 | |||
| 237 | /** | ||
| 238 | * reject the Drop. | ||
| 239 | */ | ||
| 240 | |||
| 241 | public void rejectDrop() { | ||
| 242 | getDropTargetContext().rejectDrop(); | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * This method notifies the <code>DragSource</code> | ||
| 247 | * that the drop transfer(s) are completed. | ||
| 248 | * <P> | ||
| 249 | * @param success a <code>boolean</code> indicating that the drop transfer(s) are completed. | ||
| 250 | */ | ||
| 251 | |||
| 252 | public void dropComplete(boolean success) { | ||
| 253 | getDropTargetContext().dropComplete(success); | ||
| 254 | } | ||
| 255 | |||
| 256 | /** | ||
| 257 | * This method returns an <code>int</code> indicating if | ||
| 258 | * the source is in the same JVM as the target. | ||
| 259 | * <P> | ||
| 260 | * @return if the Source is in the same JVM | ||
| 261 | */ | ||
| 262 | |||
| 263 | public boolean isLocalTransfer() { | ||
| 264 | return isLocalTx; | ||
| 265 | } | ||
| 266 | |||
| 267 | /* | ||
| 268 | * fields | ||
| 269 | */ | ||
| 270 | |||
| 271 | static final private Point zero = new Point(0,0); | ||
| 272 | |||
| 273 | /** | ||
| 274 | * The location of the drag cursor's hotspot in Component coordinates. | ||
| 275 | * | ||
| 276 | * @serial | ||
| 277 | */ | ||
| 278 | private Point location = zero; | ||
| 279 | |||
| 280 | /** | ||
| 281 | * The source drop actions. | ||
| 282 | * | ||
| 283 | * @serial | ||
| 284 | */ | ||
| 285 | private int actions = DnDConstants.ACTION_NONE; | ||
| 286 | |||
| 287 | /** | ||
| 288 | * The user drop action. | ||
| 289 | * | ||
| 290 | * @serial | ||
| 291 | */ | ||
| 292 | private int dropAction = DnDConstants.ACTION_NONE; | ||
| 293 | |||
| 294 | /** | ||
| 295 | * <code>true</code> if the source is in the same JVM as the target. | ||
| 296 | * | ||
| 297 | * @serial | ||
| 298 | */ | ||
| 299 | private boolean isLocalTx = false; | ||
| 300 | } | ||
Binary file not shown.
| @@ -0,0 +1,81 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.util.EventObject; | ||
| 29 | import java.awt.dnd.DropTargetContext; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * The <code>DropTargetEvent</code> is the base | ||
| 33 | * class for both the <code>DropTargetDragEvent</code> | ||
| 34 | * and the <code>DropTargetDropEvent</code>. | ||
| 35 | * It encapsulates the current state of the Drag and | ||
| 36 | * Drop operations, in particular the current | ||
| 37 | * <code>DropTargetContext</code>. | ||
| 38 | * | ||
| 39 | * @since 1.2 | ||
| 40 | * | ||
| 41 | */ | ||
| 42 | |||
| 43 | public class DropTargetEvent extends java.util.EventObject { | ||
| 44 | |||
| 45 | private static final long serialVersionUID = 2821229066521922993L; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Construct a <code>DropTargetEvent</code> object with | ||
| 49 | * the specified <code>DropTargetContext</code>. | ||
| 50 | * <P> | ||
| 51 | * @param dtc The <code>DropTargetContext</code> | ||
| 52 | * @throws NullPointerException if {@code dtc} equals {@code null}. | ||
| 53 | * @see #getSource() | ||
| 54 | * @see #getDropTargetContext() | ||
| 55 | */ | ||
| 56 | |||
| 57 | public DropTargetEvent(DropTargetContext dtc) { | ||
| 58 | super(dtc.getDropTarget()); | ||
| 59 | |||
| 60 | context = dtc; | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * This method returns the <code>DropTargetContext</code> | ||
| 65 | * associated with this <code>DropTargetEvent</code>. | ||
| 66 | * <P> | ||
| 67 | * @return the <code>DropTargetContext</code> | ||
| 68 | */ | ||
| 69 | |||
| 70 | public DropTargetContext getDropTargetContext() { | ||
| 71 | return context; | ||
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * The <code>DropTargetContext</code> associated with this | ||
| 76 | * <code>DropTargetEvent</code>. | ||
| 77 | * | ||
| 78 | * @serial | ||
| 79 | */ | ||
| 80 | protected DropTargetContext context; | ||
| 81 | } | ||
Binary file not shown.
| @@ -0,0 +1,152 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.util.EventListener; | ||
| 29 | |||
| 30 | import java.awt.dnd.DropTargetDragEvent; | ||
| 31 | import java.awt.dnd.DropTargetDropEvent; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * The <code>DropTargetListener</code> interface | ||
| 35 | * is the callback interface used by the | ||
| 36 | * <code>DropTarget</code> class to provide | ||
| 37 | * notification of DnD operations that involve | ||
| 38 | * the subject <code>DropTarget</code>. Methods of | ||
| 39 | * this interface may be implemented to provide | ||
| 40 | * "drag under" visual feedback to the user throughout | ||
| 41 | * the Drag and Drop operation. | ||
| 42 | * <p> | ||
| 43 | * Create a listener object by implementing the interface and then register it | ||
| 44 | * with a <code>DropTarget</code>. When the drag enters, moves over, or exits | ||
| 45 | * the operable part of the drop site for that <code>DropTarget</code>, when | ||
| 46 | * the drop action changes, and when the drop occurs, the relevant method in | ||
| 47 | * the listener object is invoked, and the <code>DropTargetEvent</code> is | ||
| 48 | * passed to it. | ||
| 49 | * <p> | ||
| 50 | * The operable part of the drop site for the <code>DropTarget</code> is | ||
| 51 | * the part of the associated <code>Component</code>'s geometry that is not | ||
| 52 | * obscured by an overlapping top-level window or by another | ||
| 53 | * <code>Component</code> higher in the Z-order that has an associated active | ||
| 54 | * <code>DropTarget</code>. | ||
| 55 | * <p> | ||
| 56 | * During the drag, the data associated with the current drag operation can be | ||
| 57 | * retrieved by calling <code>getTransferable()</code> on | ||
| 58 | * <code>DropTargetDragEvent</code> instances passed to the listener's | ||
| 59 | * methods. | ||
| 60 | * <p> | ||
| 61 | * Note that <code>getTransferable()</code> on the | ||
| 62 | * <code>DropTargetDragEvent</code> instance should only be called within the | ||
| 63 | * respective listener's method and all the necessary data should be retrieved | ||
| 64 | * from the returned <code>Transferable</code> before that method returns. | ||
| 65 | * | ||
| 66 | * @since 1.2 | ||
| 67 | */ | ||
| 68 | |||
| 69 | public interface DropTargetListener extends EventListener { | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Called while a drag operation is ongoing, when the mouse pointer enters | ||
| 73 | * the operable part of the drop site for the <code>DropTarget</code> | ||
| 74 | * registered with this listener. | ||
| 75 | * | ||
| 76 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 77 | */ | ||
| 78 | |||
| 79 | void dragEnter(DropTargetDragEvent dtde); | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Called when a drag operation is ongoing, while the mouse pointer is still | ||
| 83 | * over the operable part of the drop site for the <code>DropTarget</code> | ||
| 84 | * registered with this listener. | ||
| 85 | * | ||
| 86 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 87 | */ | ||
| 88 | |||
| 89 | void dragOver(DropTargetDragEvent dtde); | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Called if the user has modified | ||
| 93 | * the current drop gesture. | ||
| 94 | * <P> | ||
| 95 | * @param dtde the <code>DropTargetDragEvent</code> | ||
| 96 | */ | ||
| 97 | |||
| 98 | void dropActionChanged(DropTargetDragEvent dtde); | ||
| 99 | |||
| 100 | /** | ||
| 101 | * Called while a drag operation is ongoing, when the mouse pointer has | ||
| 102 | * exited the operable part of the drop site for the | ||
| 103 | * <code>DropTarget</code> registered with this listener. | ||
| 104 | * | ||
| 105 | * @param dte the <code>DropTargetEvent</code> | ||
| 106 | */ | ||
| 107 | |||
| 108 | void dragExit(DropTargetEvent dte); | ||
| 109 | |||
| 110 | /** | ||
| 111 | * Called when the drag operation has terminated with a drop on | ||
| 112 | * the operable part of the drop site for the <code>DropTarget</code> | ||
| 113 | * registered with this listener. | ||
| 114 | * <p> | ||
| 115 | * This method is responsible for undertaking | ||
| 116 | * the transfer of the data associated with the | ||
| 117 | * gesture. The <code>DropTargetDropEvent</code> | ||
| 118 | * provides a means to obtain a <code>Transferable</code> | ||
| 119 | * object that represents the data object(s) to | ||
| 120 | * be transfered.<P> | ||
| 121 | * From this method, the <code>DropTargetListener</code> | ||
| 122 | * shall accept or reject the drop via the | ||
| 123 | * acceptDrop(int dropAction) or rejectDrop() methods of the | ||
| 124 | * <code>DropTargetDropEvent</code> parameter. | ||
| 125 | * <P> | ||
| 126 | * Subsequent to acceptDrop(), but not before, | ||
| 127 | * <code>DropTargetDropEvent</code>'s getTransferable() | ||
| 128 | * method may be invoked, and data transfer may be | ||
| 129 | * performed via the returned <code>Transferable</code>'s | ||
| 130 | * getTransferData() method. | ||
| 131 | * <P> | ||
| 132 | * At the completion of a drop, an implementation | ||
| 133 | * of this method is required to signal the success/failure | ||
| 134 | * of the drop by passing an appropriate | ||
| 135 | * <code>boolean</code> to the <code>DropTargetDropEvent</code>'s | ||
| 136 | * dropComplete(boolean success) method. | ||
| 137 | * <P> | ||
| 138 | * Note: The data transfer should be completed before the call to the | ||
| 139 | * <code>DropTargetDropEvent</code>'s dropComplete(boolean success) method. | ||
| 140 | * After that, a call to the getTransferData() method of the | ||
| 141 | * <code>Transferable</code> returned by | ||
| 142 | * <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to | ||
| 143 | * succeed only if the data transfer is local; that is, only if | ||
| 144 | * <code>DropTargetDropEvent.isLocalTransfer()</code> returns | ||
| 145 | * <code>true</code>. Otherwise, the behavior of the call is | ||
| 146 | * implementation-dependent. | ||
| 147 | * <P> | ||
| 148 | * @param dtde the <code>DropTargetDropEvent</code> | ||
| 149 | */ | ||
| 150 | |||
| 151 | void drop(DropTargetDropEvent dtde); | ||
| 152 | } | ||
Binary file not shown.
| @@ -0,0 +1,55 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | /** | ||
| 29 | * This exception is thrown by various methods in the java.awt.dnd package. | ||
| 30 | * It is usually thrown to indicate that the target in question is unable | ||
| 31 | * to undertake the requested operation that the present time, since the | ||
| 32 | * undrelying DnD system is not in the appropriate state. | ||
| 33 | * | ||
| 34 | * @since 1.2 | ||
| 35 | */ | ||
| 36 | |||
| 37 | public class InvalidDnDOperationException extends IllegalStateException { | ||
| 38 | |||
| 39 | static private String dft_msg = "The operation requested cannot be performed by the DnD system since it is not in the appropriate state"; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Create a default Exception | ||
| 43 | */ | ||
| 44 | |||
| 45 | public InvalidDnDOperationException() { super(dft_msg); } | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Create an Exception with its own descriptive message | ||
| 49 | * <P> | ||
| 50 | * @param msg the detail message | ||
| 51 | */ | ||
| 52 | |||
| 53 | public InvalidDnDOperationException(String msg) { super(msg); } | ||
| 54 | |||
| 55 | } | ||
Binary file not shown.
| @@ -0,0 +1,208 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.Component; | ||
| 29 | |||
| 30 | import java.awt.event.MouseEvent; | ||
| 31 | import java.awt.event.MouseListener; | ||
| 32 | import java.awt.event.MouseMotionListener; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * This abstract subclass of <code>DragGestureRecognizer</code> | ||
| 36 | * defines a <code>DragGestureRecognizer</code> | ||
| 37 | * for mouse-based gestures. | ||
| 38 | * | ||
| 39 | * Each platform implements its own concrete subclass of this class, | ||
| 40 | * available via the Toolkit.createDragGestureRecognizer() method, | ||
| 41 | * to encapsulate | ||
| 42 | * the recognition of the platform dependent mouse gesture(s) that initiate | ||
| 43 | * a Drag and Drop operation. | ||
| 44 | * <p> | ||
| 45 | * Mouse drag gesture recognizers should honor the | ||
| 46 | * drag gesture motion threshold, available through | ||
| 47 | * {@link DragSource#getDragThreshold}. | ||
| 48 | * A drag gesture should be recognized only when the distance | ||
| 49 | * in either the horizontal or vertical direction between | ||
| 50 | * the location of the latest mouse dragged event and the | ||
| 51 | * location of the corresponding mouse button pressed event | ||
| 52 | * is greater than the drag gesture motion threshold. | ||
| 53 | * <p> | ||
| 54 | * Drag gesture recognizers created with | ||
| 55 | * {@link DragSource#createDefaultDragGestureRecognizer} | ||
| 56 | * follow this convention. | ||
| 57 | * | ||
| 58 | * @author Laurence P. G. Cable | ||
| 59 | * | ||
| 60 | * @see java.awt.dnd.DragGestureListener | ||
| 61 | * @see java.awt.dnd.DragGestureEvent | ||
| 62 | * @see java.awt.dnd.DragSource | ||
| 63 | */ | ||
| 64 | |||
| 65 | public abstract class MouseDragGestureRecognizer extends DragGestureRecognizer implements MouseListener, MouseMotionListener { | ||
| 66 | |||
| 67 | private static final long serialVersionUID = 6220099344182281120L; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Construct a new <code>MouseDragGestureRecognizer</code> | ||
| 71 | * given the <code>DragSource</code> for the | ||
| 72 | * <code>Component</code> c, the <code>Component</code> | ||
| 73 | * to observe, the action(s) | ||
| 74 | * permitted for this drag operation, and | ||
| 75 | * the <code>DragGestureListener</code> to | ||
| 76 | * notify when a drag gesture is detected. | ||
| 77 | * <P> | ||
| 78 | * @param ds The DragSource for the Component c | ||
| 79 | * @param c The Component to observe | ||
| 80 | * @param act The actions permitted for this Drag | ||
| 81 | * @param dgl The DragGestureListener to notify when a gesture is detected | ||
| 82 | * | ||
| 83 | */ | ||
| 84 | |||
| 85 | protected MouseDragGestureRecognizer(DragSource ds, Component c, int act, DragGestureListener dgl) { | ||
| 86 | super(ds, c, act, dgl); | ||
| 87 | } | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Construct a new <code>MouseDragGestureRecognizer</code> | ||
| 91 | * given the <code>DragSource</code> for | ||
| 92 | * the <code>Component</code> c, | ||
| 93 | * the <code>Component</code> to observe, and the action(s) | ||
| 94 | * permitted for this drag operation. | ||
| 95 | * <P> | ||
| 96 | * @param ds The DragSource for the Component c | ||
| 97 | * @param c The Component to observe | ||
| 98 | * @param act The actions permitted for this drag | ||
| 99 | */ | ||
| 100 | |||
| 101 | protected MouseDragGestureRecognizer(DragSource ds, Component c, int act) { | ||
| 102 | this(ds, c, act, null); | ||
| 103 | } | ||
| 104 | |||
| 105 | /** | ||
| 106 | * Construct a new <code>MouseDragGestureRecognizer</code> | ||
| 107 | * given the <code>DragSource</code> for the | ||
| 108 | * <code>Component</code> c, and the | ||
| 109 | * <code>Component</code> to observe. | ||
| 110 | * <P> | ||
| 111 | * @param ds The DragSource for the Component c | ||
| 112 | * @param c The Component to observe | ||
| 113 | */ | ||
| 114 | |||
| 115 | protected MouseDragGestureRecognizer(DragSource ds, Component c) { | ||
| 116 | this(ds, c, DnDConstants.ACTION_NONE); | ||
| 117 | } | ||
| 118 | |||
| 119 | /** | ||
| 120 | * Construct a new <code>MouseDragGestureRecognizer</code> | ||
| 121 | * given the <code>DragSource</code> for the <code>Component</code>. | ||
| 122 | * <P> | ||
| 123 | * @param ds The DragSource for the Component | ||
| 124 | */ | ||
| 125 | |||
| 126 | protected MouseDragGestureRecognizer(DragSource ds) { | ||
| 127 | this(ds, null); | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * register this DragGestureRecognizer's Listeners with the Component | ||
| 132 | */ | ||
| 133 | |||
| 134 | protected void registerListeners() { | ||
| 135 | component.addMouseListener(this); | ||
| 136 | component.addMouseMotionListener(this); | ||
| 137 | } | ||
| 138 | |||
| 139 | /** | ||
| 140 | * unregister this DragGestureRecognizer's Listeners with the Component | ||
| 141 | * | ||
| 142 | * subclasses must override this method | ||
| 143 | */ | ||
| 144 | |||
| 145 | |||
| 146 | protected void unregisterListeners() { | ||
| 147 | component.removeMouseListener(this); | ||
| 148 | component.removeMouseMotionListener(this); | ||
| 149 | } | ||
| 150 | |||
| 151 | /** | ||
| 152 | * Invoked when the mouse has been clicked on a component. | ||
| 153 | * <P> | ||
| 154 | * @param e the <code>MouseEvent</code> | ||
| 155 | */ | ||
| 156 | |||
| 157 | public void mouseClicked(MouseEvent e) { } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Invoked when a mouse button has been | ||
| 161 | * pressed on a <code>Component</code>. | ||
| 162 | * <P> | ||
| 163 | * @param e the <code>MouseEvent</code> | ||
| 164 | */ | ||
| 165 | |||
| 166 | public void mousePressed(MouseEvent e) { } | ||
| 167 | |||
| 168 | /** | ||
| 169 | * Invoked when a mouse button has been released on a component. | ||
| 170 | * <P> | ||
| 171 | * @param e the <code>MouseEvent</code> | ||
| 172 | */ | ||
| 173 | |||
| 174 | public void mouseReleased(MouseEvent e) { } | ||
| 175 | |||
| 176 | /** | ||
| 177 | * Invoked when the mouse enters a component. | ||
| 178 | * <P> | ||
| 179 | * @param e the <code>MouseEvent</code> | ||
| 180 | */ | ||
| 181 | |||
| 182 | public void mouseEntered(MouseEvent e) { } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Invoked when the mouse exits a component. | ||
| 186 | * <P> | ||
| 187 | * @param e the <code>MouseEvent</code> | ||
| 188 | */ | ||
| 189 | |||
| 190 | public void mouseExited(MouseEvent e) { } | ||
| 191 | |||
| 192 | /** | ||
| 193 | * Invoked when a mouse button is pressed on a component. | ||
| 194 | * <P> | ||
| 195 | * @param e the <code>MouseEvent</code> | ||
| 196 | */ | ||
| 197 | |||
| 198 | public void mouseDragged(MouseEvent e) { } | ||
| 199 | |||
| 200 | /** | ||
| 201 | * Invoked when the mouse button has been moved on a component | ||
| 202 | * (with no buttons no down). | ||
| 203 | * <P> | ||
| 204 | * @param e the <code>MouseEvent</code> | ||
| 205 | */ | ||
| 206 | |||
| 207 | public void mouseMoved(MouseEvent e) { } | ||
| 208 | } | ||
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,73 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.io.OutputStream; | ||
| 29 | import java.io.ObjectOutputStream; | ||
| 30 | import java.io.IOException; | ||
| 31 | import java.io.Serializable; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Tests if an object can truly be serialized by serializing it to a null | ||
| 35 | * OutputStream. | ||
| 36 | * | ||
| 37 | * @since 1.4 | ||
| 38 | */ | ||
| 39 | final class SerializationTester { | ||
| 40 | private static ObjectOutputStream stream; | ||
| 41 | static { | ||
| 42 | try { | ||
| 43 | stream = new ObjectOutputStream(new OutputStream() { | ||
| 44 | public void write(int b) {} | ||
| 45 | }); | ||
| 46 | } catch (IOException cannotHappen) { | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | static boolean test(Object obj) { | ||
| 51 | if (!(obj instanceof Serializable)) { | ||
| 52 | return false; | ||
| 53 | } | ||
| 54 | |||
| 55 | try { | ||
| 56 | stream.writeObject(obj); | ||
| 57 | } catch (IOException e) { | ||
| 58 | return false; | ||
| 59 | } finally { | ||
| 60 | // Fix for 4503661. | ||
| 61 | // Reset the stream so that it doesn't keep a reference to the | ||
| 62 | // written object. | ||
| 63 | try { | ||
| 64 | stream.reset(); | ||
| 65 | } catch (IOException e) { | ||
| 66 | // Ignore the exception. | ||
| 67 | } | ||
| 68 | } | ||
| 69 | return true; | ||
| 70 | } | ||
| 71 | |||
| 72 | private SerializationTester() {} | ||
| 73 | } | ||
| @@ -0,0 +1,35 @@ | |||
| 1 | <../../../../../mkconfig | ||
| 2 | |||
| 3 | DIRS=\ | ||
| 4 | peer\ | ||
| 5 | |||
| 6 | TARG=\ | ||
| 7 | Autoscroll.dis\ | ||
| 8 | DnDConstants.dis\ | ||
| 9 | DnDEventMulticaster.dis\ | ||
| 10 | DragGestureEvent.dis\ | ||
| 11 | DragGestureListener.dis\ | ||
| 12 | DragGestureRecognizer.dis\ | ||
| 13 | DragSource.dis\ | ||
| 14 | DragSourceAdapter.dis\ | ||
| 15 | DragSourceContext.dis\ | ||
| 16 | DragSourceDragEvent.dis\ | ||
| 17 | DragSourceDropEvent.dis\ | ||
| 18 | DragSourceEvent.dis\ | ||
| 19 | DragSourceListener.dis\ | ||
| 20 | DragSourceMotionListener.dis\ | ||
| 21 | DropTarget.dis\ | ||
| 22 | DropTargetAdapter.dis\ | ||
| 23 | DropTargetContext.dis\ | ||
| 24 | DropTargetDragEvent.dis\ | ||
| 25 | DropTargetDropEvent.dis\ | ||
| 26 | DropTargetEvent.dis\ | ||
| 27 | DropTargetListener.dis\ | ||
| 28 | InvalidDnDOperationException.dis\ | ||
| 29 | MouseDragGestureRecognizer.dis\ | ||
| 30 | SerializationTester.dis\ | ||
| 31 | |||
| 32 | DISBIN=$ROOT/java/dis/java/java/java/awt/dnd | ||
| 33 | |||
| 34 | <$ROOT/mkfiles/mkjava | ||
| 35 | <$ROOT/mkfiles/mksubdirs | ||
| @@ -0,0 +1,145 @@ | |||
| 1 | <!-- | ||
| 2 | Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | |||
| 5 | This code is free software; you can redistribute it and/or modify it | ||
| 6 | under the terms of the GNU General Public License version 2 only, as | ||
| 7 | published by the Free Software Foundation. Oracle designates this | ||
| 8 | particular file as subject to the "Classpath" exception as provided | ||
| 9 | by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | |||
| 11 | This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> | ||
| 27 | <html> | ||
| 28 | <body bgcolor="white"> | ||
| 29 | |||
| 30 | Drag and Drop is a direct manipulation gesture found in many Graphical | ||
| 31 | User Interface systems that provides a mechanism to transfer | ||
| 32 | information between two entities logically associated with presentation | ||
| 33 | elements in the GUI. Normally driven by a physical gesture of a | ||
| 34 | human user using an appropriate input device, Drag and Drop provides both | ||
| 35 | a mechanism to enable continuous feedback regarding the | ||
| 36 | possible outcome of any subsequent data transfer to the user during | ||
| 37 | navigation over the presentation elements in the GUI, and the facilities | ||
| 38 | to provide for any subsequent data negotiation and transfer. | ||
| 39 | <P> | ||
| 40 | This package defines the classes and interfaces necessary to perform Drag | ||
| 41 | and Drop operations in Java. It | ||
| 42 | defines classes for the drag-source and the drop-target, as well as | ||
| 43 | events for transferring the data being dragged. This package also provides | ||
| 44 | a means for giving visual feedback to the user throughout the | ||
| 45 | duration of the Drag and Drop operation. | ||
| 46 | <P> | ||
| 47 | A typical Drag and Drop operation can be decomposed into the following | ||
| 48 | states (not entirely sequentially): | ||
| 49 | <UL> | ||
| 50 | <LI>A <code>DragSource</code> comes into existence, | ||
| 51 | associated with some presentation | ||
| 52 | element (<code>Component</code>) in the GUI, to initiate a Drag and Drop of | ||
| 53 | some potentially <code>Transferable</code> data. | ||
| 54 | <P> | ||
| 55 | <LI>1 or more <code>DropTarget</code>(s) come into/go out of | ||
| 56 | existence, associated | ||
| 57 | with presentation elements in the GUI (Components), potentially | ||
| 58 | capable of consuming <code>Transferable</code> data types. | ||
| 59 | <P> | ||
| 60 | <LI> A <code>DragGestureRecognizer</code> is | ||
| 61 | obtained from the <code>DragSource</code> and is | ||
| 62 | associated with a <code>Component</code> in order | ||
| 63 | to track and identify any Drag | ||
| 64 | initiating gesture by the user over the <code>Component</code>. | ||
| 65 | <P> | ||
| 66 | <LI> A user makes a Drag gesture over the <code>Component</code>, | ||
| 67 | which the registered | ||
| 68 | <code>DragGestureRecognizer</code> detects, and notifies its | ||
| 69 | <code>DragGestureListener</code> of. | ||
| 70 | <P> | ||
| 71 | Note: Although this API consistently refers to the stimulus for a | ||
| 72 | drag and drop operation being a physical gesture by a human user, this | ||
| 73 | does not preclude a programmatically driven DnD operation given the | ||
| 74 | appropriate implementation of a <code>DragSource</code>. This package | ||
| 75 | contains the abstract class <code>MouseDragGestureRecognizer</code> for | ||
| 76 | recognizing mouse device gestures. Other abstract subclasses may be | ||
| 77 | provided by the platform to support other input devices or | ||
| 78 | particular <code>Component</code> class semantics. | ||
| 79 | <P> | ||
| 80 | <LI> The <code>DragGestureListener</code> causes the | ||
| 81 | <code>DragSource</code> to initiate the Drag | ||
| 82 | and Drop operation on behalf of the user, perhaps animating the | ||
| 83 | GUI Cursor and/or rendering an <code>Image</code> of the item(s) that are the | ||
| 84 | subject of the operation. | ||
| 85 | <P> | ||
| 86 | <LI> As the user gestures navigate over <code>Component</code>(s) | ||
| 87 | in the GUI with | ||
| 88 | associated <code>DropTarget</code>(s), the <code>DragSource</code> | ||
| 89 | receives notifications in order | ||
| 90 | to provide "Drag Over" feedback effects, and the <code>DropTarget</code>(s) | ||
| 91 | receive notifications in order to provide "Drag Under" feedback effects | ||
| 92 | based upon the operation(s) supported and the data type(s) involved. | ||
| 93 | </UL> | ||
| 94 | <P> | ||
| 95 | |||
| 96 | The gesture itself moves a logical cursor across the GUI hierarchy, | ||
| 97 | intersecting the geometry of GUI Component(s), possibly resulting in | ||
| 98 | the logical "Drag" cursor entering, crossing, and subsequently | ||
| 99 | leaving <code>Component</code>(s) and associated <code>DropTarget</code>(s). | ||
| 100 | <P> | ||
| 101 | The <code>DragSource</code> object manifests "Drag Over" feedback to the user, in the typical case by animating the GUI <code>Cursor</code> associated with the | ||
| 102 | logical cursor. | ||
| 103 | <P> | ||
| 104 | <code>DropTarget</code> objects manifest "Drag Under" feedback to the user, in | ||
| 105 | the typical case, by rendering animations into their associated GUI | ||
| 106 | <code>Component</code>(s) under the GUI Cursor. | ||
| 107 | <P> | ||
| 108 | The determination of the feedback effects, and the ultimate success | ||
| 109 | or failure of the data transfer, should one occur, is parameterized | ||
| 110 | as follows: | ||
| 111 | <UL> | ||
| 112 | <LI> By the transfer "operation" selected by the user, and supported by | ||
| 113 | both the <code>DragSource</code> and <code>DropTarget</code>: Copy, Move or Reference(link). | ||
| 114 | <P> | ||
| 115 | <LI> By the intersection of the set of data types provided by the | ||
| 116 | <code>DragSource</code> and the set of data types comprehensible by the | ||
| 117 | <code>DropTarget</code>. | ||
| 118 | <P> | ||
| 119 | <LI>When the user terminates the drag operation, normally resulting in a | ||
| 120 | successful Drop, both the <code>DragSource</code> and <code>DropTarget</code> | ||
| 121 | receive | ||
| 122 | notifications that include, and result in the type negotiation and | ||
| 123 | transfer of, the information associated with the <code>DragSource</code> via a | ||
| 124 | <code>Transferable</code> object. | ||
| 125 | </UL> | ||
| 126 | |||
| 127 | <!-- | ||
| 128 | <h2>Package Specification</h2> | ||
| 129 | |||
| 130 | ##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT ##### | ||
| 131 | <ul> | ||
| 132 | <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a> | ||
| 133 | </ul> | ||
| 134 | |||
| 135 | <h2>Related Documentation</h2> | ||
| 136 | |||
| 137 | For overviews, tutorials, examples, guides, and tool documentation, please see: | ||
| 138 | <ul> | ||
| 139 | <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a> | ||
| 140 | </ul> | ||
| 141 | --> | ||
| 142 | |||
| 143 | @since 1.2 | ||
| 144 | </body> | ||
| 145 | </html> | ||
Binary file not shown.
| @@ -0,0 +1,71 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.peer; | ||
| 27 | |||
| 28 | import java.awt.Cursor; | ||
| 29 | import java.awt.Image; | ||
| 30 | import java.awt.Point; | ||
| 31 | import java.awt.dnd.DragSourceContext; | ||
| 32 | import java.awt.dnd.InvalidDnDOperationException; | ||
| 33 | |||
| 34 | |||
| 35 | /** | ||
| 36 | * <p> | ||
| 37 | * This interface is supplied by the underlying window system platform to | ||
| 38 | * expose the behaviors of the Drag and Drop system to an originator of | ||
| 39 | * the same | ||
| 40 | * </p> | ||
| 41 | * | ||
| 42 | * @since 1.2 | ||
| 43 | * | ||
| 44 | */ | ||
| 45 | |||
| 46 | public interface DragSourceContextPeer { | ||
| 47 | |||
| 48 | /** | ||
| 49 | * start a drag | ||
| 50 | */ | ||
| 51 | |||
| 52 | void startDrag(DragSourceContext dsc, Cursor c, Image dragImage, Point imageOffset) throws InvalidDnDOperationException; | ||
| 53 | |||
| 54 | /** | ||
| 55 | * return the current drag cursor | ||
| 56 | */ | ||
| 57 | |||
| 58 | Cursor getCursor(); | ||
| 59 | |||
| 60 | /** | ||
| 61 | * set the current drag cursor | ||
| 62 | */ | ||
| 63 | |||
| 64 | void setCursor(Cursor c) throws InvalidDnDOperationException; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * notify the peer that the Transferables DataFlavors have changed | ||
| 68 | */ | ||
| 69 | |||
| 70 | void transferablesFlavorsChanged(); | ||
| 71 | } | ||
Binary file not shown.
| @@ -0,0 +1,111 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.peer; | ||
| 27 | |||
| 28 | import java.awt.datatransfer.DataFlavor; | ||
| 29 | import java.awt.datatransfer.Transferable; | ||
| 30 | import java.awt.dnd.DropTarget; | ||
| 31 | import java.awt.dnd.InvalidDnDOperationException; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * <p> | ||
| 35 | * This interface is exposed by the underlying window system platform to | ||
| 36 | * enable control of platform DnD operations | ||
| 37 | * </p> | ||
| 38 | * | ||
| 39 | * @since 1.2 | ||
| 40 | * | ||
| 41 | */ | ||
| 42 | |||
| 43 | public interface DropTargetContextPeer { | ||
| 44 | |||
| 45 | /** | ||
| 46 | * update the peer's notion of the Target's actions | ||
| 47 | */ | ||
| 48 | |||
| 49 | void setTargetActions(int actions); | ||
| 50 | |||
| 51 | /** | ||
| 52 | * get the current Target actions | ||
| 53 | */ | ||
| 54 | |||
| 55 | int getTargetActions(); | ||
| 56 | |||
| 57 | /** | ||
| 58 | * get the DropTarget associated with this peer | ||
| 59 | */ | ||
| 60 | |||
| 61 | DropTarget getDropTarget(); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * get the (remote) DataFlavors from the peer | ||
| 65 | */ | ||
| 66 | |||
| 67 | DataFlavor[] getTransferDataFlavors(); | ||
| 68 | |||
| 69 | /** | ||
| 70 | * get an input stream to the remote data | ||
| 71 | */ | ||
| 72 | |||
| 73 | Transferable getTransferable() throws InvalidDnDOperationException; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * @return if the DragSource Transferable is in the same JVM as the Target | ||
| 77 | */ | ||
| 78 | |||
| 79 | boolean isTransferableJVMLocal(); | ||
| 80 | |||
| 81 | /** | ||
| 82 | * accept the Drag | ||
| 83 | */ | ||
| 84 | |||
| 85 | void acceptDrag(int dragAction); | ||
| 86 | |||
| 87 | /** | ||
| 88 | * reject the Drag | ||
| 89 | */ | ||
| 90 | |||
| 91 | void rejectDrag(); | ||
| 92 | |||
| 93 | /** | ||
| 94 | * accept the Drop | ||
| 95 | */ | ||
| 96 | |||
| 97 | void acceptDrop(int dropAction); | ||
| 98 | |||
| 99 | /** | ||
| 100 | * reject the Drop | ||
| 101 | */ | ||
| 102 | |||
| 103 | void rejectDrop(); | ||
| 104 | |||
| 105 | /** | ||
| 106 | * signal complete | ||
| 107 | */ | ||
| 108 | |||
| 109 | void dropComplete(boolean success); | ||
| 110 | |||
| 111 | } | ||
Binary file not shown.
| @@ -0,0 +1,59 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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.peer; | ||
| 27 | |||
| 28 | import java.awt.dnd.DropTarget; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * <p> | ||
| 32 | * The DropTargetPeer class is the interface to the platform dependent | ||
| 33 | * DnD facilities. Since the DnD system is based on the native platform's | ||
| 34 | * facilities, a DropTargetPeer will be associated with a ComponentPeer | ||
| 35 | * of the nearsest enclosing native Container (in the case of lightweights) | ||
| 36 | * </p> | ||
| 37 | * | ||
| 38 | * @since 1.2 | ||
| 39 | * | ||
| 40 | */ | ||
| 41 | |||
| 42 | public interface DropTargetPeer { | ||
| 43 | |||
| 44 | /** | ||
| 45 | * Add the DropTarget to the System | ||
| 46 | * | ||
| 47 | * @param dt The DropTarget effected | ||
| 48 | */ | ||
| 49 | |||
| 50 | void addDropTarget(DropTarget dt); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Remove the DropTarget from the system | ||
| 54 | * | ||
| 55 | * @param dt The DropTarget effected | ||
| 56 | */ | ||
| 57 | |||
| 58 | void removeDropTarget(DropTarget dt); | ||
| 59 | } | ||
| @@ -0,0 +1,10 @@ | |||
| 1 | <../../../../../../mkconfig | ||
| 2 | |||
| 3 | TARG=\ | ||
| 4 | DragSourceContextPeer.dis\ | ||
| 5 | DropTargetContextPeer.dis\ | ||
| 6 | DropTargetPeer.dis\ | ||
| 7 | |||
| 8 | DISBIN=$ROOT/java/dis/java/java/java/awt/dnd/peer | ||
| 9 | |||
| 10 | <$ROOT/mkfiles/mkjava | ||
| @@ -0,0 +1,51 @@ | |||
| 1 | <!-- | ||
| 2 | Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | |||
| 5 | This code is free software; you can redistribute it and/or modify it | ||
| 6 | under the terms of the GNU General Public License version 2 only, as | ||
| 7 | published by the Free Software Foundation. Oracle designates this | ||
| 8 | particular file as subject to the "Classpath" exception as provided | ||
| 9 | by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | |||
| 11 | This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 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 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> | ||
| 27 | <html> | ||
| 28 | <body bgcolor="white"> | ||
| 29 | |||
| 30 | Provides for interfacing with the underlying window system | ||
| 31 | in order to access its platform-dependent drag-and-drop facilities. | ||
| 32 | This package is only used by AWT toolkit developers. | ||
| 33 | |||
| 34 | |||
| 35 | <h2>Package Specification</h2> | ||
| 36 | |||
| 37 | ##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT ##### | ||
| 38 | <ul> | ||
| 39 | <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a> | ||
| 40 | </ul> | ||
| 41 | |||
| 42 | <h2>Related Documentation</h2> | ||
| 43 | |||
| 44 | For overviews, tutorials, examples, guides, and tool documentation, please see: | ||
| 45 | <ul> | ||
| 46 | <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a> | ||
| 47 | </ul> | ||
| 48 | |||
| 49 | |||
| 50 | </body> | ||
| 51 | </html> | ||