Search this API

y.view
Class Graph2DClipboard

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

public class Graph2DClipboard
extends java.lang.Object

Provides clipboard functionality for diagrams of type Graph2D. The clipboard can be used to create a copy of the selected parts of a Graph2D instance. Also it can be used to paste a formerly copied subgraph into a graph again. Swing Actions are provided that encapsulate Cut, Copy and Paste functionality.

The clipboard uses a GraphFactory to create copies of graph elements. By default an instance of Graph2DCopyFactory is used as factory.

See Also:
setCopyFactory(y.util.GraphCopier.CopyFactory)
 

Field Summary
static byte PASTE_TARGET_GROUP_POLICY_LOCATION
          Policy that specifies that the paste action should use a group node that contains the coordinates of the paste location as parent node for the pasted graph elements.
static byte PASTE_TARGET_GROUP_POLICY_NONE
          Policy that specifies that the paste action should not try to find a suitable parent group node for the pasted graph elements.
static byte PASTE_TARGET_GROUP_POLICY_SELECTION
          Policy that specifies that the paste action should use a group node that is selected as parent node for the pasted graph elements.
 
Constructor Summary
Graph2DClipboard(ViewContainer vc)
          Creates a new clipboard for the graphs managed by the given view container.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds a PropertyChangeListener to this clipboard.
protected  Edge copyEdge(Graph targetGraph, Node newSource, Node newTarget, Edge sourceEdge)
          Copies the given source edge to the targetGraph using the getCopyFactory(y.base.Graph) and the provide new source and target nodes.
protected  NodeList copyGraph(Graph sourceGraph, Graph targetGraph, NodeCursor sourceNodes)
          Copies parts of one graph to another graph.
protected  Node copyNode(Graph targetGraph, Node sourceNode)
          Copies the given source node to the targetGraph using the getCopyFactory(y.base.Graph).
 void copyToClipBoard(Graph graph, NodeCursor nc)
          Copies parts of the given graph to the clipboard.
protected  Graph getClipboardGraph()
          Returns the internal graph that is used to store the contents of the clipboard.
 javax.swing.Action getCopyAction()
          Returns a swing action that provides the Copy operation on graphs.
 GraphCopier.CopyFactory getCopyFactory()
           
protected  GraphCopier.CopyFactory getCopyFactory(Graph forGraph)
           
 javax.swing.Action getCutAction()
          Returns a swing action that provides the Cut operation on graphs.
protected  Graph2D getGraph2D()
          Returns the graph that is displayed in the current view.
 javax.swing.Action getPasteAction()
          Returns a swing action that provides the Paste operation on graphs.
 byte getPasteTargetGroupPolicy()
          Returns the policy used to determine the parent node for nodes that are pasted using the clipboard's paste action.
 ViewContainer getViewContainer()
          Returns the viewContainer associated with this clipboard.
 boolean isEmpty()
          Returns whether or not the clipboard is currently empty.
 boolean isSelectionEmpty()
          Returns whether or not there are selected nodes in the active graph.
 boolean isSelectionStateObserverEnabled()
          Whether or not the selection state of the current graph will be observed.
 NodeList pasteFromClipBoard(Graph targetGraph)
          Pastes the elements of the clipboard graph to the given graph.
 NodeList pasteFromClipBoard(Graph targetGraph, double x, double y)
          Pastes the elements of the clipboard graph to the given graph.
 NodeList pasteFromClipBoard(Graph targetGraph, Node targetParentGroup)
          Pastes the elements of the clipboard graph to the given graph.
 NodeList pasteFromClipBoard(Graph targetGraph, Node targetParentGroup, double x, double y)
          Pastes the elements of the clipboard graph to the given graph.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes a PropertyChangeListener from this clipboard.
 void setCopyFactory(GraphCopier.CopyFactory copyFactory)
           
 void setPasteTargetGroupPolicy(byte pasteTargetGroupPolicy)
          Specifies the policy used to determine the parent node for nodes that are pasted using the clipboard's paste action.
 void setSelectionStateObserverEnabled(boolean enabled)
          Whether or not to enable the observation of the selection state of the current graph.
 void updateSelectionState()
          Forces update of the selection state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASTE_TARGET_GROUP_POLICY_NONE

public static final byte PASTE_TARGET_GROUP_POLICY_NONE
Policy that specifies that the paste action should not try to find a suitable parent group node for the pasted graph elements.

See Also:
getPasteTargetGroupPolicy(), setPasteTargetGroupPolicy(byte), Constant Field Values

PASTE_TARGET_GROUP_POLICY_LOCATION

public static final byte PASTE_TARGET_GROUP_POLICY_LOCATION
Policy that specifies that the paste action should use a group node that contains the coordinates of the paste location as parent node for the pasted graph elements.

See Also:
getPasteTargetGroupPolicy(), setPasteTargetGroupPolicy(byte), Constant Field Values

PASTE_TARGET_GROUP_POLICY_SELECTION

public static final byte PASTE_TARGET_GROUP_POLICY_SELECTION
Policy that specifies that the paste action should use a group node that is selected as parent node for the pasted graph elements.

See Also:
getPasteTargetGroupPolicy(), setPasteTargetGroupPolicy(byte), Constant Field Values
Constructor Detail

Graph2DClipboard

public Graph2DClipboard(ViewContainer vc)
Creates a new clipboard for the graphs managed by the given view container.

Method Detail

getCopyFactory

public GraphCopier.CopyFactory getCopyFactory()

setCopyFactory

public void setCopyFactory(GraphCopier.CopyFactory copyFactory)

getClipboardGraph

protected Graph getClipboardGraph()
Returns the internal graph that is used to store the contents of the clipboard.


isEmpty

public boolean isEmpty()
Returns whether or not the clipboard is currently empty. A PropertyChangeEvent will be fired whenever this state changes.


isSelectionEmpty

public boolean isSelectionEmpty()
Returns whether or not there are selected nodes in the active graph. A PropertyChangeEvent will be fired whenever this state changes.


copyToClipBoard

public void copyToClipBoard(Graph graph,
                            NodeCursor nc)
Copies parts of the given graph to the clipboard. The copied subgraph is induced by the nodes accessible via the given NodeCursor.


getCopyFactory

protected GraphCopier.CopyFactory getCopyFactory(Graph forGraph)

getGraph2D

protected Graph2D getGraph2D()
Returns the graph that is displayed in the current view. The actions provided by this class act upon this graph.


copyGraph

protected NodeList copyGraph(Graph sourceGraph,
                             Graph targetGraph,
                             NodeCursor sourceNodes)
Copies parts of one graph to another graph.


pasteFromClipBoard

public NodeList pasteFromClipBoard(Graph targetGraph,
                                   double x,
                                   double y)
Pastes the elements of the clipboard graph to the given graph. The clipboard graph will be pasted in a way that the upper left corner of its bounding box matches the given location. Invoking this method is equivalent to:
pasteFromClipBoard(targetGraph, null, x, y);

Parameters:
targetGraph - the graph pasted to.
x - the x-coordinate of the paste location
y - the y-coordinate of the paste location
Returns:
the pasted nodes.
See Also:
pasteFromClipBoard(y.base.Graph, y.base.Node, double, double)

pasteFromClipBoard

public NodeList pasteFromClipBoard(Graph targetGraph,
                                   Node targetParentGroup,
                                   double x,
                                   double y)
Pastes the elements of the clipboard graph to the given graph. The clipboard graph will be pasted in a way that the upper left corner of its bounding box matches the given location.

Parameters:
targetGraph - the graph pasted to.
targetParentGroup - the group node that is to be assigned as parent node for the pasted nodes or null if the pasted nodes should not be assigned to any group node.
x - the x-coordinate of the paste location
y - the y-coordinate of the paste location
Returns:
the pasted nodes.
Throws:
java.lang.IllegalStateException - if a non-null parent node is specified and there is no HierarchyManager assigned to the target graph.
java.lang.IllegalArgumentException - if a non-null parent node is specified and the specified parent node does not belong to the target graph, or the specified parent node is not a group node (according to HierarchyManager.isGroupNode(y.base.Node)).

pasteFromClipBoard

public NodeList pasteFromClipBoard(Graph targetGraph)
Pastes the elements of the clipboard graph to the given graph. Invoking this method is equivalent to:
pasteFromClipBoard(targetGraph, null);

Parameters:
targetGraph - the graph pasted to.
Returns:
the pasted nodes.
See Also:
pasteFromClipBoard(y.base.Graph, y.base.Node)

pasteFromClipBoard

public NodeList pasteFromClipBoard(Graph targetGraph,
                                   Node targetParentGroup)
Pastes the elements of the clipboard graph to the given graph.

Parameters:
targetGraph - the graph pasted to.
targetParentGroup - the group node that is to be assigned as parent node for the pasted nodes or null if the pasted nodes should not be assigned to any group node.
Returns:
the pasted nodes.
Throws:
java.lang.IllegalStateException - if a non-null parent node is specified and there is no HierarchyManager assigned to the target graph.
java.lang.IllegalArgumentException - if a non-null parent node is specified and the specified parent node does not belong to the target graph, or the specified parent node is not a group node (according to HierarchyManager.isGroupNode(y.base.Node)).

getPasteTargetGroupPolicy

public byte getPasteTargetGroupPolicy()
Returns the policy used to determine the parent node for nodes that are pasted using the clipboard's paste action. One of

Defaults to PASTE_TARGET_GROUP_POLICY_NONE.

Note: The paste action's PASTE_TARGET_GROUP_POLICY property value will supersede the clipboard's pasteTargetGroupPolicy value, if the action's property value is set and of type Byte.

Returns:
the policy used to determine the parent node for nodes that are pasted using the clipboard's paste action.
See Also:
setPasteTargetGroupPolicy(byte), Action.getValue(java.lang.String)

setPasteTargetGroupPolicy

public void setPasteTargetGroupPolicy(byte pasteTargetGroupPolicy)
Specifies the policy used to determine the parent node for nodes that are pasted using the clipboard's paste action.

Defaults to PASTE_TARGET_GROUP_POLICY_NONE.

Alternatively, property PASTE_TARGET_GROUP_POLICY can be used to specify the policy to determine the parent node on the paste action using the action's putValue method.

Parameters:
pasteTargetGroupPolicy - the policy used to determine the parent node for nodes that are pasted using the clipboard's paste action. One of
See Also:
getPasteTargetGroupPolicy(), Action.putValue(java.lang.String,java.lang.Object)

getCutAction

public javax.swing.Action getCutAction()
Returns a swing action that provides the Cut operation on graphs.


getCopyAction

public javax.swing.Action getCopyAction()
Returns a swing action that provides the Copy operation on graphs.


getPasteAction

public javax.swing.Action getPasteAction()
Returns a swing action that provides the Paste operation on graphs. The property value PASTE_LOCATION can be used to provide an instance of YPoint that specifies the preferred paste location. The property value PASTE_TARGET_GROUP_POLICY can be used to provide a Byte instance that specifies the preferred policy used to determine the parent node for pasted graph elements.

See Also:
setPasteTargetGroupPolicy(byte), PASTE_TARGET_GROUP_POLICY_NONE, PASTE_TARGET_GROUP_POLICY_LOCATION, PASTE_TARGET_GROUP_POLICY_SELECTION

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a PropertyChangeListener to this clipboard. Listeners will be informed when the property "empty" changes.


removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from this clipboard.


getViewContainer

public ViewContainer getViewContainer()
Returns the viewContainer associated with this clipboard.


copyNode

protected Node copyNode(Graph targetGraph,
                        Node sourceNode)
Copies the given source node to the targetGraph using the getCopyFactory(y.base.Graph).


copyEdge

protected Edge copyEdge(Graph targetGraph,
                        Node newSource,
                        Node newTarget,
                        Edge sourceEdge)
Copies the given source edge to the targetGraph using the getCopyFactory(y.base.Graph) and the provide new source and target nodes.


updateSelectionState

public void updateSelectionState()
Forces update of the selection state. Depending on the selection state the Cut and Copy actions will be enabled or not.


isSelectionStateObserverEnabled

public boolean isSelectionStateObserverEnabled()
Whether or not the selection state of the current graph will be observed.


setSelectionStateObserverEnabled

public void setSelectionStateObserverEnabled(boolean enabled)
Whether or not to enable the observation of the selection state of the current graph. Observing the selection state will allow to keep the enabled state of the Cut and Copy actions in sync with the selection state. Disabling the observation will effectively deregister all listeners from the current graph.


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