1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
32 import java.io.ObjectOutputStream;
33 import java.io.Serializable;
34
35 import java.awt.Component;
36 import java.awt.Dimension;
37 import java.awt.GraphicsEnvironment;
38 import java.awt.HeadlessException;
39 import java.awt.Insets;
40 import java.awt.Point;
41 import java.awt.Rectangle;
42 import java.awt.Toolkit;
43 import java.awt.event.ActionEvent;
44 import java.awt.event.ActionListener;
45 import java.awt.datatransfer.FlavorMap;
46 import java.awt.datatransfer.SystemFlavorMap;
47 import javax.swing.Timer;
48 import java.awt.peer.ComponentPeer;
49 import java.awt.peer.LightweightPeer;
50 import java.awt.dnd.peer.DropTargetPeer;
51
52
53 /**
54 * The <code>DropTarget</code> is associated
55 * with a <code>Component</code> when that <code>Component</code>
56 * wishes
57 * to accept drops during Drag and Drop operations.
58 * <P>
59 * Each
60 * <code>DropTarget</code> is associated with a <code>FlavorMap</code>.
61 * The default <code>FlavorMap</code> hereafter designates the
62 * <code>FlavorMap</code> returned by <code>SystemFlavorMap.getDefaultFlavorMap()</code>.
63 *
64 * @since 1.2
65 */
66
67 public class DropTarget implements DropTargetListener, Serializable {
68
69 private static final long serialVersionUID = -6283860791671019047L;
70
71 /**
482 flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
483 }
484
485 /**
486 * Notify the DropTarget that it has been associated with a Component
487 *
488 **********************************************************************
489 * This method is usually called from java.awt.Component.addNotify() of
490 * the Component associated with this DropTarget to notify the DropTarget
491 * that a ComponentPeer has been associated with that Component.
492 *
493 * Calling this method, other than to notify this DropTarget of the
494 * association of the ComponentPeer with the Component may result in
495 * a malfunction of the DnD system.
496 **********************************************************************
497 *
498 * @param peer The Peer of the Component we are associated with!
499 *
500 */
501
502 @SuppressWarnings("deprecation")
503 public void addNotify(ComponentPeer peer) {
504 if (peer == componentPeer) return;
505
506 componentPeer = peer;
507
508 for (Component c = component;
509 c != null && peer instanceof LightweightPeer; c = c.getParent()) {
510 peer = c.getPeer();
511 }
512
513 if (peer instanceof DropTargetPeer) {
514 nativePeer = peer;
515 ((DropTargetPeer)peer).addDropTarget(this);
516 } else {
517 nativePeer = null;
518 }
519 }
520
521 /**
522 * Notify the DropTarget that it has been disassociated from a Component
523 *
524 **********************************************************************
525 * This method is usually called from java.awt.Component.removeNotify() of
526 * the Component associated with this DropTarget to notify the DropTarget
527 * that a ComponentPeer has been disassociated with that Component.
528 *
529 * Calling this method, other than to notify this DropTarget of the
530 * disassociation of the ComponentPeer from the Component may result in
|
1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
32 import java.io.ObjectOutputStream;
33 import java.io.Serializable;
34
35 import java.awt.Component;
36 import java.awt.Dimension;
37 import java.awt.GraphicsEnvironment;
38 import java.awt.HeadlessException;
39 import java.awt.Insets;
40 import java.awt.Point;
41 import java.awt.Rectangle;
42 import java.awt.Toolkit;
43 import java.awt.event.ActionEvent;
44 import java.awt.event.ActionListener;
45 import java.awt.datatransfer.FlavorMap;
46 import java.awt.datatransfer.SystemFlavorMap;
47 import javax.swing.Timer;
48 import java.awt.peer.ComponentPeer;
49 import java.awt.peer.LightweightPeer;
50 import java.awt.dnd.peer.DropTargetPeer;
51
52 import sun.awt.AWTAccessor;
53 import sun.awt.AWTAccessor.ComponentAccessor;
54
55
56 /**
57 * The <code>DropTarget</code> is associated
58 * with a <code>Component</code> when that <code>Component</code>
59 * wishes
60 * to accept drops during Drag and Drop operations.
61 * <P>
62 * Each
63 * <code>DropTarget</code> is associated with a <code>FlavorMap</code>.
64 * The default <code>FlavorMap</code> hereafter designates the
65 * <code>FlavorMap</code> returned by <code>SystemFlavorMap.getDefaultFlavorMap()</code>.
66 *
67 * @since 1.2
68 */
69
70 public class DropTarget implements DropTargetListener, Serializable {
71
72 private static final long serialVersionUID = -6283860791671019047L;
73
74 /**
485 flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
486 }
487
488 /**
489 * Notify the DropTarget that it has been associated with a Component
490 *
491 **********************************************************************
492 * This method is usually called from java.awt.Component.addNotify() of
493 * the Component associated with this DropTarget to notify the DropTarget
494 * that a ComponentPeer has been associated with that Component.
495 *
496 * Calling this method, other than to notify this DropTarget of the
497 * association of the ComponentPeer with the Component may result in
498 * a malfunction of the DnD system.
499 **********************************************************************
500 *
501 * @param peer The Peer of the Component we are associated with!
502 *
503 */
504
505 public void addNotify(ComponentPeer peer) {
506 if (peer == componentPeer) return;
507
508 componentPeer = peer;
509 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
510
511 for (Component c = component;
512 c != null && peer instanceof LightweightPeer; c = c.getParent()) {
513 peer = acc.getPeer(c);
514 }
515
516 if (peer instanceof DropTargetPeer) {
517 nativePeer = peer;
518 ((DropTargetPeer)peer).addDropTarget(this);
519 } else {
520 nativePeer = null;
521 }
522 }
523
524 /**
525 * Notify the DropTarget that it has been disassociated from a Component
526 *
527 **********************************************************************
528 * This method is usually called from java.awt.Component.removeNotify() of
529 * the Component associated with this DropTarget to notify the DropTarget
530 * that a ComponentPeer has been disassociated with that Component.
531 *
532 * Calling this method, other than to notify this DropTarget of the
533 * disassociation of the ComponentPeer from the Component may result in
|