com.izforge.izpack.installer
Class LayoutHelper

java.lang.Object
  extended by com.izforge.izpack.installer.LayoutHelper
All Implemented Interfaces:
LayoutConstants, javax.swing.SwingConstants

public class LayoutHelper
extends java.lang.Object
implements LayoutConstants

This class manages the layout for IzPanels. The layout related methods in IzPanel delegates the work to this class. Use the layout helper directly because the delegating methods in IzPanel will be removed in the future.
This layout helper works with a GridBagLayout or a IzPanelLayout as layout manager. The layout manager has to be set at calling the method startLayout. This method has to be called before the first add of a component to the IzPanel.

Author:
Klaus Bartz

Field Summary
static java.lang.String ALL_X_GAP
          Identifier of x gap for all default x gaps.
static java.lang.String ALL_Y_GAP
          Identifier of x gap for all default y gaps.
protected static int ANCHOR
          Layout anchor declared in the xml file with the guiprefs modifier "layoutAnchor"
protected  java.lang.Object defaultConstraints
          The default grid bag constraint.
protected static java.lang.Double DOUBLE_ZERO
           
protected static double FULL_COLUMN_STRETCH_DEFAULT
           
protected static double FULL_LINE_STRETCH_DEFAULT
           
protected  int gridxCounter
          Current x position of grid.
protected  int gridyCounter
          Current y position of grid.
protected static java.lang.Double INITIAL_STRETCH_DEFAULT
           
protected  java.awt.LayoutManager2 izPanelLayout
          internal layout
protected  boolean layoutStarted
          Indicates whether grid bag layout was started or not
(package private)  javax.swing.JComponent parent
           
static java.lang.String[] X_GAP_NAME_LOOK_UP
          Look-up table for gap identifier to gap names for the x direction.
protected static int X_STRETCH_TYPE
           
static java.lang.String[] Y_GAP_NAME_LOOK_UP
          Look-up table for gap identifier to gap names for the y direction.
protected 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
protected LayoutHelper()
          The default constructor is only useable by derived classes.
  LayoutHelper(javax.swing.JComponent parent)
          Only useable constructor.
 
Method Summary
private  void completeGridBagLayout()
          Complete layout determining.
 void completeLayout()
          Complete layout determining.
static int getAnchor()
          Returns the anchor as value declared in GridBagConstraints.
 java.lang.Object getDefaultConstraints()
          Returns the default constraints of this panel.
static double getFullColumnStretch()
          Returns the default value for stretching to a full column.
static double getFullLineStretch()
          Returns the default value for stretching to a full line.
 java.awt.LayoutManager2 getLayout()
          Returns the layout manager which current used by this layout helper.
private static java.lang.Object getModifierValue(java.lang.Object currentVal, java.lang.Object defaultVal, java.lang.Object readLimit, java.lang.String key)
           
 java.lang.Object getNewConstraints(int gridx, int gridy)
          Returns a newly created constraints with the given values and the values from the default constraints for the other parameters.
 java.lang.Object getNewConstraints(int gridx, int gridy, int gridwidth, int gridheight)
          Returns a newly created constraints with the given values and the values from the defaultGridBagConstraints for the other parameters.
 java.lang.Object getNextXConstraints()
          Returns a newly created constraints for the next column of the current layout row.
 java.lang.Object getNextYConstraints()
          Returns a newly created constraints with column 0 for the next row.
 java.lang.Object getNextYConstraints(int gridwidth, int gridheight)
          Returns a newly created constraints with column 0 for the next row using the given parameters.
static int getXGap(int gapId)
          Returns the gap which should be used between the given gui objects for the x direction.
static int getXStretchType()
          Returns the used stretch type for the x direction.
static int getYGap(int gapId)
          Returns the gap which should be used between the given gui objects for the y direction.
static int getYStretchType()
          Returns the used stretch type for the y direction.
private  boolean isGridBag()
          Returns whether the used layout is a GridBagLayout or not.
private  boolean isIzPanel()
          Returns whether the used layout is an IzPanelLayout or not.
 void resetGridCounter()
          Resets the grid counters which are used at getNextXConstraints and getNextYConstraints.
 void setDefaultConstraints(java.lang.Object constraints)
          Sets the default constraints of this panel to the given object.
 void setLayout(java.awt.LayoutManager2 izPanelLayout)
          Sets the given layout manager for this layout helper to be used.
private  void startGridBagLayout()
          Start layout determining.
private  void startIzPanelLayout()
          Special start method for IzPanelLayout.
 void startLayout(java.awt.LayoutManager2 layout)
          Start layout determining.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

javax.swing.JComponent parent

layoutStarted

protected boolean layoutStarted
Indicates whether grid bag layout was started or not


defaultConstraints

protected java.lang.Object defaultConstraints
The default grid bag constraint.


gridxCounter

protected int gridxCounter
Current x position of grid.


gridyCounter

protected int gridyCounter
Current y position of grid.


izPanelLayout

protected java.awt.LayoutManager2 izPanelLayout
internal layout


ANCHOR

protected static int ANCHOR
Layout anchor declared in the xml file with the guiprefs modifier "layoutAnchor"


X_STRETCH_TYPE

protected static int X_STRETCH_TYPE

Y_STRETCH_TYPE

protected static int Y_STRETCH_TYPE

FULL_LINE_STRETCH_DEFAULT

protected static double FULL_LINE_STRETCH_DEFAULT

FULL_COLUMN_STRETCH_DEFAULT

protected static double FULL_COLUMN_STRETCH_DEFAULT

INITIAL_STRETCH_DEFAULT

protected static java.lang.Double INITIAL_STRETCH_DEFAULT

DOUBLE_ZERO

protected static java.lang.Double DOUBLE_ZERO

X_GAP_NAME_LOOK_UP

public static final java.lang.String[] X_GAP_NAME_LOOK_UP
Look-up table for gap identifier to gap names for the x direction. The gap names can be used in the XML installation configuration file. Be aware that case sensitivity should be used.


Y_GAP_NAME_LOOK_UP

public static final java.lang.String[] Y_GAP_NAME_LOOK_UP
Look-up table for gap identifier to gap names for the y direction. The gap names can be used in the XML installation configuration file. Be aware that case sensitivity should be used.


ALL_X_GAP

public static final java.lang.String ALL_X_GAP
Identifier of x gap for all default x gaps.

See Also:
Constant Field Values

ALL_Y_GAP

public static final java.lang.String ALL_Y_GAP
Identifier of x gap for all default y gaps.

See Also:
Constant Field Values
Constructor Detail

LayoutHelper

public LayoutHelper(javax.swing.JComponent parent)
Only useable constructor. Creates a layout manager for special purpose.

Parameters:
parent - for which this layout manager will be used

LayoutHelper

protected LayoutHelper()
The default constructor is only useable by derived classes.

Method Detail

isGridBag

private boolean isGridBag()
Returns whether the used layout is a GridBagLayout or not.

Returns:
whether the used layout is a GridBagLayout or not

isIzPanel

private boolean isIzPanel()
Returns whether the used layout is an IzPanelLayout or not.

Returns:
whether the used layout is an IzPanelLayout or not

startLayout

public void startLayout(java.awt.LayoutManager2 layout)
Start layout determining. If it is needed, a dummy component will be created as first row. This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack variable IzPanel.LayoutType are also supported.

Parameters:
layout - layout to be used by this layout helper

startIzPanelLayout

private void startIzPanelLayout()
Special start method for IzPanelLayout. Called from startLayout.


completeLayout

public void completeLayout()
Complete layout determining. If it is needed, a dummy component will be created as last row. This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack variable IzPanel.LayoutType are also supported.


getDefaultConstraints

public java.lang.Object getDefaultConstraints()
Returns the default constraints of this panel.

Returns:
the default constraints of this panel

setDefaultConstraints

public void setDefaultConstraints(java.lang.Object constraints)
Sets the default constraints of this panel to the given object.

Parameters:
constraints - which should be set as default for this object

resetGridCounter

public void resetGridCounter()
Resets the grid counters which are used at getNextXConstraints and getNextYConstraints.


getNewConstraints

public java.lang.Object getNewConstraints(int gridx,
                                          int gridy)
Returns a newly created constraints with the given values and the values from the default constraints for the other parameters.

Parameters:
gridx - value to be used for the new constraint
gridy - value to be used for the new constraint
Returns:
newly created constraints with the given values and the values from the default constraints for the other parameters

getNewConstraints

public java.lang.Object getNewConstraints(int gridx,
                                          int gridy,
                                          int gridwidth,
                                          int gridheight)
Returns a newly created constraints with the given values and the values from the defaultGridBagConstraints for the other parameters.

Parameters:
gridx - value to be used for the new constraint
gridy - value to be used for the new constraint
gridwidth - value to be used for the new constraint
gridheight - value to be used for the new constraint
Returns:
newly created constraints with the given values and the values from the default constraints for the other parameters

getNextXConstraints

public java.lang.Object getNextXConstraints()
Returns a newly created constraints for the next column of the current layout row.

Returns:
a newly created constraints for the next column of the current layout row

getNextYConstraints

public java.lang.Object getNextYConstraints()
Returns a newly created constraints with column 0 for the next row.

Returns:
a newly created constraints with column 0 for the next row

getNextYConstraints

public java.lang.Object getNextYConstraints(int gridwidth,
                                            int gridheight)
Returns a newly created constraints with column 0 for the next row using the given parameters.

Parameters:
gridwidth - width for this constraint
gridheight - height for this constraint
Returns:
a newly created constraints with column 0 for the next row using the given parameters

startGridBagLayout

private void startGridBagLayout()
Start layout determining. If it is needed, a dummy component will be created as first row. This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack variable IzPanel.LayoutType are also supported.


completeGridBagLayout

private void completeGridBagLayout()
Complete layout determining. If it is needed, a dummy component will be created as last row. This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack variable IzPanel.LayoutType are also supported.


getAnchor

public static int getAnchor()
Returns the anchor as value declared in GridBagConstraints. Possible are NORTH, NORTHWEST, SOUTH, SOUTHWEST and CENTER. The values can be configured in the xml description file with the variable "IzPanel.LayoutType". The old values "TOP" and "BOTTOM" from the xml file are mapped to NORTH and SOUTH.

Returns:
the anchor defined in the IzPanel.LayoutType variable.

getXGap

public static int getXGap(int gapId)
Returns the gap which should be used between the given gui objects for the x direction. The value will be configurable by guiprefs modifiers. Valid values are all entries in the static String array X_GAP_NAME_LOOK_UP of this class. There are constant ints for the indexes of this array.

Parameters:
gapId - index in array GAP_NAME_LOOK_UP for the needed gap
Returns:
the gap depend on the xml-configurable guiprefs modifier

getYGap

public static int getYGap(int gapId)
Returns the gap which should be used between the given gui objects for the y direction. The value will be configurable by guiprefs modifiers. Valid values are all entries in the static String array Y_GAP_NAME_LOOK_UP of this class. There are constant ints for the indexes of this array.

Parameters:
gapId - index in array GAP_NAME_LOOK_UP for the needed gap
Returns:
the gap depend on the xml-configurable guiprefs modifier

getXStretchType

public static int getXStretchType()
Returns the used stretch type for the x direction. Possible are NO_STRETCH, RELATIVE_STRETCH and ABSOLUTE_STRETCH. The stretch type will be used at rows where one or more components has a stretch value greater than 0.0 in the constraints. If NO_STRETCH is used, no stretch will be performed. If ABSOLUTE_STRETCH is used, parts of the unused area are given to the components depending on the unmodified stretch value. At RELATIVE_STRETCH first the hole stretch for a row will be computed. Relative to this value the unused area will be splited.
The default type is ABSOLUTE_STRETCH. With the modifier "layoutXStretchType" of the "info" section of the installation configuration file this can be changed.

Returns:
used stretch type

getYStretchType

public static int getYStretchType()
Returns the used stretch type for the y direction. Possible are NO_STRETCH, RELATIVE_STRETCH and ABSOLUTE_STRETCH. The stretch type will be used at rows where one or more components has a stretch value greater than 0.0 in the constraints. If NO_STRETCH is used, no stretch will be performed. If ABSOLUTE_STRETCH is used, parts of the unused area are given to the components depending on the unmodified stretch value. At RELATIVE_STRETCH first the hole stretch for a row will be computed. Relative to this value the unused area will be splited.
The default type is ABSOLUTE_STRETCH. With the modifier "layoutYStretchType" of the "info" section of the installation configuration file this can be changed.

Returns:
used stretch type

getFullLineStretch

public static double getFullLineStretch()
Returns the default value for stretching to a full line. With the modifier "layoutFullLineStretch" of the "info" section of the installation configuration file this can be changed. Valid are doubles for the value. This setting is possible to give panels a chance to center the controls in x direction also a control uses stretching.

Returns:
the default value for stretching to a full line

getFullColumnStretch

public static double getFullColumnStretch()
Returns the default value for stretching to a full column. With the modifier "layoutFullColumnStretch" of the "info" section of the installation configuration file this can be changed. Valid are doubles for the value. This setting is possible to give panels a chance to center the controls in y direction also a control uses stretching.

Returns:
the default value for stretching to a full column

getModifierValue

private static java.lang.Object getModifierValue(java.lang.Object currentVal,
                                                 java.lang.Object defaultVal,
                                                 java.lang.Object readLimit,
                                                 java.lang.String key)

getLayout

public java.awt.LayoutManager2 getLayout()
Returns the layout manager which current used by this layout helper. The layout manager implements LayoutManager2. It can be a GridBagLayout or a IzPanelLayout.

Returns:
current used layout manager

setLayout

public void setLayout(java.awt.LayoutManager2 izPanelLayout)
Sets the given layout manager for this layout helper to be used.

Parameters:
izPanelLayout - layout manager to be used