|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--kirk.gui.layout.GridSpanLayout
This class is a custom LayoutManager
that is kinda like a mix of
GridLayout
and GridBagLayout
. For me, it's not as
confusing as GridBagLayout
, but it offers more functionality than
GridLayout
.
GridSpanLayout
is contructed with width and height in cells, much
like GridLayout
. The cells are proportional to the total width and
height of the Container
using this LayoutManager
. Also,
there are horizontal and vertical gaps between Component
s, that
default to 5 pixels, but can be specified during construction time or later on by
calling the mutator methods for them.
Components
are layed out on the grid much like with
GridBagLayout
: they are allowed to span multiple cells. However,
the difference is that GridSpanLayout
has a preset amount of cells,
and that the sizes of all the cells are the same. Also, there are no weights to
worry about. Any resizing is done exactly like GridLayout
and
GridLineLayout
: all cells are resized equivalently, and remain
relatively on the same position.
This LayoutManager
is one that uses constraints to lay out its
Component
s, much like GridBagLayout
. The constraints are
in the form of GridSpanConstraints
objects, which contain the values
needed for laying out the Component
. Each Component
has
an associated constraints object.
These are the settings you can give a GridSpanConstraints
object.
Component
, in cells.
Component
, in cells.
Component
, in cells.
Component
, in cells.
Component
. The number has to be between 0.0 and 1.0, where 0.0
indicates that the Component
has no width, 1.0 indicates to
fully fill the available horizontal space, 0.5 indicates that the
Component
is as wide as halve the available space, and so on.
If you specify a value that is out of the 0.0-1.0 bounds(inclusive), then
the preferred width of the Component
(specified by
Component.getPreferredSize().width
) will be used.
Component
. The number has to be between 0.0 and 1.0, where 0.0
indicates that the Component
has no height, 1.0 indicates to
fully fill the available vertical space, 0.5 indicates that the
Component
is as high as halve the available space, and so on.
If you specify a value that is out of the 0.0-1.0 bounds(inclusive), then
the preferred height of the Component
(specified by
Component.getPreferredSize().height
) will be used.
Component
on the x-axis. The number has to be between 0.0 and
1.0, where 0.0 (the default value) indicates that the Component
should be placed at the far most left side, 1.0 indicates that the
Component
should be placed at the far most right side, 0.5
indicates that the Component
should be centered, and so on.
If you specify a value that is out of the 0.0-1.0 bounds (inclusive), then
the alignment value of the component (specified by
Component.getAlignmentX()
) will be used.
Component
on the y-axis. The number has to be between 0.0 and
1.0, where 0.0 (the default value) indicates that the Component
should be placed at the far most upper side, 1.0 indicates that the
Component
should be placed at the far most lower side, 0.5
indicates that the Component
should be centered, and so on.
If you specify a value that is out of the 0.0-1.0 bounds (inclusive),
then the alignment value of the component (specified by
Component.getAlignmentY()
) will be used.
GridBagLayout
, the GridSpanConstraints
objects
are copied. This because when you add or set a constraint, this class checks
whether it is allowed. So you can't get to the inner
GridSpanConstraints
objects because otherwise you could
(accidentally) break this LayoutManager
.
GridSpanConstraints
,
simply because it can't (it has no knowledge of a parent Container
when setting constraints, it can be effectively used to lay out multiple
Container
s, as the interface prescribes), but for easeness sake there
can be only one Component
per cell. So, if there are multiple
Component
s that are on the same cell, only the one that comes first
in the list of the parent Container
(Container.getComponent(int n)
) will be displayed.
So, take care when adding Component
s (just like you would with
GridBagLayout
... I still don't know what that class' behaviour is in
this case. I still don't know/understand a lot about it actually... What is
it with those weights :^P).
GridBagLayout
,
GridLayout
,
GridSpanConstraints
Field Summary | |
protected HashMap |
componentmap
The Map that links the Component s to their
constraints objects. |
protected int |
height
The height of the grid in cells. |
protected int |
horizontalgap
The horizontal gap. |
protected int |
verticalgap
The vertical gap. |
protected int |
width
The width of the grid in cells. |
Constructor Summary | |
GridSpanLayout(int width,
int height)
Creates a new GridSpanLayout with the given width and height, and
the default values (5) for the horizontal gap and vertical gap. |
|
GridSpanLayout(int width,
int height,
int horizontalgap,
int verticalgap)
Creates a new GridSpanLayout with the given width, height,
horizontal gap and vertical gap. |
Method Summary | |
void |
addLayoutComponent(Component comp,
Object constraints)
Adds the passed Component to the LayoutManager with
the passed constraints. |
void |
addLayoutComponent(String name,
Component comp)
Adds the passed Component to the LayoutManager with
the passed name. |
GridSpanConstraints |
getConstraints(Component component)
Returns the GridSpanConstraints that is associated with the
passed key. |
protected int |
getGridHeight(Integer[][] cellheights)
Returns the total height of the passed Array with heights, taken
into account only the largest height per row. |
protected int |
getGridWidth(Integer[][] cellwidths)
Returns the total width of the passed Array with widths, taken
into account only the largest width per column. |
int |
getHeight()
Returns the height of this grid in cells. |
int |
getHorizontalGap()
Returns the horizontal gap. |
protected int |
getLargestHeight(Integer[][] cellheights,
int row)
Return the largest height of the all the cells in the indicated row. |
protected int |
getLargestWidth(Integer[][] cellwidths,
int column)
Return the largest width of the all the cells in the indicated column. |
float |
getLayoutAlignmentX(Container target)
Returns the alignment along the x-axis of the passed Container if
it where to be layed out with this LayoutManager .
|
float |
getLayoutAlignmentY(Container target)
Returns the alignment along the y-axis of the passed Container if
it where to be layed out with this LayoutManager .
|
int |
getVerticalGap()
Returns the vertical gap. |
int |
getWidth()
Returns the width of this grid in cells. |
void |
invalidateLayout(Container target)
Invalidates this LayoutManager , indicating that if this
LayoutManager has cached information it should be discarded. |
protected boolean |
isFree(Component[][] componentgrid,
int x,
int y,
int width,
int height)
Checks whether the given portion of the Component grid does not
contain any Component s. |
void |
layoutContainer(Container parent)
Lays out the passed Container with this
LayoutManager , and the constraints objects associated with the
Component s of this Container . |
protected Component[][] |
makeGrid(Container parent,
boolean active)
Returns the grid. |
Dimension |
maximumLayoutSize(Container target)
Returns the size of the passed Container as this
LayoutManager would like it to be at maximum when the passed
Container where to be layed out with this
LayoutManager . |
Dimension |
minimumLayoutSize(Container parent)
Returns the size of the passed Container as this
LayoutManager would like it to be at minimum when the passed
Container where to be layed out with this
LayoutManager . |
protected boolean |
outOfBounds(GridSpanConstraints constraints)
Check whether the passed constraints are out of bounds. |
Dimension |
preferredLayoutSize(Container parent)
Returns the size of the passed Container as this
LayoutManager would like it best when the passed
Container where to be layed out with this
LayoutManager . |
GridSpanConstraints |
removeConstraints(Component component)
Removes the association indicated by the component from the internal mapping. |
void |
removeLayoutComponent(Component comp)
Removes the passed Component from the LayoutManager . |
GridSpanConstraints |
setConstraints(Component component,
GridSpanConstraints constraints)
Adds a new association to the internal mapping. |
void |
setHeight(int height)
Sets the height of this grid in cells. |
void |
setHorizontalGap(int horizontalgap)
Sets the horizontal gap. |
protected void |
setTaken(Component[][] componentgrid,
int x,
int y,
int width,
int height,
Component component)
Set the passed portion of the passed grid to the passed Component . |
void |
setVerticalGap(int verticalgap)
Sets the vertical gap. |
void |
setWidth(int width)
Sets the width of this grid in cells. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int width
protected int height
protected int horizontalgap
protected int verticalgap
protected HashMap componentmap
Map
that links the Component
s to their
constraints objects.
Constructor Detail |
public GridSpanLayout(int width, int height, int horizontalgap, int verticalgap)
GridSpanLayout
with the given width, height,
horizontal gap and vertical gap.
width
- The width of this grid in cells.height
- The height of this grid in cells.horizontalgap
- The horizontal gap between each cell and the cells and
borders at the left and right of the screen.verticalgap
- The vertical gap between each cell and the cells and
borders at the top and bottom of the screen.public GridSpanLayout(int width, int height)
GridSpanLayout
with the given width and height, and
the default values (5) for the horizontal gap and vertical gap.
width
- The width of this grid in cells.height
- The height of this grid in cells.Method Detail |
public int getWidth()
public void setWidth(int width)
width
- The width of this grid in cells.public int getHeight()
public void setHeight(int height)
height
- The height of this grid in cells.public int getHorizontalGap()
public void setHorizontalGap(int horizontalgap)
public int getVerticalGap()
public void setVerticalGap(int verticalgap)
protected boolean outOfBounds(GridSpanConstraints constraints)
constraints
- The constraints to be checked.
true
if the passed constraints are out of bounds,
false
otherwise.public GridSpanConstraints getConstraints(Component component)
GridSpanConstraints
that is associated with the
passed key. If no such object exists, a default one is associated with the
passed key, and returned. This because it is possible that key are passed that
do not exist in the mapping. This happens when a Container
sets
this object as its LayoutManager
after adding
Component
s. null
is not allowed as key.
component
- The key that is associated with the
GridSpanConstraints
.
GridSpanConstraints
that are associated with the
given key.public GridSpanConstraints setConstraints(Component component, GridSpanConstraints constraints)
GridSpanConstraints
, a default
GridSpanConstraints
will be returned when the passed
Component
is given as key
null
is not allowed as key.
component
- The key of the association.constraints
- The associated GridSpanConstraints
.
GridSpanConstraints
, if there
was any.public GridSpanConstraints removeConstraints(Component component)
null
is not allowed as key.
component
- The key of the association.
GridSpanConstraints
that was associated with the key.public void addLayoutComponent(String name, Component comp)
Component
to the LayoutManager
with
the passed name.
addLayoutComponent
in interface LayoutManager
LayoutManager.addLayoutComponent(java.lang.String,
java.awt.Component)
public void addLayoutComponent(Component comp, Object constraints)
Component
to the LayoutManager
with
the passed constraints. These constraints must be an instance of
GridSpanConstraints
.
addLayoutComponent
in interface LayoutManager2
comp
- The Component
to be added.constraints
- The constraints to be associated with the passed
Component
.LayoutManager2.addLayoutComponent(java.awt.Component,
java.lang.Object)
public void removeLayoutComponent(Component comp)
Component
from the LayoutManager
.
removeLayoutComponent
in interface LayoutManager
comp
- The Component
to be removed.LayoutManager.removeLayoutComponent(java.awt.Component)
public Dimension preferredLayoutSize(Container parent)
Container
as this
LayoutManager
would like it best when the passed
Container
where to be layed out with this
LayoutManager
.
preferredLayoutSize
in interface LayoutManager
Container
.LayoutManager.preferredLayoutSize(java.awt.Container)
public Dimension minimumLayoutSize(Container parent)
Container
as this
LayoutManager
would like it to be at minimum when the passed
Container
where to be layed out with this
LayoutManager
.
minimumLayoutSize
in interface LayoutManager
Container
.LayoutManager.minimumLayoutSize(java.awt.Container)
public Dimension maximumLayoutSize(Container target)
Container
as this
LayoutManager
would like it to be at maximum when the passed
Container
where to be layed out with this
LayoutManager
.
maximumLayoutSize
in interface LayoutManager2
target
- The Container
who is te be checked for maximum
size.
Container
.LayoutManager2.maximumLayoutSize(java.awt.Container)
public float getLayoutAlignmentX(Container target)
Container
if
it where to be layed out with this LayoutManager
.
Always returns that it wants to be centered.
getLayoutAlignmentX
in interface LayoutManager2
target
- The Container
who is te be checked for preference.
LayoutManager2.getLayoutAlignmentX(java.awt.Container)
public float getLayoutAlignmentY(Container target)
Container
if
it where to be layed out with this LayoutManager
.
Always returns that it wants to be centered.
getLayoutAlignmentY
in interface LayoutManager2
target
- The Container
who is te be checked for preference.
LayoutManager2.getLayoutAlignmentY(java.awt.Container)
public void invalidateLayout(Container target)
LayoutManager
, indicating that if this
LayoutManager
has cached information it should be discarded.
invalidateLayout
in interface LayoutManager2
target
- The Container
that has to invalidated.LayoutManager2.invalidateLayout(java.awt.Container)
public void layoutContainer(Container parent)
Container
with this
LayoutManager
, and the constraints objects associated with the
Component
s of this Container
.
layoutContainer
in interface LayoutManager
LayoutManager.layoutContainer(java.awt.Container)
protected Component[][] makeGrid(Container parent, boolean active)
Array
with
Component
s.
On each grid cell, there is one or no Component
. If there
are Component
s that span multiple cells, they have multiple
entries in the grid. If there are multiple Component
s in one
cell, only the one that appears first in the parent Container
will appear. Note that only visible Component
s will appear in the
grid.
parent
- The Container
that supplies the
Component
we make a grid of.active
- A boolean indicating whether this method should make unused
Component
s invisible. layoutContainer()
calls this
as true, the size methods call this as false.
Array
of Component
s that
represents the grid.protected boolean isFree(Component[][] componentgrid, int x, int y, int width, int height)
Component
grid does not
contain any Component
s.
componentgrid
- The grid with Component
s.x
- The left corner of the portion.y
- The upper corner of the portion.width
- The width of the portion.height
- The height of the portion.
true
when the given portion has only nulls,
false
otherwise.protected void setTaken(Component[][] componentgrid, int x, int y, int width, int height, Component component)
Component
.
componentgrid
- The grid with Component
s.x
- The left corner of the portion.y
- The upper corner of the portion.width
- The width of the portion.height
- The height of the portion.component
- The Component
to be set in the postion's cells.protected int getGridWidth(Integer[][] cellwidths)
Array
with widths, taken
into account only the largest width per column.
cellwidths
- The Array
with the cell widths.
null
in the Array
indicates spanned widths.
Array
.protected int getLargestWidth(Integer[][] cellwidths, int column)
cellwidths
- The Array
with the cell widths.
null
in the Array
indicates spanned widths.column
- The column to be searched.
protected int getGridHeight(Integer[][] cellheights)
Array
with heights, taken
into account only the largest height per row.
cellheights
- The Array
with the cell heights.
null
in the Array
indicates spanned heights.
Array
.protected int getLargestHeight(Integer[][] cellheights, int row)
cellheights
- The Array
with the cell heights.
null
in the Array
indicates spanned heights.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |