org.argouml.uml.diagram.static_structure.layout
Class ClassdiagramLayouter

java.lang.Object
  extended byorg.argouml.uml.diagram.static_structure.layout.ClassdiagramLayouter
All Implemented Interfaces:
Layouter

public class ClassdiagramLayouter
extends Object
implements Layouter

This class implements a layout algorithm for class diagrams.

The layout process is performed in a row by row way. The position of the nodes in a row are set using the sequence given by the natural order of the nodes

The resulting layout sequence:

  1. Standalone (i.e. without links) nodes first, followed by linked nodes
  2. Ordered by node-typ: package, interface, class, other
  3. Increasing level in link-hierarchy - root elements first
  4. Decreasing amount of weighted links
  5. Ascending name of model object

See Also:
ClassdiagramNode.compareTo(java.lang.Object)

Nested Class Summary
private  class ClassdiagramLayouter.NodeRow
          This class keeps all the nodes in one row together and provides basic functionality for them.
 
Field Summary
private  UMLDiagram diagram
          The diagram that will be layouted
private static int eGap
          Constant value for the gap between edges.
private  HashMap figNodes
          HashMap with figures as key and Nodes as elements
private static int hGap
          Constant value for the horizontal gap between nodes.
private  int lastRow
          The number of the last row
private  Vector layoutedClassNodes
          layoutedClassNodes is a convenience which holds a subset of layoutedObjects (only ClassNodes)
private  Vector layoutedEdges
          Holds all edges - subset of layoutedObjects
private  Vector layoutedObjects
          Attribute layoutedObjects holds the objects to layout.
private static Logger LOG
          Logger for logging events.
private static int maxRowWidth
          Constant value for the maximum row width
private  Vector nodeRows
          nodeRows contains all DiagramRows of the diagram
private static int vGap
          Constant value for the vertical gap between nodes.
private  int xPos
          internal
private  int yPos
          internal
 
Constructor Summary
ClassdiagramLayouter(UMLDiagram theDiagram)
          Constructor for the layouter.
 
Method Summary
 void add(LayoutedObject obj)
          Add an object to layout.
 ClassdiagramNode getClassdiagramNode(int index)
          Deprecated.  
private  int getHGap()
          Get the horizontal gap between nodes.
 Dimension getMinimumDiagramSize()
          Operation getMinimumDiagramSize returns the minimum diagram size after the layout process.
 LayoutedObject getObject(int index)
          Operation getObject returns a object with a given index from the layouter.
 LayoutedObject[] getObjects()
          Operation getObjects returns all the objects currently participating in the layout process.
private  int getVGap()
          Get the vertical gap between nodes.
 void layout()
          Operation layout implements the actual layout algorithm.
private  void placeEdges()
          All layoutedObjects of type "Edge" are placed using an edge-type specific layout algorithm.
private  void placeNode(ClassdiagramNode node)
          Set the placement coordinate for a given node.
private  void placeNodes()
          Place the NodeRows in the diagram
private  void rankAndWeightNodes()
          Rank the nodes depending on their level (position in hierarchy) and set their weight to achieve a proper node-sequence for the layout.
 void remove(LayoutedObject obj)
          Remove an object from the layout process.
private  void setupLinks()
          Set the up- and downlinks for each node based on the edges which are shown in the diagram.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eGap

private static int eGap
Constant value for the gap between edges.


hGap

private static int hGap
Constant value for the horizontal gap between nodes.


LOG

private static final Logger LOG
Logger for logging events.


maxRowWidth

private static int maxRowWidth
Constant value for the maximum row width


vGap

private static int vGap
Constant value for the vertical gap between nodes.


diagram

private UMLDiagram diagram
The diagram that will be layouted


figNodes

private HashMap figNodes
HashMap with figures as key and Nodes as elements


lastRow

private int lastRow
The number of the last row


layoutedClassNodes

private Vector layoutedClassNodes
layoutedClassNodes is a convenience which holds a subset of layoutedObjects (only ClassNodes)


layoutedEdges

private Vector layoutedEdges
Holds all edges - subset of layoutedObjects


layoutedObjects

private Vector layoutedObjects
Attribute layoutedObjects holds the objects to layout.


nodeRows

private Vector nodeRows
nodeRows contains all DiagramRows of the diagram


xPos

private int xPos
internal


yPos

private int yPos
internal

Constructor Detail

ClassdiagramLayouter

public ClassdiagramLayouter(UMLDiagram theDiagram)
Constructor for the layouter. Takes a diagram as input to extract all LayoutedObjects, which will be layouted.

Parameters:
theDiagram - the diagram to layout
Method Detail

add

public void add(LayoutedObject obj)
Add an object to layout.

Specified by:
add in interface Layouter
Parameters:
obj - represents the object to layout.

getClassdiagramNode

public ClassdiagramNode getClassdiagramNode(int index)
Deprecated.  

Get a ClassdiagramNode from the layouted objects.

Attention!
Should not be used, because the order of nodes might be changed due to a call of layout()

Parameters:
index - represents the index of this ClassdiagramNode.
Returns:
The ClassdiagramNode for this index.

getHGap

private int getHGap()
Get the horizontal gap between nodes.

Returns:
The horizontal gap between nodes.

getMinimumDiagramSize

public Dimension getMinimumDiagramSize()
Operation getMinimumDiagramSize returns the minimum diagram size after the layout process.

Specified by:
getMinimumDiagramSize in interface Layouter
Returns:
The minimum diagram size after the layout process.

getObject

public LayoutedObject getObject(int index)
Operation getObject returns a object with a given index from the layouter.

Specified by:
getObject in interface Layouter
Parameters:
index - represents the index of this object in the layouter.
Returns:
The LayoutedObject for the given index.

getObjects

public LayoutedObject[] getObjects()
Operation getObjects returns all the objects currently participating in the layout process.

Specified by:
getObjects in interface Layouter
Returns:
An array holding all the object in the layouter.

getVGap

private int getVGap()
Get the vertical gap between nodes.

Returns:
The vertical gap between nodes.

layout

public void layout()
Operation layout implements the actual layout algorithm.

Specified by:
layout in interface Layouter

placeEdges

private void placeEdges()
All layoutedObjects of type "Edge" are placed using an edge-type specific layout algorithm. The offset from a centered edge is taken from the parent node to avoid overlaps.

See Also:
ClassdiagramEdge

placeNode

private void placeNode(ClassdiagramNode node)
Set the placement coordinate for a given node.


placeNodes

private void placeNodes()
Place the NodeRows in the diagram


rankAndWeightNodes

private void rankAndWeightNodes()
Rank the nodes depending on their level (position in hierarchy) and set their weight to achieve a proper node-sequence for the layout. Rows exceeding the maximum row width are split, if standalone nodes are available.

Weight the other nodes to determine their columns.


remove

public void remove(LayoutedObject obj)
Remove an object from the layout process.

Specified by:
remove in interface Layouter
Parameters:
obj - represents the object to remove.

setupLinks

private void setupLinks()
Set the up- and downlinks for each node based on the edges which are shown in the diagram.



ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook