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 void addDummyEdgesForInterlevelConnections(KNode parentNode)
          Recursively search parents of the source and target node to find the most common parent.
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 void calcPortRanks(KNode node)
          Sets port ranks for all ports of the given node according to their relative positions.
static PortSide calcPortSide(KPort port)
          Determines the port side for the given port from its relative position at its corresponding node.
static KEdge createInitializedEdge()
          Creates a KEdge, initializes some attributes, and returns it.
static KLabel createInitializedLabel(KGraphElement parent)
          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 fillPortInfo(KNode node, LayoutDirection layoutDirection)
          Fills all missing data for the ports of the given node, such as port sides and port ranks.
static KEdgeLayout getEdgeLayout(KGraphElement graphElement)
          Deprecated. use graphElement.getData(KEdgeLayout.class) instead
static KShapeLayout getShapeLayout(KGraphElement graphElement)
          Deprecated. use graphElement.getData(KShapeLayout.class) instead
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 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 void 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 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

getShapeLayout

public static KShapeLayout getShapeLayout(KGraphElement graphElement)
Deprecated. use graphElement.getData(KShapeLayout.class) instead

Returns shape layout data for a given graph element. If there is no registered shape layout for the element, a new shape layout is created and registered.

Parameters:
graphElement - the graph element
Returns:
related shape layout data

getEdgeLayout

public static KEdgeLayout getEdgeLayout(KGraphElement graphElement)
Deprecated. use graphElement.getData(KEdgeLayout.class) instead

Returns edge layout data for a given graph element. If there is no registered edge layout for the element, a new edge layout is created and registered.

Parameters:
graphElement - the graph element
Returns:
related edge layout data

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(KGraphElement parent)
Creates a KLabel, initializes some attributes, and returns it.

Parameters:
parent - the parent graph element
Returns:
an initialized KLabel

calcPortSide

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

Parameters:
port - port to analyze
Returns:
port placement

getSortedPorts

public static KPort[] getSortedPorts(KNode node)
Returns a sorted list of the ports of the given node.

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,
                                LayoutDirection layoutDirection)
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
layoutDirection - 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 void 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

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

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

addDummyEdgesForInterlevelConnections

public static void addDummyEdgesForInterlevelConnections(KNode parentNode)
Recursively search parents of the source and target node to find the most common parent. Then add a dummy edge between the corresponding children within this common parent. Also consider that hierarchy levels of parent and target might be asymmetric. TODO this currently only works for graphs without ports... extend to work with ports

Parameters:
parentNode - the parent node