Пример #1
0
  public void dragGestureRecognized(
      java.awt.dnd.DragGestureEvent
          event) { // System.out.println( "DragGestureListener.dragGestureRecognized" );
    final Object selected = getSelectedValue();
    if (selected != null) {
      sourceIndex = getSelectedIndex();
      java.awt.datatransfer.Transferable transfer =
          new TransferableObject(
              new TransferableObject.Fetcher() {
                /**
                 * This will be called when the transfer data is requested at the very end. At this
                 * point we can remove the object from its original place in the list.
                 */
                public Object getObject() {
                  ((javax.swing.DefaultListModel) getModel()).remove(sourceIndex);
                  return selected;
                } // end getObject
              }); // end fetcher

      // as the name suggests, starts the dragging
      dragSource.startDrag(event, java.awt.dnd.DragSource.DefaultLinkDrop, transfer, this);
    } else {
      // System.out.println( "nothing was selected");
    }
  } // end dragGestureRecognized
Пример #2
0
  /**
   * 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);
      }
    }
  }
Пример #3
0
    /*
     * Drag Gesture Handler
     */
    @Override
    public void dragGestureRecognized(DragGestureEvent dge) {
      TreePath path = tree.getSelectionPath();

      if ((path == null) || (path.getPathCount() <= 1)) {
        return;
      }

      node = (TreeNode) path.getLastPathComponent();
      node.getNodeData().setCopy(false);
      transferable = new TransferableNode(node);

      if (Model.isResource(node.getNodeData()) || Model.isLiason(node.getNodeData())) {
        source.startDrag(dge, DragSource.DefaultLinkDrop, transferable, this);
      } else {
        source.startDrag(dge, DragSource.DefaultMoveDrop, transferable, this);
      }
    }
 /*
  * Drag Gesture Handler
  */
 public void dragGestureRecognized(DragGestureEvent dge) {
   TreePath path = sourceTree.getSelectionPath();
   if (path == null) {
     // We can't move an empty selection
     return;
   }
   oldNode = (DefaultMutableTreeNode) path.getLastPathComponent();
   transferable = new TransferableTreeNode(path);
   ObjectInspector.transferNode = transferable;
   try {
     source.startDrag(dge, DragSource.DefaultMoveDrop, transferable, this);
   } catch (Exception e) {
   }
 }
 /* Methods for DragGestureListener */
 public final void dragGestureRecognized(DragGestureEvent dge) {
   TreePath path = tree.getSelectionPath();
   if (path != null) {
     draggedPath = path;
     draggedNodeParentPath = path.getParentPath();
     if (drawImage) {
       Rectangle pathBounds = tree.getPathBounds(path); // getpathbounds of selectionpath
       JComponent lbl =
           (JComponent)
               tree.getCellRenderer()
                   .getTreeCellRendererComponent(
                       tree,
                       draggedPath.getLastPathComponent(),
                       false,
                       tree.isExpanded(path),
                       false,
                       0,
                       false); // returning the label
       lbl.setBounds(pathBounds); // setting bounds to lbl
       image =
           new BufferedImage(
               lbl.getWidth(),
               lbl.getHeight(),
               java.awt.image.BufferedImage
                   .TYPE_INT_ARGB_PRE); // buffered image reference passing the label's ht and
                                        // width
       Graphics2D graphics = image.createGraphics(); // creating the graphics for buffered image
       graphics.setComposite(
           AlphaComposite.getInstance(
               AlphaComposite.SRC_OVER, 0.5f)); // Sets the Composite for the Graphics2D context
       lbl.setOpaque(false);
       lbl.paint(graphics); // painting the graphics to label
       graphics.dispose();
     }
     dragSource.startDrag(
         dge,
         DragSource.DefaultMoveNoDrop,
         image,
         new Point(0, 0),
         new TransferableNode(draggedPath),
         this);
   }
 }
Пример #6
0
  /** Starts the drag process */
  @Override
  public void dragGestureRecognized(DragGestureEvent dge) {
    // Get the selected nodes (even if single select)
    List<File> list = getSelectedFileList();
    if ((list == null) || (list.size() < 1)) {
      return;
    }
    FileNodes fn = new FileNodes(list);

    // Get the Transferable Object
    Transferable transferable = fn;

    // begin the drag
    try {
      dragSource.startDrag(dge, DragSource.DefaultCopyDrop, transferable, this);
    } catch (InvalidDnDOperationException e) {
      e.printStackTrace();
    }
  }
 @Override
 public void dragGestureRecognized(DragGestureEvent evt) {
   Transferable transferable = new StringTransferable(String.valueOf(imageType.getId()));
   dragSource.startDrag(evt, DragSource.DefaultCopyDrop, transferable, this);
 }
Пример #8
0
  public void dragGestureRecognized(DragGestureEvent dge) {

    if (geoLabelList == null) geoLabelList = new ArrayList<String>();
    else geoLabelList.clear();

    for (GeoElement geo : selection.getSelectedGeos()) {
      geoLabelList.add(geo.getLabel(StringTemplate.defaultTemplate));
    }

    // if we have something ... do the drag!
    if (geoLabelList.size() > 0) {

      String latex;

      boolean showJustFirstGeoInDrag = false;

      if (selection.getSelectedGeos().size() == 1) {
        showJustFirstGeoInDrag = true;
      } else {

        // workaround for http://forge.scilab.org/index.php/p/jlatexmath/issues/749/#preview
        for (GeoElement geo : selection.getSelectedGeos()) {
          if (geo.isGeoCurveCartesian()) {
            showJustFirstGeoInDrag = true;
            break;
          }
        }
      }

      if (showJustFirstGeoInDrag) {
        latex =
            selection
                .getSelectedGeos()
                .get(0)
                .getLaTeXAlgebraDescription(true, StringTemplate.latexTemplate);
      } else {

        // create drag image
        StringBuilder sb = new StringBuilder();
        sb.append("\\fbox{\\begin{array}{l}");
        for (GeoElement geo : selection.getSelectedGeos()) {
          sb.append(geo.getLaTeXAlgebraDescription(true, StringTemplate.latexTemplate));
          sb.append("\\\\");
        }
        sb.append("\\end{array}}");
        latex = sb.toString();
      }
      ImageIcon ic =
          GeoGebraIcon.createLatexIcon(
              (AppD) app, latex, ((AppD) app).getPlainFont(), false, Color.DARK_GRAY, null);

      // start drag
      ds.startDrag(
          dge,
          DragSource.DefaultCopyDrop,
          ic.getImage(),
          new Point(-5, -30),
          new TransferableAlgebraView(geoLabelList),
          this);
    }
  }
Пример #9
0
 @Override
 public void dragGestureRecognized(DragGestureEvent dge) {
   source.startDrag(dge, DragSource.DefaultCopyDrop, this, this);
   // System.out.println(getItem().getProduct().getName() + " " + getItem().getAmount());
 }