1 package org.catacomb.druid.swing.dnd;
2
3 import java.awt.Point;
4 import java.awt.datatransfer.DataFlavor;
5 import java.awt.datatransfer.Transferable;
6 import java.awt.datatransfer.UnsupportedFlavorException;
7 import java.awt.image.BufferedImage;
8 import java.io.IOException;
9
10 import javax.swing.tree.TreePath;
11
12
13 public class DdndTransferable implements Transferable {
14
15
16 BufferedImage dragImage;
17 Point dragOffset;
18
19
20
21
22 public final static DataFlavor TREE_PATH_FLAVOR = new DataFlavor(TreePath.class,
23 "Tree Path");
24
25 DataFlavor flavors[] = { TREE_PATH_FLAVOR };
26
27 TreePath path;
28
29 public DdndTransferable(TreePath tp) {
30 path = tp;
31 }
32
33 public synchronized DataFlavor[] getTransferDataFlavors() {
34 return flavors;
35 }
36
37 public boolean isDataFlavorSupported(DataFlavor flavor) {
38 return (flavor.getRepresentationClass() == TreePath.class);
39 }
40
41 public synchronized Object getTransferData(DataFlavor flavor)
42 throws UnsupportedFlavorException, IOException {
43 if (isDataFlavorSupported(flavor)) {
44 return path;
45 } else {
46 throw new UnsupportedFlavorException(flavor);
47 }
48 }
49
50 public void setDragImage(BufferedImage dragImg, Point imgOffset) {
51 dragImage = dragImg;
52 dragOffset = imgOffset;
53
54 }
55
56
57 public BufferedImage getDragImage() {
58 return dragImage;
59 }
60
61 public Point getDragImageOffset() {
62 return dragOffset;
63 }
64
65
66
67
68 }
69