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: throws NotImplementedException
116: {
117:
118: return false;
119: }
120:
121:
128: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
129: Image dragImage, Point imageOffset,
130: Transferable trans, DragSourceListener dsl,
131: FlavorMap map)
132: {
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146: try
147: {
148: flavorMap = map;
149:
150: if (peer == null)
151: peer = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
152:
153: if (context == null)
154: context = createDragSourceContext(peer, trigger,
155: dragCursor,
156: dragImage,
157: imageOffset, trans,
158: dsl);
159:
160: if (peer == null)
161: throw new InvalidDnDOperationException();
162:
163: peer.startDrag(context, dragCursor, dragImage, imageOffset);
164: }
165: catch (Exception e)
166: {
167: throw new InvalidDnDOperationException("Drag and Drop system is "
168: + "unable to initiate a drag operation.");
169: }
170: }
171:
172:
179: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
180: Transferable trans, DragSourceListener dsl,
181: FlavorMap map)
182: {
183: startDrag(trigger, dragCursor, null, null, trans, dsl, map);
184: }
185:
186:
193: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
194: Image dragImage, Point imageOffset,
195: Transferable trans, DragSourceListener dsl)
196: {
197: startDrag(trigger, dragCursor, dragImage, imageOffset, trans, dsl, null);
198: }
199:
200:
207: public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
208: Transferable trans, DragSourceListener dsl)
209: {
210: startDrag(trigger, dragCursor, null, null, trans, dsl, null);
211: }
212:
213:
219: protected DragSourceContext
220: createDragSourceContext(DragSourceContextPeer peer, DragGestureEvent dge,
221: Cursor cursor, Image image, Point offset,
222: Transferable t, DragSourceListener dsl)
223: {
224: return new DragSourceContext(peer, dge, cursor, image, offset, t, dsl);
225: }
226:
227: public FlavorMap getFlavorMap()
228: {
229: return flavorMap;
230: }
231:
232: public DragGestureRecognizer createDragGestureRecognizer(Class recognizer,
233: Component c,
234: int actions,
235: DragGestureListener dgl)
236: {
237: return Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizer,
238: this, c,
239: actions, dgl);
240: }
241:
242: public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c,
243: int actions,
244: DragGestureListener dgl)
245: {
246: return createDragGestureRecognizer(MouseDragGestureRecognizer.class, c,
247: actions, dgl);
248: }
249:
250:
253: public void addDragSourceListener(DragSourceListener l)
254: {
255: DnDEventMulticaster.add (dragSourceListener, l);
256: }
257:
258:
261: public void removeDragSourceListener(DragSourceListener l)
262: {
263: DnDEventMulticaster.remove (dragSourceListener, l);
264: }
265:
266:
269: public DragSourceListener[] getDragSourceListeners()
270: {
271: return (DragSourceListener[]) getListeners (DragSourceListener.class);
272: }
273:
274:
277: public void addDragSourceMotionListener(DragSourceMotionListener l)
278: {
279: DnDEventMulticaster.add (dragSourceMotionListener, l);
280: }
281:
282:
285: public void removeDragSourceMotionListener(DragSourceMotionListener l)
286: {
287: DnDEventMulticaster.remove (dragSourceMotionListener, l);
288: }
289:
290:
293: public DragSourceMotionListener[] getDragSourceMotionListeners ()
294: {
295: return (DragSourceMotionListener[]) getListeners
296: (DragSourceMotionListener.class);
297: }
298:
299:
302: public EventListener[] getListeners (Class listenerType)
303: {
304: if (listenerType == DragSourceListener.class)
305: return DnDEventMulticaster.getListeners (dragSourceListener,
306: listenerType);
307:
308: if (listenerType == DragSourceMotionListener.class)
309: return DnDEventMulticaster.getListeners (dragSourceMotionListener,
310: listenerType);
311:
312:
313: return new EventListener [0];
314: }
315:
316:
322: public static int getDragThreshold()
323: throws NotImplementedException
324: {
325:
326: return 4;
327: }
328: }