JGraphAddons
v1.0


org.jgraph.layout
Class SugiyamaLayoutAlgorithm

java.lang.Object
  |
  +--org.jgraph.layout.JGraphLayoutAlgorithm
        |
        +--org.jgraph.layout.SugiyamaLayoutAlgorithm

public class SugiyamaLayoutAlgorithm
extends JGraphLayoutAlgorithm

Arranges the nodes with the Sugiyama Layout Algorithm.
Link to the algorithm


Field Summary
protected  int gridAreaSize
          represents the size of the grid in horizontal grid elements
protected  Point spacing
           
static String SUGIYAMA_CELL_WRAPPER
          Const to add the Cell Wrapper to the Nodes
static String SUGIYAMA_VISITED
          Const to add Attributes at the Nodes
 
Fields inherited from class org.jgraph.layout.JGraphLayoutAlgorithm
LAYOUT_ATTRIBUTES
 
Constructor Summary
SugiyamaLayoutAlgorithm()
           
 
Method Summary
 JGraphLayoutSettings createSettings()
          Returns an new instance of SugiyamaLayoutSettings
protected  void drawGraph(JGraph jgraph, Vector levels, Point min, Point spacing)
          This Method draws the graph.
protected  Vector fillLevels(JGraph jgraph, CellView[] selectedCellViews, Vector rootVertexViews)
          Method fills the levels and stores them in the member levels.
protected  void fillLevels(JGraph jgraph, Vector levels, int level, VertexView vertexView)
          Fills the Vector for the specified level with a wrapper for the MyGraphCell.
protected  Point findMinimumAndSpacing(CellView[] graphCellViews, Point spacing)
          calculates the minimum for the paint area.
 String getHint()
          Get a human readable hint for using this layout.
protected  boolean move(boolean toRight, Vector currentLevel, int currentIndexInTheLevel, int currentPriority)
           
protected  void moveToBarycenter(JGraph jgraph, CellView[] allSelectedViews, Vector levels)
           
protected  int moveToBarycenter(JGraph jgraph, Vector levels, int levelIndex)
           
 void run(JGraph jgraph, Object[] cells, int step)
          Implementation.
protected  Vector searchRoots(JGraph jgraph, CellView[] selectedCellViews)
          Searches all Roots for the current Graph First the method marks any Node as not visited.
protected  void searchRoots(JGraph jgraph, VertexView vertexViewToInspect, Vector roots)
          Searches Roots for the current Cell.
protected  int solveEdgeCrosses(JGraph jgraph, boolean down, Vector levels, int levelIndex)
           
protected  void solveEdgeCrosses(JGraph jgraph, Vector levels)
           
 String toString()
          Returns the name of this algorithm in human readable form.
protected  void updateProgress4Movements()
          Updates the progress based on the movements count
 
Methods inherited from class org.jgraph.layout.JGraphLayoutAlgorithm
applyLayout, createDialog, createDialog, getMaximumProgress, getProgress, isAllowedToRun, populateDialog, run, setAllowedToRun, setMaximumProgress, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SUGIYAMA_VISITED

public static final String SUGIYAMA_VISITED
Const to add Attributes at the Nodes

See Also:
Constant Field Values

SUGIYAMA_CELL_WRAPPER

public static final String SUGIYAMA_CELL_WRAPPER
Const to add the Cell Wrapper to the Nodes

See Also:
Constant Field Values

gridAreaSize

protected int gridAreaSize
represents the size of the grid in horizontal grid elements


spacing

protected Point spacing
Constructor Detail

SugiyamaLayoutAlgorithm

public SugiyamaLayoutAlgorithm()
Method Detail

createSettings

public JGraphLayoutSettings createSettings()
Returns an new instance of SugiyamaLayoutSettings

Overrides:
createSettings in class JGraphLayoutAlgorithm

toString

public String toString()
Returns the name of this algorithm in human readable form.

Overrides:
toString in class Object

getHint

public String getHint()
Get a human readable hint for using this layout.

Overrides:
getHint in class JGraphLayoutAlgorithm

run

public void run(JGraph jgraph,
                Object[] cells,
                int step)
Implementation. First of all the Algorithm searches the roots from the Graph. Starting from this roots the Algorithm creates levels and stores them in the member levels. The Member levels contains Vector Objects and the Vector per level contains Cell Wrapper Objects. After that the Algorithm tries to solve the edge crosses from level to level and goes top down and bottom up. After minimization of the edge crosses the algorithm moves each node to its bary center. Last but not Least the method draws the Graph.

Specified by:
run in class JGraphLayoutAlgorithm
See Also:
LayoutAlgorithm

searchRoots

protected Vector searchRoots(JGraph jgraph,
                             CellView[] selectedCellViews)
Searches all Roots for the current Graph First the method marks any Node as not visited. Than calls searchRoots(MyGraphCell) for each not visited Cell. The Roots are stored in the Vector named roots

Returns:
returns a Vector with the roots
See Also:
searchRoots(JGraph, CellView[])

searchRoots

protected void searchRoots(JGraph jgraph,
                           VertexView vertexViewToInspect,
                           Vector roots)
Searches Roots for the current Cell. Therefore he looks at all Ports from the Cell. At the Ports he looks for Edges. At the Edges he looks for the Target. If the Ports of the current Cell contains the target ReViewNodePort he follows the edge to the source and looks at the Cell for this source.


fillLevels

protected Vector fillLevels(JGraph jgraph,
                            CellView[] selectedCellViews,
                            Vector rootVertexViews)
Method fills the levels and stores them in the member levels. Each level was represended by a Vector with Cell Wrapper objects. These Vectors are the elements in the levels Vector.


fillLevels

protected void fillLevels(JGraph jgraph,
                          Vector levels,
                          int level,
                          VertexView vertexView)
Fills the Vector for the specified level with a wrapper for the MyGraphCell. After that the method called for each neighbor graph cell.

Parameters:
level - The level for the graphCell

findMinimumAndSpacing

protected Point findMinimumAndSpacing(CellView[] graphCellViews,
                                      Point spacing)
calculates the minimum for the paint area.


updateProgress4Movements

protected void updateProgress4Movements()
Updates the progress based on the movements count


solveEdgeCrosses

protected void solveEdgeCrosses(JGraph jgraph,
                                Vector levels)

solveEdgeCrosses

protected int solveEdgeCrosses(JGraph jgraph,
                               boolean down,
                               Vector levels,
                               int levelIndex)
Returns:
movements

moveToBarycenter

protected void moveToBarycenter(JGraph jgraph,
                                CellView[] allSelectedViews,
                                Vector levels)

moveToBarycenter

protected int moveToBarycenter(JGraph jgraph,
                               Vector levels,
                               int levelIndex)

move

protected boolean move(boolean toRight,
                       Vector currentLevel,
                       int currentIndexInTheLevel,
                       int currentPriority)
Parameters:
toRight - true = try to move the currentWrapper to right; false = try to move the currentWrapper to left;
currentLevel - Vector which contains the CellWrappers for the current level
currentIndexInTheLevel -
currentPriority -
Returns:
The free GridPosition or -1 is position is not free.

drawGraph

protected void drawGraph(JGraph jgraph,
                         Vector levels,
                         Point min,
                         Point spacing)
This Method draws the graph. For the horizontal position we are using the grid position from each graphcell. For the vertical position we are using the level position.


JGraphAddons
v1.0


Copyright (C) 2003-2004 Gaudenz Alder. All rights reserved.