Exemplo n.º 1
0
  /**
   * 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;
    }
  }
Exemplo n.º 2
0
  /**
   * 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 ae.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;
    }
  }
Exemplo n.º 3
0
  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());
    }
  }
Exemplo n.º 4
0
 /**
  * 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>
  * ae.java.awt.Toolkit.getDesktopProperty("DnD.gestureMotionThreshold")</code>.
  *
  * @return the drag gesture motion threshold
  * @see MouseDragGestureRecognizer
  * @since 1.5
  */
 public static int getDragThreshold() {
   int ts =
       ((Integer) 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;
 }
Exemplo n.º 5
0
 /**
  * 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.
  *
  * <p>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);
 }
Exemplo n.º 6
0
 /**
  * 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);
 }