ptolemy.vergil.basic
Class EditorDropTarget

java.lang.Object
  extended by java.awt.dnd.DropTarget
      extended by ptolemy.vergil.basic.EditorDropTarget
All Implemented Interfaces:
java.awt.dnd.DropTargetListener, java.io.Serializable, java.util.EventListener

public class EditorDropTarget
extends java.awt.dnd.DropTarget

This class provides drag-and-drop support. When this drop target receives a transferable object containing a ptolemy entity, it creates a new instance of the object, and adds it to the given graph. If the drop location falls on top of an icon associated with an instance of NamedObj, then the object is deposited inside that instance (so the instance becomes its container). Otherwise, the object is deposited inside the model associated with the target graph. In either case, if the target container implements the DropListener interface, then it is informed of the drop by calling its dropped() method.

Sometimes, you will want to disable the feature that a drop onto a NamedObj results in the dropped object being placed inside that NamedObj. To disable this feature, call setDropIntoEnabled() with a false argument.

Since:
Ptolemy II 2.0
Version:
$Id: EditorDropTarget.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer and Edward A. Lee, Contributor: Michael Shilman
See Also:
Serialized Form
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Nested Class Summary
private  class EditorDropTarget.DTListener
          The drop target listener used with the diva graph object.
 
Nested classes/interfaces inherited from class java.awt.dnd.DropTarget
java.awt.dnd.DropTarget.DropTargetAutoScroller
 
Field Summary
private  java.util.Vector<java.awt.dnd.DropTargetListener> _additionalListeners
          Vector to contain additional listeners.
private  boolean _dropIntoEnabled
          Flag indicating whether drop into is enabled.
 
Constructor Summary
EditorDropTarget(JGraph graph)
          Construct a new graph target to operate on the given JGraph.
 
Method Summary
 void deRegisterAdditionalListener(java.awt.dnd.DropTargetListener listener)
          Remove an additional listener.
 boolean isDropIntoEnabled()
          Return true if the feature is enabled that a a drop onto an instance of NamedObj results in that NamedObj containing the dropped object.
 void registerAdditionalListener(java.awt.dnd.DropTargetListener listener)
          Register additional DropTargetListeners.
 void setDropIntoEnabled(boolean enabled)
          If the argument is false, then disable the feature that a a drop onto an instance of NamedObj results in that NamedObj containing the dropped object.
 
Methods inherited from class java.awt.dnd.DropTarget
addDropTargetListener, addNotify, clearAutoscroll, createDropTargetAutoScroller, createDropTargetContext, dragEnter, dragExit, dragOver, drop, dropActionChanged, getComponent, getDefaultActions, getDropTargetContext, getFlavorMap, initializeAutoscrolling, isActive, removeDropTargetListener, removeNotify, setActive, setComponent, setDefaultActions, setFlavorMap, updateAutoscroll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_additionalListeners

private java.util.Vector<java.awt.dnd.DropTargetListener> _additionalListeners
Vector to contain additional listeners.


_dropIntoEnabled

private boolean _dropIntoEnabled
Flag indicating whether drop into is enabled.

Constructor Detail

EditorDropTarget

public EditorDropTarget(JGraph graph)
Construct a new graph target to operate on the given JGraph.

Parameters:
graph - The diva graph panel.
Method Detail

deRegisterAdditionalListener

public void deRegisterAdditionalListener(java.awt.dnd.DropTargetListener listener)
Remove an additional listener.

Parameters:
listener - The DropTargetListener to be removed.

isDropIntoEnabled

public boolean isDropIntoEnabled()
Return true if the feature is enabled that a a drop onto an instance of NamedObj results in that NamedObj containing the dropped object. Otherwise, return false.

Returns:
True if drop into is enabled.

registerAdditionalListener

public void registerAdditionalListener(java.awt.dnd.DropTargetListener listener)
Register additional DropTargetListeners.

Parameters:
listener - The DropTargetListener to be added.

setDropIntoEnabled

public void setDropIntoEnabled(boolean enabled)
If the argument is false, then disable the feature that a a drop onto an instance of NamedObj results in that NamedObj containing the dropped object. If the argument is true, then reenable the feature. The feature is enabled by default.

Parameters:
enabled - False to disable the drop into feature.