Exemplo n.º 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);
      }
    }
Exemplo n.º 2
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)));
 }