com.yworks.yfiles.server.graphml.folding
Class FoldedLayoutGraph

java.lang.Object
  extended byy.base.Graph
      extended byy.layout.LayoutGraph
          extended byy.layout.DefaultLayoutGraph
              extended bycom.yworks.yfiles.server.graphml.flexio.data.StyledLayoutGraph
                  extended bycom.yworks.yfiles.server.graphml.folding.FoldedLayoutGraph
All Implemented Interfaces:
GraphInterface, GraphLayout, ViewStateCreator

public class FoldedLayoutGraph
extends StyledLayoutGraph
implements ViewStateCreator

A LayoutGraph that supports folding operations.

This graph implementation supports folding through the collapse(Node) operation and provides access to dummy states for nodes and edges.

Distinct layouts and styles can be assigned to dummy states. Access to the dummy states is provided through getEdgeViewState(DummyEdgeId) and getNodeViewState(DummyNodeId).

The folded graph also supports the notion of a local root, which is relevant for layout calculations.


Field Summary
 
Fields inherited from class y.layout.DefaultLayoutGraph
edgeLabelFeatureMap, edgeLabelMap, nodeLabelFeatureMap, nodeLabelMap
 
Fields inherited from class y.layout.LayoutGraph
z
 
Fields inherited from class y.base.Graph
AFTER, BEFORE
 
Constructor Summary
FoldedLayoutGraph()
          Creates a new instance of a folded layout graph.
 
Method Summary
 void collapse(Node node)
          Collapse a group node, hiding its children from the current view.
 EdgeViewState createEdgeViewState(DummyEdgeId edgeId)
          Creates an edge view state instance for the provided edge id.
protected  DataMap createEdgeViewStateMap()
          Create the DataMap that stores the EdgeViewState instances for dummy edges.
protected  DataMap createExpansionStateMap()
          Create the DataMap that stores the node expansion state.
 Node createNode()
          Creates a new node, applying the default node size.
 NodeViewState createNodeViewState(DummyNodeId nodeId)
          Creates a node view state instance for the provided node id.
protected  DataMap createNodeViewStateMap()
          Create the DataMap that stores the NodeViewState instances for the collapsed state of group nodes.
 PortViewState createPortViewState(DummyNodePortId nodePortId)
          Creates a port view state instance for the provided dummy node port id.
 void doLayout(Layouter layouter)
          Calculates a layout for the folded graph view defined by this instance.
 void doLayout(Layouter layouter, Node root, boolean recursive, byte dummyEdgeMode)
          Calculates a layout for the folded graph view defined by this instance.
 void expand(Node node)
          Expands a collapsed group node, revealing its children in the folded graph view defined by this graph.
 EdgeViewState getEdgeViewState(DummyEdgeId edgeId)
          Returns the view state of a dummy edge defined by the provided dummy edge id.
 Node getLocalRoot()
          A non-leaf node that is considered the virtual root node of this graph.
 NodeViewState getNodeViewState(DummyNodeId nodeId)
          Returns the view state of a collapsed group node.
 java.lang.Object getPortOwner(com.yworks.yfiles.server.graphml.folding.DummyEdgePortId dummyEdgePortId)
          Returns the port owner of the port described by the provided dummy edge port id.
 PortViewState getPortViewState(DummyNodePortId nodePortId)
          Returns the view state of a node port defined by the provided dummy node port id.
 boolean isExpanded(Node node)
          Returns whether the provided node is currently in expanded state.
 boolean isReusingDummyNodePorts()
          Returns whether this implementation reuses the ports of dummy nodes of this graph for dummy edges.
 boolean isReusingMasterPorts()
          Returns whether this implementation reuses the ports of non-dummy nodes of this graph for dummy edges.
 void setEdgeViewState(DummyEdgeId edgeId, EdgeViewState viewState)
          Sets a view state of a dummy edge identified by the provided dummy edge id.
 void setLocalRoot(Node node)
          A non-leaf node that is considered the virtual root node of this graph.
 void setNodeViewState(DummyNodeId dummyNodeId, NodeViewState viewState)
          Sets the view state of a collapsed group node.
 void setPortViewState(DummyNodePortId nodePortId, PortViewState portViewState)
          Sets a view state of a node port identified by the provided dummy node port id.
 void setReusingDummyNodePorts(boolean value)
          Sets whether this implementation shall reuse the ports of dummy nodes of this graph for dummy edges.
 void setReusingMasterPorts(boolean value)
          Sets whether this implementation shall reuse the ports of non-dummy nodes of this graph for dummy edges.
 
Methods inherited from class com.yworks.yfiles.server.graphml.flexio.data.StyledLayoutGraph
addLabel, addLabel, addPort, changeEdge, changeEdge, createEdge, createEdge, createEdge, edgesAtPort, getDefaultNodeSize, getLabels, getLabels, getNodeHierarchy, getPorts, getSourcePort, getStyle, getStyle, getTargetPort, getUserTag, getZOrder, getZOrder, removePort, reverseEdge, setDefaultNodeSize, setSourcePort, setStyle, setStyle, setTargetPort, setUserTag, setZOrder, setZOrder, syncLabels, syncLabels
 
Methods inherited from class y.layout.DefaultLayoutGraph
createEdgeLayout, createGraphCopyFactory, createLabelFactory, createNodeLayout, getFeature, getFeature, getLabelLayout, getLabelLayout, getLayout, getLayout, setLabelLayout, setLabelLayout, setLabelLayout, setLayout, setLayout
 
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, clear, contains, contains, containsEdge, createCopy, createEdge, createEdgeMap, createGraph, 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, 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

FoldedLayoutGraph

public FoldedLayoutGraph()
Creates a new instance of a folded layout graph.

Creates and registers the data providers required for maintaining the expansion state, node- and edge view states and the local root.

{@inheritDoc}

Method Detail

isReusingMasterPorts

public boolean isReusingMasterPorts()
Returns whether this implementation reuses the ports of non-dummy nodes of this graph for dummy edges.

If set to false (the default), separate port instances are created for dummy edges at non-dummy nodes. This makes it possible to assign different styles and locations to source and target ports of dummy edges, which may be desirable if the style and geometry of dummy edges differs a lot from the style of the master edges. Dummy edges may of course still connect to non-dummy nodes at one of their ports. Setting this property to true will make the dummy edge connect to the represented port instance.

See Also:
isReusingDummyNodePorts()

setReusingMasterPorts

public void setReusingMasterPorts(boolean value)
Sets whether this implementation shall reuse the ports of non-dummy nodes of this graph for dummy edges.

If set to false (the default), separate port instances are created for dummy edges at non-dummy nodes. This makes it possible to assign different styles and locations to source and target ports of dummy edges, which may be desirable if the style and geometry of dummy edges differs a lot from the style of the master edges. Dummy edges may of course still connect to non-dummy nodes at one of their ports. Setting this property to true will make the dummy edge connect to the represented port instance.

See Also:
#reusingDummyNodePorts

isReusingDummyNodePorts

public boolean isReusingDummyNodePorts()
Returns whether this implementation reuses the ports of dummy nodes of this graph for dummy edges.

If set to false (the default), separate port instances are created for dummy edges at dummy nodes. This makes it possible to assign different styles and locations to source and target ports of dummy edges, which may be desirable if the style and geometry of dummy edges differs a lot from the style of the master edges. Dummy nodes (collapsed group nodes), will have all of their master's ports represented in the view by PortViewStates. This property can be used to make dummy edges that connect to the master ports connect to these PortViewStates instances instead of creating extra dummy ports for the edges. Note that ports can only be automatically reused by dummy edges if they still connect to the same nodes. Otherwise the view will have to create new dummy ports to let the edges connect to the representing adjacent nodes.

See Also:
isReusingMasterPorts()

setReusingDummyNodePorts

public void setReusingDummyNodePorts(boolean value)
Sets whether this implementation shall reuse the ports of dummy nodes of this graph for dummy edges.

If set to false (the default), separate port instances are created for dummy edges at dummy nodes. This makes it possible to assign different styles and locations to source and target ports of dummy edges, which may be desirable if the style and geometry of dummy edges differs a lot from the style of the master edges. Dummy nodes (collapsed group nodes), will have all of their master's ports represented in the view by PortViewStates. This property can be used to make dummy edges that connect to the master ports connect to these PortViewStates instances instead of creating extra dummy ports for the edges. Note that ports can only be automatically reused by dummy edges if they still connect to the same nodes. Otherwise the view will have to create new dummy ports to let the edges connect to the representing adjacent nodes.

See Also:
isReusingMasterPorts()

setLocalRoot

public void setLocalRoot(Node node)
A non-leaf node that is considered the virtual root node of this graph.

The local root is considered when a layout is calculated for a folded graph.

Parameters:
node - A group node that will be set as the virtual root node of this graph.

getLocalRoot

public Node getLocalRoot()
A non-leaf node that is considered the virtual root node of this graph.

The local root is considered when a layout is calculated for a folded graph.


createExpansionStateMap

protected DataMap createExpansionStateMap()
Create the DataMap that stores the node expansion state.

The map will be registered as a data provider with this graph, using the FoldedGraphKeys.EXPANSION_STATE_DPKEY key.


createNodeViewStateMap

protected DataMap createNodeViewStateMap()
Create the DataMap that stores the NodeViewState instances for the collapsed state of group nodes.

The map will be registered as a data provider with this graph, using the FoldedGraphKeys.NODE_VIEW_STATES_DPKEY key.


createEdgeViewStateMap

protected DataMap createEdgeViewStateMap()
Create the DataMap that stores the EdgeViewState instances for dummy edges.

The map will be registered as a data provider with this graph, using the FoldedGraphKeys.EDGE_VIEW_STATES_DPKEY key.


getNodeViewState

public NodeViewState getNodeViewState(DummyNodeId nodeId)
Returns the view state of a collapsed group node.

If no view state has been defined for the provided dummy node id yet, a new instance will be created and associated with the id.


setNodeViewState

public void setNodeViewState(DummyNodeId dummyNodeId,
                             NodeViewState viewState)
Sets the view state of a collapsed group node.

Parameters:
dummyNodeId - A dummy node id that identifies the collapsed state of a group node.
viewState - The node view state that describes the appearance of the collapsed group node.

createNodeViewState

public NodeViewState createNodeViewState(DummyNodeId nodeId)
Creates a node view state instance for the provided node id.

This implementation will use the current style and layout of the master node for the dummy node state.

Specified by:
createNodeViewState in interface ViewStateCreator

getEdgeViewState

public EdgeViewState getEdgeViewState(DummyEdgeId edgeId)
Returns the view state of a dummy edge defined by the provided dummy edge id.

If no view state has been defined for the provided dummy edge id yet, a new instance will be created and associated with the id.


setEdgeViewState

public void setEdgeViewState(DummyEdgeId edgeId,
                             EdgeViewState viewState)
Sets a view state of a dummy edge identified by the provided dummy edge id.

Parameters:
edgeId - A dummy edge id that identifies a dummy state of a master edge in a folded graph.
viewState - The edge view state that describes the visual appearance of the dummy edge.

createEdgeViewState

public EdgeViewState createEdgeViewState(DummyEdgeId edgeId)
Creates an edge view state instance for the provided edge id.

If #reusingMasterPorts and/or #reusingDummyNodePorts are set to true, the master ports resp. PortViewStates are reused if appropriate. Otherwise this implementation will use the current style of the master edge for the dummy edge state. The source and target port of the edge view state are then set to the center of the source and target nodes (i.e., Port instances with offsets (0,0) are used).

Specified by:
createEdgeViewState in interface ViewStateCreator

getPortViewState

public PortViewState getPortViewState(DummyNodePortId nodePortId)
Returns the view state of a node port defined by the provided dummy node port id.

If no view state has been defined for the provided dummy node port id yet, a new instance will be createPortViewState(DummyNodePortId) created} and associated with the id.


setPortViewState

public void setPortViewState(DummyNodePortId nodePortId,
                             PortViewState portViewState)
Sets a view state of a node port identified by the provided dummy node port id.

Parameters:
nodePortId - A dummy node port id that identifies a dummy state of a node port in a folded graph.
portViewState - The port view state that describes the visual appearance of the dummy node port.

createPortViewState

public PortViewState createPortViewState(DummyNodePortId nodePortId)
Creates a port view state instance for the provided dummy node port id.

This implementation will use the current Port.getStyle() style} and offset of the DummyNodePortId.getMasterPort() master port} for the dummy node port state.

Specified by:
createPortViewState in interface ViewStateCreator

getPortOwner

public java.lang.Object getPortOwner(com.yworks.yfiles.server.graphml.folding.DummyEdgePortId dummyEdgePortId)
Returns the port owner of the port described by the provided dummy edge port id.

If the port is at a collapsed node, the node's NodeViewState

Parameters:
dummyEdgePortId -
Returns:

collapse

public void collapse(Node node)
Collapse a group node, hiding its children from the current view.

Parameters:
node - A group node that will be collapsed.

expand

public void expand(Node node)
Expands a collapsed group node, revealing its children in the folded graph view defined by this graph.

Parameters:
node - A collapsed group node. If the group node is already expanded, this method does nothing.

isExpanded

public boolean isExpanded(Node node)
Returns whether the provided node is currently in expanded state.

See Also:
collapse(Node), expand(Node)

createNode

public Node createNode()
Creates a new node, applying the default node size.

Overrides:
createNode in class StyledLayoutGraph

doLayout

public void doLayout(Layouter layouter)
Calculates a layout for the folded graph view defined by this instance.

A FoldingLayoutStage is used to apply the provided layout algorithm to the folded graph view.

Overrides:
doLayout in class StyledLayoutGraph
Parameters:
layouter - The layout algorithm the will be applied to the folded graph.
See Also:
doLayout(Layouter, Node, boolean, byte)

doLayout

public void doLayout(Layouter layouter,
                     Node root,
                     boolean recursive,
                     byte dummyEdgeMode)
Calculates a layout for the folded graph view defined by this instance.

A FoldingLayoutStage is used to apply the provided layout algorithm to the folded graph view.

Parameters:
layouter - The layout algorithm the will be applied to the folded graph.
root - The node that should be considered the virtual local root for the layout calculation. A different local root than local root that is currently set for this graph can be used here.
recursive - Whether to apply a recursive layout calculation to the inner graphs defined by collapsed group nodes.
dummyEdgeMode - The dummy edge mode that should be used for dummy edges created by the folding layout stage.
See Also:
doLayout(Layouter)


Copyright © 2000-2013 yWorks GmbH. All rights reserved