com.yworks.yfiles.server.graphml.flexio.data
Class StyledLayoutGraph

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

public class StyledLayoutGraph
extends DefaultLayoutGraph

This class extends the DefaultLayoutGraph by adding convenient methods to configure styles and labels for nodes, edges and ports and to access and set their user tags.

It also provides access to an INodeHierarchy for this graph instance which offers grouping related functionality.


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
StyledLayoutGraph()
           
 
Method Summary
 void addLabel(Edge edge, Label label)
          Adds a label to the given edge.
 void addLabel(Node node, Label label)
          Adds a label to the given node.
 Port addPort(Node node, IPortLocationModelParameter locationModelParameter)
          Adds a port to the given node and returns it.
 void changeEdge(Edge e, Node newSource, Edge sourceReference, int sourceD, Node newTarget, Edge targetReference, int targetD)
           If the source or target node changes, a new port is added to its center and assigned as source resp. target port of the edge.
 void changeEdge(Edge e, Node newSource, Node newTarget)
           If the source or target node changes, a new port is added to its center and assigned as source resp. target port of the edge.
 Edge createEdge(Node v, Edge e1, Node w, Edge e2, int d1, int d2)
           The new edge is connected to the first free ports of the source and target node.
protected  Edge createEdge(Port sourcePort, Edge e1, Port targetPort, Edge e2, int d1, int d2)
          Creates a new edge in this graph and fires a corresponding notification event to inform registered listeners.
 Edge createEdge(Port source, Port target)
          Creates a new edge in this graph and fires a corresponding notification event to inform registered listeners.
 Node createNode()
           
 void doLayout(Layouter layouter)
          Calculates a layout for the styled graph using the given layout algorithm.
 java.util.List edgesAtPort(Port port)
          Returns a list of edges attached to port.
 YDimension getDefaultNodeSize()
          The default node size the is applied when a new node is created.
 java.util.List getLabels(Edge edge)
          Returns the list of labels registered for the given edge.
 java.util.List getLabels(Node node)
          Returns the list of labels registered for the given node.
 INodeHierarchy getNodeHierarchy()
          Returns an INodeHierarchy for this graph that can be used for grouping related functionality.
 java.util.List getPorts(Node node)
          Returns the ports of the provided node.
 Port getSourcePort(Edge edge)
          Returns the port at the source node the edge is connected to.
 IEdgeStyle getStyle(Edge edge)
          Returns the style that is currently registered for the given edge.
 INodeStyle getStyle(Node node)
          Returns the style that is currently registered for the given node.
 Port getTargetPort(Edge edge)
          Returns the port at the target node the edge is connected to.
 java.lang.Object getUserTag(java.lang.Object item)
          Returns the user tag of the provided node, edge or Label

The usertag is retrieved using the data mapper registered with key AbstractGraphRoundtripSupport.USERTAGS_DPKEY

 int getZOrder(Edge edge)
          Returns the z-order that is currently registered for the given edge.
 int getZOrder(Node node)
          Returns the z-order that is currently registered for the given node.
 void removePort(Port port)
          Removes a port from its owner.
 void reverseEdge(Edge e)
          Reverses the given edge and fires corresponding notification events to inform registered listeners.
 void setDefaultNodeSize(YDimension defaultNodeSize)
          The default node size the is applied when a new node is created.
 void setSourcePort(Edge edge, Port port)
          Assigns a new source port to edge.
 void setStyle(Edge edge, IEdgeStyle style)
          Sets an edge style for the given edge.
 void setStyle(Node node, INodeStyle style)
          Sets a node style for the given node.
 void setTargetPort(Edge edge, Port port)
          Assigns a new target port to edge.
 void setUserTag(java.lang.Object item, java.lang.Object tag)
          Sets the user tag of the provided node, edge or Label

The usertag is set on data mapper registered with key AbstractGraphRoundtripSupport.USERTAGS_DPKEY

 void setZOrder(Edge edge, int zOrder)
          Sets a z-order for the given edge.
 void setZOrder(Node node, int zOrder)
          Sets a z-order for the given node.
 void syncLabels(Edge edge, boolean createIfNotExisting)
          Synchronizes all Label instances associated with the given edge with the EdgeLabelLayouts of this graph.
 void syncLabels(Node node, boolean createIfNotExisting)
          Synchronizes all Label instances associated with the given node with the NodeLabelLayouts of this graph.
 
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

StyledLayoutGraph

public StyledLayoutGraph()
Method Detail

getNodeHierarchy

public INodeHierarchy getNodeHierarchy()
Returns an INodeHierarchy for this graph that can be used for grouping related functionality.

Returns:
An INodeHierarchy for this graph.

createNode

public Node createNode()

createEdge

public Edge createEdge(Node v,
                       Edge e1,
                       Node w,
                       Edge e2,
                       int d1,
                       int d2)
The new edge is connected to the first free ports of the source and target node. If the source and/or target node has no free port left, a new port are added to the center of it and assigned as source/target port of the new edge.


createEdge

protected Edge createEdge(Port sourcePort,
                          Edge e1,
                          Port targetPort,
                          Edge e2,
                          int d1,
                          int d2)
Creates a new edge in this graph and fires a corresponding notification event to inform registered listeners. The new edge e has source port sourcePort and target port targetPort. The source and target ports' owners are used as source node v and target node w, i.e., the new edge would be written as edge e = (v, w).

Edge e is inserted in such a way that an iteration over the edges at node v returns e and an iteration over the edges at w returns e

Parameters:
sourcePort - The source port of the edge.
e1 - An edge with source node v.
targetPort - The target port of the edge.
e2 - An edge with target node w.
d1 - One of the object insertion specifiers Graph.BEFORE or Graph.AFTER.
d2 - One of the object insertion specifiers Graph.BEFORE or Graph.AFTER.
Returns:
The newly created Edge object.

createEdge

public Edge createEdge(Port source,
                       Port target)
Creates a new edge in this graph and fires a corresponding notification event to inform registered listeners. The new edge connects the source and target ports' owners, which have to be Node instances in this graph, using these ports.

The edge is appended to the lists of incoming and outgoing edges at the source node and target node, respectively.

Parameters:
source - The source port of the source node of the edge.
target - The target port of the target node of the edge.
Returns:
The newly created Edge object.

changeEdge

public void changeEdge(Edge e,
                       Node newSource,
                       Edge sourceReference,
                       int sourceD,
                       Node newTarget,
                       Edge targetReference,
                       int targetD)
If the source or target node changes, a new port is added to its center and assigned as source resp. target port of the edge.


changeEdge

public void changeEdge(Edge e,
                       Node newSource,
                       Node newTarget)
If the source or target node changes, a new port is added to its center and assigned as source resp. target port of the edge.


addPort

public Port addPort(Node node,
                    IPortLocationModelParameter locationModelParameter)
Adds a port to the given node and returns it.

The port is added using the list found in the data mapper registered with the key GraphRoundtripSupportBase.NODE_PORTS_DPKEY

If no port list is registered in the corresponding data map yet, a new port list is created.

Parameters:
node - The node to add a port to
locationModelParameter - The model parameter describing the port location
See Also:
GraphRoundtripSupportBase.NODE_PORTS_DPKEY

removePort

public void removePort(Port port)
Removes a port from its owner.

All edges connected to this port are removed first. After that, the port is removed from the list found in the data mapper registered with the key GraphRoundtripSupportBase.NODE_PORTS_DPKEY

Parameters:
port - The port to remove from its owner.
See Also:
GraphRoundtripSupportBase.NODE_PORTS_DPKEY

getPorts

public java.util.List getPorts(Node node)
Returns the ports of the provided node.

Parameters:
node - The node to provide ports for.
Returns:
A list of ports or null.

getSourcePort

public Port getSourcePort(Edge edge)
Returns the port at the source node the edge is connected to.

Parameters:
edge - The edge to get the source port to.
Returns:
The source port of the edge.

setSourcePort

public void setSourcePort(Edge edge,
                          Port port)
Assigns a new source port to edge.

The edge's source node gets updated if the old source node doesn't correspond to the new port's owner.

To assign the port as source port of the edge, the data provider found in the data mapper registered with the key GraphRoundtripSupportBase.EDGE_SOURCE_PORT_DPKEY is updated.

Finally the edge's layout is updated to respect the new source port's location.

Parameters:
edge - The edge to assign a new source port.
port - The new source port of the edge.

getTargetPort

public Port getTargetPort(Edge edge)
Returns the port at the target node the edge is connected to.

Parameters:
edge - The edge to get the target port to.
Returns:
The target port of the edge.

setTargetPort

public void setTargetPort(Edge edge,
                          Port port)
Assigns a new target port to edge.

The edge's target node gets updated if the old target node doesn't correspond to the new port's owner.

To assign the port as target port of the edge, the data provider found in the data mapper registered with the key GraphRoundtripSupportBase.EDGE_TARGET_PORT_DPKEY is updated.

Finally the edge's layout is updated to respect the new target port's location.

Parameters:
edge - The edge to assign a new target port.
port - The new target port of the edge.

reverseEdge

public void reverseEdge(Edge e)
Reverses the given edge and fires corresponding notification events to inform registered listeners. This operation exchanges source and target node including the source and target port of the edge.


edgesAtPort

public java.util.List edgesAtPort(Port port)
Returns a list of edges attached to port.

Parameters:
port - The port to collect the attached edges from.
Returns:
A list of edges attached to port.

getStyle

public INodeStyle getStyle(Node node)
Returns the style that is currently registered for the given node.

The style is retrieved using the data mapper registered with key GraphRoundtripSupportBase.NODE_STYLE_DPKEY

Parameters:
node - The node to get the style for.
Returns:
The registered style, or null if no style has been registered yet.

setStyle

public void setStyle(Node node,
                     INodeStyle style)
Sets a node style for the given node.

The style is set using the data mapper registered with the key GraphRoundtripSupportBase.NODE_STYLE_DPKEY

Parameters:
node - The node
style - the style to use for the given node
See Also:
GraphRoundtripSupportBase.NODE_STYLE_DPKEY

getStyle

public IEdgeStyle getStyle(Edge edge)
Returns the style that is currently registered for the given edge.

The style is retrieved using the data mapper registered with key GraphRoundtripSupportBase.EDGE_STYLE_DPKEY

Parameters:
edge - The edge to get the style for.
Returns:
The registered style, or null if no style has been registered yet.

setStyle

public void setStyle(Edge edge,
                     IEdgeStyle style)
Sets an edge style for the given edge.

The style is set using the data mapper registered with the key GraphRoundtripSupportBase.EDGE_STYLE_DPKEY

Parameters:
edge - The edge
style - the style to use for the given edge
See Also:
GraphRoundtripSupportBase.EDGE_STYLE_DPKEY

getZOrder

public int getZOrder(Node node)
Returns the z-order that is currently registered for the given node.

The z-order is retrieved using the data mapper registered with key GraphRoundtripSupportBase.NODE_Z_ORDER_DPKEY

Parameters:
node - The node to get the z-order for.
Returns:
The registered z-order, or 0 if no z-order has been registered yet.

setZOrder

public void setZOrder(Node node,
                      int zOrder)
Sets a z-order for the given node.

The z-order is set using the data mapper registered with the key GraphRoundtripSupportBase.NODE_Z_ORDER_DPKEY

Parameters:
node - The node
zOrder - the z-order to use for the given node
See Also:
GraphRoundtripSupportBase.NODE_Z_ORDER_DPKEY

getZOrder

public int getZOrder(Edge edge)
Returns the z-order that is currently registered for the given edge.

The z-order is retrieved using the data mapper registered with key GraphRoundtripSupportBase.EDGE_Z_ORDER_DPKEY

Parameters:
edge - The edge to get the z-order for.
Returns:
The registered z-order, or 0 if no z-order has been registered yet.

setZOrder

public void setZOrder(Edge edge,
                      int zOrder)
Sets a z-order for the given edge.

The z-order is set using the data mapper registered with the key GraphRoundtripSupportBase.EDGE_Z_ORDER_DPKEY

Parameters:
edge - The edge
zOrder - the z-order to use for the given edge
See Also:
GraphRoundtripSupportBase.EDGE_Z_ORDER_DPKEY

addLabel

public void addLabel(Node node,
                     Label label)
Adds a label to the given node.

The label is added using the list found in the data mapper registered with the key GraphRoundtripSupportBase.NODE_LABELS_DPKEY

If no label list is registered in the corresponding data map yet, a new list is created.

Adding a label will not automatically add a label layout instance to the layout graph. Therefore, a label that was newly added using this method will not be considered in a layout calculation. To synchronize the labels of a node with the layout graph, use syncLabels(Node, boolean).

Parameters:
node - The node to add a label to.
label - The label to add to the node.
See Also:
GraphRoundtripSupportBase.NODE_LABELS_DPKEY

addLabel

public void addLabel(Edge edge,
                     Label label)
Adds a label to the given edge.

The label is added using the list found in the data mapper registered with the key GraphRoundtripSupportBase.EDGE_LABELS_DPKEY

If no label list is registered in the corresponding data map yet, a new label list is created.

Adding a label will not automatically add a label layout instance to the layout graph. Therefore, a label that was newly added using this method will not be considered in a layout calculation. To synchronize the labels of an edge with the layout graph, use syncLabels(y.base.Edge, boolean).

Parameters:
edge - The edge to add a label to.
label - The label to add to the edge.
See Also:
GraphRoundtripSupportBase.EDGE_LABELS_DPKEY

getLabels

public java.util.List getLabels(Node node)
Returns the list of labels registered for the given node.

The list is retrieved using the data mapper registered with key GraphRoundtripSupportBase.NODE_LABELS_DPKEY

If no label list is registered in the corresponding data map yet, a new list is created.

Parameters:
node - The node to get the registered labels for.
Returns:
The list of labels that are registered for the given node.

getLabels

public java.util.List getLabels(Edge edge)
Returns the list of labels registered for the given edge.

The list is retrieved using the data mapper registered with key GraphRoundtripSupportBase.EDGE_LABELS_DPKEY

If no label list is registered in the corresponding data map yet, a new list is created.

Parameters:
edge - The edge to retrieve the labels for.
Returns:
The list of labels that are registered for the given edge.

syncLabels

public void syncLabels(Node node,
                       boolean createIfNotExisting)
Synchronizes all Label instances associated with the given node with the NodeLabelLayouts of this graph.

This method can be called if a label was created on the server (e.g. using addLabel(y.base.Edge, com.yworks.yfiles.server.graphml.flexio.data.Label) and a label layout calculation will be executed before the graph is sent back to the client.

Note that either a reasonable preferred size should be set on the Label instance or a style which implements the interface LabelSizeCalculator (e.g. SimpleLabelStyle; in that case, a font should be set to that style, too). If neither is set, (40,40) is used.

Parameters:
node - The node to update the labels from.
createIfNotExisting - Whether to create new label layout instances for this graph, if there are more Label instances associated with this node than label layouts known by the LayoutGraph.

syncLabels

public void syncLabels(Edge edge,
                       boolean createIfNotExisting)
Synchronizes all Label instances associated with the given edge with the EdgeLabelLayouts of this graph.

This method can be called if a label was created on the server (e.g. using addLabel(y.base.Edge, com.yworks.yfiles.server.graphml.flexio.data.Label) and a label layout calculation will be executed before the graph is sent back to the client.

Note that either a reasonable preferred size should be set on the Label instance or a style which implements the interface LabelSizeCalculator (e.g. SimpleLabelStyle; in that case, a font should be set to that style, too). If neither is set, (40,40) is used.

Parameters:
edge - The edge to update the labels from.
createIfNotExisting - Whether to create new label layout instances for this graph, if there are more Label instances associated with this edge than label layouts known by the LayoutGraph.

getUserTag

public java.lang.Object getUserTag(java.lang.Object item)
Returns the user tag of the provided node, edge or Label

The usertag is retrieved using the data mapper registered with key AbstractGraphRoundtripSupport.USERTAGS_DPKEY

Parameters:
item - The graph item to retrieve the tag for.
Returns:
The user tag, or null if no user tag has been registered for the provided item.

setUserTag

public void setUserTag(java.lang.Object item,
                       java.lang.Object tag)
Sets the user tag of the provided node, edge or Label

The usertag is set on data mapper registered with key AbstractGraphRoundtripSupport.USERTAGS_DPKEY

Parameters:
item - The graph item to set the tag for.
tag - The user object to set.

getDefaultNodeSize

public YDimension getDefaultNodeSize()
The default node size the is applied when a new node is created.


setDefaultNodeSize

public void setDefaultNodeSize(YDimension defaultNodeSize)
The default node size the is applied when a new node is created.


doLayout

public void doLayout(Layouter layouter)
Calculates a layout for the styled graph using the given layout algorithm.

Parameters:
layouter - The layout algorithm that will be applied to the styled graph.


Copyright © 2000-2013 yWorks GmbH. All rights reserved