1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 /***
32 *
33 */
34 package org.mlc.swing.layout;
35
36 import java.awt.dnd.DnDConstants;
37 import java.awt.dnd.DragGestureEvent;
38 import java.awt.dnd.DragGestureListener;
39 import java.awt.dnd.DragSource;
40 import java.awt.dnd.DragSourceListener;
41 import java.awt.event.MouseEvent;
42
43 import javax.swing.JList;
44 import javax.swing.ListModel;
45 import javax.swing.ListSelectionModel;
46
47 class DndList extends JList implements DragSourceListener,
48 DragGestureListener
49 {
50 /***
51 *
52 */
53 private final FormEditor editor;
54 private static final long serialVersionUID = 1L;
55 protected DragSource fDragSource = null;
56
57 public DndList(FormEditor editor, ListModel listModel)
58 {
59 super(listModel);
60 this.editor = editor;
61 fDragSource = new DragSource();
62 this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
63
64
65
66
67
68
69
70
71
72 this.editor.setAutoscrolls(false);
73 fDragSource.createDefaultDragGestureRecognizer(this,
74 DnDConstants.ACTION_MOVE, this);
75 }
76
77 public void dragDropEnd(java.awt.dnd.DragSourceDropEvent dragSourceDropEvent)
78 {
79 }
80
81 public void dragEnter(java.awt.dnd.DragSourceDragEvent dragSourceDragEvent)
82 {
83 }
84
85 public void dragExit(java.awt.dnd.DragSourceEvent dragSourceEvent)
86 {
87 }
88
89 public void dragOver(java.awt.dnd.DragSourceDragEvent dragSourceDragEvent)
90 {
91 }
92
93 public void dropActionChanged(
94 java.awt.dnd.DragSourceDragEvent dragSourceDragEvent)
95 {
96 }
97
98 public void dragGestureRecognized(DragGestureEvent event)
99 {
100 int dragIndex = locationToIndex(event.getDragOrigin());
101 if (dragIndex >= 0)
102 {
103 Object draggingComponent = this.getModel().getElementAt(
104 dragIndex);
105 event.startDrag(java.awt.dnd.DragSource.DefaultCopyDrop,
106 new TransferableWrapper(draggingComponent), this);
107 }
108 }
109
110 public String getToolTipText(MouseEvent evt)
111 {
112
113
114 int index = locationToIndex(evt.getPoint());
115 if ( index == -1 )
116 return "";
117
118
119 Object o = this.getModel().getElementAt(index);
120 if ( o instanceof ComponentDef )
121 {
122 ComponentDef thisItem = (ComponentDef) o;
123 return thisItem.getDescription();
124 }
125 return "";
126 }
127
128 public void drop(java.awt.dnd.DropTargetDropEvent e)
129 {
130 }
131 }