20 package net.sf.gridarta.gui.mapmenu;
22 import java.awt.Cursor;
23 import java.awt.dnd.DnDConstants;
24 import java.awt.dnd.DragGestureEvent;
25 import java.awt.dnd.DragGestureListener;
26 import java.awt.dnd.DragSource;
27 import java.awt.dnd.DragSourceDragEvent;
28 import java.awt.dnd.DragSourceDropEvent;
29 import java.awt.dnd.DragSourceEvent;
30 import java.awt.dnd.DragSourceListener;
31 import javax.swing.JTree;
32 import javax.swing.tree.DefaultTreeModel;
33 import javax.swing.tree.MutableTreeNode;
34 import javax.swing.tree.TreePath;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
69 public void dragEnter(@NotNull
final DragSourceDragEvent dsde) {
74 public void dragOver(@NotNull
final DragSourceDragEvent dsde) {
79 public void dropActionChanged(@NotNull
final DragSourceDragEvent dsde) {
84 public void dragExit(@NotNull
final DragSourceEvent dse) {
89 public void dragDropEnd(@NotNull
final DragSourceDropEvent dsde) {
94 if (dsde.getDropSuccess()) {
95 switch (dsde.getDropAction()) {
96 case DnDConstants.ACTION_COPY:
99 case DnDConstants.ACTION_MOVE:
117 final DragGestureListener dragGestureListener =
new DragGestureListener() {
120 public void dragGestureRecognized(@NotNull
final DragGestureEvent dge) {
121 final TreePath selectionPath =
tree.getSelectionPath();
122 if (selectionPath ==
null || selectionPath.getPathCount() <= 1) {
126 draggedTreeNode = (MutableTreeNode) selectionPath.getLastPathComponent();
128 switch (dge.getDragAction()) {
129 case DnDConstants.ACTION_COPY:
130 cursor = DragSource.DefaultCopyDrop;
133 case DnDConstants.ACTION_MOVE:
134 cursor = DragSource.DefaultMoveDrop;
144 dragSource.createDefaultDragGestureRecognizer(
tree, actions, dragGestureListener);