⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dragsource.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)DragSource.java	1.42 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.dnd;import java.awt.AWTError;import java.awt.AWTException;import java.awt.event.InputEvent;import java.awt.AWTPermission;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.Serializable;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;/** * 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>.  * * @version 	1.42, 01/23/03 * @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</code> or <code>null</code> for defaults     * @param dragImage	     the image to drag or 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 <code>java.awt.dnd.InvalidDnDOperationException</code>      *    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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -