|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--kirk.gui.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 components, 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.getPreferredSize().width
) will be used.
Component.getPreferredSize().height
) will be used.
Component.getAlignmentX()
) will be used.
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
containers, as the interface prescribes), but for easeness sake there can be only
one Component
per cell. So, if there are multiple Components 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 Components (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
,
LineLayout
,
GridSpanConstraints
Field Summary | |
protected java.util.HashMap |
componentmap
The Map that links the components 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(java.awt.Component comp,
java.lang.Object constraints)
Adds the passed Component to the LayoutManager with
the passed constraints. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component comp)
Adds the passed Component to the LayoutManager with the passed
name. |
GridSpanConstraints |
getConstraints(java.awt.Component component)
Returns the GridSpanConstraints that is associated with the passed
key. |
protected int |
getGridHeight(java.lang.Integer[][] cellheights)
Returns the total height of the passed array with heights, taken into account only the largest height per row. |
protected int |
getGridWidth(java.lang.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(java.lang.Integer[][] cellheights,
int row)
Return the largest height of the all the cells in the indicated row. |
protected int |
getLargestWidth(java.lang.Integer[][] cellwidths,
int column)
Return the largest width of the all the cells in the indicated column. |
float |
getLayoutAlignmentX(java.awt.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(java.awt.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(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
protected boolean |
isFree(java.awt.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(java.awt.Container parent)
Lays out the passed container with this LayoutManager, and the constraints objects associated with the Components of this container. |
protected java.awt.Component[][] |
makeGrid(java.awt.Container parent,
boolean active)
Returns the grid. |
java.awt.Dimension |
maximumLayoutSize(java.awt.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 . |
java.awt.Dimension |
minimumLayoutSize(java.awt.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. |
java.awt.Dimension |
preferredLayoutSize(java.awt.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(java.awt.Component component)
Removes the association indicated by the component from the internal mapping. |
void |
removeLayoutComponent(java.awt.Component comp)
Removes the passed Component from the LayoutManager. |
GridSpanConstraints |
setConstraints(java.awt.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(java.awt.Component[][] componentgrid,
int x,
int y,
int width,
int height,
java.awt.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 java.util.HashMap componentmap
Constructor Detail |
public GridSpanLayout(int width, int height, int horizontalgap, int verticalgap)
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)
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(java.awt.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(java.awt.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(java.awt.Component component)
null
is not allowed as key.
component
- The key of the association.
GridSpanConstraints
that was associated with the key.public void addLayoutComponent(java.lang.String name, java.awt.Component comp)
Component
to the LayoutManager with the passed
name.
addLayoutComponent
in interface java.awt.LayoutManager
LayoutManager.addLayoutComponent(java.lang.String,
java.awt.Component)
public void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
Component
to the LayoutManager
with
the passed constraints. These constraints must be an instance of
GridSpanConstraints
.
addLayoutComponent
in interface java.awt.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(java.awt.Component comp)
Component
from the LayoutManager.
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- The Component
to be removed.LayoutManager.removeLayoutComponent(java.awt.Component)
public java.awt.Dimension preferredLayoutSize(java.awt.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 java.awt.LayoutManager
Container
.LayoutManager.preferredLayoutSize(java.awt.Container)
public java.awt.Dimension minimumLayoutSize(java.awt.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 java.awt.LayoutManager
Container
.LayoutManager.minimumLayoutSize(java.awt.Container)
public java.awt.Dimension maximumLayoutSize(java.awt.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 java.awt.LayoutManager2
target
- The Container
who is te be checked for maximum
size.
Container
.LayoutManager2.maximumLayoutSize(java.awt.Container)
public float getLayoutAlignmentX(java.awt.Container target)
LayoutManager
.
Always returns that it wants to be centered.
getLayoutAlignmentX
in interface java.awt.LayoutManager2
target
- The Container
who is te be checked for preference.
LayoutManager2.getLayoutAlignmentX(java.awt.Container)
public float getLayoutAlignmentY(java.awt.Container target)
LayoutManager
.
Always returns that it wants to be centered.
getLayoutAlignmentY
in interface java.awt.LayoutManager2
target
- The Container
who is te be checked for preference.
LayoutManager2.getLayoutAlignmentY(java.awt.Container)
public void invalidateLayout(java.awt.Container target)
invalidateLayout
in interface java.awt.LayoutManager2
target
- The Container
that has to invalidated.LayoutManager2.invalidateLayout(java.awt.Container)
public void layoutContainer(java.awt.Container parent)
layoutContainer
in interface java.awt.LayoutManager
LayoutManager.layoutContainer(java.awt.Container)
protected java.awt.Component[][] makeGrid(java.awt.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 Components that represents the
grid.protected boolean isFree(java.awt.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(java.awt.Component[][] componentgrid, int x, int y, int width, int height, java.awt.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(java.lang.Integer[][] cellwidths)
cellwidths
- The array with the cell widths. null
in the
array indicates spanned widths.
protected int getLargestWidth(java.lang.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(java.lang.Integer[][] cellheights)
cellheights
- The array with the cell heights. null
in the
array indicates spanned heights.
protected int getLargestHeight(java.lang.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 |