Class MultiSplitLayout

  • All Implemented Interfaces:
    java.awt.LayoutManager

    public class MultiSplitLayout
    extends java.lang.Object
    implements java.awt.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:
    MultiSplitPane
    • Constructor Detail

      • MultiSplitLayout

        public MultiSplitLayout()
        Create a MultiSplitLayout with a default model with a single Leaf node named "default".

        #see setModel

    • Method Detail

      • addPropertyChangeListener

        public void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Add property change listener.
        Parameters:
        listener - listener to add
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Remove property change listener.
        Parameters:
        listener - listener to remove
      • getPropertyChangeListeners

        public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
        Replies array of property change listeners.
        Returns:
        array of property change listeners
      • firePCS

        private void firePCS​(java.lang.String propertyName,
                             java.lang.Object oldValue,
                             java.lang.Object newValue)
      • setModel

        public void setModel​(MultiSplitLayout.Node newModel)
        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:
        newModel - the root of the tree of Split, Leaf, and Divider node
        Throws:
        java.lang.IllegalArgumentException - if model is a Divider or null
        See Also:
        getModel()
      • 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(int)
      • 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:
        java.lang.IllegalArgumentException - if dividerSize < 0
        See Also:
        getDividerSize()
      • 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.
        Parameters:
        floatingDividers - boolean value
        See Also:
        getFloatingDividers()
      • addLayoutComponent

        public void addLayoutComponent​(java.lang.String name,
                                       java.awt.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 java.awt.LayoutManager
        Parameters:
        name - identifies the Leaf node that defines the child's bounds
        child - the component to be added
        See Also:
        removeLayoutComponent(java.awt.Component)
      • sizeWithInsets

        private static java.awt.Dimension sizeWithInsets​(java.awt.Container parent,
                                                         java.awt.Dimension size)
      • preferredLayoutSize

        public java.awt.Dimension preferredLayoutSize​(java.awt.Container parent)
        Specified by:
        preferredLayoutSize in interface java.awt.LayoutManager
      • minimumLayoutSize

        public java.awt.Dimension minimumLayoutSize​(java.awt.Container parent)
        Specified by:
        minimumLayoutSize in interface java.awt.LayoutManager
      • boundsWithYandHeight

        private static java.awt.Rectangle boundsWithYandHeight​(java.awt.Rectangle bounds,
                                                               double y,
                                                               double height)
      • boundsWithXandWidth

        private static java.awt.Rectangle boundsWithXandWidth​(java.awt.Rectangle bounds,
                                                              double x,
                                                              double width)
      • layoutContainer

        public void layoutContainer​(java.awt.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 java.awt.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 java.util.List<MultiSplitLayout.DividerdividersThatOverlap​(java.awt.Rectangle r)
        Return the Dividers whose bounds overlap the specified Rectangle.
        Parameters:
        r - target Rectangle
        Returns:
        the Dividers that overlap r
        Throws:
        java.lang.IllegalArgumentException - if the Rectangle is null