|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.co.keang.hex.gui.HexLayout
public class HexLayout
The Hexagonal layout manager lays out components in a hexagonal grid. If components implement IHexagonal they will be rotated by this layout manager to suit the selected layout direction. Components not implementing IHexagonal and/or Components of any other shape can be laid out but their visible areas may overlap.
This layout manager supports two layout directions: Vertical and horizontal, and three layout styles: Wavey, Straight Min First and Straight Max First.
Direction /\ /\ Vertical = hexagonal components are rotated so that their sides are vertical ie | || | \/ \/ __ Horizontal = hexagonal components are rotated so that their sides are horizontal ie / \ \ / == / \ \ / --
Style: (all examples shown are for vertical layout)
Wavey = the same number of components per line
ie * * * * * * * * * * * * * * * *
Straight Min First = Alternate lines, starting with the first line, have one less component.
ie * * * * * * * * * * * * * *
Straight Max First = Alternate lines, starting with the second line, have one less component.
ie * * * * * * * * * * * * * *
The size of the layout area is described in terms of the number of components per line and the number of lines. Either dimension can be zero, in which that dimension is sized to fit the number of components in the panel. If both dimensions are specified and layout area is sized to the given dimension. The components are placed along each line until the max line length is reached. If more components are added than the size of the area permits the number of lines is increased.
For Vertical direction the components are added from left to right. For Horizontal direction the components are added from top to bottom.
By default the hexagons will be stretched to fill the window in both the X and Y axis,
if you require pure hexagons call setStretchy(false)
.
Nested Class Summary | |
---|---|
static class |
HexLayout.HexLayoutStyle
An enum defining the layout styles available |
Field Summary | |
---|---|
(package private) int |
cgap
This is the gap (in pixels) which specifies the space between components. |
(package private) int |
cpl
This is the number of rows specified for the grid. |
(package private) int |
lines
This is the number of columns specified for the grid. |
Constructor Summary | |
---|---|
HexLayout()
Creates a hex layout with a default of one column per component, in a single row. |
|
HexLayout(int r,
int c)
Creates a hex layout with the specified number of rows and columns. |
|
HexLayout(int nComps,
int nLines,
int hgap,
HexBtnUtilities.HexOrientation o,
HexLayout.HexLayoutStyle style)
Creates an offset hex layout with the specified number of lines and components per line. |
Method Summary | |
---|---|
void |
addLayoutComponent(java.lang.String name,
java.awt.Component comp)
Adds the specified component with the specified name to the layout. |
int |
getComponentsPerLine()
Gets the number of components per line in this layout. |
int |
getGap()
Gets the gap between components. |
int |
getLines()
Gets the number of lines in this layout. |
boolean |
isStretchy()
Returns true if hexagons can be stretched to fill the whole panel |
void |
layoutContainer(java.awt.Container parent)
Lays out the specified container using this layout. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Determines the minimum size of the container argument using this grid layout. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Determines the preferred size of the container argument using this grid layout. |
void |
removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout. |
void |
setComponentsPerLine(int c)
Sets the number of components per line in this layout to the specified value. |
void |
setGap(int gap)
Sets the gap between components to the specified value. |
void |
setLines(int n)
Sets the number of lines in this layout to the specified value. |
void |
setStretchy(boolean stretch)
Sets whether hexagons have to be pure or whether they can be stretched to fill the whole panel |
java.lang.String |
toString()
Returns the string representation of this grid layout's values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
int cgap
int cpl
int lines
Constructor Detail |
---|
public HexLayout()
public HexLayout(int r, int c)
One, but not both, of rows
and cols
can
be zero, which means that any number of objects can be placed in a
row or in a column.
r
- the rows, with the value zero meaning
any number of rows.c
- the columns, with the value zero meaning
any number of columns.public HexLayout(int nComps, int nLines, int hgap, HexBtnUtilities.HexOrientation o, HexLayout.HexLayoutStyle style)
In addition, the gap between components is set to the specified value.
If nComps
is zero any number of objects can be placed on a line.
If lines
is zero there can be any number of lines.
If both are zero the layout will be approximately a square layout.
All HexLayout
constructors defer to this one.
nComps
- the rows, with the value zero meaning
any number of rowsnLines
- the columns, with the value zero meaning
any number of columnshgap
- the gap around the componento
- the orientation of the hexagon ie vertical or horizontalMethod Detail |
---|
public int getComponentsPerLine()
public void setComponentsPerLine(int c)
c
- the number of components per line in this layoutpublic int getLines()
public void setLines(int n)
n
- the number of lines in this layoutpublic int getGap()
public void setGap(int gap)
gap
- the gap between componentspublic void setStretchy(boolean stretch)
stretch
- true to allow components to be stretched, false for pure hexagonspublic boolean isStretchy()
public void addLayoutComponent(java.lang.String name, java.awt.Component comp)
addLayoutComponent
in interface java.awt.LayoutManager
name
- the name of the componentcomp
- the component to be addedpublic void removeLayoutComponent(java.awt.Component comp)
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- the component to be removedpublic java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
The preferred width of a grid layout is the largest preferred width of all of the components in the container times the number of columns, plus the horizontal padding times the number of columns minus one, plus the left and right insets of the target container, plus the width of half a component if there is more than one row.
The preferred height of a grid layout is the largest preferred height of all of the components in the container plus three quarters of the largest minimum height of all of the components in the container times the number of rows greater than one, plus the vertical padding times the number of rows minus one, plus the top and bottom insets of the target container.
preferredLayoutSize
in interface java.awt.LayoutManager
parent
- the container in which to do the layout
GridLayout.minimumLayoutSize(java.awt.Container)
,
Container.getPreferredSize()
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
The minimum width of a grid layout is the largest minimum width of all of the components in the container times the number of columns, plus the horizontal padding times the number of columns minus one, plus the left and right insets of the target container, plus the width of half a component if there is more than one row.
The minimum height of a grid layout is the largest minimum height of all of the components in the container plus three quarters of the largest minimum height of all of the components in the container times the number of rows greater than one, plus the vertical padding times the number of rows minus one, plus the top and bottom insets of the target container.
minimumLayoutSize
in interface java.awt.LayoutManager
parent
- the container in which to do the layout
GridLayout.preferredLayoutSize(java.awt.Container)
,
Container.doLayout()
public void layoutContainer(java.awt.Container parent)
This method reshapes the components in the specified target
container in order to satisfy the constraints of the
GridLayout
object.
The grid layout manager determines the size of individual components by dividing the free space in the container into equal-sized portions according to the number of rows and columns in the layout. The container's free space equals the container's size minus any insets and any specified horizontal or vertical gap. All components in a grid layout are given the same size.
layoutContainer
in interface java.awt.LayoutManager
parent
- the container in which to do the layoutContainer
,
Container.doLayout()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |