com.izforge.izpack.gui
Class IzPanelLayout

java.lang.Object
  extended by com.izforge.izpack.gui.IzPanelLayout
All Implemented Interfaces:
LayoutConstants, java.awt.LayoutManager, java.awt.LayoutManager2, javax.swing.SwingConstants

public class IzPanelLayout
extends java.lang.Object
implements java.awt.LayoutManager, java.awt.LayoutManager2, LayoutConstants

This is a special layout manager for IzPanels.

Author:
Klaus Bartz

Nested Class Summary
static class IzPanelLayout.FillerComponent
          Component which will be used as placeholder if not extern component will be set or as filler for struts.
 
Field Summary
private static int ANCHOR
          Anchor to be used for the controls in all panels.
private  int columnFillOutRule
           
private  java.util.ArrayList<java.util.ArrayList<IzPanelConstraints>> components
          holds all the components and layout constraints.
private  int currentXPos
          Current column to handle symbolic values like NEXT_COLUMN in constraints.
private  int currentYPos
          Maximum rows to handle symbolic values like NEXT_ROW in constraints.
private static IzPanelConstraints[] DEFAULT_CONSTRAINTS
          Array with some default constraints.
private static int DEFAULT_TEXTFIELD_LENGTH
           
protected static int[] DEFAULT_X_ALIGNMENT
           
protected static int[] DEFAULT_X_GAPS
           
protected static int[] DEFAULT_Y_ALIGNMENT
           
protected static int[] DEFAULT_Y_GAPS
           
private static double FULL_COLUMN_STRETCH_DEFAULT
           
private static double FULL_LINE_STRETCH_DEFAULT
           
private static int[][] GAP_INTERMEDIAER_LOOKUP
           
private  java.awt.Insets oldParentInsets
           
private  java.awt.Dimension oldParentSize
           
private  double[] overallYStretch
           
private  java.awt.Dimension prefLayoutDim
          Dimension object with prefered size.
private static int X_STRETCH_TYPE
           
private static int Y_STRETCH_TYPE
           
 
Fields inherited from interface com.izforge.izpack.gui.LayoutConstants
ABSOLUTE_STRETCH, ALL_GAP, AUTOMATIC_GAP, CONTROL_CONSTRAINT, CONTROL_GAP, CONTROL_TO_LABEL_GAP, CONTROL_TO_TEXT_GAP, CURRENT_COLUMN, CURRENT_ROW, DEFAULT_CONTROL_ALIGNMENT, DEFAULT_LABEL_ALIGNMENT, DEFAULT_TEXT_ALIGNMENT, FILL_OUT_COLUMN_HEIGHT, FILL_OUT_COLUMN_SIZE, FILL_OUT_COLUMN_WIDTH, FILLER1_GAP, FILLER13_GAP, FILLER2_GAP, FILLER4_GAP, FILLER5_GAP, FULL_COLUMN_STRETCH, FULL_LINE_COMPONENT_CONSTRAINT, FULL_LINE_CONTROL_CONSTRAINT, FULL_LINE_STRETCH, GAP_LOAD_MARKER, LABEL_CONSTRAINT, LABEL_GAP, LABEL_TO_CONTROL_GAP, LABEL_TO_TEXT_GAP, NEXT_COLUMN, NEXT_LINE, NEXT_ROW, NO_FILL_OUT_COLUMN, NO_GAP, NO_STRETCH, PARAGRAPH_GAP, RELATIVE_STRETCH, TEXT_CONSTRAINT, TEXT_GAP, TEXT_TO_CONTROL_GAP, TEXT_TO_LABEL_GAP, TOP_GAP, XDUMMY_CONSTRAINT, XY_VARIABLE_CONSTRAINT, YDUMMY_CONSTRAINT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
IzPanelLayout()
          Default constructor
IzPanelLayout(int colFillOutRule)
          Creates an layout manager which consider the given column fill out rule.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
           
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
           
private  int columns()
          Returns the number of columns that need to be laid out.
static java.awt.Component createGap(int gapType, int direction)
          Returns a filler component which has self the size 0|0.
static java.awt.Component createHorizontalFiller(int fillerNumber)
          Returns a filler component which has self the size 0|0.
static java.awt.Component createHorizontalStrut(int width)
          Creates an invisible, component with a defined width.
static java.awt.Component createParagraphGap()
          Returns a filler component which has self the size 0|0.
static java.awt.Component createVerticalFiller(int fillerNumber)
          Returns a filler component which has self the size 0|0.
static java.awt.Component createVerticalStrut(int height)
          Creates an invisible, component with a defined height.
private  java.awt.Dimension determineSize()
          Method which determine minimum with and height of this layout.
private  void fastLayoutContainer(java.awt.Container parent)
           
private  int getAdaptedXPos(int xpos, int curWidth, java.awt.Dimension curDim, IzPanelConstraints currentConst)
           
private  int getAdaptedYPos(int ypos, int curHeight, java.awt.Dimension curDim, IzPanelConstraints currentConst)
           
static int getAnchor()
          Returns the anchor constant.
private  java.awt.Dimension getCellSize(int column, int row, IzPanelConstraints constraints)
          Measures and returns the minimum size required to render the component in the indicated row and column.
private  IzPanelConstraints getConstraints(int col, int row)
          Returns the constraint object of the component at the given place.
static IzPanelConstraints getDefaultConstraint(int type)
          Returns the constraint for the given type.
static int getDefaultTextfieldLength()
          Returns the default length used by textfields.
static int getDefaultXGap(int gapId)
          Returns the default x gap for the given gap id.
static int getDefaultYGap(int gapId)
          Returns the default y gap for the given gap id.
static double getFullColumnStretch()
          Returns the value which should be used stretching to a full column.
static double getFullLineStretch()
          Returns the value which should be used stretching to a full line.
private static int getIntermediarId(java.lang.Class clazz, java.awt.Component comp)
          Returns an index depending on the class type.
 float getLayoutAlignmentX(java.awt.Container target)
           
 float getLayoutAlignmentY(java.awt.Container target)
           
private  double[] getOverallYStretch()
          Returns the sum of the maximum y stretch of each row.
private static int getXGap(IzPanelConstraints curConst, IzPanelConstraints nextXConst)
          Returns the x gap for the given constraint dependant on the next x constraint.
static int getXStretchType()
          Returns the current used type of stretching for the X-direction.
private static int getYGap(IzPanelConstraints curConst, IzPanelConstraints nextYConst)
          Returns the y gap for the given constraint dependant on the next y constraint.
static int getYStretchType()
          Returns the current used type of stretching for the Y-direction.
 void invalidateLayout(java.awt.Container target)
           
 void layoutContainer(java.awt.Container parent)
           
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
           
private  int minimumAllColumnsWidth()
          Returns the minimum width needed by all columns.
private  int minimumColumnWidth(int column)
          Returns the minimum width of the column requested.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
           
private  int minimumOverallHeight()
          Minimum height of all rows.
private  boolean needNewLayout(java.awt.Container parent)
           
private  boolean needsReEvaluation(java.awt.Component comp)
          Returns whether the type of component needs potential a reevaluation or not.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
           
 void removeLayoutComponent(java.awt.Component comp)
           
private  void resolveDefaultSettings(int col, int row)
           
private  int resolveGenerellOffsets(int[] generellOffset, java.awt.Dimension realSizeDim, java.awt.Insets insets, int maxWidth, int overallHeight)
           
private  int rowHeight(int row)
          Measures and returns the minimum height required to render the components in the indicated row.
private  int rowHeight(int row, int minOverallHeight, int maxOverallHeight)
          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.
static void setAnchor(int anchor)
          Sets the anchor constant.
static void setDefaultTextfieldLength(int val)
          Sets the value for the default length of textfields.
static void setDefaultXGap(int gap, int gapId)
          Set the gap for the given gap id for the x default gaps.
static void setDefaultYGap(int gap, int gapId)
          Set the gap for the given gap id for the y default gaps.
static void setFullColumnStretch(double fullStretch)
          Sets the value which should be used as default for stretching to a full column.
static void setFullLineStretch(double fullLineStretch)
          Sets the value which should be used as default for stretching to a full line.
static void setXStretchType(int x_stretch)
          Sets the type of stretching to be used for the X-Direction.
static void setYStretchType(int y_stretch)
          Sets the type of stretching to be used for the Y-Direction.
static int verifyGapId(int gapId)
          Verifies whether a gap id is valid or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

components

private java.util.ArrayList<java.util.ArrayList<IzPanelConstraints>> components
holds all the components and layout constraints.


currentYPos

private int currentYPos
Maximum rows to handle symbolic values like NEXT_ROW in constraints.


currentXPos

private int currentXPos
Current column to handle symbolic values like NEXT_COLUMN in constraints.


prefLayoutDim

private java.awt.Dimension prefLayoutDim
Dimension object with prefered size. Will be computed new if invalidateLayout will be called.


oldParentSize

private java.awt.Dimension oldParentSize

oldParentInsets

private java.awt.Insets oldParentInsets

columnFillOutRule

private int columnFillOutRule

overallYStretch

private double[] overallYStretch

DEFAULT_Y_GAPS

protected static int[] DEFAULT_Y_GAPS

DEFAULT_X_GAPS

protected static int[] DEFAULT_X_GAPS

DEFAULT_X_ALIGNMENT

protected static int[] DEFAULT_X_ALIGNMENT

DEFAULT_Y_ALIGNMENT

protected static int[] DEFAULT_Y_ALIGNMENT

DEFAULT_CONSTRAINTS

private static IzPanelConstraints[] DEFAULT_CONSTRAINTS
Array with some default constraints.


ANCHOR

private static int ANCHOR
Anchor to be used for the controls in all panels.


X_STRETCH_TYPE

private static int X_STRETCH_TYPE

Y_STRETCH_TYPE

private static int Y_STRETCH_TYPE

FULL_LINE_STRETCH_DEFAULT

private static double FULL_LINE_STRETCH_DEFAULT

FULL_COLUMN_STRETCH_DEFAULT

private static double FULL_COLUMN_STRETCH_DEFAULT

DEFAULT_TEXTFIELD_LENGTH

private static int DEFAULT_TEXTFIELD_LENGTH

GAP_INTERMEDIAER_LOOKUP

private static final int[][] GAP_INTERMEDIAER_LOOKUP
Constructor Detail

IzPanelLayout

public IzPanelLayout()
Default constructor


IzPanelLayout

public IzPanelLayout(int colFillOutRule)
Creates an layout manager which consider the given column fill out rule. Valid rules are NO_FILL_OUT_COLUMN, FILL_OUT_COLUMN_WIDTH, FILL_OUT_HEIGHT and FILL_OUT_COLUMN_SIZE

Parameters:
colFillOutRule -
Method Detail

getYGap

private static int getYGap(IzPanelConstraints curConst,
                           IzPanelConstraints nextYConst)
Returns the y gap for the given constraint dependant on the next y constraint.

Parameters:
curConst - constraint of the component for which the gap should be returnd
nextYConst - constraint of the component which is the next in y direction
Returns:
the y gap

getXGap

private static int getXGap(IzPanelConstraints curConst,
                           IzPanelConstraints nextXConst)
Returns the x gap for the given constraint dependant on the next x constraint.

Parameters:
curConst - constraint of the component for which the gap should be returnd
nextXConst - constraint of the component which is the next in x direction
Returns:
the x gap

getIntermediarId

private static int getIntermediarId(java.lang.Class clazz,
                                    java.awt.Component comp)
Returns an index depending on the class type. Only for internal use.

Parameters:
clazz - class for which the index should be returned
comp - component for which the index should be returned
Returns:
an index depending on the class type

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Specified by:
addLayoutComponent in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Specified by:
minimumLayoutSize in interface java.awt.LayoutManager

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Specified by:
preferredLayoutSize in interface java.awt.LayoutManager

determineSize

private java.awt.Dimension determineSize()
Method which determine minimum with and height of this layout. The size will be stored after cumputing in a class member. With a call to invalidateLayout this will be deleted and at the next call to this method the values are computed again.

Returns:
current minimum size

rows

private int rows()
Returns the number of rows that need to be laid out.

Returns:
the number of rows that need to be laid out

columns

private int columns()
Returns the number of columns that need to be laid out.

Returns:
the number of columns that need to be laid out

minimumOverallHeight

private int minimumOverallHeight()
Minimum height of all rows.

Returns:
minimum height of all rows

rowHeight

private int rowHeight(int row)
Measures and returns the minimum height required to render the components in the indicated row.

Parameters:
row - the index of the row to measure
Returns:
minimum height of a row

rowHeight

private int rowHeight(int row,
                      int minOverallHeight,
                      int maxOverallHeight)
Measures and returns the minimum height required to render the components in the indicated row.

Parameters:
row - the index of the row to measure
maxOverallHeight -
minOverallHeight -
Returns:
minimum height of a row

getOverallYStretch

private double[] getOverallYStretch()
Returns the sum of the maximum y stretch of each row.

Returns:
the sum of the maximum y stretch of each row

getCellSize

private java.awt.Dimension getCellSize(int column,
                                       int row,
                                       IzPanelConstraints constraints)
Measures and returns the minimum size required to render the component in the indicated row and column. The constraints can be null.

Parameters:
row - the index of the row to measure
column - the column of the component
constraints - constraints of current component
Returns:
size of the given cell

minimumColumnWidth

private int minimumColumnWidth(int column)
Returns the minimum width of the column requested. This contains not the gaps.

Parameters:
column - the columns to measure
Returns:
the minimum width required to fit the components in this column

minimumAllColumnsWidth

private int minimumAllColumnsWidth()
Returns the minimum width needed by all columns.

Returns:
the minimum width needed by all columns

getConstraints

private IzPanelConstraints getConstraints(int col,
                                          int row)
Returns the constraint object of the component at the given place.

Parameters:
col - column of the component
row - row of the component
Returns:
the constraint object of the component at the given place

getAdaptedXPos

private int getAdaptedXPos(int xpos,
                           int curWidth,
                           java.awt.Dimension curDim,
                           IzPanelConstraints currentConst)

getAdaptedYPos

private int getAdaptedYPos(int ypos,
                           int curHeight,
                           java.awt.Dimension curDim,
                           IzPanelConstraints currentConst)

resolveDefaultSettings

private void resolveDefaultSettings(int col,
                                    int row)

layoutContainer

public void layoutContainer(java.awt.Container parent)
Specified by:
layoutContainer in interface java.awt.LayoutManager

fastLayoutContainer

private void fastLayoutContainer(java.awt.Container parent)

needNewLayout

private boolean needNewLayout(java.awt.Container parent)

resolveGenerellOffsets

private int resolveGenerellOffsets(int[] generellOffset,
                                   java.awt.Dimension realSizeDim,
                                   java.awt.Insets insets,
                                   int maxWidth,
                                   int overallHeight)

needsReEvaluation

private boolean needsReEvaluation(java.awt.Component comp)
Returns whether the type of component needs potential a reevaluation or not.

Parameters:
comp - component to check
Returns:
whether the type of component needs potential a reevaluation or not

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container target)
Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container target)
Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2

invalidateLayout

public void invalidateLayout(java.awt.Container target)
Specified by:
invalidateLayout in interface java.awt.LayoutManager2

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraints)
Specified by:
addLayoutComponent in interface java.awt.LayoutManager2

createHorizontalStrut

public static java.awt.Component createHorizontalStrut(int width)
Creates an invisible, component with a defined width. This component will be placed in the given cell of an IzPackLayout. If no constraint will be set (the default) a default constraint with NEXT_COLUMN and CURRENT_ROW will be used. This component has the height 0. The height of the row will be determined by other components in the same row.

Parameters:
width - the width of the invisible component
Returns:
the component

createVerticalStrut

public static java.awt.Component createVerticalStrut(int height)
Creates an invisible, component with a defined height. This component will be placed in the given cell of an IzPackLayout. If no constraint will be set (the default) a default constraint with column 0 and NEXT_ROW will be used. If the next component also uses NEXT_ROW, this strut goes over the hole width with the declared height. If more components are in the row, the highest of them determines the height of the row. This component has the width 0. The width of a row will be determined by other rows.

Parameters:
height - the height of the invisible component, in pixels >= 0
Returns:
the component

createParagraphGap

public static java.awt.Component createParagraphGap()
Returns a filler component which has self the size 0|0. Additional there is a constraints which has the x position 0,y position NEXT_ROW, x and y weight 10, x-stretch 1.0 and the y gap PARAGRAPH_GAP. Add the returned component to the IzPanel. Use NEXT_LINE (or NEXT_ROW in the constraints) for the next added control, else the layout will be confused.

Returns:
a filler component with the height of the defined paragraph gap

createVerticalFiller

public static java.awt.Component createVerticalFiller(int fillerNumber)
Returns a filler component which has self the size 0|0. Additional there is a constraints which has the x position 0,y position NEXT_ROW, x and y weight 10, x-stretch 1.0 and the y gap FILLER<given filler number>_GAP. Add the returned component to the IzPanel. Use NEXT_LINE (or NEXT_ROW in the constraints) for the next added control, else the layout will be confused. Attention! fillerNumber determines not directly the size of filler else the filler type. The size can be determined in the config file as modifier in the info section defining from filler1YGap to filler5YGap.

Parameters:
fillerNumber - number of the filler which should be used
Returns:
a filler component with the height of the defined paragraph gap

createHorizontalFiller

public static java.awt.Component createHorizontalFiller(int fillerNumber)
Returns a filler component which has self the size 0|0. Additional there is a constraints which has the position NEXT_COLUMN ,y position CURRENT_ROW, x and y weight 1, stretch 0.0 and the gap FILLER<given filler number>_GAP. Add the returned component to the IzPanel. Attention! fillerNumber determines not directly the size of filler else the filler type. The size can be determined in the config file as modifier in the info section defining from filler1XGap to filler5XGap.

Parameters:
fillerNumber - number of the filler which should be used
Returns:
a filler component with the width of the defined paragraph gap

createGap

public static java.awt.Component createGap(int gapType,
                                           int direction)
Returns a filler component which has self the size 0|0. Additional there is a constraints which has the gap defined for the given gap type. If direction is HORIZONTAL, the x position is NEXT_COLUMN ,y position CURRENT_ROW, x and y weight 1, stretch 0.0. If direction is VERTICAL, the x position will by 0,y position NEXT_ROW, x and y weight 10, x-stretch 1.0. Add the returned component to the IzPanel. The result will be that a gap will be inserted into the layout at the current place with the width equal to the defined paragraph gap.

Parameters:
gapType - type of gap to be used
direction - direction to be used
Returns:
a filler component with the width of the defined paragraph gap

getDefaultConstraint

public static IzPanelConstraints getDefaultConstraint(int type)
Returns the constraint for the given type. Valid types are declared in the interface LayoutConstraints. Possible are LABEL_CONSTRAINT, TEXT_CONSTRAINT and CONTROL_CONSTRAINT.

Parameters:
type - for which the constraint should be returned
Returns:
a copy of the default constraint for the given type

getAnchor

public static int getAnchor()
Returns the anchor constant.

Returns:
the anchor constant

setAnchor

public static void setAnchor(int anchor)
Sets the anchor constant.

Parameters:
anchor - symbolic constant to be used

getXStretchType

public static int getXStretchType()
Returns the current used type of stretching for the X-direction. Possible values are NO, RELATIVE and ABSOLUTE.

Returns:
the current used type of stretching for the X-direction

setXStretchType

public static void setXStretchType(int x_stretch)
Sets the type of stretching to be used for the X-Direction. Possible values are NO, RELATIVE and ABSOLUTE.

Parameters:
x_stretch - constant to be used for stretch type

getYStretchType

public static int getYStretchType()
Returns the current used type of stretching for the Y-direction. Possible values are NO, RELATIVE and ABSOLUTE.

Returns:
the current used type of stretching for the Y-direction

setYStretchType

public static void setYStretchType(int y_stretch)
Sets the type of stretching to be used for the Y-Direction. Possible values are NO, RELATIVE and ABSOLUTE.

Parameters:
y_stretch - constant to be used for stretch type

getFullLineStretch

public static double getFullLineStretch()
Returns the value which should be used stretching to a full line.

Returns:
the value which should be used stretching to a full line

setFullLineStretch

public static void setFullLineStretch(double fullLineStretch)
Sets the value which should be used as default for stretching to a full line.

Parameters:
fullLineStretch - value to be used as full line stretching default

getFullColumnStretch

public static double getFullColumnStretch()
Returns the value which should be used stretching to a full column.

Returns:
the value which should be used stretching to a full column

setFullColumnStretch

public static void setFullColumnStretch(double fullStretch)
Sets the value which should be used as default for stretching to a full column.

Parameters:
fullStretch - value to be used as full column stretching default

verifyGapId

public static int verifyGapId(int gapId)
Verifies whether a gap id is valid or not. If the id is less than zero, the sign will be removed. If the id is out of range, an IndexOutOfBoundsException will be thrown. The return value is the verified unsigned id.

Parameters:
gapId - to be verified
Returns:
the verified gap id

getDefaultXGap

public static int getDefaultXGap(int gapId)
Returns the default x gap for the given gap id.

Parameters:
gapId - for which the default x gap should be returned
Returns:
the default x gap for the given gap id

setDefaultXGap

public static void setDefaultXGap(int gap,
                                  int gapId)
Set the gap for the given gap id for the x default gaps.

Parameters:
gap - to be used as default
gapId - for which the default should be set

getDefaultYGap

public static int getDefaultYGap(int gapId)
Returns the default y gap for the given gap id.

Parameters:
gapId - for which the default y gap should be returned
Returns:
the default x gap for the given gap id

setDefaultYGap

public static void setDefaultYGap(int gap,
                                  int gapId)
Set the gap for the given gap id for the y default gaps.

Parameters:
gap - to be used as default
gapId - for which the default should be set

getDefaultTextfieldLength

public static int getDefaultTextfieldLength()
Returns the default length used by textfields.

Returns:
the default length used by textfields

setDefaultTextfieldLength

public static void setDefaultTextfieldLength(int val)
Sets the value for the default length of textfields.

Parameters:
val - to be set as default length for textfields