Class MultiSplitLayout
- java.lang.Object
-
- org.openstreetmap.josm.gui.widgets.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMultiSplitLayout.DividerModels a single vertical/horiztonal divider.static classMultiSplitLayout.InvalidLayoutExceptionThe specified Node is either the wrong type or was configured incorrectly.static classMultiSplitLayout.LeafModels a java.awt Component child.static classMultiSplitLayout.NodeBase class for the nodes that model a MultiSplitLayout.static classMultiSplitLayout.SplitDefines a vertical or horizontal subdivision into two or more tiles.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.awt.Component>childMapprivate intdividerSizeprivate booleanfloatingDividersprivate MultiSplitLayout.Nodemodelprivate java.beans.PropertyChangeSupportpcs
-
Constructor Summary
Constructors Constructor Description MultiSplitLayout()Create a MultiSplitLayout with a default model with a single Leaf node named "default".MultiSplitLayout(MultiSplitLayout.Node model)Create a MultiSplitLayout with the specified model.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLayoutComponent(java.lang.String name, java.awt.Component child)Add a component to this MultiSplitLayout.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add property change listener.private static java.awt.RectangleboundsWithXandWidth(java.awt.Rectangle bounds, double x, double width)private static java.awt.RectangleboundsWithYandHeight(java.awt.Rectangle bounds, double y, double height)private static voidcheckLayout(MultiSplitLayout.Node root)private java.awt.ComponentchildForNode(MultiSplitLayout.Node node)MultiSplitLayout.DividerdividerAt(int x, int y)Return the Divider whose bounds contain the specified point, or null if there isn't one.private static MultiSplitLayout.DividerdividerAt(MultiSplitLayout.Node root, int x, int y)java.util.List<MultiSplitLayout.Divider>dividersThatOverlap(java.awt.Rectangle r)Return the Dividers whose bounds overlap the specified Rectangle.private static java.util.List<MultiSplitLayout.Divider>dividersThatOverlap(MultiSplitLayout.Node root, java.awt.Rectangle r)private voidfirePCS(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)intgetDividerSize()Returns the width of Dividers in Split rows, and the height of Dividers in Split columns.booleangetFloatingDividers()Returns the value of the floatingDividers property.MultiSplitLayout.NodegetModel()Return the root of the tree of Split, Leaf, and Divider nodes that define this layout.java.beans.PropertyChangeListener[]getPropertyChangeListeners()Replies array of property change listeners.private voidlayout1(MultiSplitLayout.Node root, java.awt.Rectangle bounds)private voidlayout2(MultiSplitLayout.Node root, java.awt.Rectangle bounds)voidlayoutContainer(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.private voidlayoutGrow(MultiSplitLayout.Split split, java.awt.Rectangle bounds)private voidlayoutShrink(MultiSplitLayout.Split split, java.awt.Rectangle bounds)private static voidminimizeSplitBounds(MultiSplitLayout.Split split, java.awt.Rectangle bounds)java.awt.DimensionminimumLayoutSize(java.awt.Container parent)private java.awt.DimensionminimumNodeSize(MultiSplitLayout.Node root)private static booleannodeOverlapsRectangle(MultiSplitLayout.Node node, java.awt.Rectangle r2)private java.awt.DimensionpreferredComponentSize(MultiSplitLayout.Node node)java.awt.DimensionpreferredLayoutSize(java.awt.Container parent)private java.awt.DimensionpreferredNodeSize(MultiSplitLayout.Node root)voidremoveLayoutComponent(java.awt.Component child)Removes the specified component from the layout.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Remove property change listener.voidsetDividerSize(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.voidsetModel(MultiSplitLayout.Node newModel)Set the root of the tree of Split, Leaf, and Divider nodes that define this layout.private static java.awt.DimensionsizeWithInsets(java.awt.Container parent, java.awt.Dimension size)private static voidthrowInvalidLayout(java.lang.String msg, MultiSplitLayout.Node node)
-
-
-
Field Detail
-
childMap
private final java.util.Map<java.lang.String,java.awt.Component> childMap
-
pcs
private final java.beans.PropertyChangeSupport pcs
-
model
private MultiSplitLayout.Node model
-
dividerSize
private int dividerSize
-
floatingDividers
private boolean floatingDividers
-
-
Constructor Detail
-
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
- Parameters:
model- model
-
-
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)
-
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(org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Node)
-
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()
-
getFloatingDividers
public boolean getFloatingDividers()
Returns the value of the floatingDividers property.- Returns:
- the value of the floatingDividers property
- See Also:
setFloatingDividers(boolean)
-
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. 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 interfacejava.awt.LayoutManager- Parameters:
name- identifies the Leaf node that defines the child's boundschild- the component to be added- See Also:
removeLayoutComponent(java.awt.Component)
-
removeLayoutComponent
public void removeLayoutComponent(java.awt.Component child)
Removes the specified component from the layout.- Specified by:
removeLayoutComponentin interfacejava.awt.LayoutManager- Parameters:
child- the component to be removed- See Also:
addLayoutComponent(java.lang.String, java.awt.Component)
-
childForNode
private java.awt.Component childForNode(MultiSplitLayout.Node node)
-
preferredComponentSize
private java.awt.Dimension preferredComponentSize(MultiSplitLayout.Node node)
-
preferredNodeSize
private java.awt.Dimension preferredNodeSize(MultiSplitLayout.Node root)
-
minimumNodeSize
private java.awt.Dimension minimumNodeSize(MultiSplitLayout.Node root)
-
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:
preferredLayoutSizein interfacejava.awt.LayoutManager
-
minimumLayoutSize
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
- Specified by:
minimumLayoutSizein interfacejava.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)
-
minimizeSplitBounds
private static void minimizeSplitBounds(MultiSplitLayout.Split split, java.awt.Rectangle bounds)
-
layoutShrink
private void layoutShrink(MultiSplitLayout.Split split, java.awt.Rectangle bounds)
-
layoutGrow
private void layoutGrow(MultiSplitLayout.Split split, java.awt.Rectangle bounds)
-
layout2
private void layout2(MultiSplitLayout.Node root, java.awt.Rectangle bounds)
-
layout1
private void layout1(MultiSplitLayout.Node root, java.awt.Rectangle bounds)
-
throwInvalidLayout
private static void throwInvalidLayout(java.lang.String msg, MultiSplitLayout.Node node)
-
checkLayout
private static void checkLayout(MultiSplitLayout.Node root)
-
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:
layoutContainerin interfacejava.awt.LayoutManager
-
dividerAt
private static MultiSplitLayout.Divider dividerAt(MultiSplitLayout.Node root, int x, int y)
-
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 coordinatey- y coordinate- Returns:
- the Divider at x,y
-
nodeOverlapsRectangle
private static boolean nodeOverlapsRectangle(MultiSplitLayout.Node node, java.awt.Rectangle r2)
-
dividersThatOverlap
private static java.util.List<MultiSplitLayout.Divider> dividersThatOverlap(MultiSplitLayout.Node root, java.awt.Rectangle r)
-
dividersThatOverlap
public java.util.List<MultiSplitLayout.Divider> dividersThatOverlap(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
-
-