src/java.desktop/share/classes/java/awt/dnd/DropTarget.java

Print this page




 190         throws HeadlessException
 191     {
 192         this(c, ops, dtl, true);
 193     }
 194 
 195     /**
 196      * Note: this interface is required to permit the safe association
 197      * of a DropTarget with a Component in one of two ways, either:
 198      * <code> component.setDropTarget(droptarget); </code>
 199      * or <code> droptarget.setComponent(component); </code>
 200      * <P>
 201      * The Component will receive drops only if it is enabled.
 202      * @param c The new <code>Component</code> this <code>DropTarget</code>
 203      * is to be associated with.
 204      */
 205 
 206     public synchronized void setComponent(Component c) {
 207         if (component == c || component != null && component.equals(c))
 208             return;
 209 
 210         Component     old;
 211         ComponentPeer oldPeer = null;
 212 
 213         if ((old = component) != null) {
 214             clearAutoscroll();
 215 
 216             component = null;
 217 
 218             if (componentPeer != null) {
 219                 oldPeer = componentPeer;
 220                 removeNotify(componentPeer);
 221             }
 222 
 223             old.setDropTarget(null);
 224 
 225         }
 226 
 227         if ((component = c) != null) try {
 228             c.setDropTarget(this);
 229         } catch (Exception e) { // undo the change
 230             if (old != null) {
 231                 old.setDropTarget(this);
 232                 addNotify(oldPeer);
 233             }
 234         }
 235     }
 236 
 237     /**
 238      * Gets the <code>Component</code> associated
 239      * with this <code>DropTarget</code>.
 240      *
 241      * @return the current <code>Component</code>
 242      */
 243 
 244     public synchronized Component getComponent() {
 245         return component;
 246     }
 247 
 248     /**
 249      * Sets the default acceptable actions for this <code>DropTarget</code>
 250      *
 251      * @param ops the default actions
 252      * @see java.awt.dnd.DnDConstants


 480      * @param fm the new <code>FlavorMap</code>, or null to
 481      * associate the default FlavorMap with this DropTarget.
 482      */
 483 
 484     public void setFlavorMap(FlavorMap fm) {
 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
 534      * a malfunction of the DnD system.
 535      **********************************************************************
 536      *
 537      * @param peer The Peer of the Component we are being disassociated from!
 538      */
 539 
 540     public void removeNotify(ComponentPeer peer) {
 541         if (nativePeer != null)
 542             ((DropTargetPeer)nativePeer).removeDropTarget(this);
 543 
 544         componentPeer = nativePeer = null;

 545 
 546         synchronized (this) {
 547             if (isDraggingInside) {
 548                 dragExit(new DropTargetEvent(getDropTargetContext()));
 549             }
 550         }
 551     }
 552 
 553     /**
 554      * Gets the <code>DropTargetContext</code> associated
 555      * with this <code>DropTarget</code>.
 556      *
 557      * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
 558      */
 559 
 560     public DropTargetContext getDropTargetContext() {
 561         return dropTargetContext;
 562     }
 563 
 564     /**


 820      *
 821      * @serial
 822      */
 823     private DropTargetContext dropTargetContext = createDropTargetContext();
 824 
 825     /**
 826      * The Component associated with this DropTarget.
 827      *
 828      * @serial
 829      */
 830     private Component component;
 831 
 832     /*
 833      * That Component's  Peer
 834      */
 835     private transient ComponentPeer componentPeer;
 836 
 837     /*
 838      * That Component's "native" Peer
 839      */
 840     private transient ComponentPeer nativePeer;
 841 
 842 
 843     /**
 844      * Default permissible actions supported by this DropTarget.
 845      *
 846      * @see #setDefaultActions
 847      * @see #getDefaultActions
 848      * @serial
 849      */
 850     int     actions = DnDConstants.ACTION_COPY_OR_MOVE;
 851 
 852     /**
 853      * <code>true</code> if the DropTarget is accepting Drag &amp; Drop operations.
 854      *
 855      * @serial
 856      */
 857     boolean active = true;
 858 
 859     /*
 860      * the auto scrolling object




 190         throws HeadlessException
 191     {
 192         this(c, ops, dtl, true);
 193     }
 194 
 195     /**
 196      * Note: this interface is required to permit the safe association
 197      * of a DropTarget with a Component in one of two ways, either:
 198      * <code> component.setDropTarget(droptarget); </code>
 199      * or <code> droptarget.setComponent(component); </code>
 200      * <P>
 201      * The Component will receive drops only if it is enabled.
 202      * @param c The new <code>Component</code> this <code>DropTarget</code>
 203      * is to be associated with.
 204      */
 205 
 206     public synchronized void setComponent(Component c) {
 207         if (component == c || component != null && component.equals(c))
 208             return;
 209 
 210         final Component old = component;

 211 
 212         if (old  != null) {
 213             clearAutoscroll();
 214 
 215             component = null;
 216             removeNotify();





 217             old.setDropTarget(null);
 218 
 219         }
 220 
 221         if ((component = c) != null) try {
 222             c.setDropTarget(this);
 223         } catch (Exception e) { // undo the change
 224             if (old != null) {
 225                 old.setDropTarget(this);
 226                 addNotify();
 227             }
 228         }
 229     }
 230 
 231     /**
 232      * Gets the <code>Component</code> associated
 233      * with this <code>DropTarget</code>.
 234      *
 235      * @return the current <code>Component</code>
 236      */
 237 
 238     public synchronized Component getComponent() {
 239         return component;
 240     }
 241 
 242     /**
 243      * Sets the default acceptable actions for this <code>DropTarget</code>
 244      *
 245      * @param ops the default actions
 246      * @see java.awt.dnd.DnDConstants


 474      * @param fm the new <code>FlavorMap</code>, or null to
 475      * associate the default FlavorMap with this DropTarget.
 476      */
 477 
 478     public void setFlavorMap(FlavorMap fm) {
 479         flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
 480     }
 481 
 482     /**
 483      * Notify the DropTarget that it has been associated with a Component
 484      *
 485      **********************************************************************
 486      * This method is usually called from java.awt.Component.addNotify() of
 487      * the Component associated with this DropTarget to notify the DropTarget
 488      * that a ComponentPeer has been associated with that Component.
 489      *
 490      * Calling this method, other than to notify this DropTarget of the
 491      * association of the ComponentPeer with the Component may result in
 492      * a malfunction of the DnD system.
 493      **********************************************************************



 494      */
 495     public void addNotify() {
 496         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
 497         ComponentPeer peer = acc.getPeer(component);
 498         if (peer == null || peer == componentPeer) {
 499             return;
 500         }
 501 
 502         componentPeer = peer;
 503 
 504 
 505         for (Component c = component;
 506              c != null && peer instanceof LightweightPeer; c = c.getParent()) {
 507             peer = acc.getPeer(c);
 508         }
 509 
 510         if (peer instanceof DropTargetPeer) {
 511             nativePeer = (DropTargetPeer) peer;
 512             ((DropTargetPeer)peer).addDropTarget(this);
 513         } else {
 514             nativePeer = null;
 515         }
 516     }
 517 
 518     /**
 519      * Notify the DropTarget that it has been disassociated from a Component
 520      *
 521      **********************************************************************
 522      * This method is usually called from java.awt.Component.removeNotify() of
 523      * the Component associated with this DropTarget to notify the DropTarget
 524      * that a ComponentPeer has been disassociated with that Component.
 525      *
 526      * Calling this method, other than to notify this DropTarget of the
 527      * disassociation of the ComponentPeer from the Component may result in
 528      * a malfunction of the DnD system.
 529      **********************************************************************


 530      */
 531 
 532     public void removeNotify() {
 533         if (nativePeer != null) {
 534             nativePeer.removeDropTarget(this);
 535         }
 536         componentPeer = null;
 537         nativePeer = null;
 538 
 539         synchronized (this) {
 540             if (isDraggingInside) {
 541                 dragExit(new DropTargetEvent(getDropTargetContext()));
 542             }
 543         }
 544     }
 545 
 546     /**
 547      * Gets the <code>DropTargetContext</code> associated
 548      * with this <code>DropTarget</code>.
 549      *
 550      * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
 551      */
 552 
 553     public DropTargetContext getDropTargetContext() {
 554         return dropTargetContext;
 555     }
 556 
 557     /**


 813      *
 814      * @serial
 815      */
 816     private DropTargetContext dropTargetContext = createDropTargetContext();
 817 
 818     /**
 819      * The Component associated with this DropTarget.
 820      *
 821      * @serial
 822      */
 823     private Component component;
 824 
 825     /*
 826      * That Component's  Peer
 827      */
 828     private transient ComponentPeer componentPeer;
 829 
 830     /*
 831      * That Component's "native" Peer
 832      */
 833     private transient DropTargetPeer nativePeer;
 834 
 835 
 836     /**
 837      * Default permissible actions supported by this DropTarget.
 838      *
 839      * @see #setDefaultActions
 840      * @see #getDefaultActions
 841      * @serial
 842      */
 843     int     actions = DnDConstants.ACTION_COPY_OR_MOVE;
 844 
 845     /**
 846      * <code>true</code> if the DropTarget is accepting Drag &amp; Drop operations.
 847      *
 848      * @serial
 849      */
 850     boolean active = true;
 851 
 852     /*
 853      * the auto scrolling object