2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / dnd / DragSource.java
blob6ce93be277cfb209372114ff9aeca59487f6eacd
1 /* DragSource.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.dnd;
41 import java.awt.Component;
42 import java.awt.Cursor;
43 import java.awt.GraphicsEnvironment;
44 import java.awt.HeadlessException;
45 import java.awt.Image;
46 import java.awt.Point;
47 import java.awt.Toolkit;
48 import java.awt.datatransfer.FlavorMap;
49 import java.awt.datatransfer.SystemFlavorMap;
50 import java.awt.datatransfer.Transferable;
51 import java.awt.dnd.peer.DragSourceContextPeer;
52 import java.io.Serializable;
53 import java.util.EventListener;
55 /**
56 * @since 1.2
58 public class DragSource implements Serializable
60 /**
61 * Compatible with JDK 1.2+.
63 private static final long serialVersionUID = 6236096958971414066L;
65 public static final Cursor DefaultCopyDrop = null;
66 public static final Cursor DefaultMoveDrop = null;
67 public static final Cursor DefaultLinkDrop = null;
68 public static final Cursor DefaultCopyNoDrop = null;
69 public static final Cursor DefaultMoveNoDrop = null;
70 public static final Cursor DefaultLinkNoDrop = null;
72 private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap ();
74 private transient DragSourceListener dragSourceListener;
75 private transient DragSourceMotionListener dragSourceMotionListener;
77 /**
78 * Initializes the drag source.
80 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
82 public DragSource()
84 if (GraphicsEnvironment.isHeadless())
85 throw new HeadlessException ();
88 /**
89 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
91 public static DragSource getDefaultDragSource()
93 return null;
96 public static boolean isDragImageSupported()
98 return false;
102 * Start a drag, given the DragGestureEvent that initiated the drag.
104 * @exception InvalidDnDOperationException If the Drag and Drop system is
105 * unable to initiate a drag operation, or if the user attempts to start
106 * a drag while an existing drag operation is still executing.
108 public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
109 Image dragImage, Point imageOffset,
110 Transferable trans, DragSourceListener dsl,
111 FlavorMap map)
116 * Start a drag, given the DragGestureEvent that initiated the drag.
118 * @exception InvalidDnDOperationException If the Drag and Drop system is
119 * unable to initiate a drag operation, or if the user attempts to start
120 * a drag while an existing drag operation is still executing.
122 public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
123 Transferable trans, DragSourceListener dsl,
124 FlavorMap map)
126 startDrag(trigger, dragCursor, null, null, trans, dsl, map);
130 * Start a drag, given the DragGestureEvent that initiated the drag.
132 * @exception InvalidDnDOperationException If the Drag and Drop system is
133 * unable to initiate a drag operation, or if the user attempts to start
134 * a drag while an existing drag operation is still executing.
136 public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
137 Image dragImage, Point imageOffset,
138 Transferable trans, DragSourceListener dsl)
140 startDrag(trigger, dragCursor, dragImage, imageOffset, trans, dsl, null);
144 * Start a drag, given the DragGestureEvent that initiated the drag.
146 * @exception InvalidDnDOperationException If the Drag and Drop system is
147 * unable to initiate a drag operation, or if the user attempts to start
148 * a drag while an existing drag operation is still executing.
150 public void startDrag(DragGestureEvent trigger, Cursor dragCursor,
151 Transferable trans, DragSourceListener dsl)
153 startDrag(trigger, dragCursor, null, null, trans, dsl, null);
157 * Creates the DragSourceContext to handle this drag.
159 * @exception IllegalArgumentException FIXME
160 * @exception NullPointerException If dscp, dgl, dragImage or t is null.
162 protected DragSourceContext
163 createDragSourceContext(DragSourceContextPeer peer, DragGestureEvent dge,
164 Cursor cursor, Image image, Point offset,
165 Transferable t, DragSourceListener dsl)
167 return null;
170 public FlavorMap getFlavorMap()
172 return flavorMap;
175 public DragGestureRecognizer
176 createDragGestureRecognizer(Class recognizer, Component c, int actions,
177 DragGestureListener dgl)
179 return Toolkit.getDefaultToolkit ()
180 .createDragGestureRecognizer (recognizer, this, c, actions,
181 dgl);
184 public DragGestureRecognizer
185 createDefaultDragGestureRecognizer(Component c, int actions,
186 DragGestureListener dgl)
188 return createDragGestureRecognizer (MouseDragGestureRecognizer.class, c,
189 actions, dgl);
193 * @since 1.4
195 public void addDragSourceListener(DragSourceListener l)
197 DnDEventMulticaster.add (dragSourceListener, l);
201 * @since 1.4
203 public void removeDragSourceListener(DragSourceListener l)
205 DnDEventMulticaster.remove (dragSourceListener, l);
209 * @since 1.4
211 public DragSourceListener[] getDragSourceListeners()
213 return (DragSourceListener[]) getListeners (DragSourceListener.class);
217 * @since 1.4
219 public void addDragSourceMotionListener(DragSourceMotionListener l)
221 DnDEventMulticaster.add (dragSourceMotionListener, l);
225 * @since 1.4
227 public void removeDragSourceMotionListener(DragSourceMotionListener l)
229 DnDEventMulticaster.remove (dragSourceMotionListener, l);
233 * @since 1.4
235 public DragSourceMotionListener[] getDragSourceMotionListeners ()
237 return (DragSourceMotionListener[]) getListeners
238 (DragSourceMotionListener.class);
242 * @since 1.4
244 public EventListener[] getListeners (Class listenerType)
246 if (listenerType == DragSourceListener.class)
247 return DnDEventMulticaster.getListeners (dragSourceListener,
248 listenerType);
250 if (listenerType == DragSourceMotionListener.class)
251 return DnDEventMulticaster.getListeners (dragSourceMotionListener,
252 listenerType);
254 // Return an empty EventListener array.
255 return new EventListener [0];
257 } // class DragSource