Class JGraphTreeLayout

java.lang.Object
com.jgraph.layout.tree.JGraphAbstractTreeLayout
com.jgraph.layout.tree.JGraphTreeLayout
All Implemented Interfaces:
JGraphLayout
Direct Known Subclasses:
OrganizationalChart

public class JGraphTreeLayout extends JGraphAbstractTreeLayout
An implementation of a basic tree layout. The layout is created using the internal TreeNode structure with appropriate interfaces to the actual graph model. The layout can be configured by orientation, the alignment of the nodes per level, the minimum distance between
  • Field Details

    • alignment

      protected int alignment
      alignment indicates what part of the vertices will be lined up on each row (level) of the tree. Valid values are SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM. The default is TOP, i.e. the top of vertices on any one row line up. It should be noted that the alignment can sound confusing when the orientation changes. The alignment is always taken that you are looking at the tree with the root node at the top. If the root node were at the bottom ( orientation is SOUTH ) then SwingConstants.TOP would actually align the bottoms of the vertices up as you look at the graph. EAST and WEST orientations follow the same pattern. If it's confusing have a play with the values, it soon becomes clear.
    • combineLevelNodes

      protected boolean combineLevelNodes
      Whether or not to bring all nodes on the same level to the same height in the tree
  • Constructor Details

    • JGraphTreeLayout

      public JGraphTreeLayout()
  • Method Details

    • run

      public void run(JGraphFacade graph)
      The API method used to exercise the layout upon the facade description and produce a separate description of the vertex position and edge routing changes made. It first builds a representation of the tree using the inner tree class by doing a depth first search of the graph from the root. It then lays out the graph using the obtained data
      Specified by:
      run in interface JGraphLayout
      Overrides:
      run in class JGraphAbstractTreeLayout
      Parameters:
      graph - the facade describing the graph and its configuration
    • getTreeNode

      protected JGraphTreeLayout.StandardTreeNode getTreeNode(Object cell)
      Obtains the tree node corresponding to the specified cell
      Parameters:
      cell - the cell whose tree node is to be found
      Returns:
      the matching tree node, if any
    • layout

      protected void layout(JGraphTreeLayout.StandardTreeNode node)
      Top-level method that performs actual layout of tree for a specific node. Note this acts upon the internal tree node structure
      Parameters:
      node - the tree node to be laid out
    • join

      protected void join(JGraphTreeLayout.StandardTreeNode node)
      Joins nodes underneath the specified tree node
      Parameters:
      node - the node under which the tree is to be formed
    • getLeftMostX

      Obtains the left most point on the sub-tree under the specified tree node
      Parameters:
      node - the start of the sub-tree to be analysed
      Returns:
      the left-most tree node in the sub-tree
    • getRightMostX

      Obtains the right most point on the sub-tree under the specified tree node
      Parameters:
      node - the start of the sub-tree to be analysed
      Returns:
      the right-most tree node in the sub-tree
    • merge

      protected void merge(JGraphTreeLayout.PolyLine main, JGraphTreeLayout.PolyLine left, double distance)
      Merges two parts of a polyline together
      Parameters:
      main - the main part of the polyline
      left - the polyline to be added
      distance -
    • distance

      protected int distance(JGraphTreeLayout.PolyLine right, JGraphTreeLayout.PolyLine left)
      Parameters:
      right - first part of polyline
      left - second part of polyline
      Returns:
      the distance between the two polylines
    • setPosition

      protected void setPosition(List roots)
      Sets the position of the tree nodes specified
      Parameters:
      roots - the tree node whose position is to be set
    • setLevelHeights

      protected void setLevelHeights(JGraphTreeLayout.StandardTreeNode root)
      Sets the heights of the level under the specified node
      Parameters:
      root - the node under which level heights will be set
    • spaceMultipleTrees

      protected void spaceMultipleTrees(JGraphTreeLayout.StandardTreeNode root)
      Ensures that the specified root is spaced far enough from previous trees so not to overlap any cells.
      Parameters:
      root - the root of the tree to be spaced correctly
    • getAlignment

      public int getAlignment()
      Returns:
      Returns the alignment.
    • setAlignment

      public void setAlignment(int alignment)
      SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM are valid inputs to this method
      Parameters:
      alignment -
    • isCombineLevelNodes

      public boolean isCombineLevelNodes()
      Returns:
      Returns the combineLevelNodes.
    • setCombineLevelNodes

      public void setCombineLevelNodes(boolean combineLevelNodes)
      Parameters:
      combineLevelNodes - The combineLevelNodes to set.
    • toString

      public String toString()
      Returns Tree, the name of this algorithm.
      Overrides:
      toString in class Object