Class MultiSplitLayout
- java.lang.Object
-
- org.openstreetmap.josm.gui.widgets.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:
MultiSplitPane
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultiSplitLayout.Divider
Models a single vertical/horiztonal divider.static class
MultiSplitLayout.InvalidLayoutException
The specified Node is either the wrong type or was configured incorrectly.static class
MultiSplitLayout.Leaf
Models a java.awt Component child.static class
MultiSplitLayout.Node
Base class for the nodes that model a MultiSplitLayout.static class
MultiSplitLayout.Split
Defines a vertical or horizontal subdivision into two or more tiles.
-
Field Summary
Fields Modifier and Type Field Description private Map<String,Component>
childMap
private int
dividerSize
private boolean
floatingDividers
private MultiSplitLayout.Node
model
private PropertyChangeSupport
pcs
-
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 void
addLayoutComponent(String name, Component child)
Add a component to this MultiSplitLayout.void
addPropertyChangeListener(PropertyChangeListener listener)
Add property change listener.private static Rectangle
boundsWithXandWidth(Rectangle bounds, double x, double width)
private static Rectangle
boundsWithYandHeight(Rectangle bounds, double y, double height)
private static void
checkLayout(MultiSplitLayout.Node root)
private Component
childForNode(MultiSplitLayout.Node node)
MultiSplitLayout.Divider
dividerAt(int x, int y)
Return the Divider whose bounds contain the specified point, or null if there isn't one.private static MultiSplitLayout.Divider
dividerAt(MultiSplitLayout.Node root, int x, int y)
List<MultiSplitLayout.Divider>
dividersThatOverlap(Rectangle r)
Return the Dividers whose bounds overlap the specified Rectangle.private static List<MultiSplitLayout.Divider>
dividersThatOverlap(MultiSplitLayout.Node root, Rectangle r)
private void
firePCS(String propertyName, Object oldValue, Object newValue)
int
getDividerSize()
Returns the width of Dividers in Split rows, and the height of Dividers in Split columns.boolean
getFloatingDividers()
Returns the value of the floatingDividers property.MultiSplitLayout.Node
getModel()
Return the root of the tree of Split, Leaf, and Divider nodes that define this layout.PropertyChangeListener[]
getPropertyChangeListeners()
Replies list of property change listeners.private void
layout1(MultiSplitLayout.Node root, Rectangle bounds)
private void
layout2(MultiSplitLayout.Node root, Rectangle bounds)
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.private void
layoutGrow(MultiSplitLayout.Split split, Rectangle bounds)
private void
layoutShrink(MultiSplitLayout.Split split, Rectangle bounds)
private static void
minimizeSplitBounds(MultiSplitLayout.Split split, Rectangle bounds)
Dimension
minimumLayoutSize(Container parent)
private Dimension
minimumNodeSize(MultiSplitLayout.Node root)
private static boolean
nodeOverlapsRectangle(MultiSplitLayout.Node node, Rectangle r2)
private Dimension
preferredComponentSize(MultiSplitLayout.Node node)
Dimension
preferredLayoutSize(Container parent)
private Dimension
preferredNodeSize(MultiSplitLayout.Node root)
void
removeLayoutComponent(Component child)
Removes the specified component from the layout.void
removePropertyChangeListener(PropertyChangeListener listener)
Remove property change listener.void
setDividerSize(int dividerSize)
Sets the width of Dividers in Split rows, and the height of Dividers in Split columns.void
setFloatingDividers(boolean floatingDividers)
If true, Leaf node bounds match the corresponding component's preferred size and Splits/Dividers are resized accordingly.void
setModel(MultiSplitLayout.Node model)
Set the root of the tree of Split, Leaf, and Divider nodes that define this layout.private static Dimension
sizeWithInsets(Container parent, Dimension size)
private static void
throwInvalidLayout(String msg, MultiSplitLayout.Node node)
-
-
-
Field Detail
-
pcs
private final 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(PropertyChangeListener listener)
Add property change listener.- Parameters:
listener
- listener to add
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove property change listener.- Parameters:
listener
- listener to remove
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
Replies list of property change listeners.- Returns:
- list of property change listeners
-
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 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:
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:
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(String name, Component child)
Add a component to this MultiSplitLayout. Thename
should 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:
addLayoutComponent
in interfaceLayoutManager
- 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(Component child)
Removes the specified component from the layout.- Specified by:
removeLayoutComponent
in interfaceLayoutManager
- Parameters:
child
- the component to be removed- See Also:
addLayoutComponent(java.lang.String, java.awt.Component)
-
childForNode
private Component childForNode(MultiSplitLayout.Node node)
-
preferredComponentSize
private Dimension preferredComponentSize(MultiSplitLayout.Node node)
-
preferredNodeSize
private Dimension preferredNodeSize(MultiSplitLayout.Node root)
-
minimumNodeSize
private Dimension minimumNodeSize(MultiSplitLayout.Node root)
-
sizeWithInsets
private static Dimension sizeWithInsets(Container parent, Dimension size)
-
preferredLayoutSize
public Dimension preferredLayoutSize(Container parent)
- Specified by:
preferredLayoutSize
in interfaceLayoutManager
-
minimumLayoutSize
public Dimension minimumLayoutSize(Container parent)
- Specified by:
minimumLayoutSize
in interfaceLayoutManager
-
boundsWithYandHeight
private static Rectangle boundsWithYandHeight(Rectangle bounds, double y, double height)
-
boundsWithXandWidth
private static Rectangle boundsWithXandWidth(Rectangle bounds, double x, double width)
-
minimizeSplitBounds
private static void minimizeSplitBounds(MultiSplitLayout.Split split, Rectangle bounds)
-
layoutShrink
private void layoutShrink(MultiSplitLayout.Split split, Rectangle bounds)
-
layoutGrow
private void layoutGrow(MultiSplitLayout.Split split, Rectangle bounds)
-
layout2
private void layout2(MultiSplitLayout.Node root, Rectangle bounds)
-
layout1
private void layout1(MultiSplitLayout.Node root, Rectangle bounds)
-
throwInvalidLayout
private static void throwInvalidLayout(String msg, MultiSplitLayout.Node node)
-
checkLayout
private static void checkLayout(MultiSplitLayout.Node root)
-
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 interfaceLayoutManager
-
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, Rectangle r2)
-
dividersThatOverlap
private static List<MultiSplitLayout.Divider> dividersThatOverlap(MultiSplitLayout.Node root, Rectangle r)
-
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
-
-