ch.sahits.game.graphic.layout
Class SahitsMaximalGridLayout

java.lang.Object
  extended by ch.sahits.game.graphic.layout.SahitsMaximalGridLayout
All Implemented Interfaces:
ISahitsLayoutManager

public class SahitsMaximalGridLayout
extends Object
implements ISahitsLayoutManager

Grid layout that sizes the cells according the the biggest sized ISahitsComponent in the same row/column. If the ISahitsComponent does not fill the whole size of the cell it is by default positioned in the center.

Author:
Andi Hotz, (c) Sahits GmbH, 2011 Created on May 27, 2011

Field Summary
private  Hashtable<ISahitsComponent,MaximalGridLayoutConstraints> compTable
           
private  int gap
           
private  int[] maxHight
           
private  int[] maxWidth
           
private  int nbCols
           
private  int nbRows
           
private  ECellPosition position
           
 
Constructor Summary
SahitsMaximalGridLayout()
          Default constructor initializing a grid of size 1x1.
SahitsMaximalGridLayout(int cols, int rows)
          Initialize the layout with the number of columns and rows
SahitsMaximalGridLayout(int cols, int rows, int gapWidth, ECellPosition positioning)
          Initialize the layout with the number of columns and rows and the gaping between them as well as the positioning of the whole if there is any space.
 
Method Summary
 void addLayoutComponent(ISahitsComponent comp, ISahitsLayoutConstraint constraints)
          Adding a ISahitsComponent with a MaximalGridLayoutConstraints
private  int addUpColumnWidth(ISahitsContainer parent)
          Adding up the column width of a ISahitsContainer.
private  int addUpRowHeight(ISahitsContainer parent)
          Adding up the row height of a ISahitsContainer.
private  boolean checkHeight(ISahitsContainer parent)
          check if the size of the children add up to more than the parents size
private  boolean checkWidth(ISahitsContainer parent)
          check if the size of the children add up to more than the parents size
(package private)  int computeColumnIndex(int i)
          Compute the column based on the index of the ISahitsComponent
(package private)  int computeHeight(int row, ISahitsContainer parent)
          Compute the height of the highest ISahitsComponent in the specified row.
private  double computeHeightScale(ISahitsContainer parent)
          Compute the scale factor that is needed on the ISahitsComponents to resize them to the heigth of the ISahitsContainer
(package private)  int computeRowIndex(int i)
          Compute the row based on the index of the ISahitsComponent
(package private)  int computeWidth(int column, ISahitsContainer parent)
          Compute the width of the widest ISahitsComponent in the specified column.
private  double computeWidthScale(ISahitsContainer parent)
          Compute the scale factor that is needed on the ISahitsComponents to resize them to the width of the ISahitsContainer
(package private)  int computeXPadding(int columnWidth, int width, MaximalGridLayoutConstraints constraints)
          Compute the horizontal padding within a cell based upon the alignment of the ISahitsComponent
(package private)  int computeYPadding(int rowHeight, int height, MaximalGridLayoutConstraints constraints)
          Compute the vertical padding within a cell based upon the alignment of the ISahitsComponent
(package private)  int getColumnStart(int index, ISahitsContainer parent)
          Compute the x position where the column with the given index starts
 MaximalGridLayoutConstraints getConstraints(ISahitsComponent comp)
          Gets the constraints for the specified ISahitsComponent.
(package private)  int getRowStart(int index, ISahitsContainer parent)
          Compute the y position where the row with the given index starts
 void layoutContainer(ISahitsContainer parent)
          Compute the layout of the all the children in the parent container.
 Dimension preferredLayoutSize(ISahitsContainer parent)
          Computing the prefered size by adding the sizes of the columns and rows together with the insets
private  void resetSizeCache()
           
 void setConstraints(ISahitsComponent comp, MaximalGridLayoutConstraints constraints)
          Sets the constraints for the specified ISahitsComponent in this layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nbCols

private final int nbCols

nbRows

private final int nbRows

maxWidth

private final int[] maxWidth

maxHight

private final int[] maxHight

gap

private final int gap

position

private final ECellPosition position

compTable

private final Hashtable<ISahitsComponent,MaximalGridLayoutConstraints> compTable
Constructor Detail

SahitsMaximalGridLayout

public SahitsMaximalGridLayout(int cols,
                               int rows)
Initialize the layout with the number of columns and rows

Parameters:
cols -
rows -

SahitsMaximalGridLayout

public SahitsMaximalGridLayout(int cols,
                               int rows,
                               int gapWidth,
                               ECellPosition positioning)
Initialize the layout with the number of columns and rows and the gaping between them as well as the positioning of the whole if there is any space.

Parameters:
cols -
rows -
gapWidth -
positioning -

SahitsMaximalGridLayout

public SahitsMaximalGridLayout()
Default constructor initializing a grid of size 1x1.

Method Detail

resetSizeCache

private void resetSizeCache()

computeWidth

final int computeWidth(int column,
                       ISahitsContainer parent)
Compute the width of the widest ISahitsComponent in the specified column.

Parameters:
column - number of the column (starting with index 1)
parent - parent ISahitsContainer
Returns:

computeHeight

final int computeHeight(int row,
                        ISahitsContainer parent)
Compute the height of the highest ISahitsComponent in the specified row.

Parameters:
row - number of the row (starting with index 1)
parent - parent ISahitsContainer
Returns:

preferredLayoutSize

public Dimension preferredLayoutSize(ISahitsContainer parent)
Computing the prefered size by adding the sizes of the columns and rows together with the insets


layoutContainer

public void layoutContainer(ISahitsContainer parent)
Description copied from interface: ISahitsLayoutManager
Compute the layout of the all the children in the parent container.

Specified by:
layoutContainer in interface ISahitsLayoutManager

computeHeightScale

private double computeHeightScale(ISahitsContainer parent)
Compute the scale factor that is needed on the ISahitsComponents to resize them to the heigth of the ISahitsContainer

Parameters:
parent - ISahitsContainer
Returns:
scale factor

computeWidthScale

private double computeWidthScale(ISahitsContainer parent)
Compute the scale factor that is needed on the ISahitsComponents to resize them to the width of the ISahitsContainer

Parameters:
parent - ISahitsContainer
Returns:
scale factor

checkHeight

private boolean checkHeight(ISahitsContainer parent)
check if the size of the children add up to more than the parents size

Parameters:
parent - ISahitsContainer
Returns:
true if the height of the parent ISahitsContainer is larger or equal than the sum of all the rows plus the parents insets.

addUpRowHeight

private int addUpRowHeight(ISahitsContainer parent)
Adding up the row height of a ISahitsContainer. Between each row the gap height is added

Parameters:
parent - ISahitsContainer
Returns:
height of all child ISahitsComponents plus the parents insets

checkWidth

private boolean checkWidth(ISahitsContainer parent)
check if the size of the children add up to more than the parents size

Parameters:
parent - ISahitsContainer
Returns:
true if the width of the parent ISahitsContainer is larger or equal than the sum of all the columns plus the parents insets.

addUpColumnWidth

private int addUpColumnWidth(ISahitsContainer parent)
Adding up the column width of a ISahitsContainer. Between each column the gap width is added

Parameters:
parent - ISahitsContainer
Returns:
width of all child ISahitsComponents plus the parents insets

computeYPadding

final int computeYPadding(int rowHeight,
                          int height,
                          MaximalGridLayoutConstraints constraints)
Compute the vertical padding within a cell based upon the alignment of the ISahitsComponent

Parameters:
rowHeight - height of the cell
height - of the ISahitsComponent
constraints - Objects
Returns:
padding from the top

computeXPadding

final int computeXPadding(int columnWidth,
                          int width,
                          MaximalGridLayoutConstraints constraints)
Compute the horizontal padding within a cell based upon the alignment of the ISahitsComponent

Parameters:
columnWidth - width of the cell
width - of the ISahitsComponent
constraints - Object
Returns:
padding from the left

getRowStart

final int getRowStart(int index,
                      ISahitsContainer parent)
Compute the y position where the row with the given index starts

Parameters:
index - of the row
parent - ISahitsContainer
Returns:

getColumnStart

final int getColumnStart(int index,
                         ISahitsContainer parent)
Compute the x position where the column with the given index starts

Parameters:
index - of the column
parent - ISahitsContainer
Returns:

computeRowIndex

final int computeRowIndex(int i)
Compute the row based on the index of the ISahitsComponent

Parameters:
i - index of the ISahitsComponent
Returns:

computeColumnIndex

final int computeColumnIndex(int i)
Compute the column based on the index of the ISahitsComponent

Parameters:
i - index of the ISahitsComponent
Returns:

setConstraints

public void setConstraints(ISahitsComponent comp,
                           MaximalGridLayoutConstraints constraints)
Sets the constraints for the specified ISahitsComponent in this layout.

Parameters:
comp - the ISahitsComponent to be modified
constraints - the constraints to be applied

getConstraints

public MaximalGridLayoutConstraints getConstraints(ISahitsComponent comp)
Gets the constraints for the specified ISahitsComponent. A copy of the actual GridBagConstraints object is returned.

Parameters:
comp - the ISahitsComponent to be queried
Returns:
the constraint for the specified ISahitsComponent in this grid bag layout; a copy of the actual constraint object is returned

addLayoutComponent

public void addLayoutComponent(ISahitsComponent comp,
                               ISahitsLayoutConstraint constraints)
Adding a ISahitsComponent with a MaximalGridLayoutConstraints

Specified by:
addLayoutComponent in interface ISahitsLayoutManager


Copyright © 2011 Sahits GmbH. All Rights Reserved.