public class MultiSplitLayout extends Object implements 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.
JXMultiSplitPane
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
MultiSplitLayout.ColSplit |
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.RowSplit |
static class |
MultiSplitLayout.Split
Defines a vertical or horizontal subdivision into two or more
tiles.
|
Modifier and Type | Field and Description |
---|---|
private Map<String,Component> |
childMap |
static int |
DEFAULT_LAYOUT |
private int |
dividerSize |
private boolean |
floatingDividers |
private boolean |
layoutByWeight |
private int |
layoutMode |
private MultiSplitLayout.Node |
model |
static int |
NO_MIN_SIZE_LAYOUT |
private PropertyChangeSupport |
pcs |
private boolean |
removeDividers |
static int |
USER_MIN_SIZE_LAYOUT |
private int |
userMinSize |
Constructor and Description |
---|
MultiSplitLayout()
Create 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".
|
MultiSplitLayout(MultiSplitLayout.Node model)
Create a MultiSplitLayout with the specified model.
|
Modifier and Type | Method and Description |
---|---|
void |
addLayoutComponent(String name,
Component child)
Add a component to this MultiSplitLayout.
|
void |
addPropertyChangeListener(PropertyChangeListener listener) |
private static void |
addSplitChild(MultiSplitLayout.Split parent,
MultiSplitLayout.Node child) |
private Rectangle |
boundsWithXandWidth(Rectangle bounds,
double x,
double width) |
private Rectangle |
boundsWithYandHeight(Rectangle bounds,
double y,
double height) |
private void |
checkLayout(MultiSplitLayout.Node root) |
private Component |
childForNode(MultiSplitLayout.Node node) |
void |
displayNode(String name,
boolean visible)
Show/Hide nodes.
|
MultiSplitLayout.Divider |
dividerAt(int x,
int y)
Return the Divider whose bounds contain the specified
point, or null if there isn't one.
|
private MultiSplitLayout.Divider |
dividerAt(MultiSplitLayout.Node root,
int x,
int y) |
private List<MultiSplitLayout.Divider> |
dividersThatOverlap(MultiSplitLayout.Node root,
Rectangle r) |
List<MultiSplitLayout.Divider> |
dividersThatOverlap(Rectangle r)
Return the Dividers whose bounds overlap the specified
Rectangle.
|
private void |
doLayoutByWeight(Container parent)
Set the size of the child components to match the weights of the children.
|
private void |
doLayoutByWeight(MultiSplitLayout.Node node,
Rectangle bounds) |
private void |
firePCS(String propertyName,
Object oldValue,
Object newValue) |
Component |
getComponentForNode(MultiSplitLayout.Node n)
Get the component associated with a MultiSplitLayout.Node
|
int |
getDividerSize()
Returns the width of Dividers in Split rows, and the height of
Dividers in Split columns.
|
boolean |
getFloatingDividers() |
boolean |
getLayoutByWeight()
Get the layoutByWeight falg.
|
int |
getLayoutMode()
Get the layout mode
|
MultiSplitLayout.Node |
getModel()
Return the root of the tree of Split, Leaf, and Divider nodes
that define this layout.
|
String |
getNameForComponent(Component child)
Get the name used to map a component
|
MultiSplitLayout.Node |
getNodeForComponent(Component comp)
Get the MultiSplitLayout.Node associated with a component
|
MultiSplitLayout.Node |
getNodeForComponent(MultiSplitLayout.Split split,
Component comp)
Get the MultiSplitLayout.Node associated with a component
|
MultiSplitLayout.Node |
getNodeForName(MultiSplitLayout.Split split,
String name)
Get the MultiSplitLayout.Node associated with a component
|
MultiSplitLayout.Node |
getNodeForName(String name)
Get the MultiSplitLayout.Node associated with a component
|
PropertyChangeListener[] |
getPropertyChangeListeners() |
boolean |
getRemoveDividers() |
int |
getUserMinSize()
Get the minimum node size
|
boolean |
hasModel()
Is there a valid model for the layout?
|
private boolean |
hasMoreVisibleSiblings(MultiSplitLayout.Node splitChild)
Check if the specified node has any following visible siblings
|
private void |
layout1(MultiSplitLayout.Node root,
Rectangle bounds) |
private void |
layout2(MultiSplitLayout.Node root,
Rectangle bounds) |
void |
layoutByWeight(Container parent)
Set the size of the child components to match the weights of the children.
|
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) |
Dimension |
maximumNodeSize(MultiSplitLayout.Node root)
Get the maximum size of this node.
|
private void |
minimizeSplitBounds(MultiSplitLayout.Split split,
Rectangle bounds) |
private Dimension |
minimumComponentSize(MultiSplitLayout.Node node) |
Dimension |
minimumLayoutSize(Container parent) |
Dimension |
minimumNodeSize(MultiSplitLayout.Node root)
Get the minimum size of this node.
|
private boolean |
nodeOverlapsRectangle(MultiSplitLayout.Node node,
Rectangle r2) |
private static void |
parseAttribute(String name,
StreamTokenizer st,
MultiSplitLayout.Node node) |
private static void |
parseLeaf(StreamTokenizer st,
MultiSplitLayout.Split parent) |
private static MultiSplitLayout.Node |
parseModel(Reader r) |
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.
|
private static void |
parseSplit(StreamTokenizer st,
MultiSplitLayout.Split parent) |
private Dimension |
preferredComponentSize(MultiSplitLayout.Node node) |
Dimension |
preferredLayoutSize(Container parent) |
private Dimension |
preferredNodeSize(MultiSplitLayout.Node root) |
static void |
printModel(MultiSplitLayout.Node root)
Print the tree with enough detail for simple debugging.
|
private static void |
printModel(String indent,
MultiSplitLayout.Node root) |
void |
removeLayoutComponent(Component child)
Removes the specified component from the layout.
|
void |
removeLayoutNode(String name)
Removes the specified node from the layout.
|
void |
removePropertyChangeListener(PropertyChangeListener 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 |
setLayoutByWeight(boolean state)
Sset the layoutByWeight falg.
|
void |
setLayoutMode(int layoutMode)
Set the layout mode.
|
void |
setModel(MultiSplitLayout.Node model)
Set the root of the tree of Split, Leaf, and Divider nodes
that define this layout.
|
void |
setRemoveDividers(boolean removeDividers)
If true, the next divider is removed when a component is removed from the
layout.
|
void |
setUserMinSize(int minSize)
Set the user defined minimum size support in the USER_MIN_SIZE_LAYOUT
layout mode.
|
private Dimension |
sizeWithInsets(Container parent,
Dimension size) |
private void |
throwInvalidLayout(String msg,
MultiSplitLayout.Node node) |
private static void |
throwParseException(StreamTokenizer st,
String msg) |
public static final int DEFAULT_LAYOUT
public static final int NO_MIN_SIZE_LAYOUT
public static final int USER_MIN_SIZE_LAYOUT
private final PropertyChangeSupport pcs
private MultiSplitLayout.Node model
private int dividerSize
private boolean floatingDividers
private boolean removeDividers
private boolean layoutByWeight
private int layoutMode
private int userMinSize
public MultiSplitLayout()
public MultiSplitLayout(boolean layoutByWeight)
layoutByWeight
- if true the layout is initialized in proportion to
the node weights rather than the component preferred sizes.
#see setModelpublic MultiSplitLayout(MultiSplitLayout.Node model)
public void layoutByWeight(Container parent)
private void doLayoutByWeight(Container parent)
private void doLayoutByWeight(MultiSplitLayout.Node node, Rectangle bounds)
public Component getComponentForNode(MultiSplitLayout.Node n)
n
- the layout nodepublic MultiSplitLayout.Node getNodeForComponent(Component comp)
comp
- the component being positioned by the layoutpublic MultiSplitLayout.Node getNodeForName(String name)
name
- the name used to associate a component with the layoutpublic String getNameForComponent(Component child)
child
- the componentpublic MultiSplitLayout.Node getNodeForComponent(MultiSplitLayout.Split split, Component comp)
split
- the layout split that owns the requested nodecomp
- the component being positioned by the layoutpublic MultiSplitLayout.Node getNodeForName(MultiSplitLayout.Split split, String name)
split
- the layout split that owns the requested nodename
- the name used to associate a component with the layoutpublic boolean hasModel()
public void addPropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)
public PropertyChangeListener[] getPropertyChangeListeners()
public MultiSplitLayout.Node getModel()
setModel(org.jdesktop.swingx.MultiSplitLayout.Node)
public void setModel(MultiSplitLayout.Node model)
model
- the root of the tree of Split, Leaf, and Divider nodeIllegalArgumentException
- if model is a Divider or nullgetModel()
public int getDividerSize()
setDividerSize(int)
public void setDividerSize(int dividerSize)
dividerSize
- the size of dividers (pixels)IllegalArgumentException
- if dividerSize < 0getDividerSize()
public boolean getFloatingDividers()
setFloatingDividers(boolean)
public void setFloatingDividers(boolean floatingDividers)
getFloatingDividers()
public boolean getRemoveDividers()
setRemoveDividers(boolean)
public void setRemoveDividers(boolean removeDividers)
removeDividers
- true to removed the next divider whena component is
removed from teh layoutpublic void addLayoutComponent(String name, Component child)
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.addLayoutComponent
in interface LayoutManager
name
- identifies the Leaf node that defines the child's boundschild
- the component to be addedremoveLayoutComponent(java.awt.Component)
public void removeLayoutComponent(Component child)
removeLayoutComponent
in interface LayoutManager
child
- the component to be removedaddLayoutComponent(java.lang.String, java.awt.Component)
public void removeLayoutNode(String name)
name
- the name of the component to be removedaddLayoutComponent(java.lang.String, java.awt.Component)
public void displayNode(String name, boolean visible)
name
- the node namevisible
- the new node visible stateprivate Component childForNode(MultiSplitLayout.Node node)
private Dimension preferredComponentSize(MultiSplitLayout.Node node)
private Dimension minimumComponentSize(MultiSplitLayout.Node node)
private Dimension preferredNodeSize(MultiSplitLayout.Node root)
public Dimension minimumNodeSize(MultiSplitLayout.Node root)
root
- the node whose size is required.public Dimension maximumNodeSize(MultiSplitLayout.Node root)
root
- the node whose size is required.private Dimension sizeWithInsets(Container parent, Dimension size)
public Dimension preferredLayoutSize(Container parent)
preferredLayoutSize
in interface LayoutManager
public Dimension minimumLayoutSize(Container parent)
minimumLayoutSize
in interface LayoutManager
private Rectangle boundsWithYandHeight(Rectangle bounds, double y, double height)
private Rectangle boundsWithXandWidth(Rectangle bounds, double x, double width)
private void minimizeSplitBounds(MultiSplitLayout.Split split, Rectangle bounds)
private void layoutShrink(MultiSplitLayout.Split split, Rectangle bounds)
private boolean hasMoreVisibleSiblings(MultiSplitLayout.Node splitChild)
splitChild
- the node to checktrue
- if there are visible children followingprivate void layoutGrow(MultiSplitLayout.Split split, Rectangle bounds)
private void layout2(MultiSplitLayout.Node root, Rectangle bounds)
private void layout1(MultiSplitLayout.Node root, Rectangle bounds)
public int getLayoutMode()
public void setLayoutMode(int layoutMode)
layoutMode
- the layout mode
public int getUserMinSize()
public void setUserMinSize(int minSize)
minSize
- the new minimum sizepublic boolean getLayoutByWeight()
public void setLayoutByWeight(boolean state)
state
- the new layoutByWeight to setprivate void throwInvalidLayout(String msg, MultiSplitLayout.Node node)
private void checkLayout(MultiSplitLayout.Node root)
public void layoutContainer(Container parent)
layoutContainer
in interface LayoutManager
private MultiSplitLayout.Divider dividerAt(MultiSplitLayout.Node root, int x, int y)
public MultiSplitLayout.Divider dividerAt(int x, int y)
x
- x coordinatey
- y coordinateprivate boolean nodeOverlapsRectangle(MultiSplitLayout.Node node, Rectangle r2)
private List<MultiSplitLayout.Divider> dividersThatOverlap(MultiSplitLayout.Node root, Rectangle r)
public List<MultiSplitLayout.Divider> dividersThatOverlap(Rectangle r)
r
- target RectangleIllegalArgumentException
- if the Rectangle is nullprivate static void throwParseException(StreamTokenizer st, String msg) throws Exception
Exception
private static void parseAttribute(String name, StreamTokenizer st, MultiSplitLayout.Node node) throws Exception
Exception
private static void addSplitChild(MultiSplitLayout.Split parent, MultiSplitLayout.Node child)
private static void parseLeaf(StreamTokenizer st, MultiSplitLayout.Split parent) throws Exception
Exception
private static void parseSplit(StreamTokenizer st, MultiSplitLayout.Split parent) throws Exception
Exception
private static MultiSplitLayout.Node parseModel(Reader r)
public static MultiSplitLayout.Node parseModel(String s)
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.
private static void printModel(String indent, MultiSplitLayout.Node root)
public static void printModel(MultiSplitLayout.Node root)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses