Class DragAndDropTree
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JTree
-
- adams.gui.core.BaseTree
-
- adams.gui.core.DragAndDropTree
-
- All Implemented Interfaces:
DragGestureListener
,DragSourceListener
,DropTargetListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,Scrollable
- Direct Known Subclasses:
DotNotationTree
,Tree
public class DragAndDropTree extends BaseTree implements DropTargetListener, DragSourceListener, DragGestureListener
A BaseTree ehanced with drag'n'drop.
Drag'n'Drop originally taken from the DnDJTree referenced here.
Delayed expansion of collapsed nodes during drag'n'drop originally taken from here.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz), [email protected], Matt Crinklaw-Vogt
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DragAndDropTree.DropMenu
Enumeration for where to drop the node.static class
DragAndDropTree.DropPosition
Enumeration for where to drop the node.-
Nested classes/interfaces inherited from class javax.swing.JTree
JTree.AccessibleJTree, JTree.DropLocation, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeModelHandler, JTree.TreeSelectionRedirector
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected Color
m_ColorCueLine
The color of the line hinting whether the node is dropped.protected int
m_CueLineExtension
the amount of pixels for the cue line to extend further out.protected DragSource
m_DragSource
manages the drag source.protected DropTarget
m_DropTarget
manages the drop target.protected int
m_ExpansionDelay
the time in msecs before expanding a node during drag'n'drop.protected ScheduledExecutorService
m_ExpansionExecutor
used for expanding nodes during drag'n'drop.protected HashSet<NodeDroppedListener>
m_NodeDroppedListeners
the listeners for node-drop events.protected Point
m_Offset
the offset for the "ghost" image.protected Rectangle2D
m_RectCueLine
The rectangle for the line hinting where to drop the node.protected BaseTreeNode[]
m_SourceNode
the source node of the d'n'd.-
Fields inherited from class javax.swing.JTree
ANCHOR_SELECTION_PATH_PROPERTY, CELL_EDITOR_PROPERTY, CELL_RENDERER_PROPERTY, cellEditor, cellRenderer, editable, EDITABLE_PROPERTY, EXPANDS_SELECTED_PATHS_PROPERTY, INVOKES_STOP_CELL_EDITING_PROPERTY, invokesStopCellEditing, LARGE_MODEL_PROPERTY, largeModel, LEAD_SELECTION_PATH_PROPERTY, ROOT_VISIBLE_PROPERTY, rootVisible, ROW_HEIGHT_PROPERTY, rowHeight, SCROLLS_ON_EXPAND_PROPERTY, scrollsOnExpand, SELECTION_MODEL_PROPERTY, selectionModel, selectionRedirector, SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles, TOGGLE_CLICK_COUNT_PROPERTY, toggleClickCount, TREE_MODEL_PROPERTY, treeModel, treeModelListener, VISIBLE_ROW_COUNT_PROPERTY, visibleRowCount
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description DragAndDropTree()
Initializes the tree.DragAndDropTree(TreeModel model)
Initializes the tree with the given model.DragAndDropTree(TreeNode root)
Initializes the tree with the given root node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNodeDroppedListener(NodeDroppedListener l)
Adds the listener to the internal list of node drop listeners.protected boolean
canDrop(Transferable source, TreeNode target, DragAndDropTree.DropPosition position)
Checks whether the source data can be dropped here.protected boolean
canStartDrag(BaseTreeNode[] source)
Checks whether the source node can be dragged at all.protected void
doDrop(Transferable source, BaseTreeNode target, DragAndDropTree.DropPosition position)
Performs the actual drop of the dragged data.void
dragDropEnd(DragSourceDropEvent e)
This method is invoked to signify that the Drag and Drop operation is complete.void
dragEnter(DragSourceDragEvent dsde)
Called as the cursor's hotspot enters a platform-dependent drop site.void
dragEnter(DropTargetDragEvent dtde)
Called while a drag operation is ongoing, when the mouse pointer enters the operable part of the drop site for theDropTarget
registered with this listener.void
dragExit(DragSourceEvent dse)
Called as the cursor's hotspot exits a platform-dependent drop site.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 theDropTarget
registered with this listener.void
dragGestureRecognized(DragGestureEvent e)
ADragGestureRecognizer
has detected a platform-dependent drag initiating gesture and is notifying this listener in order for it to initiate the action for the user.void
dragOver(DragSourceDragEvent dsde)
Called as the cursor's hotspot moves over a platform-dependent drop site.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 theDropTarget
registered with this listener.void
drop(DropTargetDropEvent e)
Called when the drag operation has terminated with a drop on the operable part of the drop site for theDropTarget
registered with this listener.void
dropActionChanged(DragSourceDragEvent dsde)
Called when the user has modified the drop gesture.void
dropActionChanged(DropTargetDragEvent dtde)
Called if the user has modified the current drop gesture.protected String
getDropMenuActionCaption(DragAndDropTree.DropMenu action)
Returns the string for the specified action.protected ImageIcon
getDropMenuActionIcon(DragAndDropTree.DropMenu action)
Returns the icon for the drop action.int
getExpansionDelay()
Returns the delay in msecs before expanding a collapsed node during a drag'n'drop operation.protected void
initialize()
Further initialization of the tree.protected boolean
isDragEnabled()
Returns whether dragging is enabled.protected boolean
isDropEnabled()
Returns whether dropping is enabled.protected DragAndDropTreeNodeCollection
newNodeCollection(BaseTreeNode[] nodes)
Creates a new collection for transfer.protected BaseTreeNode[]
newTreeNodes(Transferable data)
Creates a new TreeNode for this tree.protected void
notifyNodeDroppedListeners(NodeDroppedEvent e)
Notifies all node dropped listeners with the specified event.void
removeNodeDroppedListener(NodeDroppedListener l)
Removes the listener from the internal list of node drop listeners.protected Cursor
selectCursor(int action)
Returns the appropriate cursor based on the DnD action.void
setExpansionDelay(int value)
Sets the delay in msecs before expanding a collapsed node during a drag'n'drop operation.protected void
showDropMenu(DropTargetDropEvent e, BaseTreeNode target)
Displays a drop menu of how to drop the data.-
Methods inherited from class adams.gui.core.BaseTree
collapse, collapseAll, collapseAll, collapseAll, collapseRoot, expand, expand, expandAll, expandAll, expandAll, expandRoot, getCommonAncestor, getExpandedState, getExpandedStateList, getExpandedTreePaths, getExpandedTreePaths, getFirstVisibleRow, getLastVisibleRow, getParentDialog, getParentFrame, getParentInternalFrame, isRootSelected, redraw, redraw, setExpandedState, setExpandedStateList, setExpandedTreePaths, setExpandedTreePaths, toggleAll, toggleAll, toPlainText, toPlainText, toString, toString
-
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearSelection, clearToggledPaths, collapsePath, collapseRow, convertValueToText, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAccessibleContext, getAnchorSelectionPath, getCellEditor, getCellRenderer, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getDropLocation, getDropMode, getEditingPath, getExpandedDescendants, getExpandsSelectedPaths, getInvokesStopCellEditing, getLastSelectedPathComponent, getLeadSelectionPath, getLeadSelectionRow, getMaxSelectionRow, getMinSelectionRow, getModel, getNextMatch, getPathBetweenRows, getPathBounds, getPathForLocation, getPathForRow, getPreferredScrollableViewportSize, getRowBounds, getRowCount, getRowForLocation, getRowForPath, getRowHeight, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollsOnExpand, getSelectionCount, getSelectionModel, getSelectionPath, getSelectionPaths, getSelectionRows, getShowsRootHandles, getToggleClickCount, getToolTipText, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, isEditing, isExpanded, isExpanded, isFixedRowHeight, isLargeModel, isPathEditable, isPathSelected, isRootVisible, isRowSelected, isSelectionEmpty, isVisible, makeVisible, paramString, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setCellRenderer, setDragEnabled, setDropMode, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setModel, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, startEditingAtPath, stopEditing, treeDidChange, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
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_NodeDroppedListeners
protected HashSet<NodeDroppedListener> m_NodeDroppedListeners
the listeners for node-drop events.
-
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 classBaseTree
-
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 theDropTarget
registered with this listener.- Specified by:
dragEnter
in interfaceDropTargetListener
- Parameters:
dtde
- theDropTargetDragEvent
-
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 theDropTarget
registered with this listener.- Specified by:
dragOver
in interfaceDropTargetListener
- Parameters:
e
- theDropTargetDragEvent
-
dropActionChanged
public void dropActionChanged(DropTargetDragEvent dtde)
Called if the user has modified the current drop gesture.- Specified by:
dropActionChanged
in interfaceDropTargetListener
- Parameters:
dtde
- theDropTargetDragEvent
-
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 theDropTarget
registered with this listener.- Specified by:
dragExit
in interfaceDropTargetListener
- Parameters:
dte
- theDropTargetEvent
-
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 theDropTarget
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 aTransferable
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 theDropTargetDropEvent
parameter.Subsequent to acceptDrop(), but not before,
DropTargetDropEvent
's getTransferable() method may be invoked, and data transfer may be performed via the returnedTransferable
'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 theDropTargetDropEvent
'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 theTransferable
returned byDropTargetDropEvent.getTransferable()
is guaranteed to succeed only if the data transfer is local; that is, only ifDropTargetDropEvent.isLocalTransfer()
returnstrue
. Otherwise, the behavior of the call is implementation-dependent.- Specified by:
drop
in interfaceDropTargetListener
- Parameters:
e
- theDropTargetDropEvent
-
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 interfaceDragSourceListener
- Parameters:
dsde
- theDragSourceDragEvent
-
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 interfaceDragSourceListener
- Parameters:
dsde
- theDragSourceDragEvent
-
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 interfaceDragSourceListener
- Parameters:
dsde
- theDragSourceDragEvent
-
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.
- The drop site associated with the previous dragEnter() invocation is no longer active.
- The drop site associated with the previous dragEnter() invocation has rejected the drag.
- Specified by:
dragExit
in interfaceDragSourceListener
- Parameters:
dse
- theDragSourceEvent
-
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 transferredtarget
- the target nodeposition
- 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 theDragSourceDropEvent
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 currentDragSourceContext
and associated resources become invalid.- Specified by:
dragDropEnd
in interfaceDragSourceListener
- Parameters:
e
- theDragSourceDropEvent
-
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 eventtarget
- 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 sourcetarget
- the target nodeposition
- 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)
ADragGestureRecognizer
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 interfaceDragGestureListener
- Parameters:
e
- theDragGestureEvent
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
-
-