Package java.awt.dnd

Examples of java.awt.dnd.DragSource


        // With the default drag-handling that is installed by the Swing code, two clicks are
        // required in order to start dragging a node that is not selected: one click to select
        // the node, and then another to start dragging. We install our own DragGestureRecognizer,
        // so that dragging can start in just one click, which, IMO, leads to a better user
        // experience.
        DragSource src = new DragSource();
        src.createDefaultDragGestureRecognizer(tree, TransferHandler.COPY, new DragGestureListener() {

            @Override
            public void dragGestureRecognized(DragGestureEvent dge) {
                tree.getTransferHandler().exportAsDrag(tree, dge.getTriggerEvent(), TransferHandler.COPY);
            }
View Full Code Here


        tabRow.container().setTransferHandler(new TawRowTransferHandler());
    }

    private void installDragSupport(final TabLabel tab) {
        tab.setTransferHandler(new TabTransferHandler(tab));
        DragSource src = new DragSource();
        src.createDefaultDragGestureRecognizer(tab, TransferHandler.MOVE, new DragGestureListener() {

            @Override
            public void dragGestureRecognized(DragGestureEvent dge) {
                tab.getTransferHandler().exportAsDrag(tab, dge.getTriggerEvent(), TransferHandler.MOVE);
            }
View Full Code Here

    public void enableTabReordering(TabReorderHandler handler) {
        checkNotNull(handler, "handler");
        if (this.reorderHandler == null) {
            tabs.setTransferHandler(new TransferHandlerImpl());
            DragSource src = new DragSource();
            src.createDefaultDragGestureRecognizer(tabs, TransferHandler.MOVE, new DragGestureListener() {

                @Override
                public void dragGestureRecognized(DragGestureEvent dge) {
                    tabs.getTransferHandler().exportAsDrag(tabs, dge.getTriggerEvent(), TransferHandler.MOVE);
                }
View Full Code Here

            }
        }
        catch(SecurityException e) { }
        // Avoid having more than one gesture recognizer active
        disableSwingDragSupport(dragSource);
        DragSource src = DragSource.getDefaultDragSource();
        src.createDefaultDragGestureRecognizer(dragSource, supportedActions, this);
    }
View Full Code Here

            else {
                ghost.returnToOrigin();
            }
            ghost = null;
        }
        DragSource src = e.getDragSourceContext().getDragSource();
        src.removeDragSourceMotionListener(this);
        moved = false;
    }
View Full Code Here

        if (model == null) {
            throw new IllegalArgumentException("model must not be null");
        }
        //this.setModel(model);

        src = new DragSource();
        src.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);

        tgt = new DropTarget(this, this);

        movingItems = false;
View Full Code Here

   * Adds a drag and drop listener to a tree.
   * @param tree the tree to which the listener is added.
   */
  private void addDragAndDropListener(JTree tree)
  {
    final DragSource dragSource = DragSource.getDefaultDragSource();
    final DragSourceListener dragSourceListener = new DragSourceListener()
    {
      /**
       * {@inheritDoc}
       */
      public void dragDropEnd(DragSourceDropEvent dsde)
      {
      }

      /**
       * {@inheritDoc}
       */
      public void dragEnter(DragSourceDragEvent dsde)
      {
        DragSourceContext context = dsde.getDragSourceContext();
        int dropAction = dsde.getDropAction();
        if ((dropAction & DnDConstants.ACTION_COPY) != 0)
        {
          context.setCursor(DragSource.DefaultCopyDrop);
        }
        else if ((dropAction & DnDConstants.ACTION_MOVE) != 0)
        {
          context.setCursor(DragSource.DefaultMoveDrop);
        }
        else
        {
          context.setCursor(DragSource.DefaultCopyNoDrop);
        }
      }

      /**
       * {@inheritDoc}
       */
      public void dragOver(DragSourceDragEvent dsde)
      {
      }

      /**
       * {@inheritDoc}
       */
      public void dropActionChanged(DragSourceDragEvent dsde)
      {
      }

      /**
       * {@inheritDoc}
       */
      public void dragExit(DragSourceEvent dsde)
      {
      }
    };
    final DragGestureListener dragGestureListener = new DragGestureListener()
    {
      /**
       * {@inheritDoc}
       */
      public void dragGestureRecognized(DragGestureEvent e)
      {
        //Get the selected node
        JTree tree = treePane.getTree();
        TreePath[] paths = tree.getSelectionPaths();
        if (paths != null)
        {
          BrowserNodeInfo[] nodes = new BrowserNodeInfo[paths.length];
          DndBrowserNodes dndNodes = new DndBrowserNodes();
          for (int i=0; i<paths.length; i++)
          {
            BrowserNodeInfo node = controller.getNodeInfoFromPath(paths[i]);
            nodes[i] = node;
          }
          dndNodes.setParent(tree);
          dndNodes.setNodes(nodes);
          //Select the appropriate cursor;
          Cursor cursor = DragSource.DefaultCopyNoDrop;
          // begin the drag
          dragSource.startDrag(e, cursor, dndNodes, dragSourceListener);
        }
      }
    };
    dragSource.createDefaultDragGestureRecognizer(tree,  //DragSource
        DnDConstants.ACTION_COPY_OR_MOVE, //specifies valid actions
        dragGestureListener
    );
  }
View Full Code Here

    JTree sourceTree;

    public TreeDragSource(JTree tree, int actions) {
        sourceTree = tree;
        source = new DragSource();
        recognizer = source.createDefaultDragGestureRecognizer(sourceTree,
                actions, this);
    }
View Full Code Here

          }
        }
      }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(
        graphComponent.getGraphControl(),
        DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
  }
View Full Code Here

            }
        }
        catch(SecurityException e) { }
        // Avoid having more than one gesture recognizer active
        disableSwingDragSupport(dragSource);
        DragSource src = DragSource.getDefaultDragSource();
        src.createDefaultDragGestureRecognizer(dragSource, supportedActions, this);
    }
View Full Code Here

TOP

Related Classes of java.awt.dnd.DragSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.