01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.dnd.*;
05: import javax.swing.*;
06:
07: import abbot.Log;
08:
09: public class DropLabel extends JLabel {
10: /** Target received drag. */
11: public volatile boolean dragEntered = false;
12: /** Target accepted the drop. */
13: public volatile boolean dropAccepted = false;
14: private DropTarget dropTarget = null;
15: private DropTargetListener dtl = null;
16: private boolean acceptDrops = false;
17:
18: public DropLabel(String name) {
19: this (name, true);
20: }
21:
22: public DropLabel(String name, boolean accept) {
23: super (name);
24: setName("DropLabel");
25: acceptDrops = accept;
26: dtl = new DropTargetListener() {
27: public void dragEnter(DropTargetDragEvent e) {
28: Log.debug("Drag enter (target) "
29: + DropLabel.this .getName());
30: dragEntered = true;
31: if (acceptDrops) {
32: setForeground(Color.blue);
33: paintImmediately(getBounds());
34: }
35: }
36:
37: public void dragOver(DropTargetDragEvent e) {
38: Log.debug("Drag over (target) "
39: + DropLabel.this .getName());
40: if (acceptDrops)
41: e.acceptDrag(e.getDropAction());
42: }
43:
44: public void dragExit(DropTargetEvent e) {
45: Log.debug("Drag exit (target)"
46: + DropLabel.this .getName());
47: if (acceptDrops) {
48: setForeground(Color.black);
49: paintImmediately(getBounds());
50: }
51: }
52:
53: public void dropActionChanged(DropTargetDragEvent e) {
54: Log.debug("Drop action changed (target)");
55: if (acceptDrops)
56: e.acceptDrag(e.getDropAction());
57: }
58:
59: public void drop(DropTargetDropEvent e) {
60: Log.debug("Drop accepted (target)");
61: if (acceptDrops) {
62: e.acceptDrop(e.getDropAction());
63: e.dropComplete(true);
64: dropAccepted = true;
65: setForeground(Color.black);
66: paintImmediately(getBounds());
67: }
68: }
69: };
70: dropTarget = new DropTarget(this ,
71: DnDConstants.ACTION_COPY_OR_MOVE, dtl, true);
72: }
73:
74: }
|