home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 5.6 KB | 198 lines |
- /*
- * @(#)DragSource.java 1.12 98/03/18
- *
- * Copyright 1997, 1998 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- package java.awt.dnd;
-
- import java.awt.AWTError;
- import java.awt.AWTException;
- import java.awt.AWTEvent;
- import java.awt.AWTPermission;
- import java.awt.Component;
- import java.awt.Cursor;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Toolkit;
-
- import java.awt.datatransfer.Transferable;
-
- import java.awt.dnd.DnDConstants;
- import java.awt.dnd.DragSourceContext;
- import java.awt.dnd.DragSourceListener;
- import java.awt.dnd.FlavorMap;
- import java.awt.dnd.SystemFlavorMap;
- import java.awt.dnd.InvalidDnDOperationException;
-
- import java.awt.dnd.peer.DragSourceContextPeer;
-
- import java.security.AccessController;
-
- /**
- * <p>
- * The DragSource class is a small class responsible for originating a
- * Drag and Drop operation.
- * </p>
- *
- * @version 1.12
- * @since JDK1.2
- *
- */
-
- public class DragSource {
-
- /*
- * load a default cursor
- */
-
- private static Cursor load(String name) {
- try {
- return (Cursor)Toolkit.getDefaultToolkit().getDesktopProperty(name);
- } catch (Exception e) {
- e.printStackTrace();
-
- throw new RuntimeException("failed to load system cursor: " + name + " : " + e.getMessage());
- }
- }
-
- /**
- * Default Cursor Constants
- */
-
- public static final Cursor DefaultCopyDrop = load("DnD.Cursor.CopyDrop");
- public static final Cursor DefaultMoveDrop = load("DnD.Cursor.MoveDrop");
- public static final Cursor DefaultLinkDrop = load("DnD.Cursor.LinkDrop");
-
- public static final Cursor DefaultCopyNoDrop = load("DnD.Cursor.CopyNoDrop");
- public static final Cursor DefaultMoveNoDrop = load("DnD.Cursor.MoveNoDrop");
- public static final Cursor DefaultLinkNoDrop = load("DnD.Cursor.LinkNoDrop");
-
- /*
- * The System FlavorMap
- */
-
- private static final FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap();
-
- private static DragSource dflt;
-
- /**
- * @return the platform DragSource
- */
-
- public static DragSource getDefaultDragSource() {
- if (dflt == null) dflt = new DragSource();
-
- return dflt;
- }
-
- /**
- * @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;
- }
- }
-
- /**
- * construct a DragSource
- */
-
- public DragSource() { super(); }
-
- /**
- * start a Drag operation.
- *
- * @param c The Component the Drag trigger occurred in
- * @param trigger The AWTEvent that initiated the operation
- * @param actions The drag "verbs" appropriate
- * @param dragCursor The initial cursor or null for defaults
- * @param dragImage The image to drag or null
- * @param imageOffset The offset of the image origin from the hotspot
- * of the cursor at the instant of the trigger
- * @param transferable The subject data of the operation
- * @param dsl The DragSourceListener
- *
- * Caller must have AWTPermission startDrag to succeed.
- *
- * @throw java.awt.dnd.InvalidDnDOperationException
- * @throw java.lang.SecurityException
- */
-
- public void startDrag(Component c,
- AWTEvent trigger,
- int actions,
- Cursor dragCursor,
- Image dragImage,
- Point imageOffset,
- Transferable transferable,
- DragSourceListener dsl) throws InvalidDnDOperationException, SecurityException {
-
- /*
- * FIX THIS FOR BETA4
- */
-
- // java.security.AccessController.checkPermission(new AWTPermission("startDrag"));
-
- DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(this, c);
- DragSourceContext dsc = createDragSourceContext(dscp,
- c,
- actions,
- dragCursor,
- dragImage,
- imageOffset,
- transferable,
- dsl
- );
-
- if (dsc == null) throw new InvalidDnDOperationException();
-
- dscp.startDrag(dsc, trigger, dsc.getCursor(), actions); // may throw
- }
-
- /**
- * Create the DragSourceContext to handle this Drag.
- *
- * To incorporate a new DragSourceContext subclass, subclass DragSource and
- * override this method.
- *
- * @param dscp The DragSourceContextPeer for this operation
- * @param c The Component the drag started in
- * @param actions The drag "verbs" appropriate
- * @param dragCursor The initial cursor
- * @param dragImage The image to drag or null
- * @param imageOffset The offset of the image origin from the hotspot
- * of the cursor at the instant of the trigger
- * @param transferable The subject data of the operation
- * @param dsl The DragSourceListener
- */
-
- protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp, Component c, int actions, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl) {
- return new DragSourceContext(this, dscp, c, actions, dragCursor, dragImage, imageOffset, t, dsl);
- }
-
- /**
- * @return the FlavorMap for this DragSource
- */
-
- public FlavorMap getFlavorMap() { return flavorMap; }
- }
-