|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--matthew.awt.StrutLayout
StrutLayout is an AWT layout manager that lays out components by logically connecting them with struts. Each StrutLayout has a root component which any number of child components may connect to. Each child component may have also have child components, and so on.
Each component in a StrutLayout may also have internal springs associated with it. These springs can be used to make the component expand horizontally and/or vertically to take up any extra space. The expansion takes into account any child components, ensuring they are not pushed off the edge of the layout area.
Additionally, each component may be a member of a size group which allows sets of components to maintain the same horizontal and/or vertical dimensions as the largest component in the group.
NOTE: although AWT layout managers are in theory able to layout more than container simultaneously, StrutLayout will get very confused if you try to use it like this. For now, you need to use one instance of StrutLayout per container.
StrutLayout.StrutConstraint,
StrutLayout.VectorConstraint,
setSprings(java.awt.Component, int),
createSizeGroup()| Inner Class Summary | |
protected static class |
StrutLayout.ComponentInfo
Stores constraint information for a component. |
class |
StrutLayout.SizeGroup
Represents a group of components who have their width and/or height tied to the size of the group. |
protected static class |
StrutLayout.SizeGroupInfo
Stores size group information. |
protected static class |
StrutLayout.SpringInfo
Stores spring constraint information. |
static class |
StrutLayout.Strut
Represents a strut going from a parent component to a child (see StrutLayout.StrutConstraint for a description of struts). |
protected static class |
StrutLayout.StrutConnection
Represents a strut from a parent to a child. |
static class |
StrutLayout.StrutConstraint
Represents a strut constraint placed on the location of a component. |
static class |
StrutLayout.VectorConstraint
Represents a strut with arbritrary direction and length. |
| Field Summary | |
protected int |
alignment
|
static int |
BOTTOM_LEFT
Represents the bottom left corner of a rectangle. |
static int |
BOTTOM_RIGHT
Represents the bottom right corner of a rectangle. |
static int |
CENTER
Represents the center of a rectangle. |
protected java.util.Hashtable |
componentInfoHash
|
protected static int |
defaultStrutLength
|
static int |
EAST
Represents the direction towards the right of the screen. |
protected boolean |
invalid
|
protected static java.awt.Dimension |
maximumLayoutSize
|
static int |
MID_BOTTOM
Represents the middle of the bottom side of a rectangle. |
static int |
MID_LEFT
Represents the middle of the left side of a rectangle. |
static int |
MID_RIGHT
Represents the middle of the right side of a rectangle. |
static int |
MID_TOP
Represents the middle of the top side of a rectangle. |
static int |
NORTH
Represents the direction towards the top of the screen. |
static int |
NORTH_EAST
Represents the direction towards the top right of the screen. |
static int |
NORTH_WEST
Represents the direction towards top left of the screen. |
protected java.awt.Dimension |
preferredLayoutSize
|
protected StrutLayout.ComponentInfo |
rootComponentInfo
|
static int |
SIZE_BOTH
Specifies a member of a size group whose width and height are tied to the group's size. |
static int |
SIZE_HEIGHT
Specifies a member of a size group whose height is tied to the group's height. |
static int |
SIZE_NONE
Specifies a member of a size group who participates in setting the group's size but which does not change size itself. |
static int |
SIZE_WIDTH
Specifies a member of a size group whose width is tied to the group's width. |
static int |
SOUTH
Represents the direction towards the bottom of the screen. |
static int |
SOUTH_EAST
Represents the direction towards the bottom right of the screen. |
static int |
SOUTH_WEST
Represents the direction towards the bottom left of the screen. |
static int |
SPRING_BOTH
Specifies a spring that expands both horizontally and vertically. |
static int |
SPRING_HORIZ
Specifies a spring that expands horizontally. |
static int |
SPRING_NONE
Specifies a non-existent spring. |
static int |
SPRING_VERT
Specifies a spring that expands vertically. |
static int |
TOP_LEFT
Represents the top left corner of a rectangle. |
static int |
TOP_RIGHT
Represents the top right corner of a rectangle. |
static int |
WEST
Represents the direction towards the left of the screen. |
| Constructor Summary | |
StrutLayout()
|
|
| Method Summary | |
void |
addLayoutComponent(java.awt.Component component,
java.lang.Object constraintObject)
Adds a component to the layout, possibly using a strut as the constraint. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component component)
Does nothing. |
static void |
addStruts(java.awt.Container container,
StrutLayout.Strut[] struts)
Adds a number of struts to the layout at once. |
protected void |
applySizeGroupings()
Apply any size group constraints. |
protected void |
assignPreferredSizes()
Sizes components to their preferred size. |
protected java.awt.Rectangle |
assignRelativePositions()
Assigns component positions starting from root, adjusting for the case where child components extend above or to the left of the root. |
protected java.awt.Rectangle |
assignRelativePositions(StrutLayout.ComponentInfo root)
Recursively assign components relative positions based on their strut constraints starting from root. |
protected java.awt.Point |
calculateAlignmentOffset(java.awt.Dimension layoutArea,
java.awt.Rectangle boundingBox)
Returns an offset that will align boundingBox within the given layoutArea according to the current alignment. |
StrutLayout.SizeGroup |
createSizeGroup()
Creates a new group of components whose sizes are tied together. |
protected void |
doAddRootComponent(java.awt.Component rootComponent)
Does the work of adding a root component to the layout. |
protected void |
doAddStrutComponent(java.awt.Component parent,
java.awt.Component child,
int fromConnector,
int toConnector,
int hdelta,
int vdelta)
Does the work of adding a component with a strut constraint to the layout. |
protected boolean |
evaluateSprings(java.awt.Dimension layoutArea)
Evaluate spring settings, expanding components where possible. |
int |
getAlignment()
Returns the current alignment the layout area within the container (see setAlignment() for details). |
static int |
getDefaultStrutLength()
Returns the current default length for struts. |
protected java.awt.Point |
getDeltaForDirection(int direction)
Computes a delta vector that codes for a direction. |
float |
getLayoutAlignmentX(java.awt.Container parent)
|
float |
getLayoutAlignmentY(java.awt.Container parent)
|
protected static java.awt.Point |
getOffsetForConnector(java.awt.Rectangle shape,
int connector)
Returns a vector (as a Point) that can be added to a component's location to get the location of the specified connector. |
StrutLayout.SizeGroup |
getSizeGroup(java.awt.Component component)
Returns the size group that a component is a member of. |
void |
invalidateLayout(java.awt.Container parent)
|
void |
layoutContainer(java.awt.Container parent)
|
java.awt.Dimension |
maximumLayoutSize(java.awt.Container parent)
|
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
|
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
|
protected void |
recalculateLayout(java.awt.Container container)
Completely recalculates the layout information. |
protected void |
removeComponentInfo(StrutLayout.ComponentInfo componentInfo)
Remove the ComponentInfo for a component and all its children. |
void |
removeLayoutComponent(java.awt.Component component)
Removes a component from a layout. |
protected void |
resetInfo()
Resets the SizeGroup maxHeight and maxWidth variables and the SpringInfo horizExtent and vertExtent variables to their initial value of 0. |
void |
setAlignment(int alignment)
Sets the alignment of the layout area within the container (the default is CENTER). |
static void |
setDefaultStrutLength(int length)
Sets the current default length for struts. |
void |
setPreferredSize(java.awt.Component component,
java.awt.Dimension preferredSize)
Fixes the preferred size for a component regardless of what its getPreferredSize () method returns. |
void |
setSprings(java.awt.Component component,
int springs)
Sets internal springs on a component which act to expand the component horizontally and/or vertically to fill empty space. |
protected void |
translateComponents(int xdelta,
int ydelta)
Translate all component locations by xdelta, ydelta. |
protected void |
updateSpringInfo(StrutLayout.ComponentInfo componentInfo,
int fromConnector,
java.awt.Rectangle childBounds)
Updates the horizontal and vertical extent settings for a component. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static final int TOP_LEFT
public static final int MID_TOP
public static final int TOP_RIGHT
public static final int MID_RIGHT
public static final int BOTTOM_RIGHT
public static final int MID_BOTTOM
public static final int BOTTOM_LEFT
public static final int MID_LEFT
public static final int CENTER
public static final int NORTH
public static final int SOUTH
public static final int EAST
public static final int WEST
public static final int NORTH_EAST
public static final int SOUTH_EAST
public static final int SOUTH_WEST
public static final int NORTH_WEST
public static final int SPRING_NONE
public static final int SPRING_HORIZ
public static final int SPRING_VERT
public static final int SPRING_BOTH
public static final int SIZE_WIDTH
public static final int SIZE_HEIGHT
public static final int SIZE_BOTH
public static final int SIZE_NONE
protected StrutLayout.ComponentInfo rootComponentInfo
protected java.util.Hashtable componentInfoHash
protected boolean invalid
protected java.awt.Dimension preferredLayoutSize
protected int alignment
protected static int defaultStrutLength
protected static final java.awt.Dimension maximumLayoutSize
| Constructor Detail |
public StrutLayout()
| Method Detail |
public void setAlignment(int alignment)
alignment - The alignment of the layout area within the
container. One of TOP_LEFT, MID_TOP, TOP_RIGHT, MID_RIGHT,
BOTTOM_RIGHT, MID_BOTTOM, BOTTOM_LEFT, MID_LEFT or CENTER (the
default).getAlignment()public int getAlignment()
setAlignment(int)
public void setSprings(java.awt.Component component,
int springs)
NOTE: while child components are protected from being covered by their sprung parent components, this does not prevent others not connected to the parent from being potentially obscured. It is up to you to ensure the layout rules do not allow this.
Example:
strutLayout.setSprings (tablePane, StrutLayout.SPRING_BOTH);
component - The component to add the spring to. The
component must already be a part of the layoutsprings - The spring(s) to add to the component. One of
SPRING_NONE, SPRING_HORIZ, SPRING_VERT or SPRING_BOTH.SPRING_NONE,
SPRING_VERT,
SPRING_HORIZ,
SPRING_BOTHpublic StrutLayout.SizeGroup createSizeGroup()
StrutLayout.SizeGroup,
getSizeGroup(java.awt.Component)public StrutLayout.SizeGroup getSizeGroup(java.awt.Component component)
component - The component to be queried.StrutLayout.SizeGroup,
createSizeGroup()public static int getDefaultStrutLength()
setDefaultStrutLength(int),
StrutLayout.StrutConstraint,
StrutLayout.Strutpublic static void setDefaultStrutLength(int length)
getDefaultStrutLength(),
StrutLayout.StrutConstraint,
StrutLayout.Strut
public void setPreferredSize(java.awt.Component component,
java.awt.Dimension preferredSize)
component - The component whose preferred size is to be
fixed.preferredSize - The new preferred size of the
component. If this is null, then the component's preferred size
reverts to the result of its getPreferredSize () method.addLayoutComponent(java.awt.Component, java.lang.Object)
public static void addStruts(java.awt.Container container,
StrutLayout.Strut[] struts)
struts - The struts to be added.StrutLayout.Strut,
addLayoutComponent(java.awt.Component, java.lang.Object)
public void addLayoutComponent(java.lang.String name,
java.awt.Component component)
addLayoutComponent(java.awt.Component, java.lang.Object)public void removeLayoutComponent(java.awt.Component component)
component - The component to remove.addLayoutComponent(java.awt.Component, java.lang.Object)
public void addLayoutComponent(java.awt.Component component,
java.lang.Object constraintObject)
NOTE: If the component has a non-zero size when added, this size will be used as its preferred size rather than the result of its getPreferredSize () method.
component - The component to add.constraintObject - The constraint to use when laying out the
component. This may be an instance of either
StrutLayout.StrutConstraint or StrutLayout.VectorConstraint or
null for the root component.StrutLayout.StrutConstraint,
StrutLayout.VectorConstraint,
setPreferredSize(java.awt.Component, java.awt.Dimension)public float getLayoutAlignmentX(java.awt.Container parent)
public float getLayoutAlignmentY(java.awt.Container parent)
public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
public void layoutContainer(java.awt.Container parent)
public void invalidateLayout(java.awt.Container parent)
protected void recalculateLayout(java.awt.Container container)
protected void resetInfo()
protected void assignPreferredSizes()
protected java.awt.Rectangle assignRelativePositions()
assignRelativePositions(StrutLayout.ComponentInfo)protected java.awt.Rectangle assignRelativePositions(StrutLayout.ComponentInfo root)
root - The component to start the layout at.
protected void updateSpringInfo(StrutLayout.ComponentInfo componentInfo,
int fromConnector,
java.awt.Rectangle childBounds)
protected boolean evaluateSprings(java.awt.Dimension layoutArea)
layoutArea - The max area available for layout.protected void applySizeGroupings()
protected void translateComponents(int xdelta,
int ydelta)
protected java.awt.Point calculateAlignmentOffset(java.awt.Dimension layoutArea,
java.awt.Rectangle boundingBox)
protected static java.awt.Point getOffsetForConnector(java.awt.Rectangle shape,
int connector)
shape - The shape to find the connector offset for. Only
the shape's width and height are used.connector - The connector. See the TOP_LEFT, etc constants.protected java.awt.Point getDeltaForDirection(int direction)
protected void doAddStrutComponent(java.awt.Component parent,
java.awt.Component child,
int fromConnector,
int toConnector,
int hdelta,
int vdelta)
protected void doAddRootComponent(java.awt.Component rootComponent)
protected void removeComponentInfo(StrutLayout.ComponentInfo componentInfo)
componentInfo - The componentInfo to remove.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||