feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
80
jdkSrc/jdk8/java/awt/dnd/Autoscroll.java
Normal file
80
jdkSrc/jdk8/java/awt/dnd/Autoscroll.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
|
||||
/**
|
||||
* During DnD operations it is possible that a user may wish to drop the
|
||||
* subject of the operation on a region of a scrollable GUI control that is
|
||||
* not currently visible to the user.
|
||||
* <p>
|
||||
* In such situations it is desirable that the GUI control detect this
|
||||
* and institute a scroll operation in order to make obscured region(s)
|
||||
* visible to the user. This feature is known as autoscrolling.
|
||||
* <p>
|
||||
* If a GUI control is both an active <code>DropTarget</code>
|
||||
* and is also scrollable, it
|
||||
* can receive notifications of autoscrolling gestures by the user from
|
||||
* the DnD system by implementing this interface.
|
||||
* <p>
|
||||
* An autoscrolling gesture is initiated by the user by keeping the drag
|
||||
* cursor motionless with a border region of the <code>Component</code>,
|
||||
* referred to as
|
||||
* the "autoscrolling region", for a predefined period of time, this will
|
||||
* result in repeated scroll requests to the <code>Component</code>
|
||||
* until the drag <code>Cursor</code> resumes its motion.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public interface Autoscroll {
|
||||
|
||||
/**
|
||||
* This method returns the <code>Insets</code> describing
|
||||
* the autoscrolling region or border relative
|
||||
* to the geometry of the implementing Component.
|
||||
* <P>
|
||||
* This value is read once by the <code>DropTarget</code>
|
||||
* upon entry of the drag <code>Cursor</code>
|
||||
* into the associated <code>Component</code>.
|
||||
* <P>
|
||||
* @return the Insets
|
||||
*/
|
||||
|
||||
public Insets getAutoscrollInsets();
|
||||
|
||||
/**
|
||||
* notify the <code>Component</code> to autoscroll
|
||||
* <P>
|
||||
* @param cursorLocn A <code>Point</code> indicating the
|
||||
* location of the cursor that triggered this operation.
|
||||
*/
|
||||
|
||||
public void autoscroll(Point cursorLocn);
|
||||
|
||||
}
|
||||
84
jdkSrc/jdk8/java/awt/dnd/DnDConstants.java
Normal file
84
jdkSrc/jdk8/java/awt/dnd/DnDConstants.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.lang.annotation.Native;
|
||||
|
||||
/**
|
||||
* This class contains constant values representing
|
||||
* the type of action(s) to be performed by a Drag and Drop operation.
|
||||
* @since 1.2
|
||||
*/
|
||||
public final class DnDConstants {
|
||||
|
||||
private DnDConstants() {} // define null private constructor.
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing no action.
|
||||
*/
|
||||
@Native public static final int ACTION_NONE = 0x0;
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing a "copy" action.
|
||||
*/
|
||||
@Native public static final int ACTION_COPY = 0x1;
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing a "move" action.
|
||||
*/
|
||||
@Native public static final int ACTION_MOVE = 0x2;
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing a "copy" or
|
||||
* "move" action.
|
||||
*/
|
||||
@Native public static final int ACTION_COPY_OR_MOVE = ACTION_COPY | ACTION_MOVE;
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing a "link" action.
|
||||
*
|
||||
* The link verb is found in many, if not all native DnD platforms, and the
|
||||
* actual interpretation of LINK semantics is both platform
|
||||
* and application dependent. Broadly speaking, the
|
||||
* semantic is "do not copy, or move the operand, but create a reference
|
||||
* to it". Defining the meaning of "reference" is where ambiguity is
|
||||
* introduced.
|
||||
*
|
||||
* The verb is provided for completeness, but its use is not recommended
|
||||
* for DnD operations between logically distinct applications where
|
||||
* misinterpretation of the operations semantics could lead to confusing
|
||||
* results for the user.
|
||||
*/
|
||||
|
||||
@Native public static final int ACTION_LINK = 0x40000000;
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing a "reference"
|
||||
* action (synonym for ACTION_LINK).
|
||||
*/
|
||||
@Native public static final int ACTION_REFERENCE = ACTION_LINK;
|
||||
|
||||
}
|
||||
231
jdkSrc/jdk8/java/awt/dnd/DnDEventMulticaster.java
Normal file
231
jdkSrc/jdk8/java/awt/dnd/DnDEventMulticaster.java
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.AWTEventMulticaster;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.EventListener;
|
||||
|
||||
|
||||
/**
|
||||
* A class extends <code>AWTEventMulticaster</code> to implement efficient and
|
||||
* thread-safe multi-cast event dispatching for the drag-and-drop events defined
|
||||
* in the java.awt.dnd package.
|
||||
*
|
||||
* @since 1.4
|
||||
* @see AWTEventMulticaster
|
||||
*/
|
||||
|
||||
class DnDEventMulticaster extends AWTEventMulticaster
|
||||
implements DragSourceListener, DragSourceMotionListener {
|
||||
|
||||
/**
|
||||
* Creates an event multicaster instance which chains listener-a
|
||||
* with listener-b. Input parameters <code>a</code> and <code>b</code>
|
||||
* should not be <code>null</code>, though implementations may vary in
|
||||
* choosing whether or not to throw <code>NullPointerException</code>
|
||||
* in that case.
|
||||
*
|
||||
* @param a listener-a
|
||||
* @param b listener-b
|
||||
*/
|
||||
protected DnDEventMulticaster(EventListener a, EventListener b) {
|
||||
super(a,b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <code>DragSourceDragEvent</code> by invoking
|
||||
* <code>dragEnter</code> on listener-a and listener-b.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragEnter(DragSourceDragEvent dsde) {
|
||||
((DragSourceListener)a).dragEnter(dsde);
|
||||
((DragSourceListener)b).dragEnter(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <code>DragSourceDragEvent</code> by invoking
|
||||
* <code>dragOver</code> on listener-a and listener-b.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragOver(DragSourceDragEvent dsde) {
|
||||
((DragSourceListener)a).dragOver(dsde);
|
||||
((DragSourceListener)b).dragOver(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <code>DragSourceDragEvent</code> by invoking
|
||||
* <code>dropActionChanged</code> on listener-a and listener-b.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dropActionChanged(DragSourceDragEvent dsde) {
|
||||
((DragSourceListener)a).dropActionChanged(dsde);
|
||||
((DragSourceListener)b).dropActionChanged(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <code>DragSourceEvent</code> by invoking
|
||||
* <code>dragExit</code> on listener-a and listener-b.
|
||||
*
|
||||
* @param dse the <code>DragSourceEvent</code>
|
||||
*/
|
||||
public void dragExit(DragSourceEvent dse) {
|
||||
((DragSourceListener)a).dragExit(dse);
|
||||
((DragSourceListener)b).dragExit(dse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <code>DragSourceDropEvent</code> by invoking
|
||||
* <code>dragDropEnd</code> on listener-a and listener-b.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDropEvent</code>
|
||||
*/
|
||||
public void dragDropEnd(DragSourceDropEvent dsde) {
|
||||
((DragSourceListener)a).dragDropEnd(dsde);
|
||||
((DragSourceListener)b).dragDropEnd(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <code>DragSourceDragEvent</code> by invoking
|
||||
* <code>dragMouseMoved</code> on listener-a and listener-b.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragMouseMoved(DragSourceDragEvent dsde) {
|
||||
((DragSourceMotionListener)a).dragMouseMoved(dsde);
|
||||
((DragSourceMotionListener)b).dragMouseMoved(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds drag-source-listener-a with drag-source-listener-b and
|
||||
* returns the resulting multicast listener.
|
||||
*
|
||||
* @param a drag-source-listener-a
|
||||
* @param b drag-source-listener-b
|
||||
*/
|
||||
public static DragSourceListener add(DragSourceListener a,
|
||||
DragSourceListener b) {
|
||||
return (DragSourceListener)addInternal(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds drag-source-motion-listener-a with drag-source-motion-listener-b and
|
||||
* returns the resulting multicast listener.
|
||||
*
|
||||
* @param a drag-source-motion-listener-a
|
||||
* @param b drag-source-motion-listener-b
|
||||
*/
|
||||
public static DragSourceMotionListener add(DragSourceMotionListener a,
|
||||
DragSourceMotionListener b) {
|
||||
return (DragSourceMotionListener)addInternal(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the old drag-source-listener from drag-source-listener-l
|
||||
* and returns the resulting multicast listener.
|
||||
*
|
||||
* @param l drag-source-listener-l
|
||||
* @param oldl the drag-source-listener being removed
|
||||
*/
|
||||
public static DragSourceListener remove(DragSourceListener l,
|
||||
DragSourceListener oldl) {
|
||||
return (DragSourceListener)removeInternal(l, oldl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the old drag-source-motion-listener from
|
||||
* drag-source-motion-listener-l and returns the resulting multicast
|
||||
* listener.
|
||||
*
|
||||
* @param l drag-source-motion-listener-l
|
||||
* @param ol the drag-source-motion-listener being removed
|
||||
*/
|
||||
public static DragSourceMotionListener remove(DragSourceMotionListener l,
|
||||
DragSourceMotionListener ol) {
|
||||
return (DragSourceMotionListener)removeInternal(l, ol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resulting multicast listener from adding listener-a
|
||||
* and listener-b together.
|
||||
* If listener-a is null, it returns listener-b;
|
||||
* If listener-b is null, it returns listener-a
|
||||
* If neither are null, then it creates and returns
|
||||
* a new AWTEventMulticaster instance which chains a with b.
|
||||
* @param a event listener-a
|
||||
* @param b event listener-b
|
||||
*/
|
||||
protected static EventListener addInternal(EventListener a, EventListener b) {
|
||||
if (a == null) return b;
|
||||
if (b == null) return a;
|
||||
return new DnDEventMulticaster(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a listener from this multicaster and returns the
|
||||
* resulting multicast listener.
|
||||
* @param oldl the listener to be removed
|
||||
*/
|
||||
protected EventListener remove(EventListener oldl) {
|
||||
if (oldl == a) return b;
|
||||
if (oldl == b) return a;
|
||||
EventListener a2 = removeInternal(a, oldl);
|
||||
EventListener b2 = removeInternal(b, oldl);
|
||||
if (a2 == a && b2 == b) {
|
||||
return this; // it's not here
|
||||
}
|
||||
return addInternal(a2, b2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resulting multicast listener after removing the
|
||||
* old listener from listener-l.
|
||||
* If listener-l equals the old listener OR listener-l is null,
|
||||
* returns null.
|
||||
* Else if listener-l is an instance of AWTEventMulticaster,
|
||||
* then it removes the old listener from it.
|
||||
* Else, returns listener l.
|
||||
* @param l the listener being removed from
|
||||
* @param oldl the listener being removed
|
||||
*/
|
||||
protected static EventListener removeInternal(EventListener l, EventListener oldl) {
|
||||
if (l == oldl || l == null) {
|
||||
return null;
|
||||
} else if (l instanceof DnDEventMulticaster) {
|
||||
return ((DnDEventMulticaster)l).remove(oldl);
|
||||
} else {
|
||||
return l; // it's not here
|
||||
}
|
||||
}
|
||||
|
||||
protected static void save(ObjectOutputStream s, String k, EventListener l)
|
||||
throws IOException {
|
||||
AWTEventMulticaster.save(s, k, l);
|
||||
}
|
||||
}
|
||||
412
jdkSrc/jdk8/java/awt/dnd/DragGestureEvent.java
Normal file
412
jdkSrc/jdk8/java/awt/dnd/DragGestureEvent.java
Normal file
@@ -0,0 +1,412 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
import java.awt.datatransfer.Transferable;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.util.EventObject;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
|
||||
/**
|
||||
* A <code>DragGestureEvent</code> is passed
|
||||
* to <code>DragGestureListener</code>'s
|
||||
* dragGestureRecognized() method
|
||||
* when a particular <code>DragGestureRecognizer</code> detects that a
|
||||
* platform dependent drag initiating gesture has occurred
|
||||
* on the <code>Component</code> that it is tracking.
|
||||
*
|
||||
* The {@code action} field of any {@code DragGestureEvent} instance should take one of the following
|
||||
* values:
|
||||
* <ul>
|
||||
* <li> {@code DnDConstants.ACTION_COPY}
|
||||
* <li> {@code DnDConstants.ACTION_MOVE}
|
||||
* <li> {@code DnDConstants.ACTION_LINK}
|
||||
* </ul>
|
||||
* Assigning the value different from listed above will cause an unspecified behavior.
|
||||
*
|
||||
* @see java.awt.dnd.DragGestureRecognizer
|
||||
* @see java.awt.dnd.DragGestureListener
|
||||
* @see java.awt.dnd.DragSource
|
||||
* @see java.awt.dnd.DnDConstants
|
||||
*/
|
||||
|
||||
public class DragGestureEvent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = 9080172649166731306L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>DragGestureEvent</code> object given by the
|
||||
* <code>DragGestureRecognizer</code> instance firing this event,
|
||||
* an {@code act} parameter representing
|
||||
* the user's preferred action, an {@code ori} parameter
|
||||
* indicating the origin of the drag, and a {@code List} of
|
||||
* events that comprise the gesture({@code evs} parameter).
|
||||
* <P>
|
||||
* @param dgr The <code>DragGestureRecognizer</code> firing this event
|
||||
* @param act The user's preferred action.
|
||||
* For information on allowable values, see
|
||||
* the class description for {@link DragGestureEvent}
|
||||
* @param ori The origin of the drag
|
||||
* @param evs The <code>List</code> of events that comprise the gesture
|
||||
* <P>
|
||||
* @throws IllegalArgumentException if any parameter equals {@code null}
|
||||
* @throws IllegalArgumentException if the act parameter does not comply with
|
||||
* the values given in the class
|
||||
* description for {@link DragGestureEvent}
|
||||
* @see java.awt.dnd.DnDConstants
|
||||
*/
|
||||
|
||||
public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori,
|
||||
List<? extends InputEvent> evs)
|
||||
{
|
||||
super(dgr);
|
||||
|
||||
if ((component = dgr.getComponent()) == null)
|
||||
throw new IllegalArgumentException("null component");
|
||||
if ((dragSource = dgr.getDragSource()) == null)
|
||||
throw new IllegalArgumentException("null DragSource");
|
||||
|
||||
if (evs == null || evs.isEmpty())
|
||||
throw new IllegalArgumentException("null or empty list of events");
|
||||
|
||||
if (act != DnDConstants.ACTION_COPY &&
|
||||
act != DnDConstants.ACTION_MOVE &&
|
||||
act != DnDConstants.ACTION_LINK)
|
||||
throw new IllegalArgumentException("bad action");
|
||||
|
||||
if (ori == null) throw new IllegalArgumentException("null origin");
|
||||
|
||||
events = evs;
|
||||
action = act;
|
||||
origin = ori;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source as a <code>DragGestureRecognizer</code>.
|
||||
* <P>
|
||||
* @return the source as a <code>DragGestureRecognizer</code>
|
||||
*/
|
||||
|
||||
public DragGestureRecognizer getSourceAsDragGestureRecognizer() {
|
||||
return (DragGestureRecognizer)getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>Component</code> associated
|
||||
* with this <code>DragGestureEvent</code>.
|
||||
* <P>
|
||||
* @return the Component
|
||||
*/
|
||||
|
||||
public Component getComponent() { return component; }
|
||||
|
||||
/**
|
||||
* Returns the <code>DragSource</code>.
|
||||
* <P>
|
||||
* @return the <code>DragSource</code>
|
||||
*/
|
||||
|
||||
public DragSource getDragSource() { return dragSource; }
|
||||
|
||||
/**
|
||||
* Returns a <code>Point</code> in the coordinates
|
||||
* of the <code>Component</code> over which the drag originated.
|
||||
* <P>
|
||||
* @return the Point where the drag originated in Component coords.
|
||||
*/
|
||||
|
||||
public Point getDragOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <code>Iterator</code> for the events
|
||||
* comprising the gesture.
|
||||
* <P>
|
||||
* @return an Iterator for the events comprising the gesture
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator<InputEvent> iterator() { return events.iterator(); }
|
||||
|
||||
/**
|
||||
* Returns an <code>Object</code> array of the
|
||||
* events comprising the drag gesture.
|
||||
* <P>
|
||||
* @return an array of the events comprising the gesture
|
||||
*/
|
||||
|
||||
public Object[] toArray() { return events.toArray(); }
|
||||
|
||||
/**
|
||||
* Returns an array of the events comprising the drag gesture.
|
||||
* <P>
|
||||
* @param array the array of <code>EventObject</code> sub(types)
|
||||
* <P>
|
||||
* @return an array of the events comprising the gesture
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray(Object[] array) { return events.toArray(array); }
|
||||
|
||||
/**
|
||||
* Returns an <code>int</code> representing the
|
||||
* action selected by the user.
|
||||
* <P>
|
||||
* @return the action selected by the user
|
||||
*/
|
||||
|
||||
public int getDragAction() { return action; }
|
||||
|
||||
/**
|
||||
* Returns the initial event that triggered the gesture.
|
||||
* <P>
|
||||
* @return the first "triggering" event in the sequence of the gesture
|
||||
*/
|
||||
|
||||
public InputEvent getTriggerEvent() {
|
||||
return getSourceAsDragGestureRecognizer().getTriggerEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the drag operation given the <code>Cursor</code> for this drag
|
||||
* operation and the <code>Transferable</code> representing the source data
|
||||
* for this drag operation.
|
||||
* <br>
|
||||
* If a <code>null</code> <code>Cursor</code> is specified no exception will
|
||||
* be thrown and default drag cursors will be used instead.
|
||||
* <br>
|
||||
* If a <code>null</code> <code>Transferable</code> is specified
|
||||
* <code>NullPointerException</code> will be thrown.
|
||||
* @param dragCursor The initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see
|
||||
* <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
|
||||
* for more details on the cursor handling mechanism
|
||||
* during drag and drop
|
||||
* @param transferable The <code>Transferable</code> representing the source
|
||||
* data for this drag operation.
|
||||
*
|
||||
* @throws InvalidDnDOperationException if the Drag and Drop
|
||||
* system is unable to initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing drag operation is
|
||||
* still executing.
|
||||
* @throws NullPointerException if the {@code Transferable} is {@code null}
|
||||
* @since 1.4
|
||||
*/
|
||||
public void startDrag(Cursor dragCursor, Transferable transferable)
|
||||
throws InvalidDnDOperationException {
|
||||
dragSource.startDrag(this, dragCursor, transferable, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the drag given the initial <code>Cursor</code> to display,
|
||||
* the <code>Transferable</code> object,
|
||||
* and the <code>DragSourceListener</code> to use.
|
||||
* <P>
|
||||
* @param dragCursor The initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see
|
||||
* <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
|
||||
* for more details on the cursor handling mechanism
|
||||
* during drag and drop
|
||||
* @param transferable The source's Transferable
|
||||
* @param dsl The source's DragSourceListener
|
||||
* <P>
|
||||
* @throws InvalidDnDOperationException if
|
||||
* the Drag and Drop system is unable to
|
||||
* initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing
|
||||
* drag operation is still executing.
|
||||
*/
|
||||
|
||||
public void startDrag(Cursor dragCursor, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException {
|
||||
dragSource.startDrag(this, dragCursor, transferable, dsl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the drag given the initial <code>Cursor</code> to display,
|
||||
* a drag <code>Image</code>, the offset of
|
||||
* the <code>Image</code>,
|
||||
* the <code>Transferable</code> object, and
|
||||
* the <code>DragSourceListener</code> to use.
|
||||
* <P>
|
||||
* @param dragCursor The initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see
|
||||
* <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
|
||||
* for more details on the cursor handling mechanism
|
||||
* during drag and drop
|
||||
* @param dragImage The source's dragImage
|
||||
* @param imageOffset The dragImage's offset
|
||||
* @param transferable The source's Transferable
|
||||
* @param dsl The source's DragSourceListener
|
||||
* <P>
|
||||
* @throws InvalidDnDOperationException if
|
||||
* the Drag and Drop system is unable to
|
||||
* initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing
|
||||
* drag operation is still executing.
|
||||
*/
|
||||
|
||||
public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException {
|
||||
dragSource.startDrag(this, dragCursor, dragImage, imageOffset, transferable, dsl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes this <code>DragGestureEvent</code>. Performs default
|
||||
* serialization and then writes out this object's <code>List</code> of
|
||||
* gesture events if and only if the <code>List</code> can be serialized.
|
||||
* If not, <code>null</code> is written instead. In this case, a
|
||||
* <code>DragGestureEvent</code> created from the resulting deserialized
|
||||
* stream will contain an empty <code>List</code> of gesture events.
|
||||
*
|
||||
* @serialData The default serializable fields, in alphabetical order,
|
||||
* followed by either a <code>List</code> instance, or
|
||||
* <code>null</code>.
|
||||
* @since 1.4
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||
s.defaultWriteObject();
|
||||
|
||||
s.writeObject(SerializationTester.test(events) ? events : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes this <code>DragGestureEvent</code>. This method first
|
||||
* performs default deserialization for all non-<code>transient</code>
|
||||
* fields. An attempt is then made to deserialize this object's
|
||||
* <code>List</code> of gesture events as well. This is first attempted
|
||||
* by deserializing the field <code>events</code>, because, in releases
|
||||
* prior to 1.4, a non-<code>transient</code> field of this name stored the
|
||||
* <code>List</code> of gesture events. If this fails, the next object in
|
||||
* the stream is used instead. If the resulting <code>List</code> is
|
||||
* <code>null</code>, this object's <code>List</code> of gesture events
|
||||
* is set to an empty <code>List</code>.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws ClassNotFoundException, IOException
|
||||
{
|
||||
ObjectInputStream.GetField f = s.readFields();
|
||||
|
||||
DragSource newDragSource = (DragSource)f.get("dragSource", null);
|
||||
if (newDragSource == null) {
|
||||
throw new InvalidObjectException("null DragSource");
|
||||
}
|
||||
dragSource = newDragSource;
|
||||
|
||||
Component newComponent = (Component)f.get("component", null);
|
||||
if (newComponent == null) {
|
||||
throw new InvalidObjectException("null component");
|
||||
}
|
||||
component = newComponent;
|
||||
|
||||
Point newOrigin = (Point)f.get("origin", null);
|
||||
if (newOrigin == null) {
|
||||
throw new InvalidObjectException("null origin");
|
||||
}
|
||||
origin = newOrigin;
|
||||
|
||||
int newAction = f.get("action", 0);
|
||||
if (newAction != DnDConstants.ACTION_COPY &&
|
||||
newAction != DnDConstants.ACTION_MOVE &&
|
||||
newAction != DnDConstants.ACTION_LINK) {
|
||||
throw new InvalidObjectException("bad action");
|
||||
}
|
||||
action = newAction;
|
||||
|
||||
// Pre-1.4 support. 'events' was previously non-transient
|
||||
List newEvents;
|
||||
try {
|
||||
newEvents = (List)f.get("events", null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// 1.4-compatible byte stream. 'events' was written explicitly
|
||||
newEvents = (List)s.readObject();
|
||||
}
|
||||
|
||||
// Implementation assumes 'events' is never null.
|
||||
if (newEvents != null && newEvents.isEmpty()) {
|
||||
// Constructor treats empty events list as invalid value
|
||||
// Throw exception if serialized list is empty
|
||||
throw new InvalidObjectException("empty list of events");
|
||||
} else if (newEvents == null) {
|
||||
newEvents = Collections.emptyList();
|
||||
}
|
||||
events = newEvents;
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private transient List events;
|
||||
|
||||
/**
|
||||
* The DragSource associated with this DragGestureEvent.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private DragSource dragSource;
|
||||
|
||||
/**
|
||||
* The Component associated with this DragGestureEvent.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Component component;
|
||||
|
||||
/**
|
||||
* The origin of the drag.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Point origin;
|
||||
|
||||
/**
|
||||
* The user's preferred action.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int action;
|
||||
}
|
||||
64
jdkSrc/jdk8/java/awt/dnd/DragGestureListener.java
Normal file
64
jdkSrc/jdk8/java/awt/dnd/DragGestureListener.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* The listener interface for receiving drag gesture events.
|
||||
* This interface is intended for a drag gesture recognition
|
||||
* implementation. See a specification for {@code DragGestureRecognizer}
|
||||
* for details on how to register the listener interface.
|
||||
* Upon recognition of a drag gesture the {@code
|
||||
* DragGestureRecognizer} calls this interface's
|
||||
* {@link #dragGestureRecognized dragGestureRecognized()}
|
||||
* method and passes a {@code DragGestureEvent}.
|
||||
|
||||
*
|
||||
* @see java.awt.dnd.DragGestureRecognizer
|
||||
* @see java.awt.dnd.DragGestureEvent
|
||||
* @see java.awt.dnd.DragSource
|
||||
*/
|
||||
|
||||
public interface DragGestureListener extends EventListener {
|
||||
|
||||
/**
|
||||
* This method is invoked by the {@code DragGestureRecognizer}
|
||||
* when the {@code DragGestureRecognizer} detects a platform-dependent
|
||||
* drag initiating gesture. To initiate the drag and drop operation,
|
||||
* if appropriate, {@link DragGestureEvent#startDrag startDrag()} method on
|
||||
* the {@code DragGestureEvent} has to be invoked.
|
||||
* <P>
|
||||
* @see java.awt.dnd.DragGestureRecognizer
|
||||
* @see java.awt.dnd.DragGestureEvent
|
||||
* @param dge the <code>DragGestureEvent</code> describing
|
||||
* the gesture that has just occurred
|
||||
*/
|
||||
|
||||
void dragGestureRecognized(DragGestureEvent dge);
|
||||
}
|
||||
479
jdkSrc/jdk8/java/awt/dnd/DragGestureRecognizer.java
Normal file
479
jdkSrc/jdk8/java/awt/dnd/DragGestureRecognizer.java
Normal file
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.util.Collections;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The <code>DragGestureRecognizer</code> is an
|
||||
* abstract base class for the specification
|
||||
* of a platform-dependent listener that can be associated with a particular
|
||||
* <code>Component</code> in order to
|
||||
* identify platform-dependent drag initiating gestures.
|
||||
* <p>
|
||||
* The appropriate <code>DragGestureRecognizer</code>
|
||||
* subclass instance is obtained from the
|
||||
* {@link DragSource} associated with
|
||||
* a particular <code>Component</code>, or from the <code>Toolkit</code> object via its
|
||||
* {@link java.awt.Toolkit#createDragGestureRecognizer createDragGestureRecognizer()}
|
||||
* method.
|
||||
* <p>
|
||||
* Once the <code>DragGestureRecognizer</code>
|
||||
* is associated with a particular <code>Component</code>
|
||||
* it will register the appropriate listener interfaces on that
|
||||
* <code>Component</code>
|
||||
* in order to track the input events delivered to the <code>Component</code>.
|
||||
* <p>
|
||||
* Once the <code>DragGestureRecognizer</code> identifies a sequence of events
|
||||
* on the <code>Component</code> as a drag initiating gesture, it will notify
|
||||
* its unicast <code>DragGestureListener</code> by
|
||||
* invoking its
|
||||
* {@link java.awt.dnd.DragGestureListener#dragGestureRecognized gestureRecognized()}
|
||||
* method.
|
||||
* <P>
|
||||
* When a concrete <code>DragGestureRecognizer</code>
|
||||
* instance detects a drag initiating
|
||||
* gesture on the <code>Component</code> it is associated with,
|
||||
* it fires a {@link DragGestureEvent} to
|
||||
* the <code>DragGestureListener</code> registered on
|
||||
* its unicast event source for <code>DragGestureListener</code>
|
||||
* events. This <code>DragGestureListener</code> is responsible
|
||||
* for causing the associated
|
||||
* <code>DragSource</code> to start the Drag and Drop operation (if
|
||||
* appropriate).
|
||||
* <P>
|
||||
* @author Laurence P. G. Cable
|
||||
* @see java.awt.dnd.DragGestureListener
|
||||
* @see java.awt.dnd.DragGestureEvent
|
||||
* @see java.awt.dnd.DragSource
|
||||
*/
|
||||
|
||||
public abstract class DragGestureRecognizer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8996673345831063337L;
|
||||
|
||||
/**
|
||||
* Construct a new <code>DragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> to be used
|
||||
* in this Drag and Drop operation, the <code>Component</code>
|
||||
* this <code>DragGestureRecognizer</code> should "observe"
|
||||
* for drag initiating gestures, the action(s) supported
|
||||
* for this Drag and Drop operation, and the
|
||||
* <code>DragGestureListener</code> to notify
|
||||
* once a drag initiating gesture has been detected.
|
||||
* <P>
|
||||
* @param ds the <code>DragSource</code> this
|
||||
* <code>DragGestureRecognizer</code>
|
||||
* will use to process the Drag and Drop operation
|
||||
*
|
||||
* @param c the <code>Component</code>
|
||||
* this <code>DragGestureRecognizer</code>
|
||||
* should "observe" the event stream to,
|
||||
* in order to detect a drag initiating gesture.
|
||||
* If this value is <code>null</code>, the
|
||||
* <code>DragGestureRecognizer</code>
|
||||
* is not associated with any <code>Component</code>.
|
||||
*
|
||||
* @param sa the set (logical OR) of the
|
||||
* <code>DnDConstants</code>
|
||||
* that this Drag and Drop operation will support
|
||||
*
|
||||
* @param dgl the <code>DragGestureRecognizer</code>
|
||||
* to notify when a drag gesture is detected
|
||||
* <P>
|
||||
* @throws IllegalArgumentException
|
||||
* if ds is <code>null</code>.
|
||||
*/
|
||||
|
||||
protected DragGestureRecognizer(DragSource ds, Component c, int sa, DragGestureListener dgl) {
|
||||
super();
|
||||
|
||||
if (ds == null) throw new IllegalArgumentException("null DragSource");
|
||||
|
||||
dragSource = ds;
|
||||
component = c;
|
||||
sourceActions = sa & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
|
||||
|
||||
try {
|
||||
if (dgl != null) addDragGestureListener(dgl);
|
||||
} catch (TooManyListenersException tmle) {
|
||||
// cant happen ...
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>DragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> to be used in this
|
||||
* Drag and Drop
|
||||
* operation, the <code>Component</code> this
|
||||
* <code>DragGestureRecognizer</code> should "observe"
|
||||
* for drag initiating gestures, and the action(s)
|
||||
* supported for this Drag and Drop operation.
|
||||
* <P>
|
||||
* @param ds the <code>DragSource</code> this
|
||||
* <code>DragGestureRecognizer</code> will use to
|
||||
* process the Drag and Drop operation
|
||||
*
|
||||
* @param c the <code>Component</code> this
|
||||
* <code>DragGestureRecognizer</code> should "observe" the event
|
||||
* stream to, in order to detect a drag initiating gesture.
|
||||
* If this value is <code>null</code>, the
|
||||
* <code>DragGestureRecognizer</code>
|
||||
* is not associated with any <code>Component</code>.
|
||||
*
|
||||
* @param sa the set (logical OR) of the <code>DnDConstants</code>
|
||||
* that this Drag and Drop operation will support
|
||||
* <P>
|
||||
* @throws IllegalArgumentException
|
||||
* if ds is <code>null</code>.
|
||||
*/
|
||||
|
||||
protected DragGestureRecognizer(DragSource ds, Component c, int sa) {
|
||||
this(ds, c, sa, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>DragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> to be used
|
||||
* in this Drag and Drop operation, and
|
||||
* the <code>Component</code> this
|
||||
* <code>DragGestureRecognizer</code>
|
||||
* should "observe" for drag initiating gestures.
|
||||
* <P>
|
||||
* @param ds the <code>DragSource</code> this
|
||||
* <code>DragGestureRecognizer</code>
|
||||
* will use to process the Drag and Drop operation
|
||||
*
|
||||
* @param c the <code>Component</code>
|
||||
* this <code>DragGestureRecognizer</code>
|
||||
* should "observe" the event stream to,
|
||||
* in order to detect a drag initiating gesture.
|
||||
* If this value is <code>null</code>,
|
||||
* the <code>DragGestureRecognizer</code>
|
||||
* is not associated with any <code>Component</code>.
|
||||
* <P>
|
||||
* @throws IllegalArgumentException
|
||||
* if ds is <code>null</code>.
|
||||
*/
|
||||
|
||||
protected DragGestureRecognizer(DragSource ds, Component c) {
|
||||
this(ds, c, DnDConstants.ACTION_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>DragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> to be used in this
|
||||
* Drag and Drop operation.
|
||||
* <P>
|
||||
* @param ds the <code>DragSource</code> this
|
||||
* <code>DragGestureRecognizer</code> will
|
||||
* use to process the Drag and Drop operation
|
||||
* <P>
|
||||
* @throws IllegalArgumentException
|
||||
* if ds is <code>null</code>.
|
||||
*/
|
||||
|
||||
protected DragGestureRecognizer(DragSource ds) {
|
||||
this(ds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* register this DragGestureRecognizer's Listeners with the Component
|
||||
*
|
||||
* subclasses must override this method
|
||||
*/
|
||||
|
||||
protected abstract void registerListeners();
|
||||
|
||||
/**
|
||||
* unregister this DragGestureRecognizer's Listeners with the Component
|
||||
*
|
||||
* subclasses must override this method
|
||||
*/
|
||||
|
||||
protected abstract void unregisterListeners();
|
||||
|
||||
/**
|
||||
* This method returns the <code>DragSource</code>
|
||||
* this <code>DragGestureRecognizer</code>
|
||||
* will use in order to process the Drag and Drop
|
||||
* operation.
|
||||
* <P>
|
||||
* @return the DragSource
|
||||
*/
|
||||
|
||||
public DragSource getDragSource() { return dragSource; }
|
||||
|
||||
/**
|
||||
* This method returns the <code>Component</code>
|
||||
* that is to be "observed" by the
|
||||
* <code>DragGestureRecognizer</code>
|
||||
* for drag initiating gestures.
|
||||
* <P>
|
||||
* @return The Component this DragGestureRecognizer
|
||||
* is associated with
|
||||
*/
|
||||
|
||||
public synchronized Component getComponent() { return component; }
|
||||
|
||||
/**
|
||||
* set the Component that the DragGestureRecognizer is associated with
|
||||
*
|
||||
* registerListeners() and unregisterListeners() are called as a side
|
||||
* effect as appropriate.
|
||||
* <P>
|
||||
* @param c The <code>Component</code> or <code>null</code>
|
||||
*/
|
||||
|
||||
public synchronized void setComponent(Component c) {
|
||||
if (component != null && dragGestureListener != null)
|
||||
unregisterListeners();
|
||||
|
||||
component = c;
|
||||
|
||||
if (component != null && dragGestureListener != null)
|
||||
registerListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an int representing the
|
||||
* type of action(s) this Drag and Drop
|
||||
* operation will support.
|
||||
* <P>
|
||||
* @return the currently permitted source action(s)
|
||||
*/
|
||||
|
||||
public synchronized int getSourceActions() { return sourceActions; }
|
||||
|
||||
/**
|
||||
* This method sets the permitted source drag action(s)
|
||||
* for this Drag and Drop operation.
|
||||
* <P>
|
||||
* @param actions the permitted source drag action(s)
|
||||
*/
|
||||
|
||||
public synchronized void setSourceActions(int actions) {
|
||||
sourceActions = actions & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the first event in the
|
||||
* series of events that initiated
|
||||
* the Drag and Drop operation.
|
||||
* <P>
|
||||
* @return the initial event that triggered the drag gesture
|
||||
*/
|
||||
|
||||
public InputEvent getTriggerEvent() { return events.isEmpty() ? null : events.get(0); }
|
||||
|
||||
/**
|
||||
* Reset the Recognizer, if its currently recognizing a gesture, ignore
|
||||
* it.
|
||||
*/
|
||||
|
||||
public void resetRecognizer() { events.clear(); }
|
||||
|
||||
/**
|
||||
* Register a new <code>DragGestureListener</code>.
|
||||
* <P>
|
||||
* @param dgl the <code>DragGestureListener</code> to register
|
||||
* with this <code>DragGestureRecognizer</code>.
|
||||
* <P>
|
||||
* @throws java.util.TooManyListenersException if a
|
||||
* <code>DragGestureListener</code> has already been added.
|
||||
*/
|
||||
|
||||
public synchronized void addDragGestureListener(DragGestureListener dgl) throws TooManyListenersException {
|
||||
if (dragGestureListener != null)
|
||||
throw new TooManyListenersException();
|
||||
else {
|
||||
dragGestureListener = dgl;
|
||||
|
||||
if (component != null) registerListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister the current DragGestureListener
|
||||
* <P>
|
||||
* @param dgl the <code>DragGestureListener</code> to unregister
|
||||
* from this <code>DragGestureRecognizer</code>
|
||||
* <P>
|
||||
* @throws IllegalArgumentException if
|
||||
* dgl is not (equal to) the currently registered <code>DragGestureListener</code>.
|
||||
*/
|
||||
|
||||
public synchronized void removeDragGestureListener(DragGestureListener dgl) {
|
||||
if (dragGestureListener == null || !dragGestureListener.equals(dgl))
|
||||
throw new IllegalArgumentException();
|
||||
else {
|
||||
dragGestureListener = null;
|
||||
|
||||
if (component != null) unregisterListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the DragGestureListener that a Drag and Drop initiating
|
||||
* gesture has occurred. Then reset the state of the Recognizer.
|
||||
* <P>
|
||||
* @param dragAction The action initially selected by the users gesture
|
||||
* @param p The point (in Component coords) where the gesture originated
|
||||
*/
|
||||
protected synchronized void fireDragGestureRecognized(int dragAction, Point p) {
|
||||
try {
|
||||
if (dragGestureListener != null) {
|
||||
dragGestureListener.dragGestureRecognized(new DragGestureEvent(this, dragAction, p, events));
|
||||
}
|
||||
} finally {
|
||||
events.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listeners registered on the Component by this Recognizer shall record
|
||||
* all Events that are recognized as part of the series of Events that go
|
||||
* to comprise a Drag and Drop initiating gesture via this API.
|
||||
*<P>
|
||||
* This method is used by a <code>DragGestureRecognizer</code>
|
||||
* implementation to add an <code>InputEvent</code>
|
||||
* subclass (that it believes is one in a series
|
||||
* of events that comprise a Drag and Drop operation)
|
||||
* to the array of events that this
|
||||
* <code>DragGestureRecognizer</code> maintains internally.
|
||||
* <P>
|
||||
* @param awtie the <code>InputEvent</code>
|
||||
* to add to this <code>DragGestureRecognizer</code>'s
|
||||
* internal array of events. Note that <code>null</code>
|
||||
* is not a valid value, and will be ignored.
|
||||
*/
|
||||
|
||||
protected synchronized void appendEvent(InputEvent awtie) {
|
||||
events.add(awtie);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes this <code>DragGestureRecognizer</code>. This method first
|
||||
* performs default serialization. Then, this object's
|
||||
* <code>DragGestureListener</code> is written out if and only if it can be
|
||||
* serialized. If not, <code>null</code> is written instead.
|
||||
*
|
||||
* @serialData The default serializable fields, in alphabetical order,
|
||||
* followed by either a <code>DragGestureListener</code>, or
|
||||
* <code>null</code>.
|
||||
* @since 1.4
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||
s.defaultWriteObject();
|
||||
|
||||
s.writeObject(SerializationTester.test(dragGestureListener)
|
||||
? dragGestureListener : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes this <code>DragGestureRecognizer</code>. This method first
|
||||
* performs default deserialization for all non-<code>transient</code>
|
||||
* fields. This object's <code>DragGestureListener</code> is then
|
||||
* deserialized as well by using the next object in the stream.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws ClassNotFoundException, IOException
|
||||
{
|
||||
ObjectInputStream.GetField f = s.readFields();
|
||||
|
||||
DragSource newDragSource = (DragSource)f.get("dragSource", null);
|
||||
if (newDragSource == null) {
|
||||
throw new InvalidObjectException("null DragSource");
|
||||
}
|
||||
dragSource = newDragSource;
|
||||
|
||||
component = (Component)f.get("component", null);
|
||||
sourceActions = f.get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
|
||||
events = (ArrayList<InputEvent>)f.get("events", new ArrayList<>(1));
|
||||
|
||||
dragGestureListener = (DragGestureListener)s.readObject();
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>DragSource</code>
|
||||
* associated with this
|
||||
* <code>DragGestureRecognizer</code>.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
protected DragSource dragSource;
|
||||
|
||||
/**
|
||||
* The <code>Component</code>
|
||||
* associated with this <code>DragGestureRecognizer</code>.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
protected Component component;
|
||||
|
||||
/**
|
||||
* The <code>DragGestureListener</code>
|
||||
* associated with this <code>DragGestureRecognizer</code>.
|
||||
*/
|
||||
protected transient DragGestureListener dragGestureListener;
|
||||
|
||||
/**
|
||||
* An <code>int</code> representing
|
||||
* the type(s) of action(s) used
|
||||
* in this Drag and Drop operation.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
protected int sourceActions;
|
||||
|
||||
/**
|
||||
* The list of events (in order) that
|
||||
* the <code>DragGestureRecognizer</code>
|
||||
* "recognized" as a "gesture" that triggers a drag.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
protected ArrayList<InputEvent> events = new ArrayList<InputEvent>(1);
|
||||
}
|
||||
921
jdkSrc/jdk8/java/awt/dnd/DragSource.java
Normal file
921
jdkSrc/jdk8/java/awt/dnd/DragSource.java
Normal file
@@ -0,0 +1,921 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.FlavorMap;
|
||||
import java.awt.datatransfer.SystemFlavorMap;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.dnd.peer.DragSourceContextPeer;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.util.EventListener;
|
||||
import sun.awt.dnd.SunDragSourceContextPeer;
|
||||
import sun.security.action.GetIntegerAction;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>DragSource</code> is the entity responsible
|
||||
* for the initiation of the Drag
|
||||
* and Drop operation, and may be used in a number of scenarios:
|
||||
* <UL>
|
||||
* <LI>1 default instance per JVM for the lifetime of that JVM.
|
||||
* <LI>1 instance per class of potential Drag Initiator object (e.g
|
||||
* TextField). [implementation dependent]
|
||||
* <LI>1 per instance of a particular
|
||||
* <code>Component</code>, or application specific
|
||||
* object associated with a <code>Component</code>
|
||||
* instance in the GUI. [implementation dependent]
|
||||
* <LI>Some other arbitrary association. [implementation dependent]
|
||||
*</UL>
|
||||
*
|
||||
* Once the <code>DragSource</code> is
|
||||
* obtained, a <code>DragGestureRecognizer</code> should
|
||||
* also be obtained to associate the <code>DragSource</code>
|
||||
* with a particular
|
||||
* <code>Component</code>.
|
||||
* <P>
|
||||
* The initial interpretation of the user's gesture,
|
||||
* and the subsequent starting of the drag operation
|
||||
* are the responsibility of the implementing
|
||||
* <code>Component</code>, which is usually
|
||||
* implemented by a <code>DragGestureRecognizer</code>.
|
||||
*<P>
|
||||
* When a drag gesture occurs, the
|
||||
* <code>DragSource</code>'s
|
||||
* startDrag() method shall be
|
||||
* invoked in order to cause processing
|
||||
* of the user's navigational
|
||||
* gestures and delivery of Drag and Drop
|
||||
* protocol notifications. A
|
||||
* <code>DragSource</code> shall only
|
||||
* permit a single Drag and Drop operation to be
|
||||
* current at any one time, and shall
|
||||
* reject any further startDrag() requests
|
||||
* by throwing an <code>IllegalDnDOperationException</code>
|
||||
* until such time as the extant operation is complete.
|
||||
* <P>
|
||||
* The startDrag() method invokes the
|
||||
* createDragSourceContext() method to
|
||||
* instantiate an appropriate
|
||||
* <code>DragSourceContext</code>
|
||||
* and associate the <code>DragSourceContextPeer</code>
|
||||
* with that.
|
||||
* <P>
|
||||
* If the Drag and Drop System is
|
||||
* unable to initiate a drag operation for
|
||||
* some reason, the startDrag() method throws
|
||||
* a <code>java.awt.dnd.InvalidDnDOperationException</code>
|
||||
* to signal such a condition. Typically this
|
||||
* exception is thrown when the underlying platform
|
||||
* system is either not in a state to
|
||||
* initiate a drag, or the parameters specified are invalid.
|
||||
* <P>
|
||||
* Note that during the drag, the
|
||||
* set of operations exposed by the source
|
||||
* at the start of the drag operation may not change
|
||||
* until the operation is complete.
|
||||
* The operation(s) are constant for the
|
||||
* duration of the operation with respect to the
|
||||
* <code>DragSource</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DragSource implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6236096958971414066L;
|
||||
|
||||
/*
|
||||
* load a system default cursor
|
||||
*/
|
||||
|
||||
private static Cursor load(String name) {
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return (Cursor)Toolkit.getDefaultToolkit().getDesktopProperty(name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new RuntimeException("failed to load system cursor: " + name + " : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The default <code>Cursor</code> to use with a copy operation indicating
|
||||
* that a drop is currently allowed. <code>null</code> if
|
||||
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
|
||||
*
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static final Cursor DefaultCopyDrop =
|
||||
load("DnD.Cursor.CopyDrop");
|
||||
|
||||
/**
|
||||
* The default <code>Cursor</code> to use with a move operation indicating
|
||||
* that a drop is currently allowed. <code>null</code> if
|
||||
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
|
||||
*
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static final Cursor DefaultMoveDrop =
|
||||
load("DnD.Cursor.MoveDrop");
|
||||
|
||||
/**
|
||||
* The default <code>Cursor</code> to use with a link operation indicating
|
||||
* that a drop is currently allowed. <code>null</code> if
|
||||
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
|
||||
*
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static final Cursor DefaultLinkDrop =
|
||||
load("DnD.Cursor.LinkDrop");
|
||||
|
||||
/**
|
||||
* The default <code>Cursor</code> to use with a copy operation indicating
|
||||
* that a drop is currently not allowed. <code>null</code> if
|
||||
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
|
||||
*
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static final Cursor DefaultCopyNoDrop =
|
||||
load("DnD.Cursor.CopyNoDrop");
|
||||
|
||||
/**
|
||||
* The default <code>Cursor</code> to use with a move operation indicating
|
||||
* that a drop is currently not allowed. <code>null</code> if
|
||||
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
|
||||
*
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static final Cursor DefaultMoveNoDrop =
|
||||
load("DnD.Cursor.MoveNoDrop");
|
||||
|
||||
/**
|
||||
* The default <code>Cursor</code> to use with a link operation indicating
|
||||
* that a drop is currently not allowed. <code>null</code> if
|
||||
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
|
||||
*
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static final Cursor DefaultLinkNoDrop =
|
||||
load("DnD.Cursor.LinkNoDrop");
|
||||
|
||||
private static final DragSource dflt =
|
||||
(GraphicsEnvironment.isHeadless()) ? null : new DragSource();
|
||||
|
||||
/**
|
||||
* Internal constants for serialization.
|
||||
*/
|
||||
static final String dragSourceListenerK = "dragSourceL";
|
||||
static final String dragSourceMotionListenerK = "dragSourceMotionL";
|
||||
|
||||
/**
|
||||
* Gets the <code>DragSource</code> object associated with
|
||||
* the underlying platform.
|
||||
*
|
||||
* @return the platform DragSource
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public static DragSource getDefaultDragSource() {
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
throw new HeadlessException();
|
||||
} else {
|
||||
return dflt;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports
|
||||
* whether or not drag
|
||||
* <code>Image</code> support
|
||||
* is available on the underlying platform.
|
||||
* <P>
|
||||
* @return if the Drag Image support is available on this platform
|
||||
*/
|
||||
|
||||
public static boolean isDragImageSupported() {
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
|
||||
Boolean supported;
|
||||
|
||||
try {
|
||||
supported = (Boolean)Toolkit.getDefaultToolkit().getDesktopProperty("DnD.isDragImageSupported");
|
||||
|
||||
return supported.booleanValue();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>DragSource</code>.
|
||||
*
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public DragSource() throws HeadlessException {
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a drag, given the <code>DragGestureEvent</code>
|
||||
* that initiated the drag, the initial
|
||||
* <code>Cursor</code> to use,
|
||||
* the <code>Image</code> to drag,
|
||||
* the offset of the <code>Image</code> origin
|
||||
* from the hotspot of the <code>Cursor</code> at
|
||||
* the instant of the trigger,
|
||||
* the <code>Transferable</code> subject data
|
||||
* of the drag, the <code>DragSourceListener</code>,
|
||||
* and the <code>FlavorMap</code>.
|
||||
* <P>
|
||||
* @param trigger the <code>DragGestureEvent</code> that initiated the drag
|
||||
* @param dragCursor the initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
|
||||
* for more details on the cursor handling mechanism during drag and drop
|
||||
* @param dragImage the image to drag or {@code null}
|
||||
* @param imageOffset the offset of the <code>Image</code> origin from the hotspot
|
||||
* of the <code>Cursor</code> at the instant of the trigger
|
||||
* @param transferable the subject data of the drag
|
||||
* @param dsl the <code>DragSourceListener</code>
|
||||
* @param flavorMap the <code>FlavorMap</code> to use, or <code>null</code>
|
||||
* <P>
|
||||
* @throws java.awt.dnd.InvalidDnDOperationException
|
||||
* if the Drag and Drop
|
||||
* system is unable to initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing drag operation
|
||||
* is still executing
|
||||
*/
|
||||
|
||||
public void startDrag(DragGestureEvent trigger,
|
||||
Cursor dragCursor,
|
||||
Image dragImage,
|
||||
Point imageOffset,
|
||||
Transferable transferable,
|
||||
DragSourceListener dsl,
|
||||
FlavorMap flavorMap) throws InvalidDnDOperationException {
|
||||
|
||||
SunDragSourceContextPeer.setDragDropInProgress(true);
|
||||
|
||||
try {
|
||||
if (flavorMap != null) this.flavorMap = flavorMap;
|
||||
|
||||
DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
|
||||
|
||||
DragSourceContext dsc = createDragSourceContext(dscp,
|
||||
trigger,
|
||||
dragCursor,
|
||||
dragImage,
|
||||
imageOffset,
|
||||
transferable,
|
||||
dsl
|
||||
);
|
||||
|
||||
if (dsc == null) {
|
||||
throw new InvalidDnDOperationException();
|
||||
}
|
||||
|
||||
dscp.startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw
|
||||
} catch (RuntimeException e) {
|
||||
SunDragSourceContextPeer.setDragDropInProgress(false);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a drag, given the <code>DragGestureEvent</code>
|
||||
* that initiated the drag, the initial
|
||||
* <code>Cursor</code> to use,
|
||||
* the <code>Transferable</code> subject data
|
||||
* of the drag, the <code>DragSourceListener</code>,
|
||||
* and the <code>FlavorMap</code>.
|
||||
* <P>
|
||||
* @param trigger the <code>DragGestureEvent</code> that
|
||||
* initiated the drag
|
||||
* @param dragCursor the initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
|
||||
* for more details on the cursor handling mechanism during drag and drop
|
||||
* @param transferable the subject data of the drag
|
||||
* @param dsl the <code>DragSourceListener</code>
|
||||
* @param flavorMap the <code>FlavorMap</code> to use or <code>null</code>
|
||||
* <P>
|
||||
* @throws java.awt.dnd.InvalidDnDOperationException
|
||||
* if the Drag and Drop
|
||||
* system is unable to initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing drag operation
|
||||
* is still executing
|
||||
*/
|
||||
|
||||
public void startDrag(DragGestureEvent trigger,
|
||||
Cursor dragCursor,
|
||||
Transferable transferable,
|
||||
DragSourceListener dsl,
|
||||
FlavorMap flavorMap) throws InvalidDnDOperationException {
|
||||
startDrag(trigger, dragCursor, null, null, transferable, dsl, flavorMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a drag, given the <code>DragGestureEvent</code>
|
||||
* that initiated the drag, the initial <code>Cursor</code>
|
||||
* to use,
|
||||
* the <code>Image</code> to drag,
|
||||
* the offset of the <code>Image</code> origin
|
||||
* from the hotspot of the <code>Cursor</code>
|
||||
* at the instant of the trigger,
|
||||
* the subject data of the drag, and
|
||||
* the <code>DragSourceListener</code>.
|
||||
* <P>
|
||||
* @param trigger the <code>DragGestureEvent</code> that initiated the drag
|
||||
* @param dragCursor the initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
|
||||
* for more details on the cursor handling mechanism during drag and drop
|
||||
* @param dragImage the <code>Image</code> to drag or <code>null</code>
|
||||
* @param dragOffset the offset of the <code>Image</code> origin from the hotspot
|
||||
* of the <code>Cursor</code> at the instant of the trigger
|
||||
* @param transferable the subject data of the drag
|
||||
* @param dsl the <code>DragSourceListener</code>
|
||||
* <P>
|
||||
* @throws java.awt.dnd.InvalidDnDOperationException
|
||||
* if the Drag and Drop
|
||||
* system is unable to initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing drag operation
|
||||
* is still executing
|
||||
*/
|
||||
|
||||
public void startDrag(DragGestureEvent trigger,
|
||||
Cursor dragCursor,
|
||||
Image dragImage,
|
||||
Point dragOffset,
|
||||
Transferable transferable,
|
||||
DragSourceListener dsl) throws InvalidDnDOperationException {
|
||||
startDrag(trigger, dragCursor, dragImage, dragOffset, transferable, dsl, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a drag, given the <code>DragGestureEvent</code>
|
||||
* that initiated the drag, the initial
|
||||
* <code>Cursor</code> to
|
||||
* use,
|
||||
* the <code>Transferable</code> subject data
|
||||
* of the drag, and the <code>DragSourceListener</code>.
|
||||
* <P>
|
||||
* @param trigger the <code>DragGestureEvent</code> that initiated the drag
|
||||
* @param dragCursor the initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> class
|
||||
* for more details on the cursor handling mechanism during drag and drop
|
||||
* @param transferable the subject data of the drag
|
||||
* @param dsl the <code>DragSourceListener</code>
|
||||
* <P>
|
||||
* @throws java.awt.dnd.InvalidDnDOperationException
|
||||
* if the Drag and Drop
|
||||
* system is unable to initiate a drag operation, or if the user
|
||||
* attempts to start a drag while an existing drag operation
|
||||
* is still executing
|
||||
*/
|
||||
|
||||
public void startDrag(DragGestureEvent trigger,
|
||||
Cursor dragCursor,
|
||||
Transferable transferable,
|
||||
DragSourceListener dsl) throws InvalidDnDOperationException {
|
||||
startDrag(trigger, dragCursor, null, null, transferable, dsl, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the {@code DragSourceContext} to handle the current drag
|
||||
* operation.
|
||||
* <p>
|
||||
* To incorporate a new <code>DragSourceContext</code>
|
||||
* subclass, subclass <code>DragSource</code> and
|
||||
* override this method.
|
||||
* <p>
|
||||
* If <code>dragImage</code> is <code>null</code>, no image is used
|
||||
* to represent the drag over feedback for this drag operation, but
|
||||
* <code>NullPointerException</code> is not thrown.
|
||||
* <p>
|
||||
* If <code>dsl</code> is <code>null</code>, no drag source listener
|
||||
* is registered with the created <code>DragSourceContext</code>,
|
||||
* but <code>NullPointerException</code> is not thrown.
|
||||
*
|
||||
* @param dscp The <code>DragSourceContextPeer</code> for this drag
|
||||
* @param dgl The <code>DragGestureEvent</code> that triggered the
|
||||
* drag
|
||||
* @param dragCursor The initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> class
|
||||
* for more details on the cursor handling mechanism during drag and drop
|
||||
* @param dragImage The <code>Image</code> to drag or <code>null</code>
|
||||
* @param imageOffset The offset of the <code>Image</code> origin from the
|
||||
* hotspot of the cursor at the instant of the trigger
|
||||
* @param t The subject data of the drag
|
||||
* @param dsl The <code>DragSourceListener</code>
|
||||
*
|
||||
* @return the <code>DragSourceContext</code>
|
||||
*
|
||||
* @throws NullPointerException if <code>dscp</code> is <code>null</code>
|
||||
* @throws NullPointerException if <code>dgl</code> is <code>null</code>
|
||||
* @throws NullPointerException if <code>dragImage</code> is not
|
||||
* <code>null</code> and <code>imageOffset</code> is <code>null</code>
|
||||
* @throws NullPointerException if <code>t</code> is <code>null</code>
|
||||
* @throws IllegalArgumentException if the <code>Component</code>
|
||||
* associated with the trigger event is <code>null</code>.
|
||||
* @throws IllegalArgumentException if the <code>DragSource</code> for the
|
||||
* trigger event is <code>null</code>.
|
||||
* @throws IllegalArgumentException if the drag action for the
|
||||
* trigger event is <code>DnDConstants.ACTION_NONE</code>.
|
||||
* @throws IllegalArgumentException if the source actions for the
|
||||
* <code>DragGestureRecognizer</code> associated with the trigger
|
||||
* event are equal to <code>DnDConstants.ACTION_NONE</code>.
|
||||
*/
|
||||
|
||||
protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl) {
|
||||
return new DragSourceContext(dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the
|
||||
* <code>FlavorMap</code> for this <code>DragSource</code>.
|
||||
* <P>
|
||||
* @return the <code>FlavorMap</code> for this <code>DragSource</code>
|
||||
*/
|
||||
|
||||
public FlavorMap getFlavorMap() { return flavorMap; }
|
||||
|
||||
/**
|
||||
* Creates a new <code>DragGestureRecognizer</code>
|
||||
* that implements the specified
|
||||
* abstract subclass of
|
||||
* <code>DragGestureRecognizer</code>, and
|
||||
* sets the specified <code>Component</code>
|
||||
* and <code>DragGestureListener</code> on
|
||||
* the newly created object.
|
||||
* <P>
|
||||
* @param recognizerAbstractClass the requested abstract type
|
||||
* @param actions the permitted source drag actions
|
||||
* @param c the <code>Component</code> target
|
||||
* @param dgl the <code>DragGestureListener</code> to notify
|
||||
* <P>
|
||||
* @return the new <code>DragGestureRecognizer</code> or <code>null</code>
|
||||
* if the <code>Toolkit.createDragGestureRecognizer</code> method
|
||||
* has no implementation available for
|
||||
* the requested <code>DragGestureRecognizer</code>
|
||||
* subclass and returns <code>null</code>
|
||||
*/
|
||||
|
||||
public <T extends DragGestureRecognizer> T
|
||||
createDragGestureRecognizer(Class<T> recognizerAbstractClass,
|
||||
Component c, int actions,
|
||||
DragGestureListener dgl)
|
||||
{
|
||||
return Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizerAbstractClass, this, c, actions, dgl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new <code>DragGestureRecognizer</code>
|
||||
* that implements the default
|
||||
* abstract subclass of <code>DragGestureRecognizer</code>
|
||||
* for this <code>DragSource</code>,
|
||||
* and sets the specified <code>Component</code>
|
||||
* and <code>DragGestureListener</code> on the
|
||||
* newly created object.
|
||||
*
|
||||
* For this <code>DragSource</code>
|
||||
* the default is <code>MouseDragGestureRecognizer</code>.
|
||||
* <P>
|
||||
* @param c the <code>Component</code> target for the recognizer
|
||||
* @param actions the permitted source actions
|
||||
* @param dgl the <code>DragGestureListener</code> to notify
|
||||
* <P>
|
||||
* @return the new <code>DragGestureRecognizer</code> or <code>null</code>
|
||||
* if the <code>Toolkit.createDragGestureRecognizer</code> method
|
||||
* has no implementation available for
|
||||
* the requested <code>DragGestureRecognizer</code>
|
||||
* subclass and returns <code>null</code>
|
||||
*/
|
||||
|
||||
public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c, int actions, DragGestureListener dgl) {
|
||||
return Toolkit.getDefaultToolkit().createDragGestureRecognizer(MouseDragGestureRecognizer.class, this, c, actions, dgl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified <code>DragSourceListener</code> to this
|
||||
* <code>DragSource</code> to receive drag source events during drag
|
||||
* operations intiated with this <code>DragSource</code>.
|
||||
* If a <code>null</code> listener is specified, no action is taken and no
|
||||
* exception is thrown.
|
||||
*
|
||||
* @param dsl the <code>DragSourceListener</code> to add
|
||||
*
|
||||
* @see #removeDragSourceListener
|
||||
* @see #getDragSourceListeners
|
||||
* @since 1.4
|
||||
*/
|
||||
public void addDragSourceListener(DragSourceListener dsl) {
|
||||
if (dsl != null) {
|
||||
synchronized (this) {
|
||||
listener = DnDEventMulticaster.add(listener, dsl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified <code>DragSourceListener</code> from this
|
||||
* <code>DragSource</code>.
|
||||
* If a <code>null</code> listener is specified, no action is taken and no
|
||||
* exception is thrown.
|
||||
* If the listener specified by the argument was not previously added to
|
||||
* this <code>DragSource</code>, no action is taken and no exception
|
||||
* is thrown.
|
||||
*
|
||||
* @param dsl the <code>DragSourceListener</code> to remove
|
||||
*
|
||||
* @see #addDragSourceListener
|
||||
* @see #getDragSourceListeners
|
||||
* @since 1.4
|
||||
*/
|
||||
public void removeDragSourceListener(DragSourceListener dsl) {
|
||||
if (dsl != null) {
|
||||
synchronized (this) {
|
||||
listener = DnDEventMulticaster.remove(listener, dsl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the <code>DragSourceListener</code>s
|
||||
* registered with this <code>DragSource</code>.
|
||||
*
|
||||
* @return all of this <code>DragSource</code>'s
|
||||
* <code>DragSourceListener</code>s or an empty array if no
|
||||
* such listeners are currently registered
|
||||
*
|
||||
* @see #addDragSourceListener
|
||||
* @see #removeDragSourceListener
|
||||
* @since 1.4
|
||||
*/
|
||||
public DragSourceListener[] getDragSourceListeners() {
|
||||
return getListeners(DragSourceListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified <code>DragSourceMotionListener</code> to this
|
||||
* <code>DragSource</code> to receive drag motion events during drag
|
||||
* operations intiated with this <code>DragSource</code>.
|
||||
* If a <code>null</code> listener is specified, no action is taken and no
|
||||
* exception is thrown.
|
||||
*
|
||||
* @param dsml the <code>DragSourceMotionListener</code> to add
|
||||
*
|
||||
* @see #removeDragSourceMotionListener
|
||||
* @see #getDragSourceMotionListeners
|
||||
* @since 1.4
|
||||
*/
|
||||
public void addDragSourceMotionListener(DragSourceMotionListener dsml) {
|
||||
if (dsml != null) {
|
||||
synchronized (this) {
|
||||
motionListener = DnDEventMulticaster.add(motionListener, dsml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified <code>DragSourceMotionListener</code> from this
|
||||
* <code>DragSource</code>.
|
||||
* If a <code>null</code> listener is specified, no action is taken and no
|
||||
* exception is thrown.
|
||||
* If the listener specified by the argument was not previously added to
|
||||
* this <code>DragSource</code>, no action is taken and no exception
|
||||
* is thrown.
|
||||
*
|
||||
* @param dsml the <code>DragSourceMotionListener</code> to remove
|
||||
*
|
||||
* @see #addDragSourceMotionListener
|
||||
* @see #getDragSourceMotionListeners
|
||||
* @since 1.4
|
||||
*/
|
||||
public void removeDragSourceMotionListener(DragSourceMotionListener dsml) {
|
||||
if (dsml != null) {
|
||||
synchronized (this) {
|
||||
motionListener = DnDEventMulticaster.remove(motionListener, dsml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all of the <code>DragSourceMotionListener</code>s
|
||||
* registered with this <code>DragSource</code>.
|
||||
*
|
||||
* @return all of this <code>DragSource</code>'s
|
||||
* <code>DragSourceMotionListener</code>s or an empty array if no
|
||||
* such listeners are currently registered
|
||||
*
|
||||
* @see #addDragSourceMotionListener
|
||||
* @see #removeDragSourceMotionListener
|
||||
* @since 1.4
|
||||
*/
|
||||
public DragSourceMotionListener[] getDragSourceMotionListeners() {
|
||||
return getListeners(DragSourceMotionListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the objects currently registered as
|
||||
* <code><em>Foo</em>Listener</code>s upon this <code>DragSource</code>.
|
||||
* <code><em>Foo</em>Listener</code>s are registered using the
|
||||
* <code>add<em>Foo</em>Listener</code> method.
|
||||
*
|
||||
* @param listenerType the type of listeners requested; this parameter
|
||||
* should specify an interface that descends from
|
||||
* <code>java.util.EventListener</code>
|
||||
* @return an array of all objects registered as
|
||||
* <code><em>Foo</em>Listener</code>s on this
|
||||
* <code>DragSource</code>, or an empty array if no such listeners
|
||||
* have been added
|
||||
* @exception ClassCastException if <code>listenerType</code>
|
||||
* doesn't specify a class or interface that implements
|
||||
* <code>java.util.EventListener</code>
|
||||
*
|
||||
* @see #getDragSourceListeners
|
||||
* @see #getDragSourceMotionListeners
|
||||
* @since 1.4
|
||||
*/
|
||||
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
|
||||
EventListener l = null;
|
||||
if (listenerType == DragSourceListener.class) {
|
||||
l = listener;
|
||||
} else if (listenerType == DragSourceMotionListener.class) {
|
||||
l = motionListener;
|
||||
}
|
||||
return DnDEventMulticaster.getListeners(l, listenerType);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls <code>dragEnter</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void processDragEnter(DragSourceDragEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragEnter(dsde);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls <code>dragOver</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void processDragOver(DragSourceDragEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragOver(dsde);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls <code>dropActionChanged</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void processDropActionChanged(DragSourceDragEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dropActionChanged(dsde);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls <code>dragExit</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceEvent</code>.
|
||||
*
|
||||
* @param dse the <code>DragSourceEvent</code>
|
||||
*/
|
||||
void processDragExit(DragSourceEvent dse) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragExit(dse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls <code>dragDropEnd</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDropEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceEvent</code>
|
||||
*/
|
||||
void processDragDropEnd(DragSourceDropEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragDropEnd(dsde);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls <code>dragMouseMoved</code> on the
|
||||
* <code>DragSourceMotionListener</code>s registered with this
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceEvent</code>
|
||||
*/
|
||||
void processDragMouseMoved(DragSourceDragEvent dsde) {
|
||||
DragSourceMotionListener dsml = motionListener;
|
||||
if (dsml != null) {
|
||||
dsml.dragMouseMoved(dsde);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes this <code>DragSource</code>. This method first performs
|
||||
* default serialization. Next, it writes out this object's
|
||||
* <code>FlavorMap</code> if and only if it can be serialized. If not,
|
||||
* <code>null</code> is written instead. Next, it writes out
|
||||
* <code>Serializable</code> listeners registered with this
|
||||
* object. Listeners are written in a <code>null</code>-terminated sequence
|
||||
* of 0 or more pairs. The pair consists of a <code>String</code> and an
|
||||
* <code>Object</code>; the <code>String</code> indicates the type of the
|
||||
* <code>Object</code> and is one of the following:
|
||||
* <ul>
|
||||
* <li><code>dragSourceListenerK</code> indicating a
|
||||
* <code>DragSourceListener</code> object;
|
||||
* <li><code>dragSourceMotionListenerK</code> indicating a
|
||||
* <code>DragSourceMotionListener</code> object.
|
||||
* </ul>
|
||||
*
|
||||
* @serialData Either a <code>FlavorMap</code> instance, or
|
||||
* <code>null</code>, followed by a <code>null</code>-terminated
|
||||
* sequence of 0 or more pairs; the pair consists of a
|
||||
* <code>String</code> and an <code>Object</code>; the
|
||||
* <code>String</code> indicates the type of the <code>Object</code>
|
||||
* and is one of the following:
|
||||
* <ul>
|
||||
* <li><code>dragSourceListenerK</code> indicating a
|
||||
* <code>DragSourceListener</code> object;
|
||||
* <li><code>dragSourceMotionListenerK</code> indicating a
|
||||
* <code>DragSourceMotionListener</code> object.
|
||||
* </ul>.
|
||||
* @since 1.4
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||
s.defaultWriteObject();
|
||||
|
||||
s.writeObject(SerializationTester.test(flavorMap) ? flavorMap : null);
|
||||
|
||||
DnDEventMulticaster.save(s, dragSourceListenerK, listener);
|
||||
DnDEventMulticaster.save(s, dragSourceMotionListenerK, motionListener);
|
||||
s.writeObject(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes this <code>DragSource</code>. This method first performs
|
||||
* default deserialization. Next, this object's <code>FlavorMap</code> is
|
||||
* deserialized by using the next object in the stream.
|
||||
* If the resulting <code>FlavorMap</code> is <code>null</code>, this
|
||||
* object's <code>FlavorMap</code> is set to the default FlavorMap for
|
||||
* this thread's <code>ClassLoader</code>.
|
||||
* Next, this object's listeners are deserialized by reading a
|
||||
* <code>null</code>-terminated sequence of 0 or more key/value pairs
|
||||
* from the stream:
|
||||
* <ul>
|
||||
* <li>If a key object is a <code>String</code> equal to
|
||||
* <code>dragSourceListenerK</code>, a <code>DragSourceListener</code> is
|
||||
* deserialized using the corresponding value object and added to this
|
||||
* <code>DragSource</code>.
|
||||
* <li>If a key object is a <code>String</code> equal to
|
||||
* <code>dragSourceMotionListenerK</code>, a
|
||||
* <code>DragSourceMotionListener</code> is deserialized using the
|
||||
* corresponding value object and added to this <code>DragSource</code>.
|
||||
* <li>Otherwise, the key/value pair is skipped.
|
||||
* </ul>
|
||||
*
|
||||
* @see java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap
|
||||
* @since 1.4
|
||||
*/
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws ClassNotFoundException, IOException {
|
||||
s.defaultReadObject();
|
||||
|
||||
// 'flavorMap' was written explicitly
|
||||
flavorMap = (FlavorMap)s.readObject();
|
||||
|
||||
// Implementation assumes 'flavorMap' is never null.
|
||||
if (flavorMap == null) {
|
||||
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
|
||||
}
|
||||
|
||||
Object keyOrNull;
|
||||
while (null != (keyOrNull = s.readObject())) {
|
||||
String key = ((String)keyOrNull).intern();
|
||||
|
||||
if (dragSourceListenerK == key) {
|
||||
addDragSourceListener((DragSourceListener)(s.readObject()));
|
||||
} else if (dragSourceMotionListenerK == key) {
|
||||
addDragSourceMotionListener(
|
||||
(DragSourceMotionListener)(s.readObject()));
|
||||
} else {
|
||||
// skip value for unrecognized key
|
||||
s.readObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the drag gesture motion threshold. The drag gesture motion threshold
|
||||
* defines the recommended behavior for {@link MouseDragGestureRecognizer}s.
|
||||
* <p>
|
||||
* If the system property <code>awt.dnd.drag.threshold</code> is set to
|
||||
* a positive integer, this method returns the value of the system property;
|
||||
* otherwise if a pertinent desktop property is available and supported by
|
||||
* the implementation of the Java platform, this method returns the value of
|
||||
* that property; otherwise this method returns some default value.
|
||||
* The pertinent desktop property can be queried using
|
||||
* <code>java.awt.Toolkit.getDesktopProperty("DnD.gestureMotionThreshold")</code>.
|
||||
*
|
||||
* @return the drag gesture motion threshold
|
||||
* @see MouseDragGestureRecognizer
|
||||
* @since 1.5
|
||||
*/
|
||||
public static int getDragThreshold() {
|
||||
int ts = AccessController.doPrivileged(
|
||||
new GetIntegerAction("awt.dnd.drag.threshold", 0)).intValue();
|
||||
if (ts > 0) {
|
||||
return ts;
|
||||
} else {
|
||||
Integer td = (Integer)Toolkit.getDefaultToolkit().
|
||||
getDesktopProperty("DnD.gestureMotionThreshold");
|
||||
if (td != null) {
|
||||
return td.intValue();
|
||||
}
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap();
|
||||
|
||||
private transient DragSourceListener listener;
|
||||
|
||||
private transient DragSourceMotionListener motionListener;
|
||||
}
|
||||
142
jdkSrc/jdk8/java/awt/dnd/DragSourceAdapter.java
Normal file
142
jdkSrc/jdk8/java/awt/dnd/DragSourceAdapter.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
/**
|
||||
* An abstract adapter class for receiving drag source events. The methods in
|
||||
* this class are empty. This class exists only as a convenience for creating
|
||||
* listener objects.
|
||||
* <p>
|
||||
* Extend this class to create a <code>DragSourceEvent</code> listener
|
||||
* and override the methods for the events of interest. (If you implement the
|
||||
* <code>DragSourceListener</code> interface, you have to define all of
|
||||
* the methods in it. This abstract class defines null methods for them
|
||||
* all, so you only have to define methods for events you care about.)
|
||||
* <p>
|
||||
* Create a listener object using the extended class and then register it with
|
||||
* a <code>DragSource</code>. When the drag enters, moves over, or exits
|
||||
* a drop site, when the drop action changes, and when the drag ends, the
|
||||
* relevant method in the listener object is invoked, and the
|
||||
* <code>DragSourceEvent</code> is passed to it.
|
||||
* <p>
|
||||
* The drop site is <i>associated with the previous <code>dragEnter()</code>
|
||||
* invocation</i> if the latest invocation of <code>dragEnter()</code> on this
|
||||
* adapter corresponds to that drop site and is not followed by a
|
||||
* <code>dragExit()</code> invocation on this adapter.
|
||||
*
|
||||
* @see DragSourceEvent
|
||||
* @see DragSourceListener
|
||||
* @see DragSourceMotionListener
|
||||
*
|
||||
* @author David Mendenhall
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class DragSourceAdapter
|
||||
implements DragSourceListener, DragSourceMotionListener {
|
||||
|
||||
/**
|
||||
* Called as the cursor's hotspot enters a platform-dependent drop site.
|
||||
* This method is invoked when all the following conditions are true:
|
||||
* <UL>
|
||||
* <LI>The cursor's hotspot enters the operable part of
|
||||
* a platform-dependent drop site.
|
||||
* <LI>The drop site is active.
|
||||
* <LI>The drop site accepts the drag.
|
||||
* </UL>
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragEnter(DragSourceDragEvent dsde) {}
|
||||
|
||||
/**
|
||||
* Called as the cursor's hotspot moves over a platform-dependent drop site.
|
||||
* This method is invoked when all the following conditions are true:
|
||||
* <UL>
|
||||
* <LI>The cursor's hotspot has moved, but still intersects the
|
||||
* operable part of the drop site associated with the previous
|
||||
* dragEnter() invocation.
|
||||
* <LI>The drop site is still active.
|
||||
* <LI>The drop site accepts the drag.
|
||||
* </UL>
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragOver(DragSourceDragEvent dsde) {}
|
||||
|
||||
/**
|
||||
* Called whenever the mouse is moved during a drag operation.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragMouseMoved(DragSourceDragEvent dsde) {}
|
||||
|
||||
/**
|
||||
* Called when the user has modified the drop gesture.
|
||||
* This method is invoked when the state of the input
|
||||
* device(s) that the user is interacting with changes.
|
||||
* Such devices are typically the mouse buttons or keyboard
|
||||
* modifiers that the user is interacting with.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dropActionChanged(DragSourceDragEvent dsde) {}
|
||||
|
||||
/**
|
||||
* Called as the cursor's hotspot exits a platform-dependent drop site.
|
||||
* This method is invoked when any of the following conditions are true:
|
||||
* <UL>
|
||||
* <LI>The cursor's hotspot no longer intersects the operable part
|
||||
* of the drop site associated with the previous dragEnter() invocation.
|
||||
* </UL>
|
||||
* OR
|
||||
* <UL>
|
||||
* <LI>The drop site associated with the previous dragEnter() invocation
|
||||
* is no longer active.
|
||||
* </UL>
|
||||
* OR
|
||||
* <UL>
|
||||
* <LI> The drop site associated with the previous dragEnter() invocation
|
||||
* has rejected the drag.
|
||||
* </UL>
|
||||
*
|
||||
* @param dse the <code>DragSourceEvent</code>
|
||||
*/
|
||||
public void dragExit(DragSourceEvent dse) {}
|
||||
|
||||
/**
|
||||
* This method is invoked to signify that the Drag and Drop
|
||||
* operation is complete. The getDropSuccess() method of
|
||||
* the <code>DragSourceDropEvent</code> can be used to
|
||||
* determine the termination state. The getDropAction() method
|
||||
* returns the operation that the drop site selected
|
||||
* to apply to the Drop operation. Once this method is complete, the
|
||||
* current <code>DragSourceContext</code> and
|
||||
* associated resources become invalid.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDropEvent</code>
|
||||
*/
|
||||
public void dragDropEnd(DragSourceDropEvent dsde) {}
|
||||
}
|
||||
663
jdkSrc/jdk8/java/awt/dnd/DragSourceContext.java
Normal file
663
jdkSrc/jdk8/java/awt/dnd/DragSourceContext.java
Normal file
@@ -0,0 +1,663 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
|
||||
import java.awt.dnd.peer.DragSourceContextPeer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
/**
|
||||
* The <code>DragSourceContext</code> class is responsible for managing the
|
||||
* initiator side of the Drag and Drop protocol. In particular, it is responsible
|
||||
* for managing drag event notifications to the
|
||||
* {@linkplain DragSourceListener DragSourceListeners}
|
||||
* and {@linkplain DragSourceMotionListener DragSourceMotionListeners}, and providing the
|
||||
* {@link Transferable} representing the source data for the drag operation.
|
||||
* <p>
|
||||
* Note that the <code>DragSourceContext</code> itself
|
||||
* implements the <code>DragSourceListener</code> and
|
||||
* <code>DragSourceMotionListener</code> interfaces.
|
||||
* This is to allow the platform peer
|
||||
* (the {@link DragSourceContextPeer} instance)
|
||||
* created by the {@link DragSource} to notify
|
||||
* the <code>DragSourceContext</code> of
|
||||
* state changes in the ongoing operation. This allows the
|
||||
* <code>DragSourceContext</code> object to interpose
|
||||
* itself between the platform and the
|
||||
* listeners provided by the initiator of the drag operation.
|
||||
* <p>
|
||||
* <a name="defaultCursor"></a>
|
||||
* By default, {@code DragSourceContext} sets the cursor as appropriate
|
||||
* for the current state of the drag and drop operation. For example, if
|
||||
* the user has chosen {@linkplain DnDConstants#ACTION_MOVE the move action},
|
||||
* and the pointer is over a target that accepts
|
||||
* the move action, the default move cursor is shown. When
|
||||
* the pointer is over an area that does not accept the transfer,
|
||||
* the default "no drop" cursor is shown.
|
||||
* <p>
|
||||
* This default handling mechanism is disabled when a custom cursor is set
|
||||
* by the {@link #setCursor} method. When the default handling is disabled,
|
||||
* it becomes the responsibility
|
||||
* of the developer to keep the cursor up to date, by listening
|
||||
* to the {@code DragSource} events and calling the {@code setCursor()} method.
|
||||
* Alternatively, you can provide custom cursor behavior by providing
|
||||
* custom implementations of the {@code DragSource}
|
||||
* and the {@code DragSourceContext} classes.
|
||||
*
|
||||
* @see DragSourceListener
|
||||
* @see DragSourceMotionListener
|
||||
* @see DnDConstants
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DragSourceContext
|
||||
implements DragSourceListener, DragSourceMotionListener, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -115407898692194719L;
|
||||
|
||||
// used by updateCurrentCursor
|
||||
|
||||
/**
|
||||
* An <code>int</code> used by updateCurrentCursor()
|
||||
* indicating that the <code>Cursor</code> should change
|
||||
* to the default (no drop) <code>Cursor</code>.
|
||||
*/
|
||||
protected static final int DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* An <code>int</code> used by updateCurrentCursor()
|
||||
* indicating that the <code>Cursor</code>
|
||||
* has entered a <code>DropTarget</code>.
|
||||
*/
|
||||
protected static final int ENTER = 1;
|
||||
|
||||
/**
|
||||
* An <code>int</code> used by updateCurrentCursor()
|
||||
* indicating that the <code>Cursor</code> is
|
||||
* over a <code>DropTarget</code>.
|
||||
*/
|
||||
protected static final int OVER = 2;
|
||||
|
||||
/**
|
||||
* An <code>int</code> used by updateCurrentCursor()
|
||||
* indicating that the user operation has changed.
|
||||
*/
|
||||
|
||||
protected static final int CHANGED = 3;
|
||||
|
||||
/**
|
||||
* Called from <code>DragSource</code>, this constructor creates a new
|
||||
* <code>DragSourceContext</code> given the
|
||||
* <code>DragSourceContextPeer</code> for this Drag, the
|
||||
* <code>DragGestureEvent</code> that triggered the Drag, the initial
|
||||
* <code>Cursor</code> to use for the Drag, an (optional)
|
||||
* <code>Image</code> to display while the Drag is taking place, the offset
|
||||
* of the <code>Image</code> origin from the hotspot at the instant of the
|
||||
* triggering event, the <code>Transferable</code> subject data, and the
|
||||
* <code>DragSourceListener</code> to use during the Drag and Drop
|
||||
* operation.
|
||||
* <br>
|
||||
* If <code>DragSourceContextPeer</code> is <code>null</code>
|
||||
* <code>NullPointerException</code> is thrown.
|
||||
* <br>
|
||||
* If <code>DragGestureEvent</code> is <code>null</code>
|
||||
* <code>NullPointerException</code> is thrown.
|
||||
* <br>
|
||||
* If <code>Cursor</code> is <code>null</code> no exception is thrown and
|
||||
* the default drag cursor behavior is activated for this drag operation.
|
||||
* <br>
|
||||
* If <code>Image</code> is <code>null</code> no exception is thrown.
|
||||
* <br>
|
||||
* If <code>Image</code> is not <code>null</code> and the offset is
|
||||
* <code>null</code> <code>NullPointerException</code> is thrown.
|
||||
* <br>
|
||||
* If <code>Transferable</code> is <code>null</code>
|
||||
* <code>NullPointerException</code> is thrown.
|
||||
* <br>
|
||||
* If <code>DragSourceListener</code> is <code>null</code> no exception
|
||||
* is thrown.
|
||||
*
|
||||
* @param dscp the <code>DragSourceContextPeer</code> for this drag
|
||||
* @param trigger the triggering event
|
||||
* @param dragCursor the initial {@code Cursor} for this drag operation
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see <a href="DragSourceContext.html#defaultCursor">class level documentation</a>
|
||||
* for more details on the cursor handling mechanism during drag and drop
|
||||
* @param dragImage the <code>Image</code> to drag (or <code>null</code>)
|
||||
* @param offset the offset of the image origin from the hotspot at the
|
||||
* instant of the triggering event
|
||||
* @param t the <code>Transferable</code>
|
||||
* @param dsl the <code>DragSourceListener</code>
|
||||
*
|
||||
* @throws IllegalArgumentException if the <code>Component</code> associated
|
||||
* with the trigger event is <code>null</code>.
|
||||
* @throws IllegalArgumentException if the <code>DragSource</code> for the
|
||||
* trigger event is <code>null</code>.
|
||||
* @throws IllegalArgumentException if the drag action for the
|
||||
* trigger event is <code>DnDConstants.ACTION_NONE</code>.
|
||||
* @throws IllegalArgumentException if the source actions for the
|
||||
* <code>DragGestureRecognizer</code> associated with the trigger
|
||||
* event are equal to <code>DnDConstants.ACTION_NONE</code>.
|
||||
* @throws NullPointerException if dscp, trigger, or t are null, or
|
||||
* if dragImage is non-null and offset is null
|
||||
*/
|
||||
public DragSourceContext(DragSourceContextPeer dscp,
|
||||
DragGestureEvent trigger, Cursor dragCursor,
|
||||
Image dragImage, Point offset, Transferable t,
|
||||
DragSourceListener dsl) {
|
||||
if (dscp == null) {
|
||||
throw new NullPointerException("DragSourceContextPeer");
|
||||
}
|
||||
|
||||
if (trigger == null) {
|
||||
throw new NullPointerException("Trigger");
|
||||
}
|
||||
|
||||
if (trigger.getDragSource() == null) {
|
||||
throw new IllegalArgumentException("DragSource");
|
||||
}
|
||||
|
||||
if (trigger.getComponent() == null) {
|
||||
throw new IllegalArgumentException("Component");
|
||||
}
|
||||
|
||||
if (trigger.getSourceAsDragGestureRecognizer().getSourceActions() ==
|
||||
DnDConstants.ACTION_NONE) {
|
||||
throw new IllegalArgumentException("source actions");
|
||||
}
|
||||
|
||||
if (trigger.getDragAction() == DnDConstants.ACTION_NONE) {
|
||||
throw new IllegalArgumentException("no drag action");
|
||||
}
|
||||
|
||||
if (t == null) {
|
||||
throw new NullPointerException("Transferable");
|
||||
}
|
||||
|
||||
if (dragImage != null && offset == null) {
|
||||
throw new NullPointerException("offset");
|
||||
}
|
||||
|
||||
peer = dscp;
|
||||
this.trigger = trigger;
|
||||
cursor = dragCursor;
|
||||
transferable = t;
|
||||
listener = dsl;
|
||||
sourceActions =
|
||||
trigger.getSourceAsDragGestureRecognizer().getSourceActions();
|
||||
|
||||
useCustomCursor = (dragCursor != null);
|
||||
|
||||
updateCurrentCursor(trigger.getDragAction(), getSourceActions(), DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>DragSource</code>
|
||||
* that instantiated this <code>DragSourceContext</code>.
|
||||
*
|
||||
* @return the <code>DragSource</code> that
|
||||
* instantiated this <code>DragSourceContext</code>
|
||||
*/
|
||||
|
||||
public DragSource getDragSource() { return trigger.getDragSource(); }
|
||||
|
||||
/**
|
||||
* Returns the <code>Component</code> associated with this
|
||||
* <code>DragSourceContext</code>.
|
||||
*
|
||||
* @return the <code>Component</code> that started the drag
|
||||
*/
|
||||
|
||||
public Component getComponent() { return trigger.getComponent(); }
|
||||
|
||||
/**
|
||||
* Returns the <code>DragGestureEvent</code>
|
||||
* that initially triggered the drag.
|
||||
*
|
||||
* @return the Event that triggered the drag
|
||||
*/
|
||||
|
||||
public DragGestureEvent getTrigger() { return trigger; }
|
||||
|
||||
/**
|
||||
* Returns a bitwise mask of <code>DnDConstants</code> that
|
||||
* represent the set of drop actions supported by the drag source for the
|
||||
* drag operation associated with this <code>DragSourceContext</code>.
|
||||
*
|
||||
* @return the drop actions supported by the drag source
|
||||
*/
|
||||
public int getSourceActions() {
|
||||
return sourceActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cursor for this drag operation to the specified
|
||||
* <code>Cursor</code>. If the specified <code>Cursor</code>
|
||||
* is <code>null</code>, the default drag cursor behavior is
|
||||
* activated for this drag operation, otherwise it is deactivated.
|
||||
*
|
||||
* @param c the initial {@code Cursor} for this drag operation,
|
||||
* or {@code null} for the default cursor handling;
|
||||
* see {@linkplain Cursor class
|
||||
* level documentation} for more details
|
||||
* on the cursor handling during drag and drop
|
||||
*
|
||||
*/
|
||||
|
||||
public synchronized void setCursor(Cursor c) {
|
||||
useCustomCursor = (c != null);
|
||||
setCursorImpl(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current drag <code>Cursor</code>.
|
||||
* <P>
|
||||
* @return the current drag <code>Cursor</code>
|
||||
*/
|
||||
|
||||
public Cursor getCursor() { return cursor; }
|
||||
|
||||
/**
|
||||
* Add a <code>DragSourceListener</code> to this
|
||||
* <code>DragSourceContext</code> if one has not already been added.
|
||||
* If a <code>DragSourceListener</code> already exists,
|
||||
* this method throws a <code>TooManyListenersException</code>.
|
||||
* <P>
|
||||
* @param dsl the <code>DragSourceListener</code> to add.
|
||||
* Note that while <code>null</code> is not prohibited,
|
||||
* it is not acceptable as a parameter.
|
||||
* <P>
|
||||
* @throws TooManyListenersException if
|
||||
* a <code>DragSourceListener</code> has already been added
|
||||
*/
|
||||
|
||||
public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException {
|
||||
if (dsl == null) return;
|
||||
|
||||
if (equals(dsl)) throw new IllegalArgumentException("DragSourceContext may not be its own listener");
|
||||
|
||||
if (listener != null)
|
||||
throw new TooManyListenersException();
|
||||
else
|
||||
listener = dsl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified <code>DragSourceListener</code>
|
||||
* from this <code>DragSourceContext</code>.
|
||||
*
|
||||
* @param dsl the <code>DragSourceListener</code> to remove;
|
||||
* note that while <code>null</code> is not prohibited,
|
||||
* it is not acceptable as a parameter
|
||||
*/
|
||||
|
||||
public synchronized void removeDragSourceListener(DragSourceListener dsl) {
|
||||
if (listener != null && listener.equals(dsl)) {
|
||||
listener = null;
|
||||
} else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the peer that the <code>Transferable</code>'s
|
||||
* <code>DataFlavor</code>s have changed.
|
||||
*/
|
||||
|
||||
public void transferablesFlavorsChanged() {
|
||||
if (peer != null) peer.transferablesFlavorsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragEnter</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSourceContext</code> and with the associated
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragEnter(DragSourceDragEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragEnter(dsde);
|
||||
}
|
||||
getDragSource().processDragEnter(dsde);
|
||||
|
||||
updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), ENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragOver</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSourceContext</code> and with the associated
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dragOver(DragSourceDragEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragOver(dsde);
|
||||
}
|
||||
getDragSource().processDragOver(dsde);
|
||||
|
||||
updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), OVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragExit</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSourceContext</code> and with the associated
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceEvent</code>.
|
||||
*
|
||||
* @param dse the <code>DragSourceEvent</code>
|
||||
*/
|
||||
public void dragExit(DragSourceEvent dse) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragExit(dse);
|
||||
}
|
||||
getDragSource().processDragExit(dse);
|
||||
|
||||
updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dropActionChanged</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSourceContext</code> and with the associated
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
public void dropActionChanged(DragSourceDragEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dropActionChanged(dsde);
|
||||
}
|
||||
getDragSource().processDropActionChanged(dsde);
|
||||
|
||||
updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), CHANGED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragDropEnd</code> on the
|
||||
* <code>DragSourceListener</code>s registered with this
|
||||
* <code>DragSourceContext</code> and with the associated
|
||||
* <code>DragSource</code>, and passes them the specified
|
||||
* <code>DragSourceDropEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDropEvent</code>
|
||||
*/
|
||||
public void dragDropEnd(DragSourceDropEvent dsde) {
|
||||
DragSourceListener dsl = listener;
|
||||
if (dsl != null) {
|
||||
dsl.dragDropEnd(dsde);
|
||||
}
|
||||
getDragSource().processDragDropEnd(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragMouseMoved</code> on the
|
||||
* <code>DragSourceMotionListener</code>s registered with the
|
||||
* <code>DragSource</code> associated with this
|
||||
* <code>DragSourceContext</code>, and them passes the specified
|
||||
* <code>DragSourceDragEvent</code>.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
* @since 1.4
|
||||
*/
|
||||
public void dragMouseMoved(DragSourceDragEvent dsde) {
|
||||
getDragSource().processDragMouseMoved(dsde);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>Transferable</code> associated with
|
||||
* this <code>DragSourceContext</code>.
|
||||
*
|
||||
* @return the <code>Transferable</code>
|
||||
*/
|
||||
public Transferable getTransferable() { return transferable; }
|
||||
|
||||
/**
|
||||
* If the default drag cursor behavior is active, this method
|
||||
* sets the default drag cursor for the specified actions
|
||||
* supported by the drag source, the drop target action,
|
||||
* and status, otherwise this method does nothing.
|
||||
*
|
||||
* @param sourceAct the actions supported by the drag source
|
||||
* @param targetAct the drop target action
|
||||
* @param status one of the fields <code>DEFAULT</code>,
|
||||
* <code>ENTER</code>, <code>OVER</code>,
|
||||
* <code>CHANGED</code>
|
||||
*/
|
||||
|
||||
protected synchronized void updateCurrentCursor(int sourceAct, int targetAct, int status) {
|
||||
|
||||
// if the cursor has been previously set then don't do any defaults
|
||||
// processing.
|
||||
|
||||
if (useCustomCursor) {
|
||||
return;
|
||||
}
|
||||
|
||||
// do defaults processing
|
||||
|
||||
Cursor c = null;
|
||||
|
||||
switch (status) {
|
||||
default:
|
||||
targetAct = DnDConstants.ACTION_NONE;
|
||||
case ENTER:
|
||||
case OVER:
|
||||
case CHANGED:
|
||||
int ra = sourceAct & targetAct;
|
||||
|
||||
if (ra == DnDConstants.ACTION_NONE) { // no drop possible
|
||||
if ((sourceAct & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
|
||||
c = DragSource.DefaultLinkNoDrop;
|
||||
else if ((sourceAct & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
|
||||
c = DragSource.DefaultMoveNoDrop;
|
||||
else
|
||||
c = DragSource.DefaultCopyNoDrop;
|
||||
} else { // drop possible
|
||||
if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
|
||||
c = DragSource.DefaultLinkDrop;
|
||||
else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
|
||||
c = DragSource.DefaultMoveDrop;
|
||||
else
|
||||
c = DragSource.DefaultCopyDrop;
|
||||
}
|
||||
}
|
||||
|
||||
setCursorImpl(c);
|
||||
}
|
||||
|
||||
private void setCursorImpl(Cursor c) {
|
||||
if (cursor == null || !cursor.equals(c)) {
|
||||
cursor = c;
|
||||
if (peer != null) peer.setCursor(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes this <code>DragSourceContext</code>. This method first
|
||||
* performs default serialization. Next, this object's
|
||||
* <code>Transferable</code> is written out if and only if it can be
|
||||
* serialized. If not, <code>null</code> is written instead. In this case,
|
||||
* a <code>DragSourceContext</code> created from the resulting deserialized
|
||||
* stream will contain a dummy <code>Transferable</code> which supports no
|
||||
* <code>DataFlavor</code>s. Finally, this object's
|
||||
* <code>DragSourceListener</code> is written out if and only if it can be
|
||||
* serialized. If not, <code>null</code> is written instead.
|
||||
*
|
||||
* @serialData The default serializable fields, in alphabetical order,
|
||||
* followed by either a <code>Transferable</code> instance, or
|
||||
* <code>null</code>, followed by either a
|
||||
* <code>DragSourceListener</code> instance, or
|
||||
* <code>null</code>.
|
||||
* @since 1.4
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||
s.defaultWriteObject();
|
||||
|
||||
s.writeObject(SerializationTester.test(transferable)
|
||||
? transferable : null);
|
||||
s.writeObject(SerializationTester.test(listener)
|
||||
? listener : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes this <code>DragSourceContext</code>. This method first
|
||||
* performs default deserialization for all non-<code>transient</code>
|
||||
* fields. This object's <code>Transferable</code> and
|
||||
* <code>DragSourceListener</code> are then deserialized as well by using
|
||||
* the next two objects in the stream. If the resulting
|
||||
* <code>Transferable</code> is <code>null</code>, this object's
|
||||
* <code>Transferable</code> is set to a dummy <code>Transferable</code>
|
||||
* which supports no <code>DataFlavor</code>s.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws ClassNotFoundException, IOException
|
||||
{
|
||||
ObjectInputStream.GetField f = s.readFields();
|
||||
|
||||
DragGestureEvent newTrigger = (DragGestureEvent)f.get("trigger", null);
|
||||
if (newTrigger == null) {
|
||||
throw new InvalidObjectException("Null trigger");
|
||||
}
|
||||
if (newTrigger.getDragSource() == null) {
|
||||
throw new InvalidObjectException("Null DragSource");
|
||||
}
|
||||
if (newTrigger.getComponent() == null) {
|
||||
throw new InvalidObjectException("Null trigger component");
|
||||
}
|
||||
|
||||
int newSourceActions = f.get("sourceActions", 0)
|
||||
& (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
|
||||
if (newSourceActions == DnDConstants.ACTION_NONE) {
|
||||
throw new InvalidObjectException("Invalid source actions");
|
||||
}
|
||||
int triggerActions = newTrigger.getDragAction();
|
||||
if (triggerActions != DnDConstants.ACTION_COPY &&
|
||||
triggerActions != DnDConstants.ACTION_MOVE &&
|
||||
triggerActions != DnDConstants.ACTION_LINK) {
|
||||
throw new InvalidObjectException("No drag action");
|
||||
}
|
||||
trigger = newTrigger;
|
||||
|
||||
cursor = (Cursor)f.get("cursor", null);
|
||||
useCustomCursor = f.get("useCustomCursor", false);
|
||||
sourceActions = newSourceActions;
|
||||
|
||||
transferable = (Transferable)s.readObject();
|
||||
listener = (DragSourceListener)s.readObject();
|
||||
|
||||
// Implementation assumes 'transferable' is never null.
|
||||
if (transferable == null) {
|
||||
if (emptyTransferable == null) {
|
||||
emptyTransferable = new Transferable() {
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[0];
|
||||
}
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException
|
||||
{
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
};
|
||||
}
|
||||
transferable = emptyTransferable;
|
||||
}
|
||||
}
|
||||
|
||||
private static Transferable emptyTransferable;
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
private transient DragSourceContextPeer peer;
|
||||
|
||||
/**
|
||||
* The event which triggered the start of the drag.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private DragGestureEvent trigger;
|
||||
|
||||
/**
|
||||
* The current drag cursor.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Cursor cursor;
|
||||
|
||||
private transient Transferable transferable;
|
||||
|
||||
private transient DragSourceListener listener;
|
||||
|
||||
/**
|
||||
* <code>true</code> if the custom drag cursor is used instead of the
|
||||
* default one.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private boolean useCustomCursor;
|
||||
|
||||
/**
|
||||
* A bitwise mask of <code>DnDConstants</code> that represents the set of
|
||||
* drop actions supported by the drag source for the drag operation associated
|
||||
* with this <code>DragSourceContext.</code>
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int sourceActions;
|
||||
}
|
||||
328
jdkSrc/jdk8/java/awt/dnd/DragSourceDragEvent.java
Normal file
328
jdkSrc/jdk8/java/awt/dnd/DragSourceDragEvent.java
Normal file
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
/**
|
||||
* The <code>DragSourceDragEvent</code> is
|
||||
* delivered from the <code>DragSourceContextPeer</code>,
|
||||
* via the <code>DragSourceContext</code>, to the <code>DragSourceListener</code>
|
||||
* registered with that <code>DragSourceContext</code> and with its associated
|
||||
* <code>DragSource</code>.
|
||||
* <p>
|
||||
* The <code>DragSourceDragEvent</code> reports the <i>target drop action</i>
|
||||
* and the <i>user drop action</i> that reflect the current state of
|
||||
* the drag operation.
|
||||
* <p>
|
||||
* <i>Target drop action</i> is one of <code>DnDConstants</code> that represents
|
||||
* the drop action selected by the current drop target if this drop action is
|
||||
* supported by the drag source or <code>DnDConstants.ACTION_NONE</code> if this
|
||||
* drop action is not supported by the drag source.
|
||||
* <p>
|
||||
* <i>User drop action</i> depends on the drop actions supported by the drag
|
||||
* source and the drop action selected by the user. The user can select a drop
|
||||
* action by pressing modifier keys during the drag operation:
|
||||
* <pre>
|
||||
* Ctrl + Shift -> ACTION_LINK
|
||||
* Ctrl -> ACTION_COPY
|
||||
* Shift -> ACTION_MOVE
|
||||
* </pre>
|
||||
* If the user selects a drop action, the <i>user drop action</i> is one of
|
||||
* <code>DnDConstants</code> that represents the selected drop action if this
|
||||
* drop action is supported by the drag source or
|
||||
* <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
|
||||
* by the drag source.
|
||||
* <p>
|
||||
* If the user doesn't select a drop action, the set of
|
||||
* <code>DnDConstants</code> that represents the set of drop actions supported
|
||||
* by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
|
||||
* then for <code>DnDConstants.ACTION_COPY</code>, then for
|
||||
* <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
|
||||
* first constant found. If no constant is found the <i>user drop action</i>
|
||||
* is <code>DnDConstants.ACTION_NONE</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
*/
|
||||
|
||||
public class DragSourceDragEvent extends DragSourceEvent {
|
||||
|
||||
private static final long serialVersionUID = 481346297933902471L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>DragSourceDragEvent</code>.
|
||||
* This class is typically
|
||||
* instantiated by the <code>DragSourceContextPeer</code>
|
||||
* rather than directly
|
||||
* by client code.
|
||||
* The coordinates for this <code>DragSourceDragEvent</code>
|
||||
* are not specified, so <code>getLocation</code> will return
|
||||
* <code>null</code> for this event.
|
||||
* <p>
|
||||
* The arguments <code>dropAction</code> and <code>action</code> should
|
||||
* be one of <code>DnDConstants</code> that represents a single action.
|
||||
* The argument <code>modifiers</code> should be either a bitwise mask
|
||||
* of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a
|
||||
* bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code>
|
||||
* constants.
|
||||
* This constructor does not throw any exception for invalid <code>dropAction</code>,
|
||||
* <code>action</code> and <code>modifiers</code>.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code> that is to manage
|
||||
* notifications for this event.
|
||||
* @param dropAction the user drop action.
|
||||
* @param action the target drop action.
|
||||
* @param modifiers the modifier keys down during event (shift, ctrl,
|
||||
* alt, meta)
|
||||
* Either extended _DOWN_MASK or old _MASK modifiers
|
||||
* should be used, but both models should not be mixed
|
||||
* in one event. Use of the extended modifiers is
|
||||
* preferred.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @see java.awt.event.InputEvent
|
||||
* @see DragSourceEvent#getLocation
|
||||
*/
|
||||
|
||||
public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
|
||||
int action, int modifiers) {
|
||||
super(dsc);
|
||||
|
||||
targetActions = action;
|
||||
gestureModifiers = modifiers;
|
||||
this.dropAction = dropAction;
|
||||
if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
|
||||
invalidModifiers = true;
|
||||
} else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
|
||||
setNewModifiers();
|
||||
} else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
|
||||
setOldModifiers();
|
||||
} else {
|
||||
invalidModifiers = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>DragSourceDragEvent</code> given the specified
|
||||
* <code>DragSourceContext</code>, user drop action, target drop action,
|
||||
* modifiers and coordinates.
|
||||
* <p>
|
||||
* The arguments <code>dropAction</code> and <code>action</code> should
|
||||
* be one of <code>DnDConstants</code> that represents a single action.
|
||||
* The argument <code>modifiers</code> should be either a bitwise mask
|
||||
* of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a
|
||||
* bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code>
|
||||
* constants.
|
||||
* This constructor does not throw any exception for invalid <code>dropAction</code>,
|
||||
* <code>action</code> and <code>modifiers</code>.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code> associated with this
|
||||
* event.
|
||||
* @param dropAction the user drop action.
|
||||
* @param action the target drop action.
|
||||
* @param modifiers the modifier keys down during event (shift, ctrl,
|
||||
* alt, meta)
|
||||
* Either extended _DOWN_MASK or old _MASK modifiers
|
||||
* should be used, but both models should not be mixed
|
||||
* in one event. Use of the extended modifiers is
|
||||
* preferred.
|
||||
* @param x the horizontal coordinate for the cursor location
|
||||
* @param y the vertical coordinate for the cursor location
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @see java.awt.event.InputEvent
|
||||
* @since 1.4
|
||||
*/
|
||||
public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
|
||||
int action, int modifiers, int x, int y) {
|
||||
super(dsc, x, y);
|
||||
|
||||
targetActions = action;
|
||||
gestureModifiers = modifiers;
|
||||
this.dropAction = dropAction;
|
||||
if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
|
||||
invalidModifiers = true;
|
||||
} else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
|
||||
setNewModifiers();
|
||||
} else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
|
||||
setOldModifiers();
|
||||
} else {
|
||||
invalidModifiers = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the target drop action.
|
||||
*
|
||||
* @return the target drop action.
|
||||
*/
|
||||
public int getTargetActions() {
|
||||
return targetActions;
|
||||
}
|
||||
|
||||
|
||||
private static final int JDK_1_3_MODIFIERS = InputEvent.SHIFT_DOWN_MASK - 1;
|
||||
private static final int JDK_1_4_MODIFIERS =
|
||||
((InputEvent.ALT_GRAPH_DOWN_MASK << 1) - 1) & ~JDK_1_3_MODIFIERS;
|
||||
|
||||
/**
|
||||
* This method returns an <code>int</code> representing
|
||||
* the current state of the input device modifiers
|
||||
* associated with the user's gesture. Typically these
|
||||
* would be mouse buttons or keyboard modifiers.
|
||||
* <P>
|
||||
* If the <code>modifiers</code> passed to the constructor
|
||||
* are invalid, this method returns them unchanged.
|
||||
*
|
||||
* @return the current state of the input device modifiers
|
||||
*/
|
||||
|
||||
public int getGestureModifiers() {
|
||||
return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_3_MODIFIERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an <code>int</code> representing
|
||||
* the current state of the input device extended modifiers
|
||||
* associated with the user's gesture.
|
||||
* See {@link InputEvent#getModifiersEx}
|
||||
* <P>
|
||||
* If the <code>modifiers</code> passed to the constructor
|
||||
* are invalid, this method returns them unchanged.
|
||||
*
|
||||
* @return the current state of the input device extended modifiers
|
||||
* @since 1.4
|
||||
*/
|
||||
|
||||
public int getGestureModifiersEx() {
|
||||
return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_4_MODIFIERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the user drop action.
|
||||
*
|
||||
* @return the user drop action.
|
||||
*/
|
||||
public int getUserAction() { return dropAction; }
|
||||
|
||||
/**
|
||||
* This method returns the logical intersection of
|
||||
* the target drop action and the set of drop actions supported by
|
||||
* the drag source.
|
||||
*
|
||||
* @return the logical intersection of the target drop action and
|
||||
* the set of drop actions supported by the drag source.
|
||||
*/
|
||||
public int getDropAction() {
|
||||
return targetActions & getDragSourceContext().getSourceActions();
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
/**
|
||||
* The target drop action.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int targetActions = DnDConstants.ACTION_NONE;
|
||||
|
||||
/**
|
||||
* The user drop action.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int dropAction = DnDConstants.ACTION_NONE;
|
||||
|
||||
/**
|
||||
* The state of the input device modifiers associated with the user
|
||||
* gesture.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int gestureModifiers = 0;
|
||||
|
||||
/**
|
||||
* Indicates whether the <code>gestureModifiers</code> are invalid.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private boolean invalidModifiers;
|
||||
|
||||
/**
|
||||
* Sets new modifiers by the old ones.
|
||||
* The mouse modifiers have higher priority than overlaying key
|
||||
* modifiers.
|
||||
*/
|
||||
private void setNewModifiers() {
|
||||
if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets old modifiers by the new ones.
|
||||
*/
|
||||
private void setOldModifiers() {
|
||||
if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.BUTTON1_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.BUTTON2_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.BUTTON3_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.SHIFT_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.CTRL_MASK;
|
||||
}
|
||||
if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
|
||||
gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
|
||||
}
|
||||
}
|
||||
}
|
||||
167
jdkSrc/jdk8/java/awt/dnd/DragSourceDropEvent.java
Normal file
167
jdkSrc/jdk8/java/awt/dnd/DragSourceDropEvent.java
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
/**
|
||||
* The <code>DragSourceDropEvent</code> is delivered
|
||||
* from the <code>DragSourceContextPeer</code>,
|
||||
* via the <code>DragSourceContext</code>, to the <code>dragDropEnd</code>
|
||||
* method of <code>DragSourceListener</code>s registered with that
|
||||
* <code>DragSourceContext</code> and with its associated
|
||||
* <code>DragSource</code>.
|
||||
* It contains sufficient information for the
|
||||
* originator of the operation
|
||||
* to provide appropriate feedback to the end user
|
||||
* when the operation completes.
|
||||
* <P>
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DragSourceDropEvent extends DragSourceEvent {
|
||||
|
||||
private static final long serialVersionUID = -5571321229470821891L;
|
||||
|
||||
/**
|
||||
* Construct a <code>DragSourceDropEvent</code> for a drop,
|
||||
* given the
|
||||
* <code>DragSourceContext</code>, the drop action,
|
||||
* and a <code>boolean</code> indicating if the drop was successful.
|
||||
* The coordinates for this <code>DragSourceDropEvent</code>
|
||||
* are not specified, so <code>getLocation</code> will return
|
||||
* <code>null</code> for this event.
|
||||
* <p>
|
||||
* The argument <code>action</code> should be one of <code>DnDConstants</code>
|
||||
* that represents a single action.
|
||||
* This constructor does not throw any exception for invalid <code>action</code>.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code>
|
||||
* associated with this <code>DragSourceDropEvent</code>
|
||||
* @param action the drop action
|
||||
* @param success a boolean indicating if the drop was successful
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @see DragSourceEvent#getLocation
|
||||
*/
|
||||
|
||||
public DragSourceDropEvent(DragSourceContext dsc, int action, boolean success) {
|
||||
super(dsc);
|
||||
|
||||
dropSuccess = success;
|
||||
dropAction = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>DragSourceDropEvent</code> for a drop, given the
|
||||
* <code>DragSourceContext</code>, the drop action, a <code>boolean</code>
|
||||
* indicating if the drop was successful, and coordinates.
|
||||
* <p>
|
||||
* The argument <code>action</code> should be one of <code>DnDConstants</code>
|
||||
* that represents a single action.
|
||||
* This constructor does not throw any exception for invalid <code>action</code>.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code>
|
||||
* associated with this <code>DragSourceDropEvent</code>
|
||||
* @param action the drop action
|
||||
* @param success a boolean indicating if the drop was successful
|
||||
* @param x the horizontal coordinate for the cursor location
|
||||
* @param y the vertical coordinate for the cursor location
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public DragSourceDropEvent(DragSourceContext dsc, int action,
|
||||
boolean success, int x, int y) {
|
||||
super(dsc, x, y);
|
||||
|
||||
dropSuccess = success;
|
||||
dropAction = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>DragSourceDropEvent</code>
|
||||
* for a drag that does not result in a drop.
|
||||
* The coordinates for this <code>DragSourceDropEvent</code>
|
||||
* are not specified, so <code>getLocation</code> will return
|
||||
* <code>null</code> for this event.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code>
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @see DragSourceEvent#getLocation
|
||||
*/
|
||||
|
||||
public DragSourceDropEvent(DragSourceContext dsc) {
|
||||
super(dsc);
|
||||
|
||||
dropSuccess = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>boolean</code> indicating
|
||||
* if the drop was successful.
|
||||
*
|
||||
* @return <code>true</code> if the drop target accepted the drop and
|
||||
* successfully performed a drop action;
|
||||
* <code>false</code> if the drop target rejected the drop or
|
||||
* if the drop target accepted the drop, but failed to perform
|
||||
* a drop action.
|
||||
*/
|
||||
|
||||
public boolean getDropSuccess() { return dropSuccess; }
|
||||
|
||||
/**
|
||||
* This method returns an <code>int</code> representing
|
||||
* the action performed by the target on the subject of the drop.
|
||||
*
|
||||
* @return the action performed by the target on the subject of the drop
|
||||
* if the drop target accepted the drop and the target drop action
|
||||
* is supported by the drag source; otherwise,
|
||||
* <code>DnDConstants.ACTION_NONE</code>.
|
||||
*/
|
||||
|
||||
public int getDropAction() { return dropAction; }
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
/**
|
||||
* <code>true</code> if the drop was successful.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private boolean dropSuccess;
|
||||
|
||||
/**
|
||||
* The drop action.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int dropAction = DnDConstants.ACTION_NONE;
|
||||
}
|
||||
185
jdkSrc/jdk8/java/awt/dnd/DragSourceEvent.java
Normal file
185
jdkSrc/jdk8/java/awt/dnd/DragSourceEvent.java
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
* This class is the base class for
|
||||
* <code>DragSourceDragEvent</code> and
|
||||
* <code>DragSourceDropEvent</code>.
|
||||
* <p>
|
||||
* <code>DragSourceEvent</code>s are generated whenever the drag enters, moves
|
||||
* over, or exits a drop site, when the drop action changes, and when the drag
|
||||
* ends. The location for the generated <code>DragSourceEvent</code> specifies
|
||||
* the mouse cursor location in screen coordinates at the moment this event
|
||||
* occurred.
|
||||
* <p>
|
||||
* In a multi-screen environment without a virtual device, the cursor location is
|
||||
* specified in the coordinate system of the <i>initiator</i>
|
||||
* <code>GraphicsConfiguration</code>. The <i>initiator</i>
|
||||
* <code>GraphicsConfiguration</code> is the <code>GraphicsConfiguration</code>
|
||||
* of the <code>Component</code> on which the drag gesture for the current drag
|
||||
* operation was recognized. If the cursor location is outside the bounds of
|
||||
* the initiator <code>GraphicsConfiguration</code>, the reported coordinates are
|
||||
* clipped to fit within the bounds of that <code>GraphicsConfiguration</code>.
|
||||
* <p>
|
||||
* In a multi-screen environment with a virtual device, the location is specified
|
||||
* in the corresponding virtual coordinate system. If the cursor location is
|
||||
* outside the bounds of the virtual device the reported coordinates are
|
||||
* clipped to fit within the bounds of the virtual device.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DragSourceEvent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = -763287114604032641L;
|
||||
|
||||
/**
|
||||
* The <code>boolean</code> indicating whether the cursor location
|
||||
* is specified for this event.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private final boolean locationSpecified;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate for the cursor location at the moment this
|
||||
* event occurred if the cursor location is specified for this event;
|
||||
* otherwise zero.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private final int x;
|
||||
|
||||
/**
|
||||
* The vertical coordinate for the cursor location at the moment this event
|
||||
* occurred if the cursor location is specified for this event;
|
||||
* otherwise zero.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private final int y;
|
||||
|
||||
/**
|
||||
* Construct a <code>DragSourceEvent</code>
|
||||
* given a specified <code>DragSourceContext</code>.
|
||||
* The coordinates for this <code>DragSourceEvent</code>
|
||||
* are not specified, so <code>getLocation</code> will return
|
||||
* <code>null</code> for this event.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code>
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @see #getLocation
|
||||
*/
|
||||
|
||||
public DragSourceEvent(DragSourceContext dsc) {
|
||||
super(dsc);
|
||||
locationSpecified = false;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>DragSourceEvent</code> given a specified
|
||||
* <code>DragSourceContext</code>, and coordinates of the cursor
|
||||
* location.
|
||||
*
|
||||
* @param dsc the <code>DragSourceContext</code>
|
||||
* @param x the horizontal coordinate for the cursor location
|
||||
* @param y the vertical coordinate for the cursor location
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>dsc</code> is <code>null</code>.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public DragSourceEvent(DragSourceContext dsc, int x, int y) {
|
||||
super(dsc);
|
||||
locationSpecified = true;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the <code>DragSourceContext</code> that
|
||||
* originated the event.
|
||||
* <P>
|
||||
* @return the <code>DragSourceContext</code> that originated the event
|
||||
*/
|
||||
|
||||
public DragSourceContext getDragSourceContext() {
|
||||
return (DragSourceContext)getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>Point</code> indicating the cursor
|
||||
* location in screen coordinates at the moment this event occurred, or
|
||||
* <code>null</code> if the cursor location is not specified for this
|
||||
* event.
|
||||
*
|
||||
* @return the <code>Point</code> indicating the cursor location
|
||||
* or <code>null</code> if the cursor location is not specified
|
||||
* @since 1.4
|
||||
*/
|
||||
public Point getLocation() {
|
||||
if (locationSpecified) {
|
||||
return new Point(x, y);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the horizontal coordinate of the cursor location in
|
||||
* screen coordinates at the moment this event occurred, or zero if the
|
||||
* cursor location is not specified for this event.
|
||||
*
|
||||
* @return an integer indicating the horizontal coordinate of the cursor
|
||||
* location or zero if the cursor location is not specified
|
||||
* @since 1.4
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the vertical coordinate of the cursor location in
|
||||
* screen coordinates at the moment this event occurred, or zero if the
|
||||
* cursor location is not specified for this event.
|
||||
*
|
||||
* @return an integer indicating the vertical coordinate of the cursor
|
||||
* location or zero if the cursor location is not specified
|
||||
* @since 1.4
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
126
jdkSrc/jdk8/java/awt/dnd/DragSourceListener.java
Normal file
126
jdkSrc/jdk8/java/awt/dnd/DragSourceListener.java
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* The <code>DragSourceListener</code> defines the
|
||||
* event interface for originators of
|
||||
* Drag and Drop operations to track the state of the user's gesture, and to
|
||||
* provide appropriate "drag over"
|
||||
* feedback to the user throughout the
|
||||
* Drag and Drop operation.
|
||||
* <p>
|
||||
* The drop site is <i>associated with the previous <code>dragEnter()</code>
|
||||
* invocation</i> if the latest invocation of <code>dragEnter()</code> on this
|
||||
* listener:
|
||||
* <ul>
|
||||
* <li>corresponds to that drop site and
|
||||
* <li> is not followed by a <code>dragExit()</code> invocation on this listener.
|
||||
* </ul>
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public interface DragSourceListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Called as the cursor's hotspot enters a platform-dependent drop site.
|
||||
* This method is invoked when all the following conditions are true:
|
||||
* <UL>
|
||||
* <LI>The cursor's hotspot enters the operable part of a platform-
|
||||
* dependent drop site.
|
||||
* <LI>The drop site is active.
|
||||
* <LI>The drop site accepts the drag.
|
||||
* </UL>
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void dragEnter(DragSourceDragEvent dsde);
|
||||
|
||||
/**
|
||||
* Called as the cursor's hotspot moves over a platform-dependent drop site.
|
||||
* This method is invoked when all the following conditions are true:
|
||||
* <UL>
|
||||
* <LI>The cursor's hotspot has moved, but still intersects the
|
||||
* operable part of the drop site associated with the previous
|
||||
* dragEnter() invocation.
|
||||
* <LI>The drop site is still active.
|
||||
* <LI>The drop site accepts the drag.
|
||||
* </UL>
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void dragOver(DragSourceDragEvent dsde);
|
||||
|
||||
/**
|
||||
* Called when the user has modified the drop gesture.
|
||||
* This method is invoked when the state of the input
|
||||
* device(s) that the user is interacting with changes.
|
||||
* Such devices are typically the mouse buttons or keyboard
|
||||
* modifiers that the user is interacting with.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void dropActionChanged(DragSourceDragEvent dsde);
|
||||
|
||||
/**
|
||||
* Called as the cursor's hotspot exits a platform-dependent drop site.
|
||||
* This method is invoked when any of the following conditions are true:
|
||||
* <UL>
|
||||
* <LI>The cursor's hotspot no longer intersects the operable part
|
||||
* of the drop site associated with the previous dragEnter() invocation.
|
||||
* </UL>
|
||||
* OR
|
||||
* <UL>
|
||||
* <LI>The drop site associated with the previous dragEnter() invocation
|
||||
* is no longer active.
|
||||
* </UL>
|
||||
* OR
|
||||
* <UL>
|
||||
* <LI> The drop site associated with the previous dragEnter() invocation
|
||||
* has rejected the drag.
|
||||
* </UL>
|
||||
*
|
||||
* @param dse the <code>DragSourceEvent</code>
|
||||
*/
|
||||
void dragExit(DragSourceEvent dse);
|
||||
|
||||
/**
|
||||
* This method is invoked to signify that the Drag and Drop
|
||||
* operation is complete. The getDropSuccess() method of
|
||||
* the <code>DragSourceDropEvent</code> can be used to
|
||||
* determine the termination state. The getDropAction() method
|
||||
* returns the operation that the drop site selected
|
||||
* to apply to the Drop operation. Once this method is complete, the
|
||||
* current <code>DragSourceContext</code> and
|
||||
* associated resources become invalid.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDropEvent</code>
|
||||
*/
|
||||
void dragDropEnd(DragSourceDropEvent dsde);
|
||||
}
|
||||
61
jdkSrc/jdk8/java/awt/dnd/DragSourceMotionListener.java
Normal file
61
jdkSrc/jdk8/java/awt/dnd/DragSourceMotionListener.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* A listener interface for receiving mouse motion events during a drag
|
||||
* operation.
|
||||
* <p>
|
||||
* The class that is interested in processing mouse motion events during
|
||||
* a drag operation either implements this interface or extends the abstract
|
||||
* <code>DragSourceAdapter</code> class (overriding only the methods of
|
||||
* interest).
|
||||
* <p>
|
||||
* Create a listener object using that class and then register it with
|
||||
* a <code>DragSource</code>. Whenever the mouse moves during a drag
|
||||
* operation initiated with this <code>DragSource</code>, that object's
|
||||
* <code>dragMouseMoved</code> method is invoked, and the
|
||||
* <code>DragSourceDragEvent</code> is passed to it.
|
||||
*
|
||||
* @see DragSourceDragEvent
|
||||
* @see DragSource
|
||||
* @see DragSourceListener
|
||||
* @see DragSourceAdapter
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
|
||||
public interface DragSourceMotionListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Called whenever the mouse is moved during a drag operation.
|
||||
*
|
||||
* @param dsde the <code>DragSourceDragEvent</code>
|
||||
*/
|
||||
void dragMouseMoved(DragSourceDragEvent dsde);
|
||||
}
|
||||
874
jdkSrc/jdk8/java/awt/dnd/DropTarget.java
Normal file
874
jdkSrc/jdk8/java/awt/dnd/DropTarget.java
Normal file
@@ -0,0 +1,874 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.datatransfer.FlavorMap;
|
||||
import java.awt.datatransfer.SystemFlavorMap;
|
||||
import javax.swing.Timer;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.LightweightPeer;
|
||||
import java.awt.dnd.peer.DropTargetPeer;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>DropTarget</code> is associated
|
||||
* with a <code>Component</code> when that <code>Component</code>
|
||||
* wishes
|
||||
* to accept drops during Drag and Drop operations.
|
||||
* <P>
|
||||
* Each
|
||||
* <code>DropTarget</code> is associated with a <code>FlavorMap</code>.
|
||||
* The default <code>FlavorMap</code> hereafter designates the
|
||||
* <code>FlavorMap</code> returned by <code>SystemFlavorMap.getDefaultFlavorMap()</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DropTarget implements DropTargetListener, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6283860791671019047L;
|
||||
|
||||
/**
|
||||
* Creates a new DropTarget given the <code>Component</code>
|
||||
* to associate itself with, an <code>int</code> representing
|
||||
* the default acceptable action(s) to
|
||||
* support, a <code>DropTargetListener</code>
|
||||
* to handle event processing, a <code>boolean</code> indicating
|
||||
* if the <code>DropTarget</code> is currently accepting drops, and
|
||||
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
|
||||
* <P>
|
||||
* The Component will receive drops only if it is enabled.
|
||||
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
|
||||
* @param ops The default acceptable actions for this <code>DropTarget</code>
|
||||
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
|
||||
* @param act Is the <code>DropTarget</code> accepting drops.
|
||||
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public DropTarget(Component c, int ops, DropTargetListener dtl,
|
||||
boolean act, FlavorMap fm)
|
||||
throws HeadlessException
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
component = c;
|
||||
|
||||
setDefaultActions(ops);
|
||||
|
||||
if (dtl != null) try {
|
||||
addDropTargetListener(dtl);
|
||||
} catch (TooManyListenersException tmle) {
|
||||
// do nothing!
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
c.setDropTarget(this);
|
||||
setActive(act);
|
||||
}
|
||||
|
||||
if (fm != null) {
|
||||
flavorMap = fm;
|
||||
} else {
|
||||
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>DropTarget</code> given the <code>Component</code>
|
||||
* to associate itself with, an <code>int</code> representing
|
||||
* the default acceptable action(s)
|
||||
* to support, a <code>DropTargetListener</code>
|
||||
* to handle event processing, and a <code>boolean</code> indicating
|
||||
* if the <code>DropTarget</code> is currently accepting drops.
|
||||
* <P>
|
||||
* The Component will receive drops only if it is enabled.
|
||||
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
|
||||
* @param ops The default acceptable actions for this <code>DropTarget</code>
|
||||
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
|
||||
* @param act Is the <code>DropTarget</code> accepting drops.
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public DropTarget(Component c, int ops, DropTargetListener dtl,
|
||||
boolean act)
|
||||
throws HeadlessException
|
||||
{
|
||||
this(c, ops, dtl, act, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>DropTarget</code>.
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public DropTarget() throws HeadlessException {
|
||||
this(null, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>DropTarget</code> given the <code>Component</code>
|
||||
* to associate itself with, and the <code>DropTargetListener</code>
|
||||
* to handle event processing.
|
||||
* <P>
|
||||
* The Component will receive drops only if it is enabled.
|
||||
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
|
||||
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public DropTarget(Component c, DropTargetListener dtl)
|
||||
throws HeadlessException
|
||||
{
|
||||
this(c, DnDConstants.ACTION_COPY_OR_MOVE, dtl, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>DropTarget</code> given the <code>Component</code>
|
||||
* to associate itself with, an <code>int</code> representing
|
||||
* the default acceptable action(s) to support, and a
|
||||
* <code>DropTargetListener</code> to handle event processing.
|
||||
* <P>
|
||||
* The Component will receive drops only if it is enabled.
|
||||
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
|
||||
* @param ops The default acceptable actions for this <code>DropTarget</code>
|
||||
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
public DropTarget(Component c, int ops, DropTargetListener dtl)
|
||||
throws HeadlessException
|
||||
{
|
||||
this(c, ops, dtl, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this interface is required to permit the safe association
|
||||
* of a DropTarget with a Component in one of two ways, either:
|
||||
* <code> component.setDropTarget(droptarget); </code>
|
||||
* or <code> droptarget.setComponent(component); </code>
|
||||
* <P>
|
||||
* The Component will receive drops only if it is enabled.
|
||||
* @param c The new <code>Component</code> this <code>DropTarget</code>
|
||||
* is to be associated with.
|
||||
*/
|
||||
|
||||
public synchronized void setComponent(Component c) {
|
||||
if (component == c || component != null && component.equals(c))
|
||||
return;
|
||||
|
||||
Component old;
|
||||
ComponentPeer oldPeer = null;
|
||||
|
||||
if ((old = component) != null) {
|
||||
clearAutoscroll();
|
||||
|
||||
component = null;
|
||||
|
||||
if (componentPeer != null) {
|
||||
oldPeer = componentPeer;
|
||||
removeNotify(componentPeer);
|
||||
}
|
||||
|
||||
old.setDropTarget(null);
|
||||
|
||||
}
|
||||
|
||||
if ((component = c) != null) try {
|
||||
c.setDropTarget(this);
|
||||
} catch (Exception e) { // undo the change
|
||||
if (old != null) {
|
||||
old.setDropTarget(this);
|
||||
addNotify(oldPeer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <code>Component</code> associated
|
||||
* with this <code>DropTarget</code>.
|
||||
* <P>
|
||||
* @return the current <code>Component</code>
|
||||
*/
|
||||
|
||||
public synchronized Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default acceptable actions for this <code>DropTarget</code>
|
||||
* <P>
|
||||
* @param ops the default actions
|
||||
* @see java.awt.dnd.DnDConstants
|
||||
*/
|
||||
|
||||
public void setDefaultActions(int ops) {
|
||||
getDropTargetContext().setTargetActions(ops & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE));
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by DropTargetContext.setTargetActions()
|
||||
* with appropriate synchronization.
|
||||
*/
|
||||
void doSetDefaultActions(int ops) {
|
||||
actions = ops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an <code>int</code> representing the
|
||||
* current action(s) supported by this <code>DropTarget</code>.
|
||||
* <P>
|
||||
* @return the current default actions
|
||||
*/
|
||||
|
||||
public int getDefaultActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the DropTarget active if <code>true</code>,
|
||||
* inactive if <code>false</code>.
|
||||
* <P>
|
||||
* @param isActive sets the <code>DropTarget</code> (in)active.
|
||||
*/
|
||||
|
||||
public synchronized void setActive(boolean isActive) {
|
||||
if (isActive != active) {
|
||||
active = isActive;
|
||||
}
|
||||
|
||||
if (!active) clearAutoscroll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports whether or not
|
||||
* this <code>DropTarget</code>
|
||||
* is currently active (ready to accept drops).
|
||||
* <P>
|
||||
* @return <CODE>true</CODE> if active, <CODE>false</CODE> if not
|
||||
*/
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new <code>DropTargetListener</code> (UNICAST SOURCE).
|
||||
* <P>
|
||||
* @param dtl The new <code>DropTargetListener</code>
|
||||
* <P>
|
||||
* @throws TooManyListenersException if a
|
||||
* <code>DropTargetListener</code> is already added to this
|
||||
* <code>DropTarget</code>.
|
||||
*/
|
||||
|
||||
public synchronized void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
|
||||
if (dtl == null) return;
|
||||
|
||||
if (equals(dtl)) throw new IllegalArgumentException("DropTarget may not be its own Listener");
|
||||
|
||||
if (dtListener == null)
|
||||
dtListener = dtl;
|
||||
else
|
||||
throw new TooManyListenersException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the current <code>DropTargetListener</code> (UNICAST SOURCE).
|
||||
* <P>
|
||||
* @param dtl the DropTargetListener to deregister.
|
||||
*/
|
||||
|
||||
public synchronized void removeDropTargetListener(DropTargetListener dtl) {
|
||||
if (dtl != null && dtListener != null) {
|
||||
if(dtListener.equals(dtl))
|
||||
dtListener = null;
|
||||
else
|
||||
throw new IllegalArgumentException("listener mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragEnter</code> on the registered
|
||||
* <code>DropTargetListener</code> and passes it
|
||||
* the specified <code>DropTargetDragEvent</code>.
|
||||
* Has no effect if this <code>DropTarget</code>
|
||||
* is not active.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*
|
||||
* @throws NullPointerException if this <code>DropTarget</code>
|
||||
* is active and <code>dtde</code> is <code>null</code>
|
||||
*
|
||||
* @see #isActive
|
||||
*/
|
||||
public synchronized void dragEnter(DropTargetDragEvent dtde) {
|
||||
isDraggingInside = true;
|
||||
|
||||
if (!active) return;
|
||||
|
||||
if (dtListener != null) {
|
||||
dtListener.dragEnter(dtde);
|
||||
} else
|
||||
dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE);
|
||||
|
||||
initializeAutoscrolling(dtde.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragOver</code> on the registered
|
||||
* <code>DropTargetListener</code> and passes it
|
||||
* the specified <code>DropTargetDragEvent</code>.
|
||||
* Has no effect if this <code>DropTarget</code>
|
||||
* is not active.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*
|
||||
* @throws NullPointerException if this <code>DropTarget</code>
|
||||
* is active and <code>dtde</code> is <code>null</code>
|
||||
*
|
||||
* @see #isActive
|
||||
*/
|
||||
public synchronized void dragOver(DropTargetDragEvent dtde) {
|
||||
if (!active) return;
|
||||
|
||||
if (dtListener != null && active) dtListener.dragOver(dtde);
|
||||
|
||||
updateAutoscroll(dtde.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dropActionChanged</code> on the registered
|
||||
* <code>DropTargetListener</code> and passes it
|
||||
* the specified <code>DropTargetDragEvent</code>.
|
||||
* Has no effect if this <code>DropTarget</code>
|
||||
* is not active.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*
|
||||
* @throws NullPointerException if this <code>DropTarget</code>
|
||||
* is active and <code>dtde</code> is <code>null</code>
|
||||
*
|
||||
* @see #isActive
|
||||
*/
|
||||
public synchronized void dropActionChanged(DropTargetDragEvent dtde) {
|
||||
if (!active) return;
|
||||
|
||||
if (dtListener != null) dtListener.dropActionChanged(dtde);
|
||||
|
||||
updateAutoscroll(dtde.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>dragExit</code> on the registered
|
||||
* <code>DropTargetListener</code> and passes it
|
||||
* the specified <code>DropTargetEvent</code>.
|
||||
* Has no effect if this <code>DropTarget</code>
|
||||
* is not active.
|
||||
* <p>
|
||||
* This method itself does not throw any exception
|
||||
* for null parameter but for exceptions thrown by
|
||||
* the respective method of the listener.
|
||||
*
|
||||
* @param dte the <code>DropTargetEvent</code>
|
||||
*
|
||||
* @see #isActive
|
||||
*/
|
||||
public synchronized void dragExit(DropTargetEvent dte) {
|
||||
isDraggingInside = false;
|
||||
|
||||
if (!active) return;
|
||||
|
||||
if (dtListener != null && active) dtListener.dragExit(dte);
|
||||
|
||||
clearAutoscroll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls <code>drop</code> on the registered
|
||||
* <code>DropTargetListener</code> and passes it
|
||||
* the specified <code>DropTargetDropEvent</code>
|
||||
* if this <code>DropTarget</code> is active.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDropEvent</code>
|
||||
*
|
||||
* @throws NullPointerException if <code>dtde</code> is null
|
||||
* and at least one of the following is true: this
|
||||
* <code>DropTarget</code> is not active, or there is
|
||||
* no a <code>DropTargetListener</code> registered.
|
||||
*
|
||||
* @see #isActive
|
||||
*/
|
||||
public synchronized void drop(DropTargetDropEvent dtde) {
|
||||
isDraggingInside = false;
|
||||
|
||||
clearAutoscroll();
|
||||
|
||||
if (dtListener != null && active)
|
||||
dtListener.drop(dtde);
|
||||
else { // we should'nt get here ...
|
||||
dtde.rejectDrop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <code>FlavorMap</code>
|
||||
* associated with this <code>DropTarget</code>.
|
||||
* If no <code>FlavorMap</code> has been set for this
|
||||
* <code>DropTarget</code>, it is associated with the default
|
||||
* <code>FlavorMap</code>.
|
||||
* <P>
|
||||
* @return the FlavorMap for this DropTarget
|
||||
*/
|
||||
|
||||
public FlavorMap getFlavorMap() { return flavorMap; }
|
||||
|
||||
/**
|
||||
* Sets the <code>FlavorMap</code> associated
|
||||
* with this <code>DropTarget</code>.
|
||||
* <P>
|
||||
* @param fm the new <code>FlavorMap</code>, or null to
|
||||
* associate the default FlavorMap with this DropTarget.
|
||||
*/
|
||||
|
||||
public void setFlavorMap(FlavorMap fm) {
|
||||
flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the DropTarget that it has been associated with a Component
|
||||
*
|
||||
**********************************************************************
|
||||
* This method is usually called from java.awt.Component.addNotify() of
|
||||
* the Component associated with this DropTarget to notify the DropTarget
|
||||
* that a ComponentPeer has been associated with that Component.
|
||||
*
|
||||
* Calling this method, other than to notify this DropTarget of the
|
||||
* association of the ComponentPeer with the Component may result in
|
||||
* a malfunction of the DnD system.
|
||||
**********************************************************************
|
||||
* <P>
|
||||
* @param peer The Peer of the Component we are associated with!
|
||||
*
|
||||
*/
|
||||
|
||||
public void addNotify(ComponentPeer peer) {
|
||||
if (peer == componentPeer) return;
|
||||
|
||||
componentPeer = peer;
|
||||
|
||||
for (Component c = component;
|
||||
c != null && peer instanceof LightweightPeer; c = c.getParent()) {
|
||||
peer = c.getPeer();
|
||||
}
|
||||
|
||||
if (peer instanceof DropTargetPeer) {
|
||||
nativePeer = peer;
|
||||
((DropTargetPeer)peer).addDropTarget(this);
|
||||
} else {
|
||||
nativePeer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the DropTarget that it has been disassociated from a Component
|
||||
*
|
||||
**********************************************************************
|
||||
* This method is usually called from java.awt.Component.removeNotify() of
|
||||
* the Component associated with this DropTarget to notify the DropTarget
|
||||
* that a ComponentPeer has been disassociated with that Component.
|
||||
*
|
||||
* Calling this method, other than to notify this DropTarget of the
|
||||
* disassociation of the ComponentPeer from the Component may result in
|
||||
* a malfunction of the DnD system.
|
||||
**********************************************************************
|
||||
* <P>
|
||||
* @param peer The Peer of the Component we are being disassociated from!
|
||||
*/
|
||||
|
||||
public void removeNotify(ComponentPeer peer) {
|
||||
if (nativePeer != null)
|
||||
((DropTargetPeer)nativePeer).removeDropTarget(this);
|
||||
|
||||
componentPeer = nativePeer = null;
|
||||
|
||||
synchronized (this) {
|
||||
if (isDraggingInside) {
|
||||
dragExit(new DropTargetEvent(getDropTargetContext()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <code>DropTargetContext</code> associated
|
||||
* with this <code>DropTarget</code>.
|
||||
* <P>
|
||||
* @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
|
||||
*/
|
||||
|
||||
public DropTargetContext getDropTargetContext() {
|
||||
return dropTargetContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the DropTargetContext associated with this DropTarget.
|
||||
* Subclasses may override this method to instantiate their own
|
||||
* DropTargetContext subclass.
|
||||
*
|
||||
* This call is typically *only* called by the platform's
|
||||
* DropTargetContextPeer as a drag operation encounters this
|
||||
* DropTarget. Accessing the Context while no Drag is current
|
||||
* has undefined results.
|
||||
*/
|
||||
|
||||
protected DropTargetContext createDropTargetContext() {
|
||||
return new DropTargetContext(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes this <code>DropTarget</code>. Performs default serialization,
|
||||
* and then writes out this object's <code>DropTargetListener</code> if and
|
||||
* only if it can be serialized. If not, <code>null</code> is written
|
||||
* instead.
|
||||
*
|
||||
* @serialData The default serializable fields, in alphabetical order,
|
||||
* followed by either a <code>DropTargetListener</code>
|
||||
* instance, or <code>null</code>.
|
||||
* @since 1.4
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||
s.defaultWriteObject();
|
||||
|
||||
s.writeObject(SerializationTester.test(dtListener)
|
||||
? dtListener : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes this <code>DropTarget</code>. This method first performs
|
||||
* default deserialization for all non-<code>transient</code> fields. An
|
||||
* attempt is then made to deserialize this object's
|
||||
* <code>DropTargetListener</code> as well. This is first attempted by
|
||||
* deserializing the field <code>dtListener</code>, because, in releases
|
||||
* prior to 1.4, a non-<code>transient</code> field of this name stored the
|
||||
* <code>DropTargetListener</code>. If this fails, the next object in the
|
||||
* stream is used instead.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws ClassNotFoundException, IOException
|
||||
{
|
||||
ObjectInputStream.GetField f = s.readFields();
|
||||
|
||||
try {
|
||||
dropTargetContext =
|
||||
(DropTargetContext)f.get("dropTargetContext", null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Pre-1.4 support. 'dropTargetContext' was previously transient
|
||||
}
|
||||
if (dropTargetContext == null) {
|
||||
dropTargetContext = createDropTargetContext();
|
||||
}
|
||||
|
||||
component = (Component)f.get("component", null);
|
||||
actions = f.get("actions", DnDConstants.ACTION_COPY_OR_MOVE);
|
||||
active = f.get("active", true);
|
||||
|
||||
// Pre-1.4 support. 'dtListener' was previously non-transient
|
||||
try {
|
||||
dtListener = (DropTargetListener)f.get("dtListener", null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// 1.4-compatible byte stream. 'dtListener' was written explicitly
|
||||
dtListener = (DropTargetListener)s.readObject();
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
/**
|
||||
* this protected nested class implements autoscrolling
|
||||
*/
|
||||
|
||||
protected static class DropTargetAutoScroller implements ActionListener {
|
||||
|
||||
/**
|
||||
* construct a DropTargetAutoScroller
|
||||
* <P>
|
||||
* @param c the <code>Component</code>
|
||||
* @param p the <code>Point</code>
|
||||
*/
|
||||
|
||||
protected DropTargetAutoScroller(Component c, Point p) {
|
||||
super();
|
||||
|
||||
component = c;
|
||||
autoScroll = (Autoscroll)component;
|
||||
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
|
||||
Integer initial = Integer.valueOf(100);
|
||||
Integer interval = Integer.valueOf(100);
|
||||
|
||||
try {
|
||||
initial = (Integer)t.getDesktopProperty("DnD.Autoscroll.initialDelay");
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
interval = (Integer)t.getDesktopProperty("DnD.Autoscroll.interval");
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
timer = new Timer(interval.intValue(), this);
|
||||
|
||||
timer.setCoalesce(true);
|
||||
timer.setInitialDelay(initial.intValue());
|
||||
|
||||
locn = p;
|
||||
prev = p;
|
||||
|
||||
try {
|
||||
hysteresis = ((Integer)t.getDesktopProperty("DnD.Autoscroll.cursorHysteresis")).intValue();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* update the geometry of the autoscroll region
|
||||
*/
|
||||
|
||||
private void updateRegion() {
|
||||
Insets i = autoScroll.getAutoscrollInsets();
|
||||
Dimension size = component.getSize();
|
||||
|
||||
if (size.width != outer.width || size.height != outer.height)
|
||||
outer.reshape(0, 0, size.width, size.height);
|
||||
|
||||
if (inner.x != i.left || inner.y != i.top)
|
||||
inner.setLocation(i.left, i.top);
|
||||
|
||||
int newWidth = size.width - (i.left + i.right);
|
||||
int newHeight = size.height - (i.top + i.bottom);
|
||||
|
||||
if (newWidth != inner.width || newHeight != inner.height)
|
||||
inner.setSize(newWidth, newHeight);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* cause autoscroll to occur
|
||||
* <P>
|
||||
* @param newLocn the <code>Point</code>
|
||||
*/
|
||||
|
||||
protected synchronized void updateLocation(Point newLocn) {
|
||||
prev = locn;
|
||||
locn = newLocn;
|
||||
|
||||
if (Math.abs(locn.x - prev.x) > hysteresis ||
|
||||
Math.abs(locn.y - prev.y) > hysteresis) {
|
||||
if (timer.isRunning()) timer.stop();
|
||||
} else {
|
||||
if (!timer.isRunning()) timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cause autoscrolling to stop
|
||||
*/
|
||||
|
||||
protected void stop() { timer.stop(); }
|
||||
|
||||
/**
|
||||
* cause autoscroll to occur
|
||||
* <P>
|
||||
* @param e the <code>ActionEvent</code>
|
||||
*/
|
||||
|
||||
public synchronized void actionPerformed(ActionEvent e) {
|
||||
updateRegion();
|
||||
|
||||
if (outer.contains(locn) && !inner.contains(locn))
|
||||
autoScroll.autoscroll(locn);
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
private Component component;
|
||||
private Autoscroll autoScroll;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private Point locn;
|
||||
private Point prev;
|
||||
|
||||
private Rectangle outer = new Rectangle();
|
||||
private Rectangle inner = new Rectangle();
|
||||
|
||||
private int hysteresis = 10;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
/**
|
||||
* create an embedded autoscroller
|
||||
* <P>
|
||||
* @param c the <code>Component</code>
|
||||
* @param p the <code>Point</code>
|
||||
*/
|
||||
|
||||
protected DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p) {
|
||||
return new DropTargetAutoScroller(c, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize autoscrolling
|
||||
* <P>
|
||||
* @param p the <code>Point</code>
|
||||
*/
|
||||
|
||||
protected void initializeAutoscrolling(Point p) {
|
||||
if (component == null || !(component instanceof Autoscroll)) return;
|
||||
|
||||
autoScroller = createDropTargetAutoScroller(component, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* update autoscrolling with current cursor location
|
||||
* <P>
|
||||
* @param dragCursorLocn the <code>Point</code>
|
||||
*/
|
||||
|
||||
protected void updateAutoscroll(Point dragCursorLocn) {
|
||||
if (autoScroller != null) autoScroller.updateLocation(dragCursorLocn);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear autoscrolling
|
||||
*/
|
||||
|
||||
protected void clearAutoscroll() {
|
||||
if (autoScroller != null) {
|
||||
autoScroller.stop();
|
||||
autoScroller = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The DropTargetContext associated with this DropTarget.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private DropTargetContext dropTargetContext = createDropTargetContext();
|
||||
|
||||
/**
|
||||
* The Component associated with this DropTarget.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Component component;
|
||||
|
||||
/*
|
||||
* That Component's Peer
|
||||
*/
|
||||
private transient ComponentPeer componentPeer;
|
||||
|
||||
/*
|
||||
* That Component's "native" Peer
|
||||
*/
|
||||
private transient ComponentPeer nativePeer;
|
||||
|
||||
|
||||
/**
|
||||
* Default permissible actions supported by this DropTarget.
|
||||
*
|
||||
* @see #setDefaultActions
|
||||
* @see #getDefaultActions
|
||||
* @serial
|
||||
*/
|
||||
int actions = DnDConstants.ACTION_COPY_OR_MOVE;
|
||||
|
||||
/**
|
||||
* <code>true</code> if the DropTarget is accepting Drag & Drop operations.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
boolean active = true;
|
||||
|
||||
/*
|
||||
* the auto scrolling object
|
||||
*/
|
||||
|
||||
private transient DropTargetAutoScroller autoScroller;
|
||||
|
||||
/*
|
||||
* The delegate
|
||||
*/
|
||||
|
||||
private transient DropTargetListener dtListener;
|
||||
|
||||
/*
|
||||
* The FlavorMap
|
||||
*/
|
||||
|
||||
private transient FlavorMap flavorMap;
|
||||
|
||||
/*
|
||||
* If the dragging is currently inside this drop target
|
||||
*/
|
||||
private transient boolean isDraggingInside;
|
||||
}
|
||||
109
jdkSrc/jdk8/java/awt/dnd/DropTargetAdapter.java
Normal file
109
jdkSrc/jdk8/java/awt/dnd/DropTargetAdapter.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
/**
|
||||
* An abstract adapter class for receiving drop target events. The methods in
|
||||
* this class are empty. This class exists only as a convenience for creating
|
||||
* listener objects.
|
||||
* <p>
|
||||
* Extend this class to create a <code>DropTargetEvent</code> listener
|
||||
* and override the methods for the events of interest. (If you implement the
|
||||
* <code>DropTargetListener</code> interface, you have to define all of
|
||||
* the methods in it. This abstract class defines a null implementation for
|
||||
* every method except <code>drop(DropTargetDropEvent)</code>, so you only have
|
||||
* to define methods for events you care about.) You must provide an
|
||||
* implementation for at least <code>drop(DropTargetDropEvent)</code>. This
|
||||
* method cannot have a null implementation because its specification requires
|
||||
* that you either accept or reject the drop, and, if accepted, indicate
|
||||
* whether the drop was successful.
|
||||
* <p>
|
||||
* Create a listener object using the extended class and then register it with
|
||||
* a <code>DropTarget</code>. When the drag enters, moves over, or exits
|
||||
* the operable part of the drop site for that <code>DropTarget</code>, when
|
||||
* the drop action changes, and when the drop occurs, the relevant method in
|
||||
* the listener object is invoked, and the <code>DropTargetEvent</code> is
|
||||
* passed to it.
|
||||
* <p>
|
||||
* The operable part of the drop site for the <code>DropTarget</code> is
|
||||
* the part of the associated <code>Component</code>'s geometry that is not
|
||||
* obscured by an overlapping top-level window or by another
|
||||
* <code>Component</code> higher in the Z-order that has an associated active
|
||||
* <code>DropTarget</code>.
|
||||
* <p>
|
||||
* During the drag, the data associated with the current drag operation can be
|
||||
* retrieved by calling <code>getTransferable()</code> on
|
||||
* <code>DropTargetDragEvent</code> instances passed to the listener's
|
||||
* methods.
|
||||
* <p>
|
||||
* Note that <code>getTransferable()</code> on the
|
||||
* <code>DropTargetDragEvent</code> instance should only be called within the
|
||||
* respective listener's method and all the necessary data should be retrieved
|
||||
* from the returned <code>Transferable</code> before that method returns.
|
||||
*
|
||||
* @see DropTargetEvent
|
||||
* @see DropTargetListener
|
||||
*
|
||||
* @author David Mendenhall
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class DropTargetAdapter implements DropTargetListener {
|
||||
|
||||
/**
|
||||
* Called while a drag operation is ongoing, when the mouse pointer enters
|
||||
* the operable part of the drop site for the <code>DropTarget</code>
|
||||
* registered with this listener.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*/
|
||||
public void dragEnter(DropTargetDragEvent dtde) {}
|
||||
|
||||
/**
|
||||
* Called when a drag operation is ongoing, while the mouse pointer is still
|
||||
* over the operable part of the drop site for the <code>DropTarget</code>
|
||||
* registered with this listener.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*/
|
||||
public void dragOver(DropTargetDragEvent dtde) {}
|
||||
|
||||
/**
|
||||
* Called if the user has modified
|
||||
* the current drop gesture.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*/
|
||||
public void dropActionChanged(DropTargetDragEvent dtde) {}
|
||||
|
||||
/**
|
||||
* Called while a drag operation is ongoing, when the mouse pointer has
|
||||
* exited the operable part of the drop site for the
|
||||
* <code>DropTarget</code> registered with this listener.
|
||||
*
|
||||
* @param dte the <code>DropTargetEvent</code>
|
||||
*/
|
||||
public void dragExit(DropTargetEvent dte) {}
|
||||
}
|
||||
420
jdkSrc/jdk8/java/awt/dnd/DropTargetContext.java
Normal file
420
jdkSrc/jdk8/java/awt/dnd/DropTargetContext.java
Normal file
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
|
||||
import java.awt.dnd.peer.DropTargetContextPeer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A <code>DropTargetContext</code> is created
|
||||
* whenever the logical cursor associated
|
||||
* with a Drag and Drop operation coincides with the visible geometry of
|
||||
* a <code>Component</code> associated with a <code>DropTarget</code>.
|
||||
* The <code>DropTargetContext</code> provides
|
||||
* the mechanism for a potential receiver
|
||||
* of a drop operation to both provide the end user with the appropriate
|
||||
* drag under feedback, but also to effect the subsequent data transfer
|
||||
* if appropriate.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DropTargetContext implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -634158968993743371L;
|
||||
|
||||
/**
|
||||
* Construct a <code>DropTargetContext</code>
|
||||
* given a specified <code>DropTarget</code>.
|
||||
* <P>
|
||||
* @param dt the DropTarget to associate with
|
||||
*/
|
||||
|
||||
DropTargetContext(DropTarget dt) {
|
||||
super();
|
||||
|
||||
dropTarget = dt;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the <code>DropTarget</code> associated with this
|
||||
* <code>DropTargetContext</code>.
|
||||
* <P>
|
||||
* @return the <code>DropTarget</code> associated with this <code>DropTargetContext</code>
|
||||
*/
|
||||
|
||||
public DropTarget getDropTarget() { return dropTarget; }
|
||||
|
||||
/**
|
||||
* This method returns the <code>Component</code> associated with
|
||||
* this <code>DropTargetContext</code>.
|
||||
* <P>
|
||||
* @return the Component associated with this Context
|
||||
*/
|
||||
|
||||
public Component getComponent() { return dropTarget.getComponent(); }
|
||||
|
||||
/**
|
||||
* Called when associated with the <code>DropTargetContextPeer</code>.
|
||||
* <P>
|
||||
* @param dtcp the <code>DropTargetContextPeer</code>
|
||||
*/
|
||||
|
||||
public void addNotify(DropTargetContextPeer dtcp) {
|
||||
dropTargetContextPeer = dtcp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when disassociated with the <code>DropTargetContextPeer</code>.
|
||||
*/
|
||||
|
||||
public void removeNotify() {
|
||||
dropTargetContextPeer = null;
|
||||
transferable = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the current actions acceptable to
|
||||
* this <code>DropTarget</code>.
|
||||
* <P>
|
||||
* @param actions an <code>int</code> representing the supported action(s)
|
||||
*/
|
||||
|
||||
protected void setTargetActions(int actions) {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer != null) {
|
||||
synchronized (peer) {
|
||||
peer.setTargetActions(actions);
|
||||
getDropTarget().doSetDefaultActions(actions);
|
||||
}
|
||||
} else {
|
||||
getDropTarget().doSetDefaultActions(actions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an <code>int</code> representing the
|
||||
* current actions this <code>DropTarget</code> will accept.
|
||||
* <P>
|
||||
* @return the current actions acceptable to this <code>DropTarget</code>
|
||||
*/
|
||||
|
||||
protected int getTargetActions() {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
return ((peer != null)
|
||||
? peer.getTargetActions()
|
||||
: dropTarget.getDefaultActions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method signals that the drop is completed and
|
||||
* if it was successful or not.
|
||||
* <P>
|
||||
* @param success true for success, false if not
|
||||
* <P>
|
||||
* @throws InvalidDnDOperationException if a drop is not outstanding/extant
|
||||
*/
|
||||
|
||||
public void dropComplete(boolean success) throws InvalidDnDOperationException{
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer != null) {
|
||||
peer.dropComplete(success);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* accept the Drag.
|
||||
* <P>
|
||||
* @param dragOperation the supported action(s)
|
||||
*/
|
||||
|
||||
protected void acceptDrag(int dragOperation) {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer != null) {
|
||||
peer.acceptDrag(dragOperation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reject the Drag.
|
||||
*/
|
||||
|
||||
protected void rejectDrag() {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer != null) {
|
||||
peer.rejectDrag();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called to signal that the drop is acceptable
|
||||
* using the specified operation.
|
||||
* must be called during DropTargetListener.drop method invocation.
|
||||
* <P>
|
||||
* @param dropOperation the supported action(s)
|
||||
*/
|
||||
|
||||
protected void acceptDrop(int dropOperation) {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer != null) {
|
||||
peer.acceptDrop(dropOperation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called to signal that the drop is unacceptable.
|
||||
* must be called during DropTargetListener.drop method invocation.
|
||||
*/
|
||||
|
||||
protected void rejectDrop() {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer != null) {
|
||||
peer.rejectDrop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the available DataFlavors of the
|
||||
* <code>Transferable</code> operand of this operation.
|
||||
* <P>
|
||||
* @return a <code>DataFlavor[]</code> containing the
|
||||
* supported <code>DataFlavor</code>s of the
|
||||
* <code>Transferable</code> operand.
|
||||
*/
|
||||
|
||||
protected DataFlavor[] getCurrentDataFlavors() {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
return peer != null ? peer.getTransferDataFlavors() : new DataFlavor[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a the currently available DataFlavors
|
||||
* of the <code>Transferable</code> operand
|
||||
* as a <code>java.util.List</code>.
|
||||
* <P>
|
||||
* @return the currently available
|
||||
* DataFlavors as a <code>java.util.List</code>
|
||||
*/
|
||||
|
||||
protected List<DataFlavor> getCurrentDataFlavorsAsList() {
|
||||
return Arrays.asList(getCurrentDataFlavors());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>boolean</code>
|
||||
* indicating if the given <code>DataFlavor</code> is
|
||||
* supported by this <code>DropTargetContext</code>.
|
||||
* <P>
|
||||
* @param df the <code>DataFlavor</code>
|
||||
* <P>
|
||||
* @return if the <code>DataFlavor</code> specified is supported
|
||||
*/
|
||||
|
||||
protected boolean isDataFlavorSupported(DataFlavor df) {
|
||||
return getCurrentDataFlavorsAsList().contains(df);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the Transferable (proxy) operand of this operation
|
||||
* <P>
|
||||
* @throws InvalidDnDOperationException if a drag is not outstanding/extant
|
||||
* <P>
|
||||
* @return the <code>Transferable</code>
|
||||
*/
|
||||
|
||||
protected Transferable getTransferable() throws InvalidDnDOperationException {
|
||||
DropTargetContextPeer peer = getDropTargetContextPeer();
|
||||
if (peer == null) {
|
||||
throw new InvalidDnDOperationException();
|
||||
} else {
|
||||
if (transferable == null) {
|
||||
Transferable t = peer.getTransferable();
|
||||
boolean isLocal = peer.isTransferableJVMLocal();
|
||||
synchronized (this) {
|
||||
if (transferable == null) {
|
||||
transferable = createTransferableProxy(t, isLocal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return transferable;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the <code>DropTargetContextPeer</code>
|
||||
* <P>
|
||||
* @return the platform peer
|
||||
*/
|
||||
|
||||
DropTargetContextPeer getDropTargetContextPeer() {
|
||||
return dropTargetContextPeer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TransferableProxy to proxy for the specified
|
||||
* Transferable.
|
||||
*
|
||||
* @param t the <tt>Transferable</tt> to be proxied
|
||||
* @param local <tt>true</tt> if <tt>t</tt> represents
|
||||
* the result of a local drag-n-drop operation.
|
||||
* @return the new <tt>TransferableProxy</tt> instance.
|
||||
*/
|
||||
protected Transferable createTransferableProxy(Transferable t, boolean local) {
|
||||
return new TransferableProxy(t, local);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* <code>TransferableProxy</code> is a helper inner class that implements
|
||||
* <code>Transferable</code> interface and serves as a proxy for another
|
||||
* <code>Transferable</code> object which represents data transfer for
|
||||
* a particular drag-n-drop operation.
|
||||
* <p>
|
||||
* The proxy forwards all requests to the encapsulated transferable
|
||||
* and automatically performs additional conversion on the data
|
||||
* returned by the encapsulated transferable in case of local transfer.
|
||||
*/
|
||||
|
||||
protected class TransferableProxy implements Transferable {
|
||||
|
||||
/**
|
||||
* Constructs a <code>TransferableProxy</code> given
|
||||
* a specified <code>Transferable</code> object representing
|
||||
* data transfer for a particular drag-n-drop operation and
|
||||
* a <code>boolean</code> which indicates whether the
|
||||
* drag-n-drop operation is local (within the same JVM).
|
||||
* <p>
|
||||
* @param t the <code>Transferable</code> object
|
||||
* @param local <code>true</code>, if <code>t</code> represents
|
||||
* the result of local drag-n-drop operation
|
||||
*/
|
||||
TransferableProxy(Transferable t, boolean local) {
|
||||
proxy = new sun.awt.datatransfer.TransferableProxy(t, local);
|
||||
transferable = t;
|
||||
isLocal = local;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of DataFlavor objects indicating the flavors
|
||||
* the data can be provided in by the encapsulated transferable.
|
||||
* <p>
|
||||
* @return an array of data flavors in which the data can be
|
||||
* provided by the encapsulated transferable
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return proxy.getTransferDataFlavors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the specified data flavor is supported by
|
||||
* the encapsulated transferable.
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return <code>true</code> if the data flavor is supported,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return proxy.isDataFlavorSupported(flavor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object which represents the data provided by
|
||||
* the encapsulated transferable for the requested data flavor.
|
||||
* <p>
|
||||
* In case of local transfer a serialized copy of the object
|
||||
* returned by the encapsulated transferable is provided when
|
||||
* the data is requested in application/x-java-serialized-object
|
||||
* data flavor.
|
||||
*
|
||||
* @param df the requested flavor for the data
|
||||
* @throws IOException if the data is no longer available
|
||||
* in the requested flavor.
|
||||
* @throws UnsupportedFlavorException if the requested data flavor is
|
||||
* not supported.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor df)
|
||||
throws UnsupportedFlavorException, IOException
|
||||
{
|
||||
return proxy.getTransferData(df);
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
// We don't need to worry about client code changing the values of
|
||||
// these variables. Since TransferableProxy is a protected class, only
|
||||
// subclasses of DropTargetContext can access it. And DropTargetContext
|
||||
// cannot be subclassed by client code because it does not have a
|
||||
// public constructor.
|
||||
|
||||
/**
|
||||
* The encapsulated <code>Transferable</code> object.
|
||||
*/
|
||||
protected Transferable transferable;
|
||||
|
||||
/**
|
||||
* A <code>boolean</code> indicating if the encapsulated
|
||||
* <code>Transferable</code> object represents the result
|
||||
* of local drag-n-drop operation (within the same JVM).
|
||||
*/
|
||||
protected boolean isLocal;
|
||||
|
||||
private sun.awt.datatransfer.TransferableProxy proxy;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
/**
|
||||
* The DropTarget associated with this DropTargetContext.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private DropTarget dropTarget;
|
||||
|
||||
private transient DropTargetContextPeer dropTargetContextPeer;
|
||||
|
||||
private transient Transferable transferable;
|
||||
}
|
||||
243
jdkSrc/jdk8/java/awt/dnd/DropTargetDragEvent.java
Normal file
243
jdkSrc/jdk8/java/awt/dnd/DropTargetDragEvent.java
Normal file
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The <code>DropTargetDragEvent</code> is delivered to a
|
||||
* <code>DropTargetListener</code> via its
|
||||
* dragEnter() and dragOver() methods.
|
||||
* <p>
|
||||
* The <code>DropTargetDragEvent</code> reports the <i>source drop actions</i>
|
||||
* and the <i>user drop action</i> that reflect the current state of
|
||||
* the drag operation.
|
||||
* <p>
|
||||
* <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code>
|
||||
* that represents the set of drop actions supported by the drag source for
|
||||
* this drag operation.
|
||||
* <p>
|
||||
* <i>User drop action</i> depends on the drop actions supported by the drag
|
||||
* source and the drop action selected by the user. The user can select a drop
|
||||
* action by pressing modifier keys during the drag operation:
|
||||
* <pre>
|
||||
* Ctrl + Shift -> ACTION_LINK
|
||||
* Ctrl -> ACTION_COPY
|
||||
* Shift -> ACTION_MOVE
|
||||
* </pre>
|
||||
* If the user selects a drop action, the <i>user drop action</i> is one of
|
||||
* <code>DnDConstants</code> that represents the selected drop action if this
|
||||
* drop action is supported by the drag source or
|
||||
* <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
|
||||
* by the drag source.
|
||||
* <p>
|
||||
* If the user doesn't select a drop action, the set of
|
||||
* <code>DnDConstants</code> that represents the set of drop actions supported
|
||||
* by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
|
||||
* then for <code>DnDConstants.ACTION_COPY</code>, then for
|
||||
* <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
|
||||
* first constant found. If no constant is found the <i>user drop action</i>
|
||||
* is <code>DnDConstants.ACTION_NONE</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DropTargetDragEvent extends DropTargetEvent {
|
||||
|
||||
private static final long serialVersionUID = -8422265619058953682L;
|
||||
|
||||
/**
|
||||
* Construct a <code>DropTargetDragEvent</code> given the
|
||||
* <code>DropTargetContext</code> for this operation,
|
||||
* the location of the "Drag" <code>Cursor</code>'s hotspot
|
||||
* in the <code>Component</code>'s coordinates, the
|
||||
* user drop action, and the source drop actions.
|
||||
* <P>
|
||||
* @param dtc The DropTargetContext for this operation
|
||||
* @param cursorLocn The location of the "Drag" Cursor's
|
||||
* hotspot in Component coordinates
|
||||
* @param dropAction The user drop action
|
||||
* @param srcActions The source drop actions
|
||||
*
|
||||
* @throws NullPointerException if cursorLocn is null
|
||||
* @throws IllegalArgumentException if dropAction is not one of
|
||||
* <code>DnDConstants</code>.
|
||||
* @throws IllegalArgumentException if srcActions is not
|
||||
* a bitwise mask of <code>DnDConstants</code>.
|
||||
* @throws IllegalArgumentException if dtc is <code>null</code>.
|
||||
*/
|
||||
|
||||
public DropTargetDragEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) {
|
||||
super(dtc);
|
||||
|
||||
if (cursorLocn == null) throw new NullPointerException("cursorLocn");
|
||||
|
||||
if (dropAction != DnDConstants.ACTION_NONE &&
|
||||
dropAction != DnDConstants.ACTION_COPY &&
|
||||
dropAction != DnDConstants.ACTION_MOVE &&
|
||||
dropAction != DnDConstants.ACTION_LINK
|
||||
) throw new IllegalArgumentException("dropAction" + dropAction);
|
||||
|
||||
if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions");
|
||||
|
||||
location = cursorLocn;
|
||||
actions = srcActions;
|
||||
this.dropAction = dropAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>Point</code>
|
||||
* indicating the <code>Cursor</code>'s current
|
||||
* location within the <code>Component'</code>s
|
||||
* coordinates.
|
||||
* <P>
|
||||
* @return the current cursor location in
|
||||
* <code>Component</code>'s coords.
|
||||
*/
|
||||
|
||||
public Point getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the current <code>DataFlavor</code>s from the
|
||||
* <code>DropTargetContext</code>.
|
||||
* <P>
|
||||
* @return current DataFlavors from the DropTargetContext
|
||||
*/
|
||||
|
||||
public DataFlavor[] getCurrentDataFlavors() {
|
||||
return getDropTargetContext().getCurrentDataFlavors();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the current <code>DataFlavor</code>s
|
||||
* as a <code>java.util.List</code>
|
||||
* <P>
|
||||
* @return a <code>java.util.List</code> of the Current <code>DataFlavor</code>s
|
||||
*/
|
||||
|
||||
public List<DataFlavor> getCurrentDataFlavorsAsList() {
|
||||
return getDropTargetContext().getCurrentDataFlavorsAsList();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>boolean</code> indicating
|
||||
* if the specified <code>DataFlavor</code> is supported.
|
||||
* <P>
|
||||
* @param df the <code>DataFlavor</code> to test
|
||||
* <P>
|
||||
* @return if a particular DataFlavor is supported
|
||||
*/
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor df) {
|
||||
return getDropTargetContext().isDataFlavorSupported(df);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the source drop actions.
|
||||
*
|
||||
* @return the source drop actions
|
||||
*/
|
||||
public int getSourceActions() { return actions; }
|
||||
|
||||
/**
|
||||
* This method returns the user drop action.
|
||||
*
|
||||
* @return the user drop action
|
||||
*/
|
||||
public int getDropAction() { return dropAction; }
|
||||
|
||||
/**
|
||||
* This method returns the Transferable object that represents
|
||||
* the data associated with the current drag operation.
|
||||
*
|
||||
* @return the Transferable associated with the drag operation
|
||||
* @throws InvalidDnDOperationException if the data associated with the drag
|
||||
* operation is not available
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public Transferable getTransferable() {
|
||||
return getDropTargetContext().getTransferable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the drag.
|
||||
*
|
||||
* This method should be called from a
|
||||
* <code>DropTargetListeners</code> <code>dragEnter</code>,
|
||||
* <code>dragOver</code>, and <code>dropActionChanged</code>
|
||||
* methods if the implementation wishes to accept an operation
|
||||
* from the srcActions other than the one selected by
|
||||
* the user as represented by the <code>dropAction</code>.
|
||||
*
|
||||
* @param dragOperation the operation accepted by the target
|
||||
*/
|
||||
public void acceptDrag(int dragOperation) {
|
||||
getDropTargetContext().acceptDrag(dragOperation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects the drag as a result of examining either the
|
||||
* <code>dropAction</code> or the available <code>DataFlavor</code>
|
||||
* types.
|
||||
*/
|
||||
public void rejectDrag() {
|
||||
getDropTargetContext().rejectDrag();
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
/**
|
||||
* The location of the drag cursor's hotspot in Component coordinates.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Point location;
|
||||
|
||||
/**
|
||||
* The source drop actions.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int actions;
|
||||
|
||||
/**
|
||||
* The user drop action.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int dropAction;
|
||||
}
|
||||
299
jdkSrc/jdk8/java/awt/dnd/DropTargetDropEvent.java
Normal file
299
jdkSrc/jdk8/java/awt/dnd/DropTargetDropEvent.java
Normal file
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The <code>DropTargetDropEvent</code> is delivered
|
||||
* via the <code>DropTargetListener</code> drop() method.
|
||||
* <p>
|
||||
* The <code>DropTargetDropEvent</code> reports the <i>source drop actions</i>
|
||||
* and the <i>user drop action</i> that reflect the current state of the
|
||||
* drag-and-drop operation.
|
||||
* <p>
|
||||
* <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code>
|
||||
* that represents the set of drop actions supported by the drag source for
|
||||
* this drag-and-drop operation.
|
||||
* <p>
|
||||
* <i>User drop action</i> depends on the drop actions supported by the drag
|
||||
* source and the drop action selected by the user. The user can select a drop
|
||||
* action by pressing modifier keys during the drag operation:
|
||||
* <pre>
|
||||
* Ctrl + Shift -> ACTION_LINK
|
||||
* Ctrl -> ACTION_COPY
|
||||
* Shift -> ACTION_MOVE
|
||||
* </pre>
|
||||
* If the user selects a drop action, the <i>user drop action</i> is one of
|
||||
* <code>DnDConstants</code> that represents the selected drop action if this
|
||||
* drop action is supported by the drag source or
|
||||
* <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
|
||||
* by the drag source.
|
||||
* <p>
|
||||
* If the user doesn't select a drop action, the set of
|
||||
* <code>DnDConstants</code> that represents the set of drop actions supported
|
||||
* by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
|
||||
* then for <code>DnDConstants.ACTION_COPY</code>, then for
|
||||
* <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
|
||||
* first constant found. If no constant is found the <i>user drop action</i>
|
||||
* is <code>DnDConstants.ACTION_NONE</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class DropTargetDropEvent extends DropTargetEvent {
|
||||
|
||||
private static final long serialVersionUID = -1721911170440459322L;
|
||||
|
||||
/**
|
||||
* Construct a <code>DropTargetDropEvent</code> given
|
||||
* the <code>DropTargetContext</code> for this operation,
|
||||
* the location of the drag <code>Cursor</code>'s
|
||||
* hotspot in the <code>Component</code>'s coordinates,
|
||||
* the currently
|
||||
* selected user drop action, and the current set of
|
||||
* actions supported by the source.
|
||||
* By default, this constructor
|
||||
* assumes that the target is not in the same virtual machine as
|
||||
* the source; that is, {@link #isLocalTransfer()} will
|
||||
* return <code>false</code>.
|
||||
* <P>
|
||||
* @param dtc The <code>DropTargetContext</code> for this operation
|
||||
* @param cursorLocn The location of the "Drag" Cursor's
|
||||
* hotspot in <code>Component</code> coordinates
|
||||
* @param dropAction the user drop action.
|
||||
* @param srcActions the source drop actions.
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if cursorLocn is <code>null</code>
|
||||
* @throws IllegalArgumentException
|
||||
* if dropAction is not one of <code>DnDConstants</code>.
|
||||
* @throws IllegalArgumentException
|
||||
* if srcActions is not a bitwise mask of <code>DnDConstants</code>.
|
||||
* @throws IllegalArgumentException if dtc is <code>null</code>.
|
||||
*/
|
||||
|
||||
public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) {
|
||||
super(dtc);
|
||||
|
||||
if (cursorLocn == null) throw new NullPointerException("cursorLocn");
|
||||
|
||||
if (dropAction != DnDConstants.ACTION_NONE &&
|
||||
dropAction != DnDConstants.ACTION_COPY &&
|
||||
dropAction != DnDConstants.ACTION_MOVE &&
|
||||
dropAction != DnDConstants.ACTION_LINK
|
||||
) throw new IllegalArgumentException("dropAction = " + dropAction);
|
||||
|
||||
if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions");
|
||||
|
||||
location = cursorLocn;
|
||||
actions = srcActions;
|
||||
this.dropAction = dropAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>DropTargetEvent</code> given the
|
||||
* <code>DropTargetContext</code> for this operation,
|
||||
* the location of the drag <code>Cursor</code>'s hotspot
|
||||
* in the <code>Component</code>'s
|
||||
* coordinates, the currently selected user drop action,
|
||||
* the current set of actions supported by the source,
|
||||
* and a <code>boolean</code> indicating if the source is in the same JVM
|
||||
* as the target.
|
||||
* <P>
|
||||
* @param dtc The DropTargetContext for this operation
|
||||
* @param cursorLocn The location of the "Drag" Cursor's
|
||||
* hotspot in Component's coordinates
|
||||
* @param dropAction the user drop action.
|
||||
* @param srcActions the source drop actions.
|
||||
* @param isLocal True if the source is in the same JVM as the target
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if cursorLocn is <code>null</code>
|
||||
* @throws IllegalArgumentException
|
||||
* if dropAction is not one of <code>DnDConstants</code>.
|
||||
* @throws IllegalArgumentException if srcActions is not a bitwise mask of <code>DnDConstants</code>.
|
||||
* @throws IllegalArgumentException if dtc is <code>null</code>.
|
||||
*/
|
||||
|
||||
public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions, boolean isLocal) {
|
||||
this(dtc, cursorLocn, dropAction, srcActions);
|
||||
|
||||
isLocalTx = isLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>Point</code>
|
||||
* indicating the <code>Cursor</code>'s current
|
||||
* location in the <code>Component</code>'s coordinates.
|
||||
* <P>
|
||||
* @return the current <code>Cursor</code> location in Component's coords.
|
||||
*/
|
||||
|
||||
public Point getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the current DataFlavors.
|
||||
* <P>
|
||||
* @return current DataFlavors
|
||||
*/
|
||||
|
||||
public DataFlavor[] getCurrentDataFlavors() {
|
||||
return getDropTargetContext().getCurrentDataFlavors();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the currently available
|
||||
* <code>DataFlavor</code>s as a <code>java.util.List</code>.
|
||||
* <P>
|
||||
* @return the currently available DataFlavors as a java.util.List
|
||||
*/
|
||||
|
||||
public List<DataFlavor> getCurrentDataFlavorsAsList() {
|
||||
return getDropTargetContext().getCurrentDataFlavorsAsList();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a <code>boolean</code> indicating if the
|
||||
* specified <code>DataFlavor</code> is available
|
||||
* from the source.
|
||||
* <P>
|
||||
* @param df the <code>DataFlavor</code> to test
|
||||
* <P>
|
||||
* @return if the DataFlavor specified is available from the source
|
||||
*/
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor df) {
|
||||
return getDropTargetContext().isDataFlavorSupported(df);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the source drop actions.
|
||||
*
|
||||
* @return the source drop actions.
|
||||
*/
|
||||
public int getSourceActions() { return actions; }
|
||||
|
||||
/**
|
||||
* This method returns the user drop action.
|
||||
*
|
||||
* @return the user drop actions.
|
||||
*/
|
||||
public int getDropAction() { return dropAction; }
|
||||
|
||||
/**
|
||||
* This method returns the <code>Transferable</code> object
|
||||
* associated with the drop.
|
||||
* <P>
|
||||
* @return the <code>Transferable</code> associated with the drop
|
||||
*/
|
||||
|
||||
public Transferable getTransferable() {
|
||||
return getDropTargetContext().getTransferable();
|
||||
}
|
||||
|
||||
/**
|
||||
* accept the drop, using the specified action.
|
||||
* <P>
|
||||
* @param dropAction the specified action
|
||||
*/
|
||||
|
||||
public void acceptDrop(int dropAction) {
|
||||
getDropTargetContext().acceptDrop(dropAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* reject the Drop.
|
||||
*/
|
||||
|
||||
public void rejectDrop() {
|
||||
getDropTargetContext().rejectDrop();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method notifies the <code>DragSource</code>
|
||||
* that the drop transfer(s) are completed.
|
||||
* <P>
|
||||
* @param success a <code>boolean</code> indicating that the drop transfer(s) are completed.
|
||||
*/
|
||||
|
||||
public void dropComplete(boolean success) {
|
||||
getDropTargetContext().dropComplete(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an <code>int</code> indicating if
|
||||
* the source is in the same JVM as the target.
|
||||
* <P>
|
||||
* @return if the Source is in the same JVM
|
||||
*/
|
||||
|
||||
public boolean isLocalTransfer() {
|
||||
return isLocalTx;
|
||||
}
|
||||
|
||||
/*
|
||||
* fields
|
||||
*/
|
||||
|
||||
static final private Point zero = new Point(0,0);
|
||||
|
||||
/**
|
||||
* The location of the drag cursor's hotspot in Component coordinates.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Point location = zero;
|
||||
|
||||
/**
|
||||
* The source drop actions.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int actions = DnDConstants.ACTION_NONE;
|
||||
|
||||
/**
|
||||
* The user drop action.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int dropAction = DnDConstants.ACTION_NONE;
|
||||
|
||||
/**
|
||||
* <code>true</code> if the source is in the same JVM as the target.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private boolean isLocalTx = false;
|
||||
}
|
||||
81
jdkSrc/jdk8/java/awt/dnd/DropTargetEvent.java
Normal file
81
jdkSrc/jdk8/java/awt/dnd/DropTargetEvent.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.util.EventObject;
|
||||
import java.awt.dnd.DropTargetContext;
|
||||
|
||||
/**
|
||||
* The <code>DropTargetEvent</code> is the base
|
||||
* class for both the <code>DropTargetDragEvent</code>
|
||||
* and the <code>DropTargetDropEvent</code>.
|
||||
* It encapsulates the current state of the Drag and
|
||||
* Drop operations, in particular the current
|
||||
* <code>DropTargetContext</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
*/
|
||||
|
||||
public class DropTargetEvent extends java.util.EventObject {
|
||||
|
||||
private static final long serialVersionUID = 2821229066521922993L;
|
||||
|
||||
/**
|
||||
* Construct a <code>DropTargetEvent</code> object with
|
||||
* the specified <code>DropTargetContext</code>.
|
||||
* <P>
|
||||
* @param dtc The <code>DropTargetContext</code>
|
||||
* @throws NullPointerException if {@code dtc} equals {@code null}.
|
||||
* @see #getSource()
|
||||
* @see #getDropTargetContext()
|
||||
*/
|
||||
|
||||
public DropTargetEvent(DropTargetContext dtc) {
|
||||
super(dtc.getDropTarget());
|
||||
|
||||
context = dtc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the <code>DropTargetContext</code>
|
||||
* associated with this <code>DropTargetEvent</code>.
|
||||
* <P>
|
||||
* @return the <code>DropTargetContext</code>
|
||||
*/
|
||||
|
||||
public DropTargetContext getDropTargetContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>DropTargetContext</code> associated with this
|
||||
* <code>DropTargetEvent</code>.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
protected DropTargetContext context;
|
||||
}
|
||||
152
jdkSrc/jdk8/java/awt/dnd/DropTargetListener.java
Normal file
152
jdkSrc/jdk8/java/awt/dnd/DropTargetListener.java
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
import java.awt.dnd.DropTargetDragEvent;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
|
||||
/**
|
||||
* The <code>DropTargetListener</code> interface
|
||||
* is the callback interface used by the
|
||||
* <code>DropTarget</code> class to provide
|
||||
* notification of DnD operations that involve
|
||||
* the subject <code>DropTarget</code>. Methods of
|
||||
* this interface may be implemented to provide
|
||||
* "drag under" visual feedback to the user throughout
|
||||
* the Drag and Drop operation.
|
||||
* <p>
|
||||
* Create a listener object by implementing the interface and then register it
|
||||
* with a <code>DropTarget</code>. When the drag enters, moves over, or exits
|
||||
* the operable part of the drop site for that <code>DropTarget</code>, when
|
||||
* the drop action changes, and when the drop occurs, the relevant method in
|
||||
* the listener object is invoked, and the <code>DropTargetEvent</code> is
|
||||
* passed to it.
|
||||
* <p>
|
||||
* The operable part of the drop site for the <code>DropTarget</code> is
|
||||
* the part of the associated <code>Component</code>'s geometry that is not
|
||||
* obscured by an overlapping top-level window or by another
|
||||
* <code>Component</code> higher in the Z-order that has an associated active
|
||||
* <code>DropTarget</code>.
|
||||
* <p>
|
||||
* During the drag, the data associated with the current drag operation can be
|
||||
* retrieved by calling <code>getTransferable()</code> on
|
||||
* <code>DropTargetDragEvent</code> instances passed to the listener's
|
||||
* methods.
|
||||
* <p>
|
||||
* Note that <code>getTransferable()</code> on the
|
||||
* <code>DropTargetDragEvent</code> instance should only be called within the
|
||||
* respective listener's method and all the necessary data should be retrieved
|
||||
* from the returned <code>Transferable</code> before that method returns.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public interface DropTargetListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Called while a drag operation is ongoing, when the mouse pointer enters
|
||||
* the operable part of the drop site for the <code>DropTarget</code>
|
||||
* registered with this listener.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*/
|
||||
|
||||
void dragEnter(DropTargetDragEvent dtde);
|
||||
|
||||
/**
|
||||
* Called when a drag operation is ongoing, while the mouse pointer is still
|
||||
* over the operable part of the drop site for the <code>DropTarget</code>
|
||||
* registered with this listener.
|
||||
*
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*/
|
||||
|
||||
void dragOver(DropTargetDragEvent dtde);
|
||||
|
||||
/**
|
||||
* Called if the user has modified
|
||||
* the current drop gesture.
|
||||
* <P>
|
||||
* @param dtde the <code>DropTargetDragEvent</code>
|
||||
*/
|
||||
|
||||
void dropActionChanged(DropTargetDragEvent dtde);
|
||||
|
||||
/**
|
||||
* Called while a drag operation is ongoing, when the mouse pointer has
|
||||
* exited the operable part of the drop site for the
|
||||
* <code>DropTarget</code> registered with this listener.
|
||||
*
|
||||
* @param dte the <code>DropTargetEvent</code>
|
||||
*/
|
||||
|
||||
void dragExit(DropTargetEvent dte);
|
||||
|
||||
/**
|
||||
* Called when the drag operation has terminated with a drop on
|
||||
* the operable part of the drop site for the <code>DropTarget</code>
|
||||
* registered with this listener.
|
||||
* <p>
|
||||
* This method is responsible for undertaking
|
||||
* the transfer of the data associated with the
|
||||
* gesture. The <code>DropTargetDropEvent</code>
|
||||
* provides a means to obtain a <code>Transferable</code>
|
||||
* object that represents the data object(s) to
|
||||
* be transfered.<P>
|
||||
* From this method, the <code>DropTargetListener</code>
|
||||
* shall accept or reject the drop via the
|
||||
* acceptDrop(int dropAction) or rejectDrop() methods of the
|
||||
* <code>DropTargetDropEvent</code> parameter.
|
||||
* <P>
|
||||
* Subsequent to acceptDrop(), but not before,
|
||||
* <code>DropTargetDropEvent</code>'s getTransferable()
|
||||
* method may be invoked, and data transfer may be
|
||||
* performed via the returned <code>Transferable</code>'s
|
||||
* getTransferData() method.
|
||||
* <P>
|
||||
* At the completion of a drop, an implementation
|
||||
* of this method is required to signal the success/failure
|
||||
* of the drop by passing an appropriate
|
||||
* <code>boolean</code> to the <code>DropTargetDropEvent</code>'s
|
||||
* dropComplete(boolean success) method.
|
||||
* <P>
|
||||
* Note: The data transfer should be completed before the call to the
|
||||
* <code>DropTargetDropEvent</code>'s dropComplete(boolean success) method.
|
||||
* After that, a call to the getTransferData() method of the
|
||||
* <code>Transferable</code> returned by
|
||||
* <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to
|
||||
* succeed only if the data transfer is local; that is, only if
|
||||
* <code>DropTargetDropEvent.isLocalTransfer()</code> returns
|
||||
* <code>true</code>. Otherwise, the behavior of the call is
|
||||
* implementation-dependent.
|
||||
* <P>
|
||||
* @param dtde the <code>DropTargetDropEvent</code>
|
||||
*/
|
||||
|
||||
void drop(DropTargetDropEvent dtde);
|
||||
}
|
||||
57
jdkSrc/jdk8/java/awt/dnd/InvalidDnDOperationException.java
Normal file
57
jdkSrc/jdk8/java/awt/dnd/InvalidDnDOperationException.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
/**
|
||||
* This exception is thrown by various methods in the java.awt.dnd package.
|
||||
* It is usually thrown to indicate that the target in question is unable
|
||||
* to undertake the requested operation that the present time, since the
|
||||
* underlying DnD system is not in the appropriate state.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
|
||||
public class InvalidDnDOperationException extends IllegalStateException {
|
||||
|
||||
private static final long serialVersionUID = -6062568741193956678L;
|
||||
|
||||
static private String dft_msg = "The operation requested cannot be performed by the DnD system since it is not in the appropriate state";
|
||||
|
||||
/**
|
||||
* Create a default Exception
|
||||
*/
|
||||
|
||||
public InvalidDnDOperationException() { super(dft_msg); }
|
||||
|
||||
/**
|
||||
* Create an Exception with its own descriptive message
|
||||
* <P>
|
||||
* @param msg the detail message
|
||||
*/
|
||||
|
||||
public InvalidDnDOperationException(String msg) { super(msg); }
|
||||
|
||||
}
|
||||
208
jdkSrc/jdk8/java/awt/dnd/MouseDragGestureRecognizer.java
Normal file
208
jdkSrc/jdk8/java/awt/dnd/MouseDragGestureRecognizer.java
Normal file
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
/**
|
||||
* This abstract subclass of <code>DragGestureRecognizer</code>
|
||||
* defines a <code>DragGestureRecognizer</code>
|
||||
* for mouse-based gestures.
|
||||
*
|
||||
* Each platform implements its own concrete subclass of this class,
|
||||
* available via the Toolkit.createDragGestureRecognizer() method,
|
||||
* to encapsulate
|
||||
* the recognition of the platform dependent mouse gesture(s) that initiate
|
||||
* a Drag and Drop operation.
|
||||
* <p>
|
||||
* Mouse drag gesture recognizers should honor the
|
||||
* drag gesture motion threshold, available through
|
||||
* {@link DragSource#getDragThreshold}.
|
||||
* A drag gesture should be recognized only when the distance
|
||||
* in either the horizontal or vertical direction between
|
||||
* the location of the latest mouse dragged event and the
|
||||
* location of the corresponding mouse button pressed event
|
||||
* is greater than the drag gesture motion threshold.
|
||||
* <p>
|
||||
* Drag gesture recognizers created with
|
||||
* {@link DragSource#createDefaultDragGestureRecognizer}
|
||||
* follow this convention.
|
||||
*
|
||||
* @author Laurence P. G. Cable
|
||||
*
|
||||
* @see java.awt.dnd.DragGestureListener
|
||||
* @see java.awt.dnd.DragGestureEvent
|
||||
* @see java.awt.dnd.DragSource
|
||||
*/
|
||||
|
||||
public abstract class MouseDragGestureRecognizer extends DragGestureRecognizer implements MouseListener, MouseMotionListener {
|
||||
|
||||
private static final long serialVersionUID = 6220099344182281120L;
|
||||
|
||||
/**
|
||||
* Construct a new <code>MouseDragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> for the
|
||||
* <code>Component</code> c, the <code>Component</code>
|
||||
* to observe, the action(s)
|
||||
* permitted for this drag operation, and
|
||||
* the <code>DragGestureListener</code> to
|
||||
* notify when a drag gesture is detected.
|
||||
* <P>
|
||||
* @param ds The DragSource for the Component c
|
||||
* @param c The Component to observe
|
||||
* @param act The actions permitted for this Drag
|
||||
* @param dgl The DragGestureListener to notify when a gesture is detected
|
||||
*
|
||||
*/
|
||||
|
||||
protected MouseDragGestureRecognizer(DragSource ds, Component c, int act, DragGestureListener dgl) {
|
||||
super(ds, c, act, dgl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>MouseDragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> for
|
||||
* the <code>Component</code> c,
|
||||
* the <code>Component</code> to observe, and the action(s)
|
||||
* permitted for this drag operation.
|
||||
* <P>
|
||||
* @param ds The DragSource for the Component c
|
||||
* @param c The Component to observe
|
||||
* @param act The actions permitted for this drag
|
||||
*/
|
||||
|
||||
protected MouseDragGestureRecognizer(DragSource ds, Component c, int act) {
|
||||
this(ds, c, act, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>MouseDragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> for the
|
||||
* <code>Component</code> c, and the
|
||||
* <code>Component</code> to observe.
|
||||
* <P>
|
||||
* @param ds The DragSource for the Component c
|
||||
* @param c The Component to observe
|
||||
*/
|
||||
|
||||
protected MouseDragGestureRecognizer(DragSource ds, Component c) {
|
||||
this(ds, c, DnDConstants.ACTION_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>MouseDragGestureRecognizer</code>
|
||||
* given the <code>DragSource</code> for the <code>Component</code>.
|
||||
* <P>
|
||||
* @param ds The DragSource for the Component
|
||||
*/
|
||||
|
||||
protected MouseDragGestureRecognizer(DragSource ds) {
|
||||
this(ds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* register this DragGestureRecognizer's Listeners with the Component
|
||||
*/
|
||||
|
||||
protected void registerListeners() {
|
||||
component.addMouseListener(this);
|
||||
component.addMouseMotionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister this DragGestureRecognizer's Listeners with the Component
|
||||
*
|
||||
* subclasses must override this method
|
||||
*/
|
||||
|
||||
|
||||
protected void unregisterListeners() {
|
||||
component.removeMouseListener(this);
|
||||
component.removeMouseMotionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the mouse has been clicked on a component.
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mouseClicked(MouseEvent e) { }
|
||||
|
||||
/**
|
||||
* Invoked when a mouse button has been
|
||||
* pressed on a <code>Component</code>.
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mousePressed(MouseEvent e) { }
|
||||
|
||||
/**
|
||||
* Invoked when a mouse button has been released on a component.
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mouseReleased(MouseEvent e) { }
|
||||
|
||||
/**
|
||||
* Invoked when the mouse enters a component.
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mouseEntered(MouseEvent e) { }
|
||||
|
||||
/**
|
||||
* Invoked when the mouse exits a component.
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mouseExited(MouseEvent e) { }
|
||||
|
||||
/**
|
||||
* Invoked when a mouse button is pressed on a component.
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mouseDragged(MouseEvent e) { }
|
||||
|
||||
/**
|
||||
* Invoked when the mouse button has been moved on a component
|
||||
* (with no buttons no down).
|
||||
* <P>
|
||||
* @param e the <code>MouseEvent</code>
|
||||
*/
|
||||
|
||||
public void mouseMoved(MouseEvent e) { }
|
||||
}
|
||||
73
jdkSrc/jdk8/java/awt/dnd/SerializationTester.java
Normal file
73
jdkSrc/jdk8/java/awt/dnd/SerializationTester.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Tests if an object can truly be serialized by serializing it to a null
|
||||
* OutputStream.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
final class SerializationTester {
|
||||
private static ObjectOutputStream stream;
|
||||
static {
|
||||
try {
|
||||
stream = new ObjectOutputStream(new OutputStream() {
|
||||
public void write(int b) {}
|
||||
});
|
||||
} catch (IOException cannotHappen) {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean test(Object obj) {
|
||||
if (!(obj instanceof Serializable)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
stream.writeObject(obj);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
// Fix for 4503661.
|
||||
// Reset the stream so that it doesn't keep a reference to the
|
||||
// written object.
|
||||
try {
|
||||
stream.reset();
|
||||
} catch (IOException e) {
|
||||
// Ignore the exception.
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private SerializationTester() {}
|
||||
}
|
||||
71
jdkSrc/jdk8/java/awt/dnd/peer/DragSourceContextPeer.java
Normal file
71
jdkSrc/jdk8/java/awt/dnd/peer/DragSourceContextPeer.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd.peer;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.dnd.DragSourceContext;
|
||||
import java.awt.dnd.InvalidDnDOperationException;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This interface is supplied by the underlying window system platform to
|
||||
* expose the behaviors of the Drag and Drop system to an originator of
|
||||
* the same
|
||||
* </p>
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
*/
|
||||
|
||||
public interface DragSourceContextPeer {
|
||||
|
||||
/**
|
||||
* start a drag
|
||||
*/
|
||||
|
||||
void startDrag(DragSourceContext dsc, Cursor c, Image dragImage, Point imageOffset) throws InvalidDnDOperationException;
|
||||
|
||||
/**
|
||||
* return the current drag cursor
|
||||
*/
|
||||
|
||||
Cursor getCursor();
|
||||
|
||||
/**
|
||||
* set the current drag cursor
|
||||
*/
|
||||
|
||||
void setCursor(Cursor c) throws InvalidDnDOperationException;
|
||||
|
||||
/**
|
||||
* notify the peer that the Transferables DataFlavors have changed
|
||||
*/
|
||||
|
||||
void transferablesFlavorsChanged();
|
||||
}
|
||||
111
jdkSrc/jdk8/java/awt/dnd/peer/DropTargetContextPeer.java
Normal file
111
jdkSrc/jdk8/java/awt/dnd/peer/DropTargetContextPeer.java
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd.peer;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.dnd.DropTarget;
|
||||
import java.awt.dnd.InvalidDnDOperationException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This interface is exposed by the underlying window system platform to
|
||||
* enable control of platform DnD operations
|
||||
* </p>
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
*/
|
||||
|
||||
public interface DropTargetContextPeer {
|
||||
|
||||
/**
|
||||
* update the peer's notion of the Target's actions
|
||||
*/
|
||||
|
||||
void setTargetActions(int actions);
|
||||
|
||||
/**
|
||||
* get the current Target actions
|
||||
*/
|
||||
|
||||
int getTargetActions();
|
||||
|
||||
/**
|
||||
* get the DropTarget associated with this peer
|
||||
*/
|
||||
|
||||
DropTarget getDropTarget();
|
||||
|
||||
/**
|
||||
* get the (remote) DataFlavors from the peer
|
||||
*/
|
||||
|
||||
DataFlavor[] getTransferDataFlavors();
|
||||
|
||||
/**
|
||||
* get an input stream to the remote data
|
||||
*/
|
||||
|
||||
Transferable getTransferable() throws InvalidDnDOperationException;
|
||||
|
||||
/**
|
||||
* @return if the DragSource Transferable is in the same JVM as the Target
|
||||
*/
|
||||
|
||||
boolean isTransferableJVMLocal();
|
||||
|
||||
/**
|
||||
* accept the Drag
|
||||
*/
|
||||
|
||||
void acceptDrag(int dragAction);
|
||||
|
||||
/**
|
||||
* reject the Drag
|
||||
*/
|
||||
|
||||
void rejectDrag();
|
||||
|
||||
/**
|
||||
* accept the Drop
|
||||
*/
|
||||
|
||||
void acceptDrop(int dropAction);
|
||||
|
||||
/**
|
||||
* reject the Drop
|
||||
*/
|
||||
|
||||
void rejectDrop();
|
||||
|
||||
/**
|
||||
* signal complete
|
||||
*/
|
||||
|
||||
void dropComplete(boolean success);
|
||||
|
||||
}
|
||||
59
jdkSrc/jdk8/java/awt/dnd/peer/DropTargetPeer.java
Normal file
59
jdkSrc/jdk8/java/awt/dnd/peer/DropTargetPeer.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.dnd.peer;
|
||||
|
||||
import java.awt.dnd.DropTarget;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The DropTargetPeer class is the interface to the platform dependent
|
||||
* DnD facilities. Since the DnD system is based on the native platform's
|
||||
* facilities, a DropTargetPeer will be associated with a ComponentPeer
|
||||
* of the nearsest enclosing native Container (in the case of lightweights)
|
||||
* </p>
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
*/
|
||||
|
||||
public interface DropTargetPeer {
|
||||
|
||||
/**
|
||||
* Add the DropTarget to the System
|
||||
*
|
||||
* @param dt The DropTarget effected
|
||||
*/
|
||||
|
||||
void addDropTarget(DropTarget dt);
|
||||
|
||||
/**
|
||||
* Remove the DropTarget from the system
|
||||
*
|
||||
* @param dt The DropTarget effected
|
||||
*/
|
||||
|
||||
void removeDropTarget(DropTarget dt);
|
||||
}
|
||||
Reference in New Issue
Block a user