Class DragAndDropTree

    • Field Detail

      • m_Offset

        protected Point m_Offset
        the offset for the "ghost" image.
      • m_CueLineExtension

        protected int m_CueLineExtension
        the amount of pixels for the cue line to extend further out.
      • m_ColorCueLine

        protected Color m_ColorCueLine
        The color of the line hinting whether the node is dropped.
      • m_RectCueLine

        protected Rectangle2D m_RectCueLine
        The rectangle for the line hinting where to drop the node.
      • m_SourceNode

        protected BaseTreeNode[] m_SourceNode
        the source node of the d'n'd.
      • m_DragSource

        protected DragSource m_DragSource
        manages the drag source.
      • m_DropTarget

        protected DropTarget m_DropTarget
        manages the drop target.
      • m_ExpansionExecutor

        protected ScheduledExecutorService m_ExpansionExecutor
        used for expanding nodes during drag'n'drop.
      • m_ExpansionDelay

        protected int m_ExpansionDelay
        the time in msecs before expanding a node during drag'n'drop.
    • Constructor Detail

      • DragAndDropTree

        public DragAndDropTree()
        Initializes the tree.
      • DragAndDropTree

        public DragAndDropTree​(TreeModel model)
        Initializes the tree with the given model.
        Parameters:
        model - the tree model to use
      • DragAndDropTree

        public DragAndDropTree​(TreeNode root)
        Initializes the tree with the given root node.
        Parameters:
        root - the root node to use
    • Method Detail

      • initialize

        protected void initialize()
        Further initialization of the tree.
        Overrides:
        initialize in class BaseTree
      • setExpansionDelay

        public void setExpansionDelay​(int value)
        Sets the delay in msecs before expanding a collapsed node during a drag'n'drop operation.
        Parameters:
        value - the delay in msecs, use 0 or smaller to turn delay off
      • getExpansionDelay

        public int getExpansionDelay()
        Returns the delay in msecs before expanding a collapsed node during a drag'n'drop operation.
        Returns:
        the delay in msecs
      • newTreeNodes

        protected BaseTreeNode[] newTreeNodes​(Transferable data)
        Creates a new TreeNode for this tree.

        Default implementation uses the toString() method of the transferable as user object (and splits it on the "\n").
        Parameters:
        data - the data to use
        Returns:
        the new nodes
      • dragEnter

        public void dragEnter​(DropTargetDragEvent dtde)
        Called while a drag operation is ongoing, when the mouse pointer enters the operable part of the drop site for the DropTarget registered with this listener.
        Specified by:
        dragEnter in interface DropTargetListener
        Parameters:
        dtde - the DropTargetDragEvent
      • dragOver

        public void dragOver​(DropTargetDragEvent e)
        Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site for the DropTarget registered with this listener.
        Specified by:
        dragOver in interface DropTargetListener
        Parameters:
        e - the DropTargetDragEvent
      • dragExit

        public void dragExit​(DropTargetEvent dte)
        Called while a drag operation is ongoing, when the mouse pointer has exited the operable part of the drop site for the DropTarget registered with this listener.
        Specified by:
        dragExit in interface DropTargetListener
        Parameters:
        dte - the DropTargetEvent
      • drop

        public void drop​(DropTargetDropEvent e)
        Called when the drag operation has terminated with a drop on the operable part of the drop site for the DropTarget registered with this listener.

        This method is responsible for undertaking the transfer of the data associated with the gesture. The DropTargetDropEvent provides a means to obtain a Transferable object that represents the data object(s) to be transfered.

        From this method, the DropTargetListener shall accept or reject the drop via the acceptDrop(int dropAction) or rejectDrop() methods of the DropTargetDropEvent parameter.

        Subsequent to acceptDrop(), but not before, DropTargetDropEvent's getTransferable() method may be invoked, and data transfer may be performed via the returned Transferable's getTransferData() method.

        At the completion of a drop, an implementation of this method is required to signal the success/failure of the drop by passing an appropriate boolean to the DropTargetDropEvent's dropComplete(boolean success) method.

        Note: The data transfer should be completed before the call to the DropTargetDropEvent's dropComplete(boolean success) method. After that, a call to the getTransferData() method of the Transferable returned by DropTargetDropEvent.getTransferable() is guaranteed to succeed only if the data transfer is local; that is, only if DropTargetDropEvent.isLocalTransfer() returns true. Otherwise, the behavior of the call is implementation-dependent.

        Specified by:
        drop in interface DropTargetListener
        Parameters:
        e - the DropTargetDropEvent
      • dragEnter

        public void dragEnter​(DragSourceDragEvent dsde)
        Called as the cursor's hotspot enters a platform-dependent drop site. This method is invoked when all the following conditions are true:
        • The cursor's hotspot enters the operable part of a platform- dependent drop site.
        • The drop site is active.
        • The drop site accepts the drag.
        Specified by:
        dragEnter in interface DragSourceListener
        Parameters:
        dsde - the DragSourceDragEvent
      • dragOver

        public void dragOver​(DragSourceDragEvent dsde)
        Called as the cursor's hotspot moves over a platform-dependent drop site. This method is invoked when all the following conditions are true:
        • The cursor's hotspot has moved, but still intersects the operable part of the drop site associated with the previous dragEnter() invocation.
        • The drop site is still active.
        • The drop site accepts the drag.
        Specified by:
        dragOver in interface DragSourceListener
        Parameters:
        dsde - the DragSourceDragEvent
      • dropActionChanged

        public void dropActionChanged​(DragSourceDragEvent dsde)
        Called when the user has modified the drop gesture. This method is invoked when the state of the input device(s) that the user is interacting with changes. Such devices are typically the mouse buttons or keyboard modifiers that the user is interacting with.
        Specified by:
        dropActionChanged in interface DragSourceListener
        Parameters:
        dsde - the DragSourceDragEvent
      • dragExit

        public void dragExit​(DragSourceEvent dse)
        Called as the cursor's hotspot exits a platform-dependent drop site. This method is invoked when any of the following conditions are true:
        • The cursor's hotspot no longer intersects the operable part of the drop site associated with the previous dragEnter() invocation.
        OR
        • The drop site associated with the previous dragEnter() invocation is no longer active.
        OR
        • The drop site associated with the previous dragEnter() invocation has rejected the drag.
        Specified by:
        dragExit in interface DragSourceListener
        Parameters:
        dse - the DragSourceEvent
      • canDrop

        protected boolean canDrop​(Transferable source,
                                  TreeNode target,
                                  DragAndDropTree.DropPosition position)
        Checks whether the source data can be dropped here.

        The default implementation always allows the drop.
        Parameters:
        source - the data being transferred
        target - the target node
        position - where to drop the data
        Returns:
        true if can be dropped
        See Also:
        BaseTreeNode
      • dragDropEnd

        public void dragDropEnd​(DragSourceDropEvent e)
        This method is invoked to signify that the Drag and Drop operation is complete. The getDropSuccess() method of the DragSourceDropEvent can be used to determine the termination state. The getDropAction() method returns the operation that the drop site selected to apply to the Drop operation. Once this method is complete, the current DragSourceContext and associated resources become invalid.
        Specified by:
        dragDropEnd in interface DragSourceListener
        Parameters:
        e - the DragSourceDropEvent
      • getDropMenuActionCaption

        protected String getDropMenuActionCaption​(DragAndDropTree.DropMenu action)
        Returns the string for the specified action.
        Parameters:
        action - the action to get the string for
        Returns:
        the caption
      • getDropMenuActionIcon

        protected ImageIcon getDropMenuActionIcon​(DragAndDropTree.DropMenu action)
        Returns the icon for the drop action.
        Parameters:
        action - the action to get the icon for
        Returns:
        the icon or null if none available
      • showDropMenu

        protected void showDropMenu​(DropTargetDropEvent e,
                                    BaseTreeNode target)
        Displays a drop menu of how to drop the data.
        Parameters:
        e - the drop event
        target - the node that is targeted by the drop
      • doDrop

        protected void doDrop​(Transferable source,
                              BaseTreeNode target,
                              DragAndDropTree.DropPosition position)
        Performs the actual drop of the dragged data.
        Parameters:
        source - the data dragged from the source
        target - the target node
        position - the drop position
      • selectCursor

        protected Cursor selectCursor​(int action)
        Returns the appropriate cursor based on the DnD action.
        Parameters:
        action - the DnD action
        Returns:
        the cursor
      • isDragEnabled

        protected boolean isDragEnabled()
        Returns whether dragging is enabled.

        The default implementation always returns false
        Returns:
        true if dragging is enabled
      • isDropEnabled

        protected boolean isDropEnabled()
        Returns whether dropping is enabled.

        The default implementation always returns false
        Returns:
        true if dropping is enabled
      • canStartDrag

        protected boolean canStartDrag​(BaseTreeNode[] source)
        Checks whether the source node can be dragged at all.

        The default implementation allows all nodes to be dragged.
        Parameters:
        source - the source node that is about to be dragged
        Returns:
        true if the source node can be dragged
      • newNodeCollection

        protected DragAndDropTreeNodeCollection newNodeCollection​(BaseTreeNode[] nodes)
        Creates a new collection for transfer.
        Parameters:
        nodes - the nodes to package
        Returns:
        the new collection
      • dragGestureRecognized

        public void dragGestureRecognized​(DragGestureEvent e)
        A DragGestureRecognizer has detected a platform-dependent drag initiating gesture and is notifying this listener in order for it to initiate the action for the user.

        Specified by:
        dragGestureRecognized in interface DragGestureListener
        Parameters:
        e - the DragGestureEvent describing the gesture that has just occurred
      • addNodeDroppedListener

        public void addNodeDroppedListener​(NodeDroppedListener l)
        Adds the listener to the internal list of node drop listeners.
        Parameters:
        l - the listener to add
      • removeNodeDroppedListener

        public void removeNodeDroppedListener​(NodeDroppedListener l)
        Removes the listener from the internal list of node drop listeners.
        Parameters:
        l - the listener to remove
      • notifyNodeDroppedListeners

        protected void notifyNodeDroppedListeners​(NodeDroppedEvent e)
        Notifies all node dropped listeners with the specified event.
        Parameters:
        e - the node dropped event to send