1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57:
60: public class DragSource implements Serializable
61: {
62:
65: private static final long serialVersionUID = 6236096958971414066L;
66:
67: public static final Cursor DefaultCopyDrop = null;
68: public static final Cursor DefaultMoveDrop = null;
69: public static final Cursor DefaultLinkDrop = null;
70: public static final Cursor DefaultCopyNoDrop = null;
71: public static final Cursor DefaultMoveNoDrop = null;
72: public static final Cursor DefaultLinkNoDrop = null;
73:
74: private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap ();
75: private transient DragSourceListener dragSourceListener;
76: private transient DragSourceMotionListener dragSourceMotionListener;
77:
78: private static DragSource ds;
79: private DragSourceContextPeer peer;
80: private DragSourceContext context;
81:
82:
87: public DragSource()
88: {
89: if (GraphicsEnvironment.isHeadless())
90: {
91: ds = null;
92: throw new HeadlessException();
93: }
94: }
95:
96:
101: public static DragSource getDefaultDragSource()
102: {
103: if (GraphicsEnvironment.isHeadless())
104: {
105: ds = null;
106: throw new HeadlessException();
107: }
108:
109: if (ds == null)
110: ds = new DragSource();
111: return ds;
112: }
113:
114: public static boolean isDragImageSupported()
115: {
116:
117: return false;
118: }
119:
120:
127: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
128: Image dragImage, Point imageOffset,
129: Transferable trans, DragSourceListener dsl,
130: FlavorMap map)
131: {
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143: try
144: {
145: flavorMap = map;
146:
147: if (peer == null)
148: peer = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
149:
150: if (context == null)
151: context = createDragSourceContext(peer, trigger,
152: dragCursor,
153: dragImage,
154: imageOffset, trans,
155: dsl);
156:
157: if (peer == null)
158: throw new InvalidDnDOperationException();
159:
160: peer.startDrag(context, dragCursor, dragImage, imageOffset);
161: }
162: catch (Exception e)
163: {
164: throw new InvalidDnDOperationException("Drag and Drop system is "
165: + "unable to initiate a drag operation.");
166: }
167: }
168:
169:
176: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
177: Transferable trans, DragSourceListener dsl,
178: FlavorMap map)
179: {
180: startDrag(trigger, dragCursor, null, null, trans, dsl, map);
181: }
182:
183:
190: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
191: Image dragImage, Point imageOffset,
192: Transferable trans, DragSourceListener dsl)
193: {
194: startDrag(trigger, dragCursor, dragImage, imageOffset, trans, dsl, null);
195: }
196:
197:
204: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
205: Transferable trans, DragSourceListener dsl)
206: {
207: startDrag(trigger, dragCursor, null, null, trans, dsl, null);
208: }
209:
210:
216: protected DragSourceContext
217: createDragSourceContext(DragSourceContextPeer peer, DragGestureEvent dge,
218: Cursor cursor, Image image, Point offset,
219: Transferable t, DragSourceListener dsl)
220: {
221: return new DragSourceContext(peer, dge, cursor, image, offset, t, dsl);
222: }
223:
224: public FlavorMap getFlavorMap()
225: {
226: return flavorMap;
227: }
228:
229: public <T extends DragGestureRecognizer> T
230: createDragGestureRecognizer(Class<T> recognizer,
231: Component c,
232: int actions,
233: DragGestureListener dgl)
234: {
235: return (T) Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizer,
236: this, c,
237: actions, dgl);
238: }
239:
240: public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c,
241: int actions,
242: DragGestureListener dgl)
243: {
244: return createDragGestureRecognizer(MouseDragGestureRecognizer.class, c,
245: actions, dgl);
246: }
247:
248:
251: public void addDragSourceListener(DragSourceListener l)
252: {
253: DnDEventMulticaster.add (dragSourceListener, l);
254: }
255:
256:
259: public void removeDragSourceListener(DragSourceListener l)
260: {
261: DnDEventMulticaster.remove (dragSourceListener, l);
262: }
263:
264:
267: public DragSourceListener[] getDragSourceListeners()
268: {
269: return (DragSourceListener[]) getListeners (DragSourceListener.class);
270: }
271:
272:
275: public void addDragSourceMotionListener(DragSourceMotionListener l)
276: {
277: DnDEventMulticaster.add (dragSourceMotionListener, l);
278: }
279:
280:
283: public void removeDragSourceMotionListener(DragSourceMotionListener l)
284: {
285: DnDEventMulticaster.remove (dragSourceMotionListener, l);
286: }
287:
288:
291: public DragSourceMotionListener[] getDragSourceMotionListeners ()
292: {
293: return (DragSourceMotionListener[]) getListeners
294: (DragSourceMotionListener.class);
295: }
296:
297:
300: public <T extends EventListener> T[] getListeners (Class<T> listenerType)
301: {
302: if (listenerType == DragSourceListener.class)
303: return DnDEventMulticaster.getListeners (dragSourceListener,
304: listenerType);
305:
306: if (listenerType == DragSourceMotionListener.class)
307: return DnDEventMulticaster.getListeners (dragSourceMotionListener,
308: listenerType);
309:
310:
311: return (T[]) new EventListener [0];
312: }
313:
314:
320: public static int getDragThreshold()
321: throws NotImplementedException
322: {
323:
324: return 8;
325: }
326: }