KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > dnd > DropTarget


1 /*
2  * @(#)DropTarget.java 1.48 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt.dnd;
9
10 import java.util.TooManyListenersException JavaDoc;
11
12 import java.io.IOException JavaDoc;
13 import java.io.ObjectInputStream JavaDoc;
14 import java.io.ObjectOutputStream JavaDoc;
15 import java.io.Serializable JavaDoc;
16
17 import java.awt.AWTEvent JavaDoc;
18 import java.awt.Component JavaDoc;
19 import java.awt.Dimension JavaDoc;
20 import java.awt.GraphicsEnvironment JavaDoc;
21 import java.awt.HeadlessException JavaDoc;
22 import java.awt.Insets JavaDoc;
23 import java.awt.Point JavaDoc;
24 import java.awt.Rectangle JavaDoc;
25 import java.awt.Toolkit JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.awt.datatransfer.FlavorMap JavaDoc;
29 import java.awt.datatransfer.SystemFlavorMap JavaDoc;
30 import javax.swing.Timer JavaDoc;
31 import java.awt.peer.ComponentPeer;
32 import java.awt.peer.LightweightPeer;
33 import java.awt.dnd.peer.DropTargetPeer;
34
35
36 /**
37  * The <code>DropTarget</code> is associated
38  * with a <code>Component</code> when that <code>Component</code>
39  * wishes
40  * to accept drops during Drag and Drop operations.
41  * <P>
42  * Each
43  * <code>DropTarget</code> is associated with a <code>FlavorMap</code>.
44  * The default <code>FlavorMap</code> hereafter designates the
45  * <code>FlavorMap</code> returned by <code>SystemFlavorMap.getDefaultFlavorMap()</code>.
46  *
47  * @version 1.48, 12/19/03
48  * @since 1.2
49  */

50
51 public class DropTarget implements DropTargetListener JavaDoc, Serializable JavaDoc {
52
53     private static final long serialVersionUID = -6283860791671019047L;
54
55     /**
56      * Creates a new DropTarget given the <code>Component</code>
57      * to associate itself with, an <code>int</code> representing
58      * the default acceptable action(s) to
59      * support, a <code>DropTargetListener</code>
60      * to handle event processing, a <code>boolean</code> indicating
61      * if the <code>DropTarget</code> is currently accepting drops, and
62      * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
63      * <P>
64      * The Component will receive drops only if it is enabled.
65      * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
66      * @param ops The default acceptable actions for this <code>DropTarget</code>
67      * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
68      * @param act Is the <code>DropTarget</code> accepting drops.
69      * @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
70      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
71      * returns true
72      * @see java.awt.GraphicsEnvironment#isHeadless
73      */

74     public DropTarget(Component JavaDoc c, int ops, DropTargetListener JavaDoc dtl,
75               boolean act, FlavorMap JavaDoc fm)
76         throws HeadlessException JavaDoc
77     {
78         if (GraphicsEnvironment.isHeadless()) {
79             throw new HeadlessException JavaDoc();
80         }
81
82     component = c;
83
84     setDefaultActions(ops);
85
86     if (dtl != null) try {
87         addDropTargetListener(dtl);
88     } catch (TooManyListenersException JavaDoc tmle) {
89         // do nothing!
90
}
91
92     if (c != null) {
93         c.setDropTarget(this);
94         setActive(act);
95     }
96
97         if (fm != null) flavorMap = fm;
98     }
99
100     /**
101      * Creates a <code>DropTarget</code> given the <code>Component</code>
102      * to associate itself with, an <code>int</code> representing
103      * the default acceptable action(s)
104      * to support, a <code>DropTargetListener</code>
105      * to handle event processing, and a <code>boolean</code> indicating
106      * if the <code>DropTarget</code> is currently accepting drops.
107      * <P>
108      * The Component will receive drops only if it is enabled.
109      * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
110      * @param ops The default acceptable actions for this <code>DropTarget</code>
111      * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
112      * @param act Is the <code>DropTarget</code> accepting drops.
113      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
114      * returns true
115      * @see java.awt.GraphicsEnvironment#isHeadless
116      */

117     public DropTarget(Component JavaDoc c, int ops, DropTargetListener JavaDoc dtl,
118               boolean act)
119         throws HeadlessException JavaDoc
120     {
121     this(c, ops, dtl, act, null);
122     }
123
124     /**
125      * Creates a <code>DropTarget</code>.
126      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
127      * returns true
128      * @see java.awt.GraphicsEnvironment#isHeadless
129      */

130     public DropTarget() throws HeadlessException JavaDoc {
131     this(null, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null);
132     }
133
134     /**
135      * Creates a <code>DropTarget</code> given the <code>Component</code>
136      * to associate itself with, and the <code>DropTargetListener</code>
137      * to handle event processing.
138      * <P>
139      * The Component will receive drops only if it is enabled.
140      * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
141      * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
142      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
143      * returns true
144      * @see java.awt.GraphicsEnvironment#isHeadless
145      */

146     public DropTarget(Component JavaDoc c, DropTargetListener JavaDoc dtl)
147         throws HeadlessException JavaDoc
148     {
149     this(c, DnDConstants.ACTION_COPY_OR_MOVE, dtl, true, null);
150     }
151
152     /**
153      * Creates a <code>DropTarget</code> given the <code>Component</code>
154      * to associate itself with, an <code>int</code> representing
155      * the default acceptable action(s) to support, and a
156      * <code>DropTargetListener</code> to handle event processing.
157      * <P>
158      * The Component will receive drops only if it is enabled.
159      * @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
160      * @param ops The default acceptable actions for this <code>DropTarget</code>
161      * @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
162      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
163      * returns true
164      * @see java.awt.GraphicsEnvironment#isHeadless
165      */

166     public DropTarget(Component JavaDoc c, int ops, DropTargetListener JavaDoc dtl)
167         throws HeadlessException JavaDoc
168     {
169     this(c, ops, dtl, true);
170     }
171
172     /**
173      * Note: this interface is required to permit the safe association
174      * of a DropTarget with a Component in one of two ways, either:
175      * <code> component.setDropTarget(droptarget); </code>
176      * or <code> droptarget.setComponent(component); </code>
177      * <P>
178      * The Component will receive drops only if it is enabled.
179      * @param c The new <code>Component</code> this <code>DropTarget</code>
180      * is to be associated with.<P>
181      */

182
183     public synchronized void setComponent(Component JavaDoc c) {
184     if (component == c || component != null && component.equals(c))
185         return;
186     
187     Component JavaDoc old;
188     ComponentPeer oldPeer = null;
189
190     if ((old = component) != null) {
191         clearAutoscroll();
192
193         component = null;
194
195         if (componentPeer != null) {
196         oldPeer = componentPeer;
197         removeNotify(componentPeer);
198         }
199
200         old.setDropTarget(null);
201
202     }
203
204     if ((component = c) != null) try {
205         c.setDropTarget(this);
206     } catch (Exception JavaDoc e) { // undo the change
207
if (old != null) {
208         old.setDropTarget(this);
209         addNotify(oldPeer);
210         }
211     }
212     }
213
214     /**
215      * Gets the <code>Component</code> associated
216      * with this <code>DropTarget</code>.
217      * <P>
218      * @return the current </code>Component</code>
219      */

220
221     public synchronized Component JavaDoc getComponent() {
222     return component;
223     }
224
225     /**
226      * Sets the default acceptable actions for this <code>DropTarget</code>
227      * <P>
228      * @param ops the default actions
229      * <P>
230      * @see java.awt.dnd.DnDConstants
231      */

232
233     public void setDefaultActions(int ops) {
234         getDropTargetContext().setTargetActions(ops & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE));
235     }
236
237     /*
238      * Called by DropTargetContext.setTargetActions()
239      * with appropriate synchronization.
240      */

241     void doSetDefaultActions(int ops) {
242         actions = ops;
243     }
244
245     /**
246      * Gets an <code>int</code> representing the
247      * current action(s) supported by this <code>DropTarget</code>.
248      * <P>
249      * @return the current default actions
250      */

251
252     public int getDefaultActions() {
253     return actions;
254     }
255
256     /**
257      * Sets the DropTarget active if <code>true</code>,
258      * inactive if <code>false</code>.
259      * <P>
260      * @param isActive sets the <code>DropTarget</code> (in)active.
261      */

262
263     public synchronized void setActive(boolean isActive) {
264     if (isActive != active) {
265         active = isActive;
266     }
267
268     if (!active) clearAutoscroll();
269     }
270
271     /**
272      * Reports whether or not
273      * this <code>DropTarget</code>
274      * is currently active (ready to accept drops).
275      * <P>
276      * @return <CODE>true</CODE> if active, <CODE>false</CODE> if not
277      */

278
279     public boolean isActive() {
280     return active;
281     }
282
283     /**
284      * Adds a new <code>DropTargetListener</code> (UNICAST SOURCE).
285      * <P>
286      * @param dtl The new <code>DropTargetListener</code>
287      * <P>
288      * @throws <code>TooManyListenersException</code> if a
289      * <code>DropTargetListener</code> is already added to this
290      * <code>DropTarget</code>.
291      */

292
293     public synchronized void addDropTargetListener(DropTargetListener JavaDoc dtl) throws TooManyListenersException JavaDoc {
294     if (dtl == null) return;
295
296     if (equals(dtl)) throw new IllegalArgumentException JavaDoc("DropTarget may not be its own Listener");
297
298     if (dtListener == null)
299         dtListener = dtl;
300     else
301         throw new TooManyListenersException JavaDoc();
302     }
303
304     /**
305      * Removes the current <code>DropTargetListener</code> (UNICAST SOURCE).
306      * <P>
307      * @param dtl the DropTargetListener to deregister.
308      */

309
310     public synchronized void removeDropTargetListener(DropTargetListener JavaDoc dtl) {
311     if (dtl != null && dtListener != null) {
312         if(dtListener.equals(dtl))
313         dtListener = null;
314         else
315         throw new IllegalArgumentException JavaDoc("listener mismatch");
316     }
317     }
318
319     /**
320      * Calls <code>dragEnter</code> on the registered
321      * <code>DropTargetListener</code> and passes it
322      * the specified <code>DropTargetDragEvent</code>.
323      * Has no effect if this <code>DropTarget</code>
324      * is not active.
325      *
326      * @param dtde the <code>DropTargetDragEvent</code>
327      *
328      * @throws NullPointerException if this <code>DropTarget</code>
329      * is active and <code>dtde</code> is <code>null</code>
330      *
331      * @see #isActive
332      */

333     public synchronized void dragEnter(DropTargetDragEvent JavaDoc dtde) {
334     if (!active) return;
335
336     if (dtListener != null) {
337         dtListener.dragEnter(dtde);
338     } else
339             dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE);
340
341     initializeAutoscrolling(dtde.getLocation());
342     }
343
344     /**
345      * Calls <code>dragOver</code> on the registered
346      * <code>DropTargetListener</code> and passes it
347      * the specified <code>DropTargetDragEvent</code>.
348      * Has no effect if this <code>DropTarget</code>
349      * is not active.
350      *
351      * @param dtde the <code>DropTargetDragEvent</code>
352      *
353      * @throws NullPointerException if this <code>DropTarget</code>
354      * is active and <code>dtde</code> is <code>null</code>
355      *
356      * @see #isActive
357      */

358     public synchronized void dragOver(DropTargetDragEvent JavaDoc dtde) {
359     if (!active) return;
360
361     if (dtListener != null && active) dtListener.dragOver(dtde);
362
363     updateAutoscroll(dtde.getLocation());
364     }
365
366     /**
367      * Calls <code>dropActionChanged</code> on the registered
368      * <code>DropTargetListener</code> and passes it
369      * the specified <code>DropTargetDragEvent</code>.
370      * Has no effect if this <code>DropTarget</code>
371      * is not active.
372      *
373      * @param dtde the <code>DropTargetDragEvent</code>
374      *
375      * @throws NullPointerException if this <code>DropTarget</code>
376      * is active and <code>dtde</code> is <code>null</code>
377      *
378      * @see #isActive
379      */

380     public synchronized void dropActionChanged(DropTargetDragEvent JavaDoc dtde) {
381     if (!active) return;
382
383     if (dtListener != null) dtListener.dropActionChanged(dtde);
384
385     updateAutoscroll(dtde.getLocation());
386     }
387
388     /**
389      * Calls <code>dragExit</code> on the registered
390      * <code>DropTargetListener</code> and passes it
391      * the specified <code>DropTargetEvent</code>.
392      * Has no effect if this <code>DropTarget</code>
393      * is not active.
394      * <p>
395      * This method itself does not throw any exception
396      * for null parameter but for exceptions thrown by
397      * the respective method of the listener.
398      *
399      * @param dte the <code>DropTargetEvent</code>
400      *
401      * @see #isActive
402      */

403     public synchronized void dragExit(DropTargetEvent JavaDoc dte) {
404     if (!active) return;
405
406     if (dtListener != null && active) dtListener.dragExit(dte);
407
408     clearAutoscroll();
409     }
410
411     /**
412      * Calls <code>drop</code> on the registered
413      * <code>DropTargetListener</code> and passes it
414      * the specified <code>DropTargetDropEvent</code>
415      * if this <code>DropTarget</code> is active.
416      *
417      * @param dtde the <code>DropTargetDropEvent</code>
418      *
419      * @throws NullPointerException if <code>dtde</code> is null
420      * and at least one of the following is true: this
421      * <code>DropTarget</code> is not active, or there is
422      * no a <code>DropTargetListener</code> registered.
423      *
424      * @see #isActive
425      */

426     public synchronized void drop(DropTargetDropEvent JavaDoc dtde) {
427     clearAutoscroll();
428
429     if (dtListener != null && active)
430         dtListener.drop(dtde);
431     else { // we should'nt get here ...
432
dtde.rejectDrop();
433     }
434     }
435
436     /**
437      * Gets the <code>FlavorMap</code>
438      * associated with this <code>DropTarget</code>.
439      * If no <code>FlavorMap</code> has been set for this
440      * <code>DropTarget</code>, it is associated with the default
441      * <code>FlavorMap</code>.
442      * <P>
443      * @return the FlavorMap for this DropTarget
444      */

445
446     public FlavorMap JavaDoc getFlavorMap() { return flavorMap; }
447
448     /**
449      * Sets the <code>FlavorMap</code> associated
450      * with this <code>DropTarget</code>.
451      * <P>
452      * @param fm the new <code>FlavorMap</code>, or null to
453      * associate the default FlavorMap with this DropTarget.
454      */

455
456     public void setFlavorMap(FlavorMap JavaDoc fm) {
457         flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
458     }
459
460     /**
461      * Notify the DropTarget that it has been associated with a Component
462      *
463      **********************************************************************
464      * This method is usually called from java.awt.Component.addNotify() of
465      * the Component associated with this DropTarget to notify the DropTarget
466      * that a ComponentPeer has been associated with that Component.
467      *
468      * Calling this method, other than to notify this DropTarget of the
469      * association of the ComponentPeer with the Component may result in
470      * a malfunction of the DnD system.
471      **********************************************************************
472      * <P>
473      * @param peer The Peer of the Component we are associated with!
474      *
475      */

476
477     public void addNotify(ComponentPeer peer) {
478     if (peer == componentPeer) return;
479
480     componentPeer = peer;
481
482         for (Component JavaDoc c = component;
483              c != null && peer instanceof LightweightPeer; c = c.getParent()) {
484             peer = c.getPeer();
485         }
486
487         if (peer instanceof DropTargetPeer) {
488             nativePeer = peer;
489             ((DropTargetPeer)peer).addDropTarget(this);
490         } else {
491             nativePeer = null;
492         }
493     }
494
495     /**
496      * Notify the DropTarget that it has been disassociated from a Component
497      *
498      **********************************************************************
499      * This method is usually called from java.awt.Component.removeNotify() of
500      * the Component associated with this DropTarget to notify the DropTarget
501      * that a ComponentPeer has been disassociated with that Component.
502      *
503      * Calling this method, other than to notify this DropTarget of the
504      * disassociation of the ComponentPeer from the Component may result in
505      * a malfunction of the DnD system.
506      **********************************************************************
507      * <P>
508      * @param peer The Peer of the Component we are being disassociated from!
509      */

510
511     public void removeNotify(ComponentPeer peer) {
512     if (nativePeer != null)
513         ((DropTargetPeer)nativePeer).removeDropTarget(this);
514
515     componentPeer = nativePeer = null;
516     }
517
518     /**
519      * Gets the <code>DropTargetContext</code> associated
520      * with this <code>DropTarget</code>.
521      * <P>
522      * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
523      */

524
525     public DropTargetContext JavaDoc getDropTargetContext() {
526     return dropTargetContext;
527     }
528
529     /**
530      * Creates the DropTargetContext associated with this DropTarget.
531      * Subclasses may override this method to instantiate their own
532      * DropTargetContext subclass.
533      *
534      * This call is typically *only* called by the platform's
535      * DropTargetContextPeer as a drag operation encounters this
536      * DropTarget. Accessing the Context while no Drag is current
537      * has undefined results.
538      */

539
540     protected DropTargetContext JavaDoc createDropTargetContext() {
541     return new DropTargetContext JavaDoc(this);
542     }
543
544     /**
545      * Serializes this <code>DropTarget</code>. Performs default serialization,
546      * and then writes out this object's <code>DropTargetListener</code> if and
547      * only if it can be serialized. If not, <code>null</code> is written
548      * instead.
549      *
550      * @serialData The default serializable fields, in alphabetical order,
551      * followed by either a <code>DropTargetListener</code>
552      * instance, or <code>null</code>.
553      * @since 1.4
554      */

555     private void writeObject(ObjectOutputStream JavaDoc s) throws IOException JavaDoc {
556         s.defaultWriteObject();
557
558         s.writeObject(SerializationTester.test(dtListener)
559                       ? dtListener : null);
560     }
561
562     /**
563      * Deserializes this <code>DropTarget</code>. This method first performs
564      * default deserialization for all non-<code>transient</code> fields. An
565      * attempt is then made to deserialize this object's
566      * <code>DropTargetListener</code> as well. This is first attempted by
567      * deserializing the field <code>dtListener</code>, because, in releases
568      * prior to 1.4, a non-<code>transient</code> field of this name stored the
569      * <code>DropTargetListener</code>. If this fails, the next object in the
570      * stream is used instead.
571      *
572      * @since 1.4
573      */

574     private void readObject(ObjectInputStream JavaDoc s)
575         throws ClassNotFoundException JavaDoc, IOException JavaDoc
576     {
577         ObjectInputStream.GetField JavaDoc f = s.readFields();
578
579         try {
580             dropTargetContext =
581                 (DropTargetContext JavaDoc)f.get("dropTargetContext", null);
582         } catch (IllegalArgumentException JavaDoc e) {
583             // Pre-1.4 support. 'dropTargetContext' was previoulsy transient
584
}
585         if (dropTargetContext == null) {
586             dropTargetContext = createDropTargetContext();
587         }
588
589         component = (Component JavaDoc)f.get("component", null);
590         actions = f.get("actions", DnDConstants.ACTION_COPY_OR_MOVE);
591         active = f.get("active", true);
592
593         // Pre-1.4 support. 'dtListener' was previously non-transient
594
try {
595             dtListener = (DropTargetListener JavaDoc)f.get("dtListener", null);
596         } catch (IllegalArgumentException JavaDoc e) {
597             // 1.4-compatible byte stream. 'dtListener' was written explicitly
598
dtListener = (DropTargetListener JavaDoc)s.readObject();
599         }
600     }
601
602     /*********************************************************************/
603
604     /**
605      * this protected nested class implements autoscrolling
606      */

607
608     protected static class DropTargetAutoScroller implements ActionListener JavaDoc {
609
610     /**
611          * construct a DropTargetAutoScroller
612          * <P>
613          * @param c the <code>Component</code>
614          * @param p the <code>Point</code>
615      */

616
617     protected DropTargetAutoScroller(Component JavaDoc c, Point JavaDoc p) {
618         super();
619
620         component = c;
621         autoScroll = (Autoscroll JavaDoc)component;
622
623         Toolkit JavaDoc t = Toolkit.getDefaultToolkit();
624
625         Integer JavaDoc initial = new Integer JavaDoc(100);
626         Integer JavaDoc interval = new Integer JavaDoc(100);
627
628         try {
629         initial = (Integer JavaDoc)t.getDesktopProperty("DnD.Autoscroll.initialDelay");
630         } catch (Exception JavaDoc e) {
631         // ignore
632
}
633
634         try {
635             interval = (Integer JavaDoc)t.getDesktopProperty("DnD.Autoscroll.interval");
636         } catch (Exception JavaDoc e) {
637         // ignore
638
}
639
640         timer = new Timer JavaDoc(interval.intValue(), this);
641
642         timer.setCoalesce(true);
643         timer.setInitialDelay(initial.intValue());
644
645         locn = p;
646         prev = p;
647
648         try {
649         hysteresis = ((Integer JavaDoc)t.getDesktopProperty("DnD.Autoscroll.cursorHysteresis")).intValue();
650         } catch (Exception JavaDoc e) {
651         // ignore
652
}
653
654         timer.start();
655     }
656
657     /**
658      * update the geometry of the autoscroll region
659      */

660
661     private void updateRegion() {
662        Insets JavaDoc i = autoScroll.getAutoscrollInsets();
663        Dimension JavaDoc size = component.getSize();
664
665        if (size.width != outer.width || size.height != outer.height)
666         outer.reshape(0, 0, size.width, size.height);
667
668        if (inner.x != i.left || inner.y != i.top)
669         inner.setLocation(i.left, i.top);
670         
671        int newWidth = size.width - (i.left + i.right);
672        int newHeight = size.height - (i.top + i.bottom);
673
674        if (newWidth != inner.width || newHeight != inner.height)
675         inner.setSize(newWidth, newHeight);
676     
677     }
678
679     /**
680      * cause autoscroll to occur
681          * <P>
682          * @param newLocn the <code>Point</code>
683      */

684
685     protected synchronized void updateLocation(Point JavaDoc newLocn) {
686         prev = locn;
687         locn = newLocn;
688
689         if (Math.abs(locn.x - prev.x) > hysteresis ||
690         Math.abs(locn.y - prev.y) > hysteresis) {
691         if (timer.isRunning()) timer.stop();
692         } else {
693         if (!timer.isRunning()) timer.start();
694         }
695     }
696
697     /**
698      * cause autoscrolling to stop
699      */

700
701     protected void stop() { timer.stop(); }
702
703     /**
704      * cause autoscroll to occur
705          * <P>
706          * @param e the <code>ActionEvent</code>
707      */

708
709     public synchronized void actionPerformed(ActionEvent JavaDoc e) {
710         updateRegion();
711
712         if (outer.contains(locn) && !inner.contains(locn))
713             autoScroll.autoscroll(locn);
714     }
715
716     /*
717      * fields
718      */

719
720     private Component JavaDoc component;
721     private Autoscroll JavaDoc autoScroll;
722
723     private Timer JavaDoc timer;
724
725     private Point JavaDoc locn;
726     private Point JavaDoc prev;
727
728     private Rectangle JavaDoc outer = new Rectangle JavaDoc();
729     private Rectangle JavaDoc inner = new Rectangle JavaDoc();
730
731     private int hysteresis = 10;
732     }
733
734     /*********************************************************************/
735
736     /**
737      * create an embedded autoscroller
738      * <P>
739      * @param c the <code>Component</code>
740      * @param p the <code>Point</code>
741      */

742
743     protected DropTargetAutoScroller createDropTargetAutoScroller(Component JavaDoc c, Point JavaDoc p) {
744     return new DropTargetAutoScroller(c, p);
745     }
746
747     /**
748      * initialize autoscrolling
749      * <P>
750      * @param p the <code>Point</code>
751      */

752
753     protected void initializeAutoscrolling(Point JavaDoc p) {
754     if (component == null || !(component instanceof Autoscroll JavaDoc)) return;
755
756     autoScroller = createDropTargetAutoScroller(component, p);
757     }
758
759     /**
760      * update autoscrolling with current cursor locn
761      * <P>
762      * @param dragCursorLocn the <code>Point</code>
763      */

764
765     protected void updateAutoscroll(Point JavaDoc dragCursorLocn) {
766     if (autoScroller != null) autoScroller.updateLocation(dragCursorLocn);
767     }
768
769     /**
770      * clear autoscrolling
771      */

772
773     protected void clearAutoscroll() {
774     if (autoScroller != null) {
775         autoScroller.stop();
776         autoScroller = null;
777     }
778     }
779
780     /**
781      * The DropTargetContext associated with this DropTarget.
782      *
783      * @serial
784      */

785     private DropTargetContext JavaDoc dropTargetContext = createDropTargetContext();
786
787     /**
788      * The Component associated with this DropTarget.
789      *
790      * @serial
791      */

792     private Component JavaDoc component;
793  
794     /*
795      * That Component's Peer
796      */

797     private transient ComponentPeer componentPeer;
798
799     /*
800      * That Component's "native" Peer
801      */

802     private transient ComponentPeer nativePeer;
803  
804
805     /**
806      * Default permissible actions supported by this DropTarget.
807      *
808      * @see #setDefaultActions
809      * @see #getDefaultActions
810      * @serial
811      */

812     int actions = DnDConstants.ACTION_COPY_OR_MOVE;
813
814     /**
815      * <code>true</code> if the DropTarget is accepting Drag & Drop operations.
816      *
817      * @serial
818      */

819     boolean active = true;
820
821     /*
822      * the auto scrolling object
823      */

824
825     private transient DropTargetAutoScroller autoScroller;
826
827     /*
828      * The delegate
829      */

830
831     private transient DropTargetListener JavaDoc dtListener;
832
833     /*
834      * The FlavorMap
835      */

836
837     private transient FlavorMap JavaDoc flavorMap = SystemFlavorMap.getDefaultFlavorMap();
838 }
839
Popular Tags