Class MultiSplitLayout
- All Implemented Interfaces:
LayoutManager,Serializable
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.
- Author:
- Hans Muller, Luan O'Carroll
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classModels a single vertical/horiztonal divider.static classThe specified Node is either the wrong type or was configured incorrectly.static classModels a java.awt Component child.static classBase class for the nodes that model a MultiSplitLayout.static classstatic classDefines a vertical or horizontal subdivision into two or more tiles. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionCreate a MultiSplitLayout with a default model with a single Leaf node named "default".MultiSplitLayout(boolean layoutByWeight) Create a MultiSplitLayout with a default model with a single Leaf node named "default".Create a MultiSplitLayout with the specified model. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayoutComponent(String name, Component child) Add a component to this MultiSplitLayout.voidvoiddisplayNode(String name, boolean visible) Show/Hide nodes.dividerAt(int x, int y) Return the Divider whose bounds contain the specified point, or null if there isn't one.Return the Dividers whose bounds overlap the specified Rectangle.Get the component associated with a MultiSplitLayout.NodeintReturns the width of Dividers in Split rows, and the height of Dividers in Split columns.booleanbooleanGet the layoutByWeight falg.intGet the layout modegetModel()Return the root of the tree of Split, Leaf, and Divider nodes that define this layout.getNameForComponent(Component child) Get the name used to map a componentgetNodeForComponent(Component comp) Get the MultiSplitLayout.Node associated with a componentgetNodeForComponent(MultiSplitLayout.Split split, Component comp) Get the MultiSplitLayout.Node associated with a componentgetNodeForName(String name) Get the MultiSplitLayout.Node associated with a componentgetNodeForName(MultiSplitLayout.Split split, String name) Get the MultiSplitLayout.Node associated with a componentbooleanintGet the minimum node sizebooleanhasModel()Is there a valid model for the layout?voidlayoutByWeight(Container parent) Set the size of the child components to match the weights of the children.voidlayoutContainer(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.Get the maximum size of this node.minimumLayoutSize(Container parent) Get the minimum size of this node.static MultiSplitLayout.NodeparseModel(String s) A convenience method that converts a string to a MultiSplitLayout model (a tree of Nodes) using a a simple syntax.preferredLayoutSize(Container parent) static voidPrint the tree with enough detail for simple debugging.voidremoveLayoutComponent(Component child) Removes the specified component from the layout.voidremoveLayoutNode(String name) Removes the specified node from the layout.voidvoidsetDividerSize(int dividerSize) Sets the width of Dividers in Split rows, and the height of Dividers in Split columns.voidsetFloatingDividers(boolean floatingDividers) If true, Leaf node bounds match the corresponding component's preferred size and Splits/Dividers are resized accordingly.voidsetLayoutByWeight(boolean state) Sset the layoutByWeight falg.voidsetLayoutMode(int layoutMode) Set the layout mode.voidsetModel(MultiSplitLayout.Node model) Set the root of the tree of Split, Leaf, and Divider nodes that define this layout.voidsetRemoveDividers(boolean removeDividers) If true, the next divider is removed when a component is removed from the layout.voidsetUserMinSize(int minSize) Set the user defined minimum size support in the USER_MIN_SIZE_LAYOUT layout mode.
-
Field Details
-
DEFAULT_LAYOUT
public static final int DEFAULT_LAYOUT- See Also:
-
NO_MIN_SIZE_LAYOUT
public static final int NO_MIN_SIZE_LAYOUT- See Also:
-
USER_MIN_SIZE_LAYOUT
public static final int USER_MIN_SIZE_LAYOUT- 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(boolean layoutByWeight) Create a MultiSplitLayout with a default model with a single Leaf node named "default".- Parameters:
layoutByWeight- if true the layout is initialized in proportion to the node weights rather than the component preferred sizes. #see setModel
-
MultiSplitLayout
Create a MultiSplitLayout with the specified model. #see setModel
-
-
Method Details
-
layoutByWeight
Set the size of the child components to match the weights of the children. If the components to not all specify a weight then the available layout space is divided equally between the components. -
getComponentForNode
Get the component associated with a MultiSplitLayout.Node- Parameters:
n- the layout node- Returns:
- the component handled by the layout or null if not found
-
getNodeForComponent
Get the MultiSplitLayout.Node associated with a component- Parameters:
comp- the component being positioned by the layout- Returns:
- the node associated with the component
-
getNodeForName
Get the MultiSplitLayout.Node associated with a component- Parameters:
name- the name used to associate a component with the layout- Returns:
- the node associated with the component
-
getNameForComponent
Get the name used to map a component- Parameters:
child- the component- Returns:
- the name used to map the component or null if no mapping is found
-
getNodeForComponent
Get the MultiSplitLayout.Node associated with a component- Parameters:
split- the layout split that owns the requested nodecomp- the component being positioned by the layout- Returns:
- the node associated with the component
-
getNodeForName
Get the MultiSplitLayout.Node associated with a component- Parameters:
split- the layout split that owns the requested nodename- the name used to associate a component with the layout- Returns:
- the node associated with the component
-
hasModel
public boolean hasModel()Is there a valid model for the layout?- Returns:
- true if there is a model
-
addPropertyChangeListener
-
removePropertyChangeListener
-
getPropertyChangeListeners
-
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
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)- 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:
-
getRemoveDividers
public boolean getRemoveDividers()- Returns:
- the value of the removeDividers property
- See Also:
-
setRemoveDividers
public void setRemoveDividers(boolean removeDividers) If true, the next divider is removed when a component is removed from the layout. If false, only the node itself is removed. Normally the next divider should be removed from the layout when a component is removed.- Parameters:
removeDividers- true to removed the next divider whena component is removed from teh layout
-
addLayoutComponent
Add a component to this MultiSplitLayout. Thenameshould match the name property of the Leaf node that represents the bounds ofchild. 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 withname. Note: if a component was already added with the same name, this method does not remove it from its parent.- Specified by:
addLayoutComponentin interfaceLayoutManager- Parameters:
name- identifies the Leaf node that defines the child's boundschild- the component to be added- See Also:
-
removeLayoutComponent
Removes the specified component from the layout.- Specified by:
removeLayoutComponentin interfaceLayoutManager- Parameters:
child- the component to be removed- See Also:
-
removeLayoutNode
Removes the specified node from the layout.- Parameters:
name- the name of the component to be removed- See Also:
-
displayNode
Show/Hide nodes. Any dividers that are no longer required due to one of the nodes being made visible/invisible are also shown/hidden. The visibility of the component managed by the node is also changed by this method- Parameters:
name- the node namevisible- the new node visible state
-
minimumNodeSize
Get the minimum size of this node. Sums the minumum sizes of rows or columns to get the overall minimum size for the layout node, including the dividers.- Parameters:
root- the node whose size is required.- Returns:
- the minimum size.
-
maximumNodeSize
Get the maximum size of this node. Sums the minumum sizes of rows or columns to get the overall maximum size for the layout node, including the dividers.- Parameters:
root- the node whose size is required.- Returns:
- the minimum size.
-
preferredLayoutSize
- Specified by:
preferredLayoutSizein interfaceLayoutManager
-
minimumLayoutSize
- Specified by:
minimumLayoutSizein interfaceLayoutManager
-
getLayoutMode
public int getLayoutMode()Get the layout mode- Returns:
- current layout mode
-
setLayoutMode
public void setLayoutMode(int layoutMode) Set the layout mode. By default this layout uses the preferred and minimum sizes of the child components. To ignore the minimum size set the layout mode to MultiSplitLayout.LAYOUT_NO_MIN_SIZE.- Parameters:
layoutMode- the layout mode- DEFAULT_LAYOUT - use the preferred and minimum sizes when sizing the children
- LAYOUT_NO_MIN_SIZE - ignore the minimum size when sizing the children
-
getUserMinSize
public int getUserMinSize()Get the minimum node size- Returns:
- the minimum size
-
setUserMinSize
public void setUserMinSize(int minSize) Set the user defined minimum size support in the USER_MIN_SIZE_LAYOUT layout mode.- Parameters:
minSize- the new minimum size
-
getLayoutByWeight
public boolean getLayoutByWeight()Get the layoutByWeight falg. If the flag is true the layout initializes itself using the model weights- Returns:
- the layoutByWeight
-
setLayoutByWeight
public void setLayoutByWeight(boolean state) Sset the layoutByWeight falg. If the flag is true the layout initializes itself using the model weights- Parameters:
state- the new layoutByWeight to set
-
layoutContainer
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:
layoutContainerin interfaceLayoutManager
-
dividerAt
Return the Divider whose bounds contain the specified point, or null if there isn't one.- Parameters:
x- x coordinatey- y coordinate- Returns:
- the Divider at x,y
-
dividersThatOverlap
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
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
Print the tree with enough detail for simple debugging.
-