OSDN Git Service

Imported GNU Classpath 0.90
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / awt / dnd / DropTarget.java
1 /* DropTarget.java -- 
2    Copyright (C) 2002, 2003, 2004  Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20
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.
25
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. */
37
38
39 package java.awt.dnd;
40
41 import java.awt.Component;
42 import java.awt.GraphicsEnvironment;
43 import java.awt.HeadlessException;
44 import java.awt.Point;
45 import java.awt.datatransfer.FlavorMap;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.io.Serializable;
49 import java.util.EventListener;
50 import java.util.TooManyListenersException;
51
52 /**
53  * @author Michael Koch
54  * @since 1.2
55  */
56 public class DropTarget
57   implements DropTargetListener, EventListener, Serializable
58 {
59   /**
60    * Compatible with JDK 1.2+
61    */
62   private static final long serialVersionUID = -6283860791671019047L;
63
64   protected static class DropTargetAutoScroller
65     implements ActionListener
66   {
67     private Component component;
68     private Point point;
69     
70     protected DropTargetAutoScroller (Component c, Point p)
71     {
72       component = c;
73       point = p;
74     }
75
76     protected void updateLocation (Point newLocn)
77     {
78       point = newLocn;
79     }
80
81     protected void stop ()
82     {
83     }
84
85     public void actionPerformed (ActionEvent e)
86     {
87     }
88   }
89
90   private Component component;
91   private FlavorMap flavorMap;
92   private int actions;
93   private DropTargetContext dropTargetContext;
94   private DropTargetListener dropTargetListener;
95   private boolean active = true;
96     
97   /**
98    * Creates a <code>DropTarget</code> object.
99    *
100    * @exception HeadlessException If GraphicsEnvironment.isHeadless()
101    * returns true.
102    */
103   public DropTarget ()
104   {
105     this (null, 0, null, true, null);
106   }
107   
108   /**
109    * Creates a <code>DropTarget</code> object.
110    *
111    * @exception HeadlessException If GraphicsEnvironment.isHeadless()
112    * returns true.
113    */
114   public DropTarget (Component c, DropTargetListener dtl)
115   {
116     this (c, 0, dtl, true, null);
117   }
118   
119   /**
120    * Creates a <code>DropTarget</code> object.
121    *
122    * @exception HeadlessException If GraphicsEnvironment.isHeadless()
123    * returns true.
124    */
125   public DropTarget (Component c, int i, DropTargetListener dtl)
126   {
127     this (c, i, dtl, true, null);
128   }
129   
130   /**
131    * Creates a <code>DropTarget</code> object.
132    *
133    * @exception HeadlessException If GraphicsEnvironment.isHeadless()
134    * returns true.
135    */
136   public DropTarget (Component c, int i, DropTargetListener dtl, boolean b)
137   {
138     this (c, i, dtl, b, null);
139   }
140   
141   /**
142    * Creates a <code>DropTarget</code> object.
143    *
144    * @exception HeadlessException If GraphicsEnvironment.isHeadless()
145    * returns true.
146    */
147   public DropTarget (Component c, int i, DropTargetListener dtl, boolean b,
148                      FlavorMap fm)
149   {
150     if (GraphicsEnvironment.isHeadless ())
151       throw new HeadlessException ();
152
153     component = c;
154     actions = i;
155     dropTargetListener = dtl;
156     flavorMap = fm;
157     
158     setActive (b);
159   }
160
161   /**
162    * Sets the component associated with this drop target object.
163    */
164   public void setComponent (Component c)
165   {
166     component = c;
167   }
168
169   /**
170    * Returns the component associated with this drop target object.
171    */
172   public Component getComponent ()
173   {
174     return component;
175   }
176
177   /**
178    * Sets the default actions.
179    */
180   public void setDefaultActions (int ops)
181   {
182     actions = ops;
183   }
184
185   /**
186    * Returns the default actions.
187    */
188   public int getDefaultActions ()
189   {
190     return actions;
191   }
192
193   public void setActive (boolean active)
194   {
195     this.active = active;
196   }
197
198   public boolean isActive()
199   {
200     return active;
201   }
202
203   /**
204    * Adds a new <code>DropTargetListener</code>.
205    * 
206    * @exception TooManyListenersException Sun's JDK does not, despite
207    * documentation, throw this exception here when you install an additional
208    * <code>DropTargetListener</code>.  So to be compatible, we do the same
209    * thing.
210    */
211   public void addDropTargetListener (DropTargetListener dtl)
212     throws TooManyListenersException
213   {
214     dropTargetListener = dtl;
215   }
216
217   public void removeDropTargetListener(DropTargetListener dtl)
218   {
219     // FIXME: Do we need to do something with dtl ?
220     dropTargetListener = null;
221   }
222
223   public void dragEnter(DropTargetDragEvent dtde)
224   {
225   }
226
227   public void dragOver(DropTargetDragEvent dtde)
228   {
229   }
230
231   public void dropActionChanged(DropTargetDragEvent dtde)
232   {
233   }
234
235   public void dragExit(DropTargetEvent dte)
236   {
237   }
238
239   public void drop(DropTargetDropEvent dtde)
240   {
241   }
242
243   public FlavorMap getFlavorMap()
244   {
245     return flavorMap;
246   }
247
248   public void setFlavorMap(FlavorMap fm)
249   {
250     flavorMap = fm;
251   }
252
253   public void addNotify(java.awt.peer.ComponentPeer peer)
254   {
255   }
256
257   public void removeNotify(java.awt.peer.ComponentPeer peer)
258   {
259   }
260
261   public DropTargetContext getDropTargetContext()
262   {
263     if (dropTargetContext == null)
264       dropTargetContext = createDropTargetContext ();
265     
266     return dropTargetContext;
267   }
268
269   protected DropTargetContext createDropTargetContext()
270   {
271     return new DropTargetContext (this);
272   }
273
274   protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller
275                                                        (Component c, Point p)
276   {
277     return new DropTarget.DropTargetAutoScroller (c, p);
278   }
279
280   protected void initializeAutoscrolling(Point p)
281   {
282   }
283
284   protected void updateAutoscroll(Point dragCursorLocn)
285   {
286   }
287
288   protected void clearAutoscroll()
289   {
290   }
291 } // class DropTarget