org.jgraph.layout
Class SugiyamaLayoutAlgorithm

java.lang.Object
  extended byorg.jgraph.layout.JGraphLayoutAlgorithm
      extended byorg.jgraph.layout.SugiyamaLayoutAlgorithm

public class SugiyamaLayoutAlgorithm
extends JGraphLayoutAlgorithm

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


Field Summary
protected  boolean flushToOrigin
          Controls whether the graph should be placed as close to the origin as possible.
protected  int gridAreaSize
          represents the size of the grid in horizontal grid elements
protected  java.awt.Point spacing
          The default grid spacing is (250, 150).
static java.lang.String SUGIYAMA_CELL_WRAPPER
          Const to add the Cell Wrapper to the Nodes
static java.lang.String SUGIYAMA_SELECTED
          Const to add Attributes at the Nodes indicating that the cell was explicitly specified to the layout.
static java.lang.String SUGIYAMA_VISITED
          Const to add Attributes at the Nodes
protected  boolean vertical
          The default layout direction is vertical (top-down)
 
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, java.util.List levels, java.awt.Point min, java.awt.Point spacing)
          This Method draws the graph.
protected  java.util.List fillLevels(JGraph jgraph, CellView[] selectedCellViews, java.util.List rootVertexViews)
          Method fills the levels and stores them in the member levels.
protected  void fillLevels(JGraph jgraph, java.util.List levels, int level, VertexView vertexView)
          Fills the Vector for the specified level with a wrapper for the MyGraphCell.
protected  java.awt.Point findMinimumAndSpacing(CellView[] graphCellViews, java.awt.Point spacing)
          calculates the minimum for the paint area.
 boolean getFlushToOrigin()
          Get the FlushToOrigin value.
 java.lang.String getHint()
          Get a human readable hint for using this layout.
 java.awt.Point getSpacing()
          Returns the spacing.
protected  boolean isSelected(GraphLayoutCache cache, java.lang.Object cell)
          Detects whether the specified cell has been marked selected.
 boolean isVertical()
          Returns the current layout direction
protected  void markSelected(CellView[] selectedCellViews, boolean addMark)
          Adds an attribute SUGIYAMA_SELECTED to the specified selected cell views.
protected  boolean move(boolean toRight, java.util.List currentLevel, int currentIndexInTheLevel, int currentPriority)
           
protected  void moveToBarycenter(JGraph jgraph, CellView[] allSelectedViews, java.util.List levels)
           
protected  int moveToBarycenter(JGraph jgraph, java.util.List levels, int levelIndex)
           
 void run(JGraph graph, java.lang.Object[] dynamic_cells, java.lang.Object[] static_cells)
          Implementation.
protected  java.util.List 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, java.util.List roots)
          Searches Roots for the current Cell.
 void setFlushToOrigin(boolean newFlushToOrigin)
          After layout, moves the graph as close to origin as possible.
 void setSpacing(java.awt.Point spacing)
          Sets grid spacing.
 void setVertical(boolean vertical)
          Sets the layout direction.
protected  int solveEdgeCrosses(JGraph jgraph, boolean down, java.util.List levels, int levelIndex)
           
protected  void solveEdgeCrosses(JGraph jgraph, java.util.List levels)
           
 java.lang.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, 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 java.lang.String SUGIYAMA_VISITED
Const to add Attributes at the Nodes

See Also:
Constant Field Values

SUGIYAMA_CELL_WRAPPER

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

See Also:
Constant Field Values

SUGIYAMA_SELECTED

public static final java.lang.String SUGIYAMA_SELECTED
Const to add Attributes at the Nodes indicating that the cell was explicitly specified to the layout.

See Also:
#run(org.jgraph.JGraph,Object[],Object[]), Constant Field Values

gridAreaSize

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


vertical

protected boolean vertical
The default layout direction is vertical (top-down)


spacing

protected java.awt.Point spacing
The default grid spacing is (250, 150).


flushToOrigin

protected boolean flushToOrigin
Controls whether the graph should be placed as close to the origin as possible.

Constructor Detail

SugiyamaLayoutAlgorithm

public SugiyamaLayoutAlgorithm()
Method Detail

createSettings

public JGraphLayoutSettings createSettings()
Returns an new instance of SugiyamaLayoutSettings

Overrides:
createSettings in class JGraphLayoutAlgorithm

toString

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


getHint

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

Overrides:
getHint in class JGraphLayoutAlgorithm

run

public void run(JGraph graph,
                java.lang.Object[] dynamic_cells,
                java.lang.Object[] static_cells)
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
Parameters:
graph - JGraph instance
dynamic_cells - List of all nodes the layout should move
static_cells - List of node the layout should not move but allow for
See Also:
LayoutAlgorithm

markSelected

protected void markSelected(CellView[] selectedCellViews,
                            boolean addMark)
Adds an attribute SUGIYAMA_SELECTED to the specified selected cell views.

Parameters:
selectedCellViews - the specified cell views
addMark - true to add the mark, false to remove the mark

isSelected

protected boolean isSelected(GraphLayoutCache cache,
                             java.lang.Object cell)
Detects whether the specified cell has been marked selected.

Parameters:
cell - the cell to inspect
Returns:
true if the view has been marked selected and false otherwise.
See Also:
markSelected(CellView[], boolean)

searchRoots

protected java.util.List 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,
                           java.util.List 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 java.util.List fillLevels(JGraph jgraph,
                                    CellView[] selectedCellViews,
                                    java.util.List 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,
                          java.util.List 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 java.awt.Point findMinimumAndSpacing(CellView[] graphCellViews,
                                               java.awt.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,
                                java.util.List levels)

solveEdgeCrosses

protected int solveEdgeCrosses(JGraph jgraph,
                               boolean down,
                               java.util.List levels,
                               int levelIndex)
Returns:
movements

moveToBarycenter

protected void moveToBarycenter(JGraph jgraph,
                                CellView[] allSelectedViews,
                                java.util.List levels)

moveToBarycenter

protected int moveToBarycenter(JGraph jgraph,
                               java.util.List levels,
                               int levelIndex)

move

protected boolean move(boolean toRight,
                       java.util.List currentLevel,
                       int currentIndexInTheLevel,
                       int currentPriority)
Parameters:
toRight - true = try to move the currentWrapper to right; false = try to move the currentWrapper to left;
currentLevel - List 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,
                         java.util.List levels,
                         java.awt.Point min,
                         java.awt.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.


getSpacing

public java.awt.Point getSpacing()
Returns the spacing.

See Also:
setSpacing(java.awt.Point)

setSpacing

public void setSpacing(java.awt.Point spacing)
Sets grid spacing. The Algorithm distributes the nodes on a grid. For this grid you can configure the vertical and horizontal spacing.


isVertical

public boolean isVertical()
Returns the current layout direction

Returns:
boolean whether or not direction is vertical
See Also:
setVertical(boolean)

setVertical

public void setVertical(boolean vertical)
Sets the layout direction.

Parameters:
vertical - true for vertical and false for horizontal direction

getFlushToOrigin

public final boolean getFlushToOrigin()
Get the FlushToOrigin value.

Returns:
a boolean value
See Also:
setFlushToOrigin(boolean)

setFlushToOrigin

public final void setFlushToOrigin(boolean newFlushToOrigin)
After layout, moves the graph as close to origin as possible.

After the layout has complete, this algorithm calculates the minimum X and Y coordinates over all selected cells. If flushToOrigin parameter is set to false, the algorithm will place cells starting at coordinates corresponding to those minimum values.

If set to true, the layout will place cells starting at the origin, possibly shrinking the overall graph canvas size

Parameters:
newFlushToOrigin - The new FlushToOrigin value.