コード例 #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
     */
    @Override
    public void dragGestureRecognized(DragGestureEvent e) {
      logger.info("dragGestureRecognized");

      // if the action is ok we go ahead
      // otherwise we punt
      if ((e.getDragAction() & dragAction) == 0) {
        return;
        // get the label's text and put it inside a Transferable
        // Transferable transferable = new StringSelection(
        // DragLabel.this.getText() );
      }

      Point p =
          SwingUtilities.convertPoint(e.getComponent(), e.getDragOrigin(), PaletteElementView.this);
      PaletteElementTransferable transferable = new PaletteElementTransferable(getDrawable(), p);

      try {
        // initial cursor, transferrable, dsource listener
        e.startDrag(DrawingPalette.dropKO, transferable, dsListener);
        logger.info("Starting drag for " + getGraphicalRepresentation());
        getDrawingView().captureDraggedNode(PaletteElementView.this, e);
      } catch (Exception idoe) {
        logger.warning("Unexpected exception " + idoe);
      }
    }
コード例 #2
0
ファイル: EntityPallet.java プロジェクト: mchudleigh/jaamsim
  @Override
  public void dragGestureRecognized(DragGestureEvent event) {

    TreePath path = tree.getSelectionPath();
    if (path != null) {

      // Dragged node is a DefaultMutableTreeNode
      if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path.getLastPathComponent();

        // This is an ObjectType node
        if (treeNode.getUserObject() instanceof ObjectType) {
          ObjectType type = (ObjectType) treeNode.getUserObject();
          Cursor cursor = null;

          if (event.getDragAction() == DnDConstants.ACTION_COPY) {
            cursor = DragSource.DefaultCopyDrop;
          }
          if (RenderManager.isGood()) {
            // The new renderer is initialized
            RenderManager.inst().startDragAndDrop(type);
            event.startDrag(cursor, new TransferableObjectType(type), RenderManager.inst());

          } else {
            event.startDrag(cursor, new TransferableObjectType(type));
          }
        }
      }
    }
  }
コード例 #3
0
ファイル: DragLabel.java プロジェクト: chackotemp/codetestmap
    /**
     * 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);
      }
    }
コード例 #4
0
 public void dragGestureRecognized(DragGestureEvent dge) {
   Point dragOrigin = dge.getDragOrigin();
   int row = AnimatedTileList.this.locationToIndex(dragOrigin);
   if (row == -1) { //  clicked on empty area
     return;
   }
   Tile tile = (Tile) AnimatedTileList.this.getModel().getElementAt(row);
   TileTransferable payload = new TileTransferable();
   payload.getTiles().add(tile);
   dge.startDrag(null, payload, this);
 }
コード例 #5
0
  public void dragGestureRecognized(DragGestureEvent event) {
    if (folderPanel.getMainFrame().getNoEventsMode()) return;

    FileTable fileTable = folderPanel.getFileTable();
    FileTableModel tableModel = fileTable.getFileTableModel();

    // Return (do not initiate drag) if mouse button2 or button3 was used
    if ((event.getTriggerEvent().getModifiers()
            & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK))
        != 0) return;

    // Do not use that to retrieve the current selected file as it is inaccurate: the selection
    // could have changed since the
    // the mouse was clicked.
    //        AbstractFile selectedFile = fileTable.getSelectedFile(false);
    //        // Return if selected file is null (could happen if '..' is selected)
    //        if(selectedFile==null)
    //            return;

    // Find out which row was clicked
    int clickedRow = fileTable.rowAtPoint(event.getDragOrigin());
    // Return (do not initiate drag) if the selected file is the parent folder '..'
    if (clickedRow == -1 || fileTable.isParentFolder(clickedRow)) return;

    // Retrieve the file corresponding to the clicked row
    AbstractFile selectedFile = tableModel.getFileAtRow(clickedRow);

    // Find out which files are to be dragged, based on the selected file and currenlty marked
    // files.
    // If there are some files marked, drag marked files only if the selected file is one of the
    // marked files.
    // In any other case, only drag the selected file.
    FileSet markedFiles;
    FileSet draggedFiles;
    if (tableModel.getNbMarkedFiles() > 0
        && (markedFiles = fileTable.getSelectedFiles()).contains(selectedFile)) {
      draggedFiles = markedFiles;
    } else {
      draggedFiles = new FileSet(fileTable.getCurrentFolder(), selectedFile);
    }

    // Set initial DnDContext information
    DnDContext.setDragInitiatedByMucommander(true);
    DnDContext.setDragInitiator(folderPanel);
    DnDContext.setDragGestureModifiersEx(event.getTriggerEvent().getModifiersEx());

    // Start dragging
    DragSource.getDefaultDragSource()
        .startDrag(event, null, new TransferableFileSet(draggedFiles), this);
    //        DragSource.getDefaultDragSource().startDrag(createCustomDragGestureEvent(event,
    // DnDConstants.ACTION_MOVE), null, new TransferableFileSet(draggedFiles), this);
  }
コード例 #6
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)));
 }
コード例 #7
0
ファイル: TextItemPanel.java プロジェクト: oscarmoutinho/JMRI
 /** ************** DragGestureListener ************** */
 public void dragGestureRecognized(DragGestureEvent e) {
   if (log.isDebugEnabled()) {
     log.debug("DragPositionable.dragGestureRecognized ");
   }
   // Transferable t = getTransferable(this);
   e.startDrag(DragSource.DefaultCopyDrop, this, this);
 }
コード例 #8
0
ファイル: DraggableTree.java プロジェクト: jbudynk/starjava
  /**
   * This method is called when the user initiates a drag operation. It attempts to start the drag.
   *
   * @param event the DragGestureEvent describing the gesture that has just occurred
   */
  public void dragGestureRecognized(DragGestureEvent event) {
    // Give subclasses a chance to stop the drag
    if (!isSelectionDraggable()) {
      return;
    }

    if (getSelectionCount() == 1) {
      TreePath path = getSelectionPath();
      if (path != null) {
        DefaultMutableTreeNode selection = (DefaultMutableTreeNode) path.getLastPathComponent();

        if (selection instanceof Transferable) {
          // Start the drag - a single Transferable node
          fDragSource.startDrag(
              event,
              (event.getDragAction() == DnDConstants.ACTION_COPY)
                  ? DragSource.DefaultCopyDrop
                  : DragSource.DefaultMoveDrop,
              (Transferable) selection,
              sDragSourceListener);
        }
      }
    } else if (getSelectionCount() > 1) {
      TreePath[] paths = getSelectionPaths();

      TransferableList selections = new TransferableList();

      for (int i = 0; i < paths.length; ++i) {
        DefaultMutableTreeNode selection = (DefaultMutableTreeNode) paths[i].getLastPathComponent();

        if (selection instanceof Transferable) {
          selections.add(selection);
        }
      }

      if (selections.size() > 0) {
        // Start the drag - a TransferableList of nodes
        fDragSource.startDrag(
            event,
            (event.getDragAction() == DnDConstants.ACTION_COPY)
                ? DragSource.DefaultCopyDrop
                : DragSource.DefaultMoveDrop,
            selections,
            sDragSourceListener);
      }
    }
  }
コード例 #9
0
  public void dragGestureRecognized(DragGestureEvent evt) {
    if (files == null) return;
    if (files.length <= 0) {
      return;
    }
    Icon icn = files[0].getIcon(false);
    Toolkit tk = Toolkit.getDefaultToolkit();
    if (icn == null) icn = new EmptyIcon();
    Dimension dim = tk.getBestCursorSize(icn.getIconWidth(), icn.getIconHeight());

    // set up drag image
    if (DragSource.isDragImageSupported()) {
      BufferedImage buff =
          new BufferedImage(dim.width + 100, dim.height, BufferedImage.TYPE_INT_ARGB);
      Graphics graphics = buff.getGraphics();
      Color color = graphics.getColor();
      icn.paintIcon(null, graphics, 0, 0);
      graphics.setColor(color);
      graphics.setColor(Color.RED);
      graphics.drawString(files.length + " Elements", icn.getIconWidth(), dim.height / 2);
      try {
        evt.startDrag(
            DragSource.DefaultCopyDrop,
            buff,
            new Point(0, 0),
            new FileTransferable(files, table.getTableModel()),
            this);
      } catch (IOException ex) {
        Logger.getLogger(FileDragGestureListener.class.getName()).log(Level.SEVERE, null, ex);
      }
    } else {
      BufferedImage buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
      Graphics graphics = buff.getGraphics();
      icn.paintIcon(null, graphics, 0, 0);
      try {
        cursor = tk.createCustomCursor(buff, new Point(0, 0), "tempcursor");
        evt.startDrag(
            cursor,
            null,
            new Point(0, 0),
            new FileTransferable(files, table.getTableModel()),
            this);
      } catch (IOException ex) {
        Logger.getLogger(FileDragGestureListener.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
コード例 #10
0
ファイル: DragJLabel.java プロジェクト: KenC57/JMRI
 /** ************** DragGestureListener ************** */
 public void dragGestureRecognized(DragGestureEvent e) {
   if (log.isDebugEnabled()) {
     log.debug("DragJLabel.dragGestureRecognized ");
   }
   if (okToDrag()) {
     e.startDrag(DragSource.DefaultCopyDrop, this, this);
   }
 }
コード例 #11
0
 @Override
 public void dragGestureRecognized(DragGestureEvent dge) {
   System.out.println("dragGestureRecognized");
   Point clickPoint = dge.getDragOrigin();
   TreePath path = getPathForLocation(clickPoint.x, clickPoint.y);
   if (path == null) return;
   draggedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
   Transferable trans = new RJLTransferable(draggedNode);
   dragSource.startDrag(dge, Cursor.getDefaultCursor(), trans, this);
 }
コード例 #12
0
ファイル: DroppableList.java プロジェクト: JsonChiu/Jasonse
	/**
	 * 当从List中选择一项拖放到文件系统或者其他地方时,调用此方法。 这是DragGestureListener接口定义的方法。
	 */
	public void dragGestureRecognized(DragGestureEvent dragGestureEvent) {
		System.out
				.println("method: dragGestureRecognized(DragGestureEvent dragGestureEvent)");
		if (getSelectedIndex() == -1)
			return;
		// 获得被选择的项的数据。
		Object obj = getSelectedValue();
		if (obj == null) {
			// 如果没有选择列表中的项,则不能视为一个拖动,则蜂鸣。
			System.out.println("Nothing selected - beep");
			getToolkit().beep();
		} else {
			// 将List中被选择的项打包成一个Transfer对象
			Hashtable table = (Hashtable) obj;
			FileSelection transferable = new FileSelection(new File(
					(String) table.get("path")));
			// 开始拖放,第一个参数为拖放时的光标;第二个参数为被拖放的数据对象;第三个是拖放拖放源侦听器
			dragGestureEvent.startDrag(DragSource.DefaultCopyDrop,
					transferable, this);
		}
	}
コード例 #13
0
ファイル: JDragTree.java プロジェクト: TheSeeker/Thaw
  // DragGestureListener interface method
  public void dragGestureRecognized(final DragGestureEvent e) {
    // we should make sure we aren't in edit mode
    final InputEvent ievent = e.getTriggerEvent();
    if (ievent instanceof MouseEvent) {
      // even though I tell dgRecognizer to ignore the the right mouse button,
      // it thinks the RMB starts a drag event...argh
      if ((((MouseEvent) ievent).getModifiers() & InputEvent.BUTTON3_MASK) != 0) return;
    }

    // begin dnd
    final Point ptDragOrigin = e.getDragOrigin();
    final TreePath path = getPathForLocation(ptDragOrigin.x, ptDragOrigin.y);
    if (path == null) return;
    if (isRootPath(path)) return; // Ignore user trying to drag the root node

    // Work out the offset of the drag point from the TreePath bounding rectangle origin
    final Rectangle raPath = getPathBounds(path);
    _ptOffset.setLocation(ptDragOrigin.x - raPath.x, ptDragOrigin.y - raPath.y);

    // Get the cell renderer (which is a JLabel) for the path being dragged
    final JLabel lbl =
        (JLabel)
            getCellRenderer()
                .getTreeCellRendererComponent(
                    this, // tree
                    path.getLastPathComponent(), // value
                    false, // isSelected   (dont want a colored background)
                    this.isExpanded(path), // isExpanded
                    getModel().isLeaf(path.getLastPathComponent()), // isLeaf
                    0, // row          (not important for rendering)
                    false // hasFocus     (dont want a focus rectangle)
                    );
    lbl.setSize(
        (int) raPath.getWidth(),
        (int) raPath.getHeight()); // <-- The layout manager would normally do this

    // Get a buffered image of the selection for dragging a ghost image
    _imgGhost =
        new BufferedImage(
            (int) raPath.getWidth(), (int) raPath.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
    final Graphics2D g2 = _imgGhost.createGraphics();

    // Ask the cell renderer to paint itself into the BufferedImage
    g2.setComposite(
        AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f)); // Make the image ghostlike
    lbl.paint(g2);

    // Now paint a gradient UNDER the ghosted JLabel text (but not under the icon if any)
    // Note: this will need tweaking if your icon is not positioned to the left of the text
    final Icon icon = lbl.getIcon();
    final int nStartOfText = (icon == null) ? 0 : icon.getIconWidth() + lbl.getIconTextGap();
    g2.setComposite(
        AlphaComposite.getInstance(AlphaComposite.DST_OVER, 0.5f)); // Make the gradient ghostlike
    g2.setPaint(
        new GradientPaint(
            nStartOfText,
            0,
            SystemColor.controlShadow,
            getWidth(),
            0,
            new Color(255, 255, 255, 0)));
    g2.fillRect(nStartOfText, 0, getWidth(), _imgGhost.getHeight());
    g2.dispose();

    setSelectionPath(path); // Select this path in the tree

    // Wrap the path being transferred into a Transferable object
    final Transferable transferable = new CTransferableTreePath(path);

    // Remember the path being dragged (because if it is being moved, we will have to delete it
    // later)
    _pathSource = path;

    // We pass our drag image just in case it IS supported by the platform
    e.startDrag(null, _imgGhost, new Point(5, 5), transferable, this);
  }
コード例 #14
0
ファイル: MartComponent.java プロジェクト: JoeCarlson/BioMart
 @Override
 public void dragGestureRecognized(DragGestureEvent dge) {
   dge.startDrag(DragSource.DefaultCopyDrop, this);
 }
コード例 #15
0
    /** A Drag gesture has been recognized. */
    public void dragGestureRecognized(DragGestureEvent dge) {
      JComponent c = (JComponent) dge.getComponent();
      DefaultTransferHandler th = (DefaultTransferHandler) c.getTransferHandler();
      Transferable t = th.createTransferable(c);

      if (t != null) {
        scrolls = c.getAutoscrolls();
        c.setAutoscrolls(false);
        try {
          if (c instanceof JLabel && ((JLabel) c).getIcon() instanceof ImageIcon) {
            Toolkit tk = Toolkit.getDefaultToolkit();
            ImageIcon imageIcon = ((ImageIcon) ((JLabel) c).getIcon());
            Dimension bestSize =
                tk.getBestCursorSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());

            if (bestSize.width == 0 || bestSize.height == 0) {
              dge.startDrag(null, t, this);
              return;
            }

            Image image;
            if (bestSize.width > bestSize.height) {
              bestSize.height =
                  (int)
                      ((((double) bestSize.width) / ((double) imageIcon.getIconWidth()))
                          * imageIcon.getIconHeight());
            } else {
              bestSize.width =
                  (int)
                      ((((double) bestSize.height) / ((double) imageIcon.getIconHeight()))
                          * imageIcon.getIconWidth());
            }
            image =
                imageIcon
                    .getImage()
                    .getScaledInstance(bestSize.width, bestSize.height, Image.SCALE_DEFAULT);

            /*
              We have to use a MediaTracker to ensure that the
              image has been scaled before we use it.
            */
            MediaTracker mt = new MediaTracker(c);
            mt.addImage(image, 0, bestSize.width, bestSize.height);
            try {
              mt.waitForID(0);
            } catch (InterruptedException e) {
              dge.startDrag(null, t, this);
              return;
            }

            Point point = new Point(bestSize.width / 2, bestSize.height / 2);
            Cursor cursor;
            try {
              cursor = tk.createCustomCursor(image, point, "freeColDragIcon");
            } catch (RuntimeException re) {
              cursor = null;
            }
            // Point point = new Point(0, 0);
            dge.startDrag(cursor, t, this);
          } else {
            dge.startDrag(null, t, this);
          }

          return;
        } catch (RuntimeException re) {
          c.setAutoscrolls(scrolls);
        }
      }

      th.exportDone(c, null, NONE);
    }
コード例 #16
0
 @Override
 protected void dragStarted(DragGestureEvent e) {
   GuiCard guiCard = (GuiCard) e.getComponent();
   guiCard.setLocation(guiCard.getOrigin());
 }