TreePath parentpath = targetTree.getClosestPathForLocation(pt.x, pt.y);
// For simplicity's sake, we'll assume that the tree uses the
// DefaultTreeModel
// and DefaultMutableTreeNode classes.
Node parent = (Node)parentpath.getLastPathComponent();
// Now check to see if it was dropped on a folder. If not, reject it.
if (parent instanceof PatternNode) {
dtde.rejectDrop();
return;
}
try {
// Grab the data.
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
if (tr.isDataFlavorSupported(flavors[i])) {
// It's a usable node, so pull it out of the transferable
// object and add it
// to our tree.
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
TreePath p = (TreePath)tr.getTransferData(flavors[i]);
Node node = (Node)p.getLastPathComponent();
YKDictionary dict = (YKDictionary)targetTree.getModel();
if (node instanceof PatternNode)
dict.addPattern((PatternNode)node, (CategoryNode)parent);
else if (node instanceof CategoryNode)
dict.addCategory((CategoryNode)node, (CategoryNode)parent);