Exemplo n.º 1
0
 private void initialize() {
   // install drag n drop support
   dragSource = DragSource.getDefaultDragSource();
   dgRecognizer =
       dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
   // don't act on right mouse button
   dgRecognizer.setSourceActions(
       dgRecognizer.getSourceActions() & ~InputEvent.BUTTON3_MASK & ~InputEvent.BUTTON2_MASK);
   new DropTarget(this, new CDropTargetListener());
 }
Exemplo n.º 2
0
  /** convenience routine for setting up drag and drop */
  private void setupDnD() {

    // gesture recognizer establishes what action starts the dnd

    DragGestureRecognizer dgr =
        dragSource.createDefaultDragGestureRecognizer(
            this, // DragSource
            DnDConstants.ACTION_COPY, // specifies valid actions
            this // DragGestureListener
            );

    /*
     * Eliminates right mouse clicks as valid actions - useful especially if
     * you implement a JPopupMenu for the JTree
     */
    dgr.setSourceActions(dgr.getSourceActions() & ~InputEvent.BUTTON3_MASK);
  }
Exemplo n.º 3
0
  protected void enableDragging() {
    dgr.setComponent(this);

    /**
     * FIX for bug where element is not draggable when initial click begins on label
     *
     * <p>There is a big trick here: the label view is not a subcomponent of view, so dragging on
     * this component will not be seen by palette element view, so we need here to force disable
     * mouse listeners registered for this palette view
     */
    if (getLabelView() != null) {
      if (labelDgr == null) {
        labelDgr = createDragGestureRecognizer();
      }
      getLabelView().disableTextComponentMouseListeners();
      labelDgr.setComponent(getLabelView().getTextComponent());
    }
  }
Exemplo n.º 4
0
 protected void disableDragging() {
   // dgr.setComponent(null);
   if (getLabelView() != null) {
     getLabelView().enableTextComponentMouseListeners();
   }
   if (labelDgr != null) {
     labelDgr.setComponent(null);
   }
 }