public class TwoColumnLayout extends Object implements LayoutManager2
TwoColumnConstraints
Modifier and Type | Field and Description |
---|---|
private int |
alignment |
static int |
CENTER |
private int |
centerRule |
private Vector[] |
components
holds all the components and layout constraints.
|
private int |
gap
the gap between the two columns
|
private int |
indent
the indent setting in % of the conteiner's width
|
static int |
LEFT |
private int |
leftRule |
private int |
margin
the margin setting in % of the container's width
|
static int |
RIGHT |
private int |
rightRule |
private TwoColumnConstraints |
title
holds the component to be placed in the title region, including layout constraints.
|
private int |
titleHeight |
private int |
topBuffer
the setting for the buffer area on top of hte comonent cluster in % of the left over height.
|
Constructor and Description |
---|
TwoColumnLayout(int margin,
int gap,
int indent,
int topBuffer,
int alignment)
Constructs a
TwoColumnLayout layout manager. |
Modifier and Type | Method and Description |
---|---|
void |
addLayoutComponent(Component comp,
Object constraints)
Sets the constraints for the specified component in this layout.
|
void |
addLayoutComponent(String name,
Component comp)
Adds the specified component with the specified name to the layout.
|
float |
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis.
|
float |
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis.
|
private int |
height(int row,
int column)
Measures and returns the minimum height required to render the component in the indicated row
and column.
|
void |
invalidateLayout(Container parent)
Invalidates the layout, indicating that if the layout manager has cached information it
should be discarded.
|
void |
layoutContainer(Container parent)
Lays out the container in the specified panel.
|
private int |
margin(Container parent)
Computes the margin value based on the container width and the margin setting.
|
Dimension |
maximumLayoutSize(Container parent)
Calculates the maximum size dimensions for the specified panel given the components in the
specified parent container.
|
private int |
minimumBothColumnsWidth(Container parent)
Retrunds the minimum width both columns together should have based on the minimum widths of
all the components that straddle both columns and the minimum width of the title component.
|
private int |
minimumClusterHeight() |
private int |
minimumColumnWidth(int column,
Container parent)
Returns the minimum width of the column requested.
|
Dimension |
minimumLayoutSize(Container parent)
Calculates the minimum size dimensions for the specified panel given the components in the
specified parent container.
|
private void |
positionComponent(int y,
int row,
int column,
Container parent)
Positiones one component as instructed.
|
private void |
positionComponents(Container parent)
Positions all components in the container.
|
private void |
positionRules(Container parent)
Positions the three rules in preparation for layout.
|
private void |
positionTitle(Container parent)
Positions the title component and sets the variable
titleHeight . |
Dimension |
preferredLayoutSize(Container parent)
Calculates the preferred size dimensions for the specified panel given the components in the
specified parent container.
|
void |
removeLayoutComponent(Component comp)
This functionality is not supported
|
private int |
rowHeight(int row)
Measures and returns the minimum height required to render the components in the indicated
row.
|
private int |
rows()
Returns the number of rows that need to be laid out.
|
void |
showRules(Graphics2D graphics,
Color color)
This method is provided for conveninence of debugging layout problems.
|
private int |
topBuffer(int usedHeight,
Container parent)
Computes the top buffer value based on the container width and the setting for the top buffer
|
public static final int LEFT
public static final int RIGHT
public static final int CENTER
private Vector[] components
private TwoColumnConstraints title
private int margin
private int topBuffer
private int indent
private int gap
private int alignment
private int leftRule
private int rightRule
private int centerRule
private int titleHeight
public TwoColumnLayout(int margin, int gap, int indent, int topBuffer, int alignment)
TwoColumnLayout
layout manager. To add components use the
container's add(comp, constraints)
method with a TwoColumnConstraints object.margin
- the margin width to use on the left and right side in % of the total container
width. Values less than 0% and greater than 50% are not accepted.gap
- the gap between the two columns.indent
- the indent to use for components that have that constraint set. This is a value
in pixels.topBuffer
- the percentage of left over vertical space to place on top of the component
cluster. Values between 0% and 100% are accepted.alignment
- how to align the overall layout. Legal values are LEFT, CENTER, RIGHT.public void addLayoutComponent(Component comp, Object constraints)
null
is a
legal value for a component, but not for a constraints object.addLayoutComponent
in interface LayoutManager2
comp
- the component to be modified.constraints
- the constraints to be applied.public void layoutContainer(Container parent)
layoutContainer
in interface LayoutManager
parent
- the component which needs to be laid out.private void positionRules(Container parent)
leftRule
rightRule
centerRule
parent
- the component which needs to be laid out.private void positionTitle(Container parent)
titleHeight
. Note:
this method depends on the fact that the rules are set to their correct layout position.parent
- the component which needs to be laid out.private void positionComponents(Container parent)
parent
- the component which needs to be laid out.private void positionComponent(int y, int row, int column, Container parent)
stretch
, BOTH
and indent
are taken into
account. In addition, empty comonents are handled properly.y
- the y location within the continer, where the component should be positioned.row
- the row of the componentcolumn
- the column of the componentparent
- the container which needs to be laid out.private int minimumColumnWidth(int column, Container parent)
column
- the columns to measure (LEFT / RIGHT)parent
- the component which needs to be laid out.private int minimumBothColumnsWidth(Container parent)
parent
- the component which needs to be laid out.private int minimumClusterHeight()
private int rows()
private int rowHeight(int row)
row
- the index of the row to measureprivate int height(int row, int column)
row
- the index of the row to measurecolumn
- the column of the component to measure (LEFT
or
RIGHT
)private int margin(Container parent)
parent
- the component which needs to be laid out.private int topBuffer(int usedHeight, Container parent)
usedHeight
- the amount of the parent component's height that is already in use (height
of the title and the combined height of all rows).parent
- the component which needs to be laid out.public Dimension preferredLayoutSize(Container parent)
preferredLayoutSize
in interface LayoutManager
parent
- the component to be laid outpublic Dimension minimumLayoutSize(Container parent)
minimumLayoutSize
in interface LayoutManager
parent
- the component to be laid outpublic Dimension maximumLayoutSize(Container parent)
maximumLayoutSize
in interface LayoutManager2
parent
- the component to be laid outpublic float getLayoutAlignmentX(Container parent)
getLayoutAlignmentX
in interface LayoutManager2
parent
- the component to be laid outpublic float getLayoutAlignmentY(Container parent)
getLayoutAlignmentY
in interface LayoutManager2
parent
- the component to be laid outpublic void invalidateLayout(Container parent)
invalidateLayout
in interface LayoutManager2
parent
- the component to be laid outpublic void addLayoutComponent(String name, Component comp)
addLayoutComponent
with layout contsraints.addLayoutComponent
in interface LayoutManager
name
- the component namecomp
- the component to be addedpublic void removeLayoutComponent(Component comp)
removeLayoutComponent
in interface LayoutManager
comp
- the component to be removedpublic void showRules(Graphics2D graphics, Color color)
paint()
method.
super.paint()
paint()
method to
Graphics2D
when making the call.graphics
- the graphics context used for drawing.color
- the color to use for rendering the layout gridWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses