de.cau.cs.kieler.kiml.util
Class KimlUtil

java.lang.Object
  extended by de.cau.cs.kieler.kiml.util.KimlUtil

public final class KimlUtil
extends Object

Utility methods for KGraphs and layout data.

Rating proposed yellow
(2009-12-11) msp

Nested Class Summary
static class KimlUtil.PortComparator
          Comparator class used to sort ports according to their ranks.
 
Method Summary
static int calcFlow(KPort port)
          Determines the flow of the given port, that is the difference between the number of outgoing edges and the number of incoming edges.
static float calcPortOffset(KPort port, PortSide side)
          Calculate the offset for a port, that is the amount by which it is moved outside of the node.
static void calcPortRanks(KNode node)
          Sets port ranks for all ports of the given node according to their relative positions.
static PortSide calcPortSide(KPort port, Direction direction)
          Determines the port side for the given port from its relative position at its corresponding node.
static void createIdentifier(KGraphElement element)
          Create a unique identifier for the given graph element.
static KEdge createInitializedEdge()
          Creates a KEdge, initializes some attributes, and returns it.
static KLabel createInitializedLabel(KLabeledGraphElement element)
          Creates a KLabel, initializes some attributes, and returns it.
static KNode createInitializedNode()
          Creates a KNode, initializes some attributes, and returns it.
static KPort createInitializedPort()
          Creates a KPort, initializes some attributes, and returns it.
static void excludeContent(KNode node)
          Excludes the content of the given node from layout.
static void excludeLabels(KLabeledGraphElement element)
          Exclude all labels of the given graph element from layout.
static void excludePorts(KNode node)
          Exclude all ports of the given graph element from layout.
static void fillPortInfo(KNode node, Direction direction)
          Fills all missing data for the ports of the given node, such as port sides and port ranks.
static KPort[] getSortedPorts(KNode node)
          Returns a sorted list of the ports of the given node.
static boolean isDescendant(KNode child, KNode parent)
          Determines whether the given child node is a descendant of the parent node.
static void persistDataElements(KNode graph)
          Persists all KGraphData elements of a KNode graph.
static void placePoints(List<KPoint> points, float minPos, float maxPos, float offset, boolean vertical, boolean forward)
          Determines positions of a sorted set of points by placing them with equal distances.
static KVector resizeNode(KNode node)
          Sets the size of a given node, depending on the minimal size, the number of ports on each side, the insets, and the label.
static KVector resizeNode(KNode node, float newWidth, float newHeight, boolean movePorts)
          Resize a node to the given width and height, adjusting port and label positions if needed.
static void setOption(KGraphData graphData, String id, String value)
          Set a layout option using a serialized key / value pair.
static void toAbsolute(KVector point, KNode parent)
          Converts the given relative point to an absolute location.
static void toRelative(KVector point, KNode parent)
          Converts the given absolute point to a relative location.
static void translate(KNode parent, float xoffset, float yoffset)
          Translates the contents of the given node by an offset.
static void translate(KPoint point, float xoffset, float yoffset)
          Translates the given point by an offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createInitializedNode

public static KNode createInitializedNode()
Creates a KNode, initializes some attributes, and returns it.

Returns:
an initialized KNode

createInitializedEdge

public static KEdge createInitializedEdge()
Creates a KEdge, initializes some attributes, and returns it.

Returns:
an initialized KEdge

createInitializedPort

public static KPort createInitializedPort()
Creates a KPort, initializes some attributes, and returns it.

Returns:
an initialized KPort

createInitializedLabel

public static KLabel createInitializedLabel(KLabeledGraphElement element)
Creates a KLabel, initializes some attributes, and returns it.

Parameters:
element - a labeled graph element
Returns:
an initialized KLabel

createIdentifier

public static void createIdentifier(KGraphElement element)
Create a unique identifier for the given graph element. Note that this identifier is not necessarily universally unique, since it uses the hash code, which usually covers only the range of heap space addresses.

Parameters:
element - a graph element

calcPortSide

public static PortSide calcPortSide(KPort port,
                                    Direction direction)
Determines the port side for the given port from its relative position at its corresponding node.

Parameters:
port - port to analyze
direction - the overall layout direction
Returns:
port placement

calcPortOffset

public static float calcPortOffset(KPort port,
                                   PortSide side)
Calculate the offset for a port, that is the amount by which it is moved outside of the node. An offset value of 0 means the port has no intersection with the node and touches the outside border of the node.

Parameters:
port - a port
side - the side on the node for the given port
Returns:
the offset on the side

getSortedPorts

public static KPort[] getSortedPorts(KNode node)
Returns a sorted list of the ports of the given node. This requires port sides to be already calculated.

Parameters:
node - a node
Returns:
sorted list of ports

calcPortRanks

public static void calcPortRanks(KNode node)
Sets port ranks for all ports of the given node according to their relative positions.

Parameters:
node - node for which port ranks shall be set

fillPortInfo

public static void fillPortInfo(KNode node,
                                Direction direction)
Fills all missing data for the ports of the given node, such as port sides and port ranks.

Parameters:
node - node for which port data shall be created
direction - layout direction

placePoints

public static void placePoints(List<KPoint> points,
                               float minPos,
                               float maxPos,
                               float offset,
                               boolean vertical,
                               boolean forward)
Determines positions of a sorted set of points by placing them with equal distances.

Parameters:
points - list of points
minPos - minimal position for placing
maxPos - maximal position for placing
offset - offset to be added to positions
vertical - if true, the vertical position is processed, else the horizontal position is processed
forward - if true, ports are placed from the minimum to the maximum position

resizeNode

public static KVector resizeNode(KNode node)
Sets the size of a given node, depending on the minimal size, the number of ports on each side, the insets, and the label.

Parameters:
node - the node that shall be resized
Returns:
a vector holding the width and height resizing ratio

resizeNode

public static KVector resizeNode(KNode node,
                                 float newWidth,
                                 float newHeight,
                                 boolean movePorts)
Resize a node to the given width and height, adjusting port and label positions if needed.

Parameters:
node - a node
newWidth - the new width to set
newHeight - the new height to set
movePorts - whether port positions shall be adjusted
Returns:
a vector holding the width and height resizing ratio

calcFlow

public static int calcFlow(KPort port)
Determines the flow of the given port, that is the difference between the number of outgoing edges and the number of incoming edges. Edges that connect to descendant nodes are counted in their reverse direction.

Parameters:
port - port for which the flow shall be calculated
Returns:
difference between number of outgoing and incoming edges

isDescendant

public static boolean isDescendant(KNode child,
                                   KNode parent)
Determines whether the given child node is a descendant of the parent node.

Parameters:
child - a child node
parent - a parent node
Returns:
true if child is a direct or indirect child of parent

toAbsolute

public static void toAbsolute(KVector point,
                              KNode parent)
Converts the given relative point to an absolute location. The insets of the parent node are included in this calculation.

Parameters:
point - a relative point
parent - the parent node to which the point is relative to

toRelative

public static void toRelative(KVector point,
                              KNode parent)
Converts the given absolute point to a relative location. The insets of the parent node are included in this calculation.

Parameters:
point - an absolute point
parent - the parent node to which the point shall be made relative to

translate

public static void translate(KNode parent,
                             float xoffset,
                             float yoffset)
Translates the contents of the given node by an offset.

Parameters:
parent - parent node whose children shall be translated
xoffset - x coordinate offset
yoffset - y coordinate offset

translate

public static void translate(KPoint point,
                             float xoffset,
                             float yoffset)
Translates the given point by an offset.

Parameters:
point - point that shall be translated
xoffset - x coordinate offset
yoffset - y coordinate offset

excludeContent

public static void excludeContent(KNode node)
Excludes the content of the given node from layout. This means setting the LayoutOptions.NO_LAYOUT option to true for all children.

Parameters:
node - a parent node

excludeLabels

public static void excludeLabels(KLabeledGraphElement element)
Exclude all labels of the given graph element from layout. This means setting the LayoutOptions.NO_LAYOUT option to true for all labels.

Parameters:
element - a graph element with labels

excludePorts

public static void excludePorts(KNode node)
Exclude all ports of the given graph element from layout. This means setting the LayoutOptions.NO_LAYOUT option to true for all ports and their labels.

Parameters:
node - a node with ports

setOption

public static void setOption(KGraphData graphData,
                             String id,
                             String value)
Set a layout option using a serialized key / value pair.

Parameters:
graphData - the graph data instance to modify
id - the layout option identifier
value - the value for the layout option

persistDataElements

public static void persistDataElements(KNode graph)
Persists all KGraphData elements of a KNode graph.

Parameters:
graph - the root element of the graph to persist elements of.