Class MultiSplitLayout

java.lang.Object
org.jdesktop.swingx.MultiSplitLayout
All Implemented Interfaces:
LayoutManager

public class MultiSplitLayout extends Object implements LayoutManager
The MultiSplitLayout layout manager recursively arranges its components in row and column groups called "Splits". Elements of the layout are separated by gaps called "Dividers". The overall layout is defined with a simple tree model whose nodes are instances of MultiSplitLayout.Split, MultiSplitLayout.Divider, and MultiSplitLayout.Leaf. Named Leaf nodes represent the space allocated to a component that was added with a constraint that matches the Leaf's name. Extra space is distributed among row/column siblings according to their 0.0 to 1.0 weight. If no weights are specified then the last sibling always gets all of the extra space, or space reduction.

Although MultiSplitLayout can be used with any Container, it's the default layout manager for MultiSplitPane. MultiSplitPane supports interactively dragging the Dividers, accessibility, and other features associated with split panes.

All properties in this class are bound: when a properties value is changed, all PropertyChangeListeners are fired.

See Also:
  • Constructor Details

    • MultiSplitLayout

      public MultiSplitLayout()
      Create a MultiSplitLayout with a default model with a single Leaf node named "default". #see setModel
    • MultiSplitLayout

      public MultiSplitLayout(MultiSplitLayout.Node model)
      Create a MultiSplitLayout with the specified model. #see setModel
  • Method Details

    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
    • getPropertyChangeListeners

      public PropertyChangeListener[] getPropertyChangeListeners()
    • getModel

      public MultiSplitLayout.Node getModel()
      Return the root of the tree of Split, Leaf, and Divider nodes that define this layout.
      Returns:
      the value of the model property
      See Also:
    • setModel

      public void setModel(MultiSplitLayout.Node model)
      Set the root of the tree of Split, Leaf, and Divider nodes that define this layout. The model can be a Split node (the typical case) or a Leaf. The default value of this property is a Leaf named "default".
      Parameters:
      model - the root of the tree of Split, Leaf, and Divider node
      Throws:
      IllegalArgumentException - if model is a Divider or null
      See Also:
    • getDividerSize

      public int getDividerSize()
      Returns the width of Dividers in Split rows, and the height of Dividers in Split columns.
      Returns:
      the value of the dividerSize property
      See Also:
    • setDividerSize

      public void setDividerSize(int dividerSize)
      Sets the width of Dividers in Split rows, and the height of Dividers in Split columns. The default value of this property is the same as for JSplitPane Dividers.
      Parameters:
      dividerSize - the size of dividers (pixels)
      Throws:
      IllegalArgumentException - if dividerSize < 0
      See Also:
    • getFloatingDividers

      public boolean getFloatingDividers()
      Returns:
      the value of the floatingDividers property
      See Also:
    • setFloatingDividers

      public void setFloatingDividers(boolean floatingDividers)
      If true, Leaf node bounds match the corresponding component's preferred size and Splits/Dividers are resized accordingly. If false then the Dividers define the bounds of the adjacent Split and Leaf nodes. Typically this property is set to false after the (MultiSplitPane) user has dragged a Divider.
      See Also:
    • addLayoutComponent

      public void addLayoutComponent(String name, Component child)
      Add a component to this MultiSplitLayout. The name should match the name property of the Leaf node that represents the bounds of child. After layoutContainer() recomputes the bounds of all of the nodes in the model, it will set this child's bounds to the bounds of the Leaf node with name. Note: if a component was already added with the same name, this method does not remove it from its parent.
      Specified by:
      addLayoutComponent in interface LayoutManager
      Parameters:
      name - identifies the Leaf node that defines the child's bounds
      child - the component to be added
      See Also:
    • removeLayoutComponent

      public void removeLayoutComponent(Component child)
      Removes the specified component from the layout.
      Specified by:
      removeLayoutComponent in interface LayoutManager
      Parameters:
      child - the component to be removed
      See Also:
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Specified by:
      preferredLayoutSize in interface LayoutManager
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container parent)
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • layoutContainer

      public void layoutContainer(Container parent)
      Compute the bounds of all of the Split/Divider/Leaf Nodes in the layout model, and then set the bounds of each child component with a matching Leaf Node.
      Specified by:
      layoutContainer in interface LayoutManager
    • dividerAt

      public MultiSplitLayout.Divider dividerAt(int x, int y)
      Return the Divider whose bounds contain the specified point, or null if there isn't one.
      Parameters:
      x - x coordinate
      y - y coordinate
      Returns:
      the Divider at x,y
    • dividersThatOverlap

      public List<MultiSplitLayout.Divider> dividersThatOverlap(Rectangle r)
      Return the Dividers whose bounds overlap the specified Rectangle.
      Parameters:
      r - target Rectangle
      Returns:
      the Dividers that overlap r
      Throws:
      IllegalArgumentException - if the Rectangle is null
    • parseModel

      public static MultiSplitLayout.Node parseModel(String s)
      A convenience method that converts a string to a MultiSplitLayout model (a tree of Nodes) using a a simple syntax. Nodes are represented by parenthetical expressions whose first token is one of ROW/COLUMN/LEAF. ROW and COLUMN specify horizontal and vertical Split nodes respectively, LEAF specifies a Leaf node. A Leaf's name and weight can be specified with attributes, name=myLeafName weight=myLeafWeight. Similarly, a Split's weight can be specified with weight=mySplitWeight.

      For example, the following expression generates a horizontal Split node with three children: the Leafs named left and right, and a Divider in between:

       (ROW (LEAF name=left) (LEAF name=right weight=1.0))
       

      Dividers should not be included in the string, they're added automatcially as needed. Because Leaf nodes often only need to specify a name, one can specify a Leaf by just providing the name. The previous example can be written like this:

       (ROW left (LEAF name=right weight=1.0))
       

      Here's a more complex example. One row with three elements, the first and last of which are columns with two leaves each:

       (ROW (COLUMN weight=0.5 left.top left.bottom) 
            (LEAF name=middle)
            (COLUMN weight=0.5 right.top right.bottom))
       

      This syntax is not intended for archiving or configuration files . It's just a convenience for examples and tests.

      Returns:
      the Node root of a tree based on s.
    • printModel

      public static void printModel(MultiSplitLayout.Node root)
      Print the tree with enough detail for simple debugging.