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

Print this page




 334             else
 335                 throw new IllegalArgumentException("listener mismatch");
 336         }
 337     }
 338 
 339     /**
 340      * Calls <code>dragEnter</code> on the registered
 341      * <code>DropTargetListener</code> and passes it
 342      * the specified <code>DropTargetDragEvent</code>.
 343      * Has no effect if this <code>DropTarget</code>
 344      * is not active.
 345      *
 346      * @param dtde the <code>DropTargetDragEvent</code>
 347      *
 348      * @throws NullPointerException if this <code>DropTarget</code>
 349      *         is active and <code>dtde</code> is <code>null</code>
 350      *
 351      * @see #isActive
 352      */
 353     public synchronized void dragEnter(DropTargetDragEvent dtde) {


 354         if (!active) return;
 355 
 356         if (dtListener != null) {
 357             dtListener.dragEnter(dtde);
 358         } else
 359             dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE);
 360 
 361         initializeAutoscrolling(dtde.getLocation());
 362     }
 363 
 364     /**
 365      * Calls <code>dragOver</code> on the registered
 366      * <code>DropTargetListener</code> and passes it
 367      * the specified <code>DropTargetDragEvent</code>.
 368      * Has no effect if this <code>DropTarget</code>
 369      * is not active.
 370      *
 371      * @param dtde the <code>DropTargetDragEvent</code>
 372      *
 373      * @throws NullPointerException if this <code>DropTarget</code>


 404 
 405         updateAutoscroll(dtde.getLocation());
 406     }
 407 
 408     /**
 409      * Calls <code>dragExit</code> on the registered
 410      * <code>DropTargetListener</code> and passes it
 411      * the specified <code>DropTargetEvent</code>.
 412      * Has no effect if this <code>DropTarget</code>
 413      * is not active.
 414      * <p>
 415      * This method itself does not throw any exception
 416      * for null parameter but for exceptions thrown by
 417      * the respective method of the listener.
 418      *
 419      * @param dte the <code>DropTargetEvent</code>
 420      *
 421      * @see #isActive
 422      */
 423     public synchronized void dragExit(DropTargetEvent dte) {


 424         if (!active) return;
 425 
 426         if (dtListener != null && active) dtListener.dragExit(dte);
 427 
 428         clearAutoscroll();
 429     }
 430 
 431     /**
 432      * Calls <code>drop</code> on the registered
 433      * <code>DropTargetListener</code> and passes it
 434      * the specified <code>DropTargetDropEvent</code>
 435      * if this <code>DropTarget</code> is active.
 436      *
 437      * @param dtde the <code>DropTargetDropEvent</code>
 438      *
 439      * @throws NullPointerException if <code>dtde</code> is null
 440      *         and at least one of the following is true: this
 441      *         <code>DropTarget</code> is not active, or there is
 442      *         no a <code>DropTargetListener</code> registered.
 443      *
 444      * @see #isActive
 445      */
 446     public synchronized void drop(DropTargetDropEvent dtde) {


 447         clearAutoscroll();
 448 
 449         if (dtListener != null && active)
 450             dtListener.drop(dtde);
 451         else { // we should'nt get here ...
 452             dtde.rejectDrop();
 453         }
 454     }
 455 
 456     /**
 457      * Gets the <code>FlavorMap</code>
 458      * associated with this <code>DropTarget</code>.
 459      * If no <code>FlavorMap</code> has been set for this
 460      * <code>DropTarget</code>, it is associated with the default
 461      * <code>FlavorMap</code>.
 462      * <P>
 463      * @return the FlavorMap for this DropTarget
 464      */
 465 
 466     public FlavorMap getFlavorMap() { return flavorMap; }


 516      * Notify the DropTarget that it has been disassociated from a Component
 517      *
 518      **********************************************************************
 519      * This method is usually called from java.awt.Component.removeNotify() of
 520      * the Component associated with this DropTarget to notify the DropTarget
 521      * that a ComponentPeer has been disassociated with that Component.
 522      *
 523      * Calling this method, other than to notify this DropTarget of the
 524      * disassociation of the ComponentPeer from the Component may result in
 525      * a malfunction of the DnD system.
 526      **********************************************************************
 527      * <P>
 528      * @param peer The Peer of the Component we are being disassociated from!
 529      */
 530 
 531     public void removeNotify(ComponentPeer peer) {
 532         if (nativePeer != null)
 533             ((DropTargetPeer)nativePeer).removeDropTarget(this);
 534 
 535         componentPeer = nativePeer = null;






 536     }
 537 
 538     /**
 539      * Gets the <code>DropTargetContext</code> associated
 540      * with this <code>DropTarget</code>.
 541      * <P>
 542      * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
 543      */
 544 
 545     public DropTargetContext getDropTargetContext() {
 546         return dropTargetContext;
 547     }
 548 
 549     /**
 550      * Creates the DropTargetContext associated with this DropTarget.
 551      * Subclasses may override this method to instantiate their own
 552      * DropTargetContext subclass.
 553      *
 554      * This call is typically *only* called by the platform's
 555      * DropTargetContextPeer as a drag operation encounters this


 838      */
 839     boolean active = true;
 840 
 841     /*
 842      * the auto scrolling object
 843      */
 844 
 845     private transient DropTargetAutoScroller autoScroller;
 846 
 847     /*
 848      * The delegate
 849      */
 850 
 851     private transient DropTargetListener dtListener;
 852 
 853     /*
 854      * The FlavorMap
 855      */
 856 
 857     private transient FlavorMap flavorMap;





 858 }


 334             else
 335                 throw new IllegalArgumentException("listener mismatch");
 336         }
 337     }
 338 
 339     /**
 340      * Calls <code>dragEnter</code> on the registered
 341      * <code>DropTargetListener</code> and passes it
 342      * the specified <code>DropTargetDragEvent</code>.
 343      * Has no effect if this <code>DropTarget</code>
 344      * is not active.
 345      *
 346      * @param dtde the <code>DropTargetDragEvent</code>
 347      *
 348      * @throws NullPointerException if this <code>DropTarget</code>
 349      *         is active and <code>dtde</code> is <code>null</code>
 350      *
 351      * @see #isActive
 352      */
 353     public synchronized void dragEnter(DropTargetDragEvent dtde) {
 354         isDraggingInside = true;
 355 
 356         if (!active) return;
 357 
 358         if (dtListener != null) {
 359             dtListener.dragEnter(dtde);
 360         } else
 361             dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE);
 362 
 363         initializeAutoscrolling(dtde.getLocation());
 364     }
 365 
 366     /**
 367      * Calls <code>dragOver</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>


 406 
 407         updateAutoscroll(dtde.getLocation());
 408     }
 409 
 410     /**
 411      * Calls <code>dragExit</code> on the registered
 412      * <code>DropTargetListener</code> and passes it
 413      * the specified <code>DropTargetEvent</code>.
 414      * Has no effect if this <code>DropTarget</code>
 415      * is not active.
 416      * <p>
 417      * This method itself does not throw any exception
 418      * for null parameter but for exceptions thrown by
 419      * the respective method of the listener.
 420      *
 421      * @param dte the <code>DropTargetEvent</code>
 422      *
 423      * @see #isActive
 424      */
 425     public synchronized void dragExit(DropTargetEvent dte) {
 426         isDraggingInside = false;
 427 
 428         if (!active) return;
 429 
 430         if (dtListener != null && active) dtListener.dragExit(dte);
 431 
 432         clearAutoscroll();
 433     }
 434 
 435     /**
 436      * Calls <code>drop</code> on the registered
 437      * <code>DropTargetListener</code> and passes it
 438      * the specified <code>DropTargetDropEvent</code>
 439      * if this <code>DropTarget</code> is active.
 440      *
 441      * @param dtde the <code>DropTargetDropEvent</code>
 442      *
 443      * @throws NullPointerException if <code>dtde</code> is null
 444      *         and at least one of the following is true: this
 445      *         <code>DropTarget</code> is not active, or there is
 446      *         no a <code>DropTargetListener</code> registered.
 447      *
 448      * @see #isActive
 449      */
 450     public synchronized void drop(DropTargetDropEvent dtde) {
 451         isDraggingInside = false;
 452 
 453         clearAutoscroll();
 454 
 455         if (dtListener != null && active)
 456             dtListener.drop(dtde);
 457         else { // we should'nt get here ...
 458             dtde.rejectDrop();
 459         }
 460     }
 461 
 462     /**
 463      * Gets the <code>FlavorMap</code>
 464      * associated with this <code>DropTarget</code>.
 465      * If no <code>FlavorMap</code> has been set for this
 466      * <code>DropTarget</code>, it is associated with the default
 467      * <code>FlavorMap</code>.
 468      * <P>
 469      * @return the FlavorMap for this DropTarget
 470      */
 471 
 472     public FlavorMap getFlavorMap() { return flavorMap; }


 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
 531      * a malfunction of the DnD system.
 532      **********************************************************************
 533      * <P>
 534      * @param peer The Peer of the Component we are being disassociated from!
 535      */
 536 
 537     public void removeNotify(ComponentPeer peer) {
 538         if (nativePeer != null)
 539             ((DropTargetPeer)nativePeer).removeDropTarget(this);
 540 
 541         componentPeer = nativePeer = null;
 542 
 543         synchronized (this) {
 544             if (isDraggingInside) {
 545                 dragExit(new DropTargetEvent(getDropTargetContext()));
 546             }
 547         }
 548     }
 549 
 550     /**
 551      * Gets the <code>DropTargetContext</code> associated
 552      * with this <code>DropTarget</code>.
 553      * <P>
 554      * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
 555      */
 556 
 557     public DropTargetContext getDropTargetContext() {
 558         return dropTargetContext;
 559     }
 560 
 561     /**
 562      * Creates the DropTargetContext associated with this DropTarget.
 563      * Subclasses may override this method to instantiate their own
 564      * DropTargetContext subclass.
 565      *
 566      * This call is typically *only* called by the platform's
 567      * DropTargetContextPeer as a drag operation encounters this


 850      */
 851     boolean active = true;
 852 
 853     /*
 854      * the auto scrolling object
 855      */
 856 
 857     private transient DropTargetAutoScroller autoScroller;
 858 
 859     /*
 860      * The delegate
 861      */
 862 
 863     private transient DropTargetListener dtListener;
 864 
 865     /*
 866      * The FlavorMap
 867      */
 868 
 869     private transient FlavorMap flavorMap;
 870 
 871     /*
 872      * If the dragging is currently inside this drop target
 873      */
 874     private transient boolean isDraggingInside;
 875 }