Search this API

y.view
Class DropSupport

java.lang.Object
  extended by y.view.DropSupport

public class DropSupport
extends java.lang.Object

A support class for Graph2DView that facilitates the drop part of drag and drop operations. This class has support for dropping NodeRealizer and EdgeRealizer instances onto a Graph2DView to create nodes or start edge creation. Also it allows to temporarily add a DropTargetListener to the view as a one-shot operation.

 
Your browser does not support SVG content.

Nested Class Summary
static class DropSupport.EdgeSplitSupport
          Handles edge splitting on node drops if edge splitting is enabled.
static interface DropSupport.EventHandler
          Handles data flavor dependent access to drag and drop events for DropSupport's default node and edge transfers.
 
Constructor Summary
DropSupport()
          Creates a new instance of the class for no specific view.
DropSupport(Graph2DView view)
          Creates a new instance of the class and creates support for dropping node realizer and edge realizer instances onto the view.
 
Method Summary
protected  DropSupport.EdgeSplitSupport createEdgeSplitSupport()
          Creates an instance of EdgeSplitSupport to handle edge splitting on node drops if edge splitting is enabled.
protected  Node createNode(Graph2DView view, NodeRealizer r, double worldCoordX, double worldCoordY)
          Callback that creates the node in response to dropNodeRealizer(Graph2DView, NodeRealizer, double, double).
 void createRealizerDropSupport(Graph2DView view)
          Registers support for dropping node realizer and edge realizer instances onto the provided view.
 void createSupport(Graph2DView view)
          Creates a support class for the provided Graph2DView that will enable the provided view to react to started drag operations.
 java.awt.datatransfer.Transferable createTransferable(EdgeRealizer er)
          Creates a Transferable for the given EdgeRealizer that is understood by this instance's support for dropEdgeRealizer(Graph2DView, EdgeRealizer, double, double) dropping edges}.
 java.awt.datatransfer.Transferable createTransferable(NodeRealizer nr)
          Creates a Transferable for the given NodeRealizer that is understood by this instance's support for dropping nodes.
protected  void drawSourceNodeIndicator(java.awt.Graphics2D g, NodeRealizer nodeRealizer)
          Paints the isIndicatingSourceNode() source node indicator} during edge drag operations.
protected  boolean dropEdgeRealizer(Graph2DView view, EdgeRealizer realizer, double worldCoordX, double worldCoordY)
          Tries to start the edge creation using the edit mode in the provided view.
protected  boolean dropNodeRealizer(Graph2DView view, NodeRealizer r, double worldCoordX, double worldCoordY)
          Callback method that creates the node after a drop operation.
protected  EditMode findEditMode(Graph2DView view)
          Tries to find the EditMode instance in the given view to start the edge creation.
 DropSupport.EventHandler getEdgeEventHandler()
          Returns the event handler for edge transfers.
 DropSupport.EdgeSplitSupport getEdgeSplitSupport()
          Specifies the support class that handles edge splitting on node drops if edge splitting is enabled.
 DropSupport.EventHandler getNodeEventHandler()
          Returns the event handler for node transfers.
 MoveSnapContext getSnapContext()
          Gets the MoveSnapContext that is used by this instance if snapping is enabled.
protected  java.awt.Rectangle getSourceNodeIndicatorBounds(NodeRealizer nodeRealizer)
          Calculates the bounds of the isIndicatingSourceNode() source node indicator} during edge drag operations.
protected  boolean isEdgeCreationAllowed(EditMode editMode)
          Determines whether edge creation is allowed for the provided EditMode This implementation uses the EditMode.doAllowEdgeCreation() property to determine the result.
 boolean isEdgeSplittingEnabled()
          Determines whether or not this drop support should split an edge when a dragged node is dropped onto it.
 boolean isIndicatingSourceNode()
          Determines whether or not possible source nodes are highlighted during edge drag operations.
 boolean isPreviewEnabled()
          Returns whether or not this support class should show a preview of the dragged node realizer during the drag operation.
 boolean isSnappingEnabled()
          Returns whether or not this support class should use the snap context to provide snap lines during the drag operation.
 void removeListener(Graph2DView view, java.awt.datatransfer.DataFlavor flavor)
          Removes a previously set listener from the provided view.
 void removeRealizerDropSupport(Graph2DView view)
          Removes previously added support for dropping realizers from the given view.
 void removeSupport(Graph2DView view)
          Removes the previously created support from the provided view.
protected  void requestFocus(Graph2DView view)
          Requests the input focus for the given view after a successful edge or node drop.
 void setEdgeEventHandler(DropSupport.EventHandler handler)
          Sets the event handler for edge transfers.
 void setEdgeSplitSupport(DropSupport.EdgeSplitSupport splitter)
          Specifies the support class that handles edge splitting on node drops if edge splitting is enabled.
 void setEdgeSplittingEnabled(boolean enabled)
          Specifies whether or not this drop support should split an edge when a dragged node is dropped onto it.
 void setIndicatingSourceNode(boolean enabled)
          Specifies whether or not possible source nodes are highlighted during edge drag operations.
 void setListener(Graph2DView view, java.awt.datatransfer.DataFlavor flavor, java.awt.dnd.DropTargetListener listener)
          Sets a specific DropTargetListener that will be used in the Graph2DView if the given DataFlavor is being dragged into the view.
 void setNodeEventHandler(DropSupport.EventHandler handler)
          Sets the event handler for node transfers.
protected  void setParent(Node child, Node parent)
          Assigns the specified child node to the specified parent node.
 void setPreviewEnabled(boolean enabled)
          Specifies whether or not this support class should show a preview of the dragged node realizer during the drag operation.
 void setSnapContext(MoveSnapContext snapContext)
          Sets the new MoveSnapContext that is used by this instance if snapping is enabled.
 void setSnappingEnabled(boolean enabled)
          Specifies whether or not this support class should use the snap context to provide snap lines during the drag operation.
 void startDrag(java.awt.dnd.DragSource source, java.awt.dnd.DropTargetListener listener, java.awt.dnd.DragGestureEvent trigger, java.awt.Cursor dragCursor)
          One shot drag and drop operation that will be available on the registered Graph2DViews.
 void startDrag(java.awt.dnd.DragSource source, EdgeRealizer er, java.awt.dnd.DragGestureEvent trigger, java.awt.Cursor dragCursor)
          Initiates dragging an EdgeRealizer on a given DragSource that can be handled by registered Graph2DViews.
 void startDrag(java.awt.dnd.DragSource source, NodeRealizer nr, java.awt.dnd.DragGestureEvent trigger, java.awt.Cursor dragCursor)
          Initiates dragging a NodeRealizer on a given DragSource that can be handled by registered Graph2DViews.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DropSupport

public DropSupport()
Creates a new instance of the class for no specific view.


DropSupport

public DropSupport(Graph2DView view)
Creates a new instance of the class and creates support for dropping node realizer and edge realizer instances onto the view.

Parameters:
view - The view to enable realizer drop support onto.
Method Detail

createEdgeSplitSupport

protected DropSupport.EdgeSplitSupport createEdgeSplitSupport()
Creates an instance of EdgeSplitSupport to handle edge splitting on node drops if edge splitting is enabled. Client code may overwrite this method to create a customized version of EdgeSplitSupport.

Returns:
a new EdgeSplitSupport instance.

getEdgeSplitSupport

public DropSupport.EdgeSplitSupport getEdgeSplitSupport()
Specifies the support class that handles edge splitting on node drops if edge splitting is enabled.

Returns:
the support class that handles edge splitting on node drops.
See Also:
setEdgeSplitSupport(y.view.DropSupport.EdgeSplitSupport), createEdgeSplitSupport()

setEdgeSplitSupport

public void setEdgeSplitSupport(DropSupport.EdgeSplitSupport splitter)
Specifies the support class that handles edge splitting on node drops if edge splitting is enabled.

Parameters:
splitter - the the support class to handles edge splitting on node drops.
See Also:
getEdgeSplitSupport(), createEdgeSplitSupport()

startDrag

public void startDrag(java.awt.dnd.DragSource source,
                      java.awt.dnd.DropTargetListener listener,
                      java.awt.dnd.DragGestureEvent trigger,
                      java.awt.Cursor dragCursor)
One shot drag and drop operation that will be available on the registered Graph2DViews. This method will actually start a drag on the source and will use the specified listener to handle drop operations on registered Graph2DViews.

Parameters:
source - The source that actually started the drag.
listener - The listener that will be used as a callback. Note that the carried data is for internal use, only. The listener needs to know the data of the drag and drop operation.
trigger - The trigger to pass on to DragSource.startDrag().
dragCursor - The cursor to pass on to DragSource.startDrag().

startDrag

public void startDrag(java.awt.dnd.DragSource source,
                      NodeRealizer nr,
                      java.awt.dnd.DragGestureEvent trigger,
                      java.awt.Cursor dragCursor)
Initiates dragging a NodeRealizer on a given DragSource that can be handled by registered Graph2DViews.

Parameters:
source - The source that actually started the drag.
nr - The NodeRealizer to display during the drag and to drop into the view in dropNodeRealizer().
trigger - The trigger to pass on to DragSource.startDrag().
dragCursor - The cursor to pass on to DragSource.startDrag()

startDrag

public void startDrag(java.awt.dnd.DragSource source,
                      EdgeRealizer er,
                      java.awt.dnd.DragGestureEvent trigger,
                      java.awt.Cursor dragCursor)
Initiates dragging an EdgeRealizer on a given DragSource that can be handled by registered Graph2DViews.

Parameters:
source - The source that actually started the drag.
er - The realizer to drop into the view in dropEdgeRealizer().
trigger - The trigger to pass on to DragSource.startDrag().
dragCursor - The cursor to pass on to DragSource.startDrag().

isSnappingEnabled

public boolean isSnappingEnabled()
Returns whether or not this support class should use the snap context to provide snap lines during the drag operation.

The default is false.

Returns:
true if snap lines are provided during the drag operation; false otherwise.
See Also:
setSnappingEnabled(boolean)

setSnappingEnabled

public void setSnappingEnabled(boolean enabled)
Specifies whether or not this support class should use the snap context to provide snap lines during the drag operation.

The default is false.

Parameters:
enabled - if true snap line are provided during the drag operation.
See Also:
isSnappingEnabled()

isPreviewEnabled

public boolean isPreviewEnabled()
Returns whether or not this support class should show a preview of the dragged node realizer during the drag operation.

The default is true.

Returns:
true if a node preview is shown during the drag operation; false otherwise.
See Also:
setPreviewEnabled(boolean)

setPreviewEnabled

public void setPreviewEnabled(boolean enabled)
Specifies whether or not this support class should show a preview of the dragged node realizer during the drag operation.

The default is true.

Parameters:
enabled - if true a node preview is shown during the drag operation.
See Also:
isPreviewEnabled()

isIndicatingSourceNode

public boolean isIndicatingSourceNode()
Determines whether or not possible source nodes are highlighted during edge drag operations.

Defaults to false.

Returns:
true if source nodes are highlighted; false otherwise.
See Also:
setIndicatingSourceNode(boolean), drawSourceNodeIndicator(java.awt.Graphics2D, NodeRealizer), getSourceNodeIndicatorBounds(NodeRealizer)

setIndicatingSourceNode

public void setIndicatingSourceNode(boolean enabled)
Specifies whether or not possible source nodes are highlighted during edge drag operations.

Defaults to false.

Parameters:
enabled - if true possible source nodes are highlighted during edge drag operations.
See Also:
isIndicatingSourceNode(), drawSourceNodeIndicator(java.awt.Graphics2D, NodeRealizer), getSourceNodeIndicatorBounds(NodeRealizer)

getSnapContext

public MoveSnapContext getSnapContext()
Gets the MoveSnapContext that is used by this instance if snapping is enabled.

Returns:
the MoveSnapContext instance used to provide snap lines.
See Also:
setSnapContext(MoveSnapContext)

setSnapContext

public void setSnapContext(MoveSnapContext snapContext)
Sets the new MoveSnapContext that is used by this instance if snapping is enabled.

Parameters:
snapContext - the MoveSnapContext instance to provide snap lines.
See Also:
getSnapContext()

createSupport

public void createSupport(Graph2DView view)
Creates a support class for the provided Graph2DView that will enable the provided view to react to started drag operations.

Parameters:
view - The view to register the specialized DropTarget with.
See Also:
removeSupport(Graph2DView), createRealizerDropSupport(Graph2DView)

removeSupport

public void removeSupport(Graph2DView view)
Removes the previously created support from the provided view.

Parameters:
view - The view to remove the drop support from.
See Also:
createSupport(Graph2DView)

createRealizerDropSupport

public void createRealizerDropSupport(Graph2DView view)
Registers support for dropping node realizer and edge realizer instances onto the provided view. This will automatically create support for drop operations on the view if this has not been done, already.

Parameters:
view - The to add support to.
See Also:
removeRealizerDropSupport(Graph2DView)

removeRealizerDropSupport

public void removeRealizerDropSupport(Graph2DView view)
Removes previously added support for dropping realizers from the given view.

Parameters:
view - The view to remove the support from.
See Also:
createRealizerDropSupport(Graph2DView)

setListener

public void setListener(Graph2DView view,
                        java.awt.datatransfer.DataFlavor flavor,
                        java.awt.dnd.DropTargetListener listener)
Sets a specific DropTargetListener that will be used in the Graph2DView if the given DataFlavor is being dragged into the view. This allows for registering different DropTargetListener instances to which the event will be multiplexed, depending on the DataFlavor.

Parameters:
view - The view to add a listener to.
flavor - The flavor for which the listener will be registered.
listener - The listener to delegate to or null in order to remove a previously registered listener.
See Also:
removeListener(Graph2DView, java.awt.datatransfer.DataFlavor)

removeListener

public void removeListener(Graph2DView view,
                           java.awt.datatransfer.DataFlavor flavor)
Removes a previously set listener from the provided view.

Parameters:
view - The view to remove the listener from.
flavor - The flavor for which the listener had been registered.

getNodeEventHandler

public DropSupport.EventHandler getNodeEventHandler()
Returns the event handler for node transfers.

Returns:
the event handler for node transfers.
See Also:
setNodeEventHandler(y.view.DropSupport.EventHandler)

setNodeEventHandler

public void setNodeEventHandler(DropSupport.EventHandler handler)
Sets the event handler for node transfers.

A custom event handler may be used if the built-in support for node transfers has to be used with custom data flavors. E.g. for inter-process drag and drop support, the internal data flavor for node transfers cannot be used and a custom data flavor is necessary to access transfer data.

The specified handler's getTransferData methods have to return NodeRealizer instances. Otherwise, a ClassCastException will be thrown during drag and drop operations.

Parameters:
handler - the event handler for node transfers.
Throws:
java.lang.IllegalArgumentException - if the specified handler is null.

getEdgeEventHandler

public DropSupport.EventHandler getEdgeEventHandler()
Returns the event handler for edge transfers.

Returns:
the event handler for edge transfers.
See Also:
setEdgeEventHandler(y.view.DropSupport.EventHandler)

setEdgeEventHandler

public void setEdgeEventHandler(DropSupport.EventHandler handler)
Sets the event handler for edge transfers.

A custom event handler may be used if the built-in support for edge transfers has to be used with custom data flavors. E.g. for inter-process drag and drop support, the internal data flavor for edge transfers cannot be used and a custom data flavor is necessary to access transfer data.

The specified handler's getTransferData methods have to return EdgeRealizer instances. Otherwise, a ClassCastException will be thrown during drag and drop operations.

Parameters:
handler - the event handler for edge transfers.
Throws:
java.lang.IllegalArgumentException - if the specified handler is null.

requestFocus

protected void requestFocus(Graph2DView view)
Requests the input focus for the given view after a successful edge or node drop.

Parameters:
view - the view that should receive the input focus.
See Also:
dropEdgeRealizer(Graph2DView, EdgeRealizer, double, double), dropNodeRealizer(Graph2DView, NodeRealizer, double, double)

getSourceNodeIndicatorBounds

protected java.awt.Rectangle getSourceNodeIndicatorBounds(NodeRealizer nodeRealizer)
Calculates the bounds of the isIndicatingSourceNode() source node indicator} during edge drag operations. Client code that overrides drawSourceNodeIndicator(java.awt.Graphics2D, NodeRealizer) should also override this method accordingly.

Parameters:
nodeRealizer - The realizer to highlight.
Returns:
The bounds of the drawable.

drawSourceNodeIndicator

protected void drawSourceNodeIndicator(java.awt.Graphics2D g,
                                       NodeRealizer nodeRealizer)
Paints the isIndicatingSourceNode() source node indicator} during edge drag operations. Client code that overrides this method to draw a custom indicator should also override getSourceNodeIndicatorBounds(NodeRealizer) accordingly.

Parameters:
g - the graphics context to paint upon.
nodeRealizer - the realizer to highlight.

findEditMode

protected EditMode findEditMode(Graph2DView view)
Tries to find the EditMode instance in the given view to start the edge creation.

Parameters:
view - The view to search.
Returns:
The EditMode instance or null.

dropNodeRealizer

protected boolean dropNodeRealizer(Graph2DView view,
                                   NodeRealizer r,
                                   double worldCoordX,
                                   double worldCoordY)
Callback method that creates the node after a drop operation.

Parameters:
view - The view to create the node in
r - The realizer to use
worldCoordX - The center world coordinates.
worldCoordY - The center world coordinates.
Returns:
Whether the creation was successful.

createNode

protected Node createNode(Graph2DView view,
                          NodeRealizer r,
                          double worldCoordX,
                          double worldCoordY)
Callback that creates the node in response to dropNodeRealizer(Graph2DView, NodeRealizer, double, double).

Parameters:
view - The view to create the node in.
r - The realizer to create.
worldCoordX - The center world coordinates.
worldCoordY - The center world coordinates.
Returns:
The created node or null.

isEdgeSplittingEnabled

public boolean isEdgeSplittingEnabled()
Determines whether or not this drop support should split an edge when a dragged node is dropped onto it.

Defaults to false.

Returns:
true if this drop support should split an edge when a dragged node is dropped onto it; false otherwise.
See Also:
setEdgeSplittingEnabled(boolean), EdgeSplitSupportImpl.getSplitEdge(Graph2DView, YPoint), EdgeSplitSupportImpl.splitEdge(Graph2D, y.base.Edge, YPoint, y.base.Node), EdgeSplitSupportImpl.setIndicatingSplitEdge(boolean)

setEdgeSplittingEnabled

public void setEdgeSplittingEnabled(boolean enabled)
Specifies whether or not this drop support should split an edge when a dragged node is dropped onto it.

Defaults to false.

Parameters:
enabled - if true an edge is split when a dragged node is dropped onto it.
See Also:
isEdgeSplittingEnabled(), EdgeSplitSupportImpl.getSplitEdge(Graph2DView, YPoint), EdgeSplitSupportImpl.splitEdge(Graph2D, y.base.Edge, YPoint, y.base.Node), EdgeSplitSupportImpl.setIndicatingSplitEdge(boolean)

setParent

protected void setParent(Node child,
                         Node parent)
Assigns the specified child node to the specified parent node.

Parameters:
child - the node that is assigned to a new group node.
parent - the container group node.

dropEdgeRealizer

protected boolean dropEdgeRealizer(Graph2DView view,
                                   EdgeRealizer realizer,
                                   double worldCoordX,
                                   double worldCoordY)
Tries to start the edge creation using the edit mode in the provided view.

Parameters:
view - The view to start the creation in.
realizer - The realizer to use as a template.
worldCoordX - The location of the mouse during the drop operation.
worldCoordY - The location of the mouse during the drop operation.
Returns:
Whether or not creation was successful.

isEdgeCreationAllowed

protected boolean isEdgeCreationAllowed(EditMode editMode)
Determines whether edge creation is allowed for the provided EditMode This implementation uses the EditMode.doAllowEdgeCreation() property to determine the result.

Parameters:
editMode - The mode to inspect
Returns:
Whether edges may be created.

createTransferable

public java.awt.datatransfer.Transferable createTransferable(NodeRealizer nr)
Creates a Transferable for the given NodeRealizer that is understood by this instance's support for dropping nodes.

Parameters:
nr - The realizer to drag.
Returns:
A transferable.

createTransferable

public java.awt.datatransfer.Transferable createTransferable(EdgeRealizer er)
Creates a Transferable for the given EdgeRealizer that is understood by this instance's support for dropEdgeRealizer(Graph2DView, EdgeRealizer, double, double) dropping edges}.

Parameters:
er - The realizer to use for the edge creation.
Returns:
A transferable.

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.