예제 #1
0
    /**
     * Start the drag if the operation is ok. uses java.awt.datatransfer.StringSelection to transfer
     * the label's data
     *
     * @param e the event object
     */
    public void dragGestureRecognized(DragGestureEvent e) {

      // if the action is ok we go ahead
      // otherwise we punt
      System.out.println(e.getDragAction());
      if ((e.getDragAction() & DragLabel.this.dragAction) == 0) return;
      System.out.println("kicking off drag");

      // get the label's text and put it inside a Transferable
      // Transferable transferable = new StringSelection( DragLabel.this.getText() );
      Transferable transferable = new StringTransferable(DragLabel.this.getText());

      // now kick off the drag
      try {
        // initial cursor, transferrable, dsource listener
        e.startDrag(DragSource.DefaultCopyNoDrop, transferable, DragLabel.this.dsListener);

        // or if dragSource is a variable
        // dragSource.startDrag(e, DragSource.DefaultCopyDrop, transferable, dsListener);

        // or if you'd like to use a drag image if supported

        /*
          if(DragSource.isDragImageSupported() )
          // cursor, image, point, transferrable, dsource listener
          e.startDrag(DragSource.DefaultCopyDrop, image, point, transferable, dsListener);
        */

      } catch (InvalidDnDOperationException idoe) {
        System.err.println(idoe);
      }
    }
  /**
   * Initializes a drag source context.
   *
   * @exception IllegalArgumentException If Component or DragSource of trigger are null, the drag
   *     action for the trigger event is DnDConstants.ACTION_NONE or if the source actions for the
   *     DragGestureRecognizer associated with the trigger event are equal to
   *     DnDConstants.ACTION_NONE.
   * @exception NullPointerException If peer or trigger is null.
   */
  public DragSourceContext(
      DragSourceContextPeer peer,
      DragGestureEvent trigger,
      Cursor cursor,
      Image image,
      Point offset,
      Transferable trans,
      DragSourceListener dsl) {
    if (peer == null || trigger == null) throw new NullPointerException();

    if (trigger.getComponent() == null
        || trigger.getDragSource() == null
        || trigger.getDragAction() == DnDConstants.ACTION_NONE
        || trigger.getSourceAsDragGestureRecognizer().getSourceActions()
            == DnDConstants.ACTION_NONE) throw new IllegalArgumentException();

    this.peer = peer;
    this.trigger = trigger;
    this.cursor = cursor;
    this.image = image;
    this.offset = offset;
    this.transferable = trans;
    this.dragSourceListener = dsl;

    throw new Error("not implemented");
  }
예제 #3
0
 @Override
 public void dragGestureRecognized(DragGestureEvent dge) {
   Cursor cursor = null;
   BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   paint(bi.getGraphics());
   ImageMover.start(bi, MouseInfo.getPointerInfo().getLocation());
   String s = "[ANDITEM]";
   if (dge.getDragAction() == DnDConstants.ACTION_COPY) {
     cursor = DragSource.DefaultCopyDrop;
   }
   dge.startDrag(
       cursor, new SimpleDragObject.TransferableSimpleDragObject(new SimpleDragObject(s)));
 }