1 package org.catacomb.druid.swing;
2
3
4 import org.catacomb.druid.swing.dnd.DragAndDrop;
5 import org.catacomb.report.E;
6
7 import java.awt.Graphics;
8 import java.awt.Point;
9 import java.awt.Rectangle;
10 import java.awt.dnd.*;
11 import java.awt.image.BufferedImage;
12
13
14
15
16
17 public class DTreeDropTarget implements DropTargetListener {
18
19 DropTarget target;
20 DTree targetTree;
21 Rectangle dragBounds;
22
23
24 public DTreeDropTarget(DTree tree) {
25 targetTree = tree;
26 target = new DropTarget(targetTree, this);
27
28 }
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public void dragEnter(DropTargetDragEvent dtde) {
44
45 E.info("drag entered " + dtde);
46
47 dtde.rejectDrag();
48
49
50
51
52
53
54
55 }
56
57
58 public void dragOver(DropTargetDragEvent dtde) {
59
60
61 if (false) {
62
63 } else {
64
65 if (dragBounds != null) {
66 targetTree.paintImmediately(dragBounds);
67 } else {
68 dragBounds = new Rectangle();
69 }
70
71 Point p = dtde.getLocation();
72
73 Object obj = DragAndDrop.getDnD();
74
75 if (obj instanceof ImageDragSource) {
76 ImageDragSource ids = (ImageDragSource)obj;
77
78 BufferedImage bim = ids.getDragImage();
79 Point poff = ids.getDragImageOffset();
80
81 if (bim == null) {
82 E.warning("no drag image?");
83 } else {
84
85
86 dragBounds.setRect(p.x - poff.x, p.y - poff.y, bim.getWidth(), bim.getHeight());
87
88 Graphics g = targetTree.getGraphics();
89 g.drawImage(bim, (int)(dragBounds.getX()), (int)(dragBounds.getY()), null);
90 }
91 } else {
92 E.warning("wrong type of source " + obj);
93 }
94 }
95
96
97
98
99 dtde.rejectDrag();
100 }
101
102
103
104
105
106
107
108
109
110
111 public void dragExit(DropTargetEvent dte) {
112 if (dragBounds != null) {
113 targetTree.paintImmediately(dragBounds);
114 }
115 }
116
117
118
119 public void dropActionChanged(DropTargetDragEvent dtde) {
120 }
121
122
123 public void drop(DropTargetDropEvent dtde) {
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 }
145 }