Search this API

y.layout
Class CopiedLayoutGraph

java.lang.Object
  extended by y.base.Graph
      extended by y.layout.LayoutGraph
          extended by y.layout.CopiedLayoutGraph
All Implemented Interfaces:
GraphInterface, GraphLayout

public class CopiedLayoutGraph
extends LayoutGraph

A CopiedLayoutGraph is a LayoutGraph that serves as a copy of another graph with layout information.

This graph can either be described by another LayoutGraph instance or a combination of GraphInterface and GraphLayout implementations.

A CopiedLayoutGraph comes to use if a layout algorithm should not run directly on the original graph. Using a copy, the calculated layout will not be applied to the original graph before the layout algorithm finished successfully. This can prevent inconsistencies in case something goes wrong during layout calculations.

Concept

CopiedLayoutGraph contains corresponding nodes and edges for each node and edge in the original graph and copies the labels of the original nodes and edges. It also delegates all DataProviders registered with the original graph.

To preserve the relations between the original elements and the copied elements in this graph, CopiedLayoutGraph updates mappings between those elements.

If there are structural changes to the original graph, they can be transferred to this copied graph using syncStructure(). Then the copied graph will be altered, adding and removing elements, until it corresponds to the original again.

Method commitLayoutToOriginalGraph() will transfer updated layout information to the original graph. The original graph will stay unchanged until this method is called.

See Also:
BufferedLayouter
 

Field Summary
 
Fields inherited from class y.base.Graph
AFTER, BEFORE
 
Constructor Summary
CopiedLayoutGraph(GraphInterface graph, GraphLayout layout)
          Creates a new CopiedLayoutGraph instance which is a copy of the graph specified by the given GraphInterface and GraphLayout.
CopiedLayoutGraph(LayoutGraph graph)
          Creates a new CopiedLayoutGraph instance which is a copy of the given graph.
 
Method Summary
 void commitLayoutToOriginalGraph()
          Writes the current layout information of all elements of this copied graph to the original graph.
 Edge createEdge(java.lang.Object originalEdge)
          Creates an edge in the copied graph that corresponds to the given original edge.
protected  GraphCopier.CopyFactory createGraphCopyFactory()
          Creates a factory that creates a CopiedLayoutGraph when copying a graph using GraphCopier.
protected  LabelLayoutFactory createLabelFactory()
          Creates a new LabelLayoutFactory for this CopiedLayoutGraph.
 Node createNode(java.lang.Object originalNode)
          Creates a node in the copied graph that corresponds to the given original node.
 Edge getCopiedEdge(java.lang.Object originalEdge)
          Returns the copied edge that corresponds to the given original edge.
 Node getCopiedNode(java.lang.Object originalNode)
          Returns the copied node that corresponds to the given original node.
 Edge getFeature(EdgeLabelLayout labelLayout)
          Returns the edge of the copied graph to which the given EdgeLabelLayout belongs.
 Node getFeature(NodeLabelLayout labelLayout)
          Returns the node of the copied graph to which the given NodeLabelLayout belongs.
 EdgeLabelLayout[] getLabelLayout(Edge copiedEdge)
          Returns the layout information for all labels associated with the given edge of the copied graph.
 NodeLabelLayout[] getLabelLayout(Node copiedNode)
          Returns the layout information for all labels associated with the given node of the copied graph.
 EdgeLayout getLayout(Edge copiedEdge)
          Returns the layout information for the given edge of the copied graph.
 NodeLayout getLayout(Node copiedNode)
          Returns the layout information for the given node of the copied graph.
 GraphLayout getLayoutForOriginalGraph()
          Returns a GraphLayout that is valid for the original graph.
 java.lang.Object getOriginalEdge(Edge copiedEdge)
          Returns the original edge that corresponds to the given copied edge.
 GraphInterface getOriginalGraph()
          Returns the original graph.
 GraphLayout getOriginalLayout()
          Returns the original layout information of the graph.
 java.lang.Object getOriginalNode(Node copiedNode)
          Returns the original node that corresponds to the given copied node.
 void syncStructure()
          Synchronizes the structure of the CopiedLayoutGraph with the actual structure of the underlying original graph.
 
Methods inherited from class y.layout.LayoutGraph
getBoundingBox, getCenter, getCenterX, getCenterY, getEdgeLabelLayout, getEdgeLayout, getEdgeList, getHeight, getLocation, getNodeLabelLayout, getNodeLayout, getPath, getPathList, getPointList, getPoints, getRectangle, getSize, getSourcePointAbs, getSourcePointRel, getTargetPointAbs, getTargetPointRel, getWidth, getX, getY, moveBy, setCenter, setCenter, setEndPointsAbs, setLocation, setLocation, setPath, setPath, setPoints, setPoints, setSize, setSize, setSourcePointAbs, setSourcePointRel, setTargetPointAbs, setTargetPointRel
 
Methods inherited from class y.base.Graph
addDataProvider, addGraphListener, changeEdge, changeEdge, changeEdge, clear, contains, contains, containsEdge, createCopy, createEdge, createEdge, createEdgeMap, createGraph, createNode, createNodeMap, disposeEdgeMap, disposeNodeMap, E, edgeCount, edgeObjects, edges, fireGraphEvent, firePostEvent, firePostEvent, firePreEvent, firePreEvent, firstEdge, firstNode, firstOutEdge, getDataProvider, getDataProviderKeys, getEdgeArray, getGraphCopyFactory, getGraphListeners, getNodeArray, getRegisteredEdgeMaps, getRegisteredNodeMaps, getSource, getTarget, hasListeners, hide, hide, isEmpty, lastEdge, lastNode, moveSubGraph, moveToFirst, moveToFirst, moveToLast, moveToLast, N, nodeCount, nodeObjects, nodes, printNodeSlotSize, reInsertEdge, reInsertNode, removeDataProvider, removeEdge, removeGraphListener, removeNode, reverseEdge, setGraphCopyFactory, sortEdges, sortEdges, sortNodes, toString, unhide, unhide
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CopiedLayoutGraph

public CopiedLayoutGraph(LayoutGraph graph)
Creates a new CopiedLayoutGraph instance which is a copy of the given graph.

Parameters:
graph - the original graph

CopiedLayoutGraph

public CopiedLayoutGraph(GraphInterface graph,
                         GraphLayout layout)
Creates a new CopiedLayoutGraph instance which is a copy of the graph specified by the given GraphInterface and GraphLayout.

Parameters:
graph - the original graph
layout - the layout information for the original graph
Method Detail

createEdge

public Edge createEdge(java.lang.Object originalEdge)
Creates an edge in the copied graph that corresponds to the given original edge.

The edge will connect to the copies of the source and target of the original edge. All labels of the original edge will be also copied and assigned to this edge.

The mappings are updated. Hence, it is possible to look up the newly created edge by using getCopiedEdge(Object) or the original edge by using getOriginalEdge(Edge).

This method can be used for keeping the CopiedLayoutGraph in sync with the original graph.

Parameters:
originalEdge - the original edge
Returns:
the copy of the original edge

createGraphCopyFactory

protected GraphCopier.CopyFactory createGraphCopyFactory()
Creates a factory that creates a CopiedLayoutGraph when copying a graph using GraphCopier.

Subclasses must delegate to the methods createNode(Object) and createEdge(Object) to create new graph elements. Otherwise, the mappings are not correctly built.

Specified by:
createGraphCopyFactory in class LayoutGraph
Returns:
a new instance of GraphCopier.CopyFactory that builds up a CopiedLayoutGraph

createNode

public Node createNode(java.lang.Object originalNode)
Creates a node in the copied graph that corresponds to the given original node.

All labels of the original node will be copied and assigned to this node.

The mappings are updated. Hence, it is possible to look up the newly created node by using getCopiedNode(Object) or the original node by using getOriginalNode(Node).

This method can be used for keeping the CopiedLayoutGraph in sync with the original graph.

Parameters:
originalNode - the original node
Returns:
the copy of the original node

syncStructure

public void syncStructure()
Synchronizes the structure of the CopiedLayoutGraph with the actual structure of the underlying original graph.


getLayout

public NodeLayout getLayout(Node copiedNode)
Returns the layout information for the given node of the copied graph.

If there is no layout information for this node, yet, a new implementation of NodeLayout is returned.

Specified by:
getLayout in class LayoutGraph
Parameters:
copiedNode - the node
Returns:
the layout information for the node

getLayout

public EdgeLayout getLayout(Edge copiedEdge)
Returns the layout information for the given edge of the copied graph.

If there is no layout information for this edge, yet, a new implementation of EdgeLayout is returned.

Specified by:
getLayout in class LayoutGraph
Parameters:
copiedEdge - the edge
Returns:
the layout information for the edge

getLabelLayout

public NodeLabelLayout[] getLabelLayout(Node copiedNode)
Returns the layout information for all labels associated with the given node of the copied graph.

If there is no layout information for a label, yet, a new implementation of NodeLabelLayout is created.

Specified by:
getLabelLayout in class LayoutGraph
Parameters:
copiedNode - the node
Returns:
the label layout information for all labels of the given node

getLabelLayout

public EdgeLabelLayout[] getLabelLayout(Edge copiedEdge)
Returns the layout information for all labels associated with the given edge of the copied graph.

If there is no layout information for a label, yet, a new implementation of EdgeLabelLayout is created.

Specified by:
getLabelLayout in class LayoutGraph
Parameters:
copiedEdge - the edge
Returns:
the label layout information for all labels of the given edge

getFeature

public Node getFeature(NodeLabelLayout labelLayout)
Returns the node of the copied graph to which the given NodeLabelLayout belongs.

Specified by:
getFeature in class LayoutGraph
Parameters:
labelLayout - a label layout information of a node in the copied graph
Returns:
the node that belongs to the given label layout

getFeature

public Edge getFeature(EdgeLabelLayout labelLayout)
Returns the edge of the copied graph to which the given EdgeLabelLayout belongs.

Specified by:
getFeature in class LayoutGraph
Parameters:
labelLayout - a label layout information of an edge in the copied graph
Returns:
the edge that belongs to the given label layout

getLayoutForOriginalGraph

public GraphLayout getLayoutForOriginalGraph()
Returns a GraphLayout that is valid for the original graph.

The GraphLayout contains the identical layout information as the copied graph. However, it uses the original graph elements as lookup domain. Therefore, this GraphLayout will return the same layout information for an original node as getLayout(Node) does for the corresponding copied node.

 
The original LayoutGraph or GraphLayout is not altered by this method.
Returns:
the GraphLayout of the copied graph adjusted to the original graph

commitLayoutToOriginalGraph

public void commitLayoutToOriginalGraph()
Writes the current layout information of all elements of this copied graph to the original graph.

 
This works only if the original graph structure was not changed.

getOriginalNode

public java.lang.Object getOriginalNode(Node copiedNode)
Returns the original node that corresponds to the given copied node.

Parameters:
copiedNode - the node in this graph that is a copy of the returned node
Returns:
the node in the original graph whose copy is the given node

getOriginalEdge

public java.lang.Object getOriginalEdge(Edge copiedEdge)
Returns the original edge that corresponds to the given copied edge.

Parameters:
copiedEdge - the edge in this graph that is a copy of the returned edge
Returns:
the edge in the original graph whose copy is the given edge

getCopiedNode

public Node getCopiedNode(java.lang.Object originalNode)
Returns the copied node that corresponds to the given original node.

Parameters:
originalNode - a node of the original graph whose copy resides in this graph
Returns:
a node in this graph that is the copy of the given original node

getCopiedEdge

public Edge getCopiedEdge(java.lang.Object originalEdge)
Returns the copied edge that corresponds to the given original edge.

Parameters:
originalEdge - an edge of the original graph whose copy resides in this graph
Returns:
an edge in this graph that is the copy of the given original edge

getOriginalGraph

public GraphInterface getOriginalGraph()
Returns the original graph.

Returns:
the original graph

getOriginalLayout

public GraphLayout getOriginalLayout()
Returns the original layout information of the graph.

Returns:
the original layout

createLabelFactory

protected LabelLayoutFactory createLabelFactory()
Creates a new LabelLayoutFactory for this CopiedLayoutGraph.

Subclasses overriding this method must provide an instance that manages the mapping between copied and original LabelLayouts.

Specified by:
createLabelFactory in class LayoutGraph
Returns:
the new label layout factory

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