20 package net.sf.gridarta.gui.mapmenu;
22 import java.awt.Cursor;
23 import java.awt.dnd.DnDConstants;
24 import java.awt.dnd.DragGestureListener;
25 import java.awt.dnd.DragSource;
26 import java.awt.dnd.DragSourceDragEvent;
27 import java.awt.dnd.DragSourceDropEvent;
28 import java.awt.dnd.DragSourceEvent;
29 import java.awt.dnd.DragSourceListener;
30 import javax.swing.JTree;
31 import javax.swing.tree.DefaultTreeModel;
32 import javax.swing.tree.MutableTreeNode;
33 import javax.swing.tree.TreePath;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
68 public void dragEnter(@NotNull
final DragSourceDragEvent dsde) {
73 public void dragOver(@NotNull
final DragSourceDragEvent dsde) {
78 public void dropActionChanged(@NotNull
final DragSourceDragEvent dsde) {
83 public void dragExit(@NotNull
final DragSourceEvent dse) {
88 public void dragDropEnd(@NotNull
final DragSourceDropEvent dsde) {
93 if (dsde.getDropSuccess()) {
94 switch (dsde.getDropAction()) {
95 case DnDConstants.ACTION_COPY:
98 case DnDConstants.ACTION_MOVE:
116 final DragGestureListener dragGestureListener = dge -> {
117 final TreePath selectionPath =
tree.getSelectionPath();
118 if (selectionPath ==
null || selectionPath.getPathCount() <= 1) {
122 draggedTreeNode = (MutableTreeNode) selectionPath.getLastPathComponent();
124 switch (dge.getDragAction()) {
125 case DnDConstants.ACTION_COPY:
126 cursor = DragSource.DefaultCopyDrop;
129 case DnDConstants.ACTION_MOVE:
130 cursor = DragSource.DefaultMoveDrop;
138 dragSource.createDefaultDragGestureRecognizer(
tree, actions, dragGestureListener);