Package net.sf.jguiraffe.gui.layout
Class ButtonLayout
- java.lang.Object
-
- net.sf.jguiraffe.gui.layout.PercentLayoutBase
-
- net.sf.jguiraffe.gui.layout.ButtonLayout
-
- All Implemented Interfaces:
Serializable
public class ButtonLayout extends PercentLayoutBase
A layout manager that deals with button bars for dialogs.
With this layout manager typical horizontal button bars for dialogs can be created in an easy way. The button objects simply need to be added to the container, no constraints need to be passed. These button bars have the following properties:
- All buttons have the same width. This is the width of the widest button.
- Between the buttons there is a gap, which can be configured.
- Margins can be defined for all directions. All margins and the gap between the buttons can be defined in several units.
- The alignment of the buttons can be defined. This can be left aligned (i.e. the right margin grows if more space is available in the dialog), right aligned (the left margins grows) or center aligned (both margins grow).
This class is a special implementation of
PercentLayoutBase
. It implements the button layout on top of a percent layout. As its ancestor this class is platform neutral, i.e. it can work together with different GUI libraries for which aPercentLayoutPlatformAdapter
implementation is available.- Version:
- $Id: ButtonLayout.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ButtonLayout.Alignment
An enumeration class for the alignment of aButtonLayout
.
-
Constructor Summary
Constructors Constructor Description ButtonLayout()
Creates a new instance ofButtonLayout
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ButtonLayout.Alignment
getAlignment()
Returns the alignment of the button bar.NumberWithUnit
getBottomMargin()
Returns the bottom margin.NumberWithUnit
getGap()
Returns the width of the gap between the buttons.NumberWithUnit
getLeftMargin()
Returns the left margin.NumberWithUnit
getRightMargin()
Returns the right margin.NumberWithUnit
getTopMargin()
Returns the top margin.protected void
initCells(PercentLayoutPlatformAdapter adapter)
Initializes the whole layout.protected void
initColumnConstraints(int lastIndex, int buttonCount)
Initializes the column constraints.protected void
initRowConstraints()
Initializes the row constraints.protected void
insertButtons(PercentLayoutPlatformAdapter adapter, int buttonCount)
Inserts all buttons into the percent layout.void
setAlignment(ButtonLayout.Alignment alignment)
Sets the alignment of the button bar.void
setBottomMargin(NumberWithUnit bottomMargin)
Sets the bottom margin.void
setGap(NumberWithUnit gap)
Sets the width of the gap between the buttons.void
setLeftMargin(NumberWithUnit leftMargin)
Sets the left margin.void
setRightMargin(NumberWithUnit rightMargin)
Sets the right margin.void
setTopMargin(NumberWithUnit topMargin)
Sets the top margin.-
Methods inherited from class net.sf.jguiraffe.gui.layout.PercentLayoutBase
addColumnGroup, addRowGroup, alignComponent, applyCellGroups, applyWeightFactors, applyWeightFactors, calcCellPositions, calcCellSize, calcCellSizes, calcCellSizesWithGroups, calcComponentSize, calcComponentSizes, calcMinimumLayoutSize, calcPreferredLayoutSize, calcSizes, calcTotalWeight, checkConstraints, clearCells, clearCells, constraintsFor, fetchPlatformAdapter, flushCache, getAllColumnConstraints, getAllRowConstraints, getColumnConstraints, getColumnCount, getColumnGroups, getComponent, getConstraintsBuilder, getInternalAllColumnConstraints, getInternalAllRowConstraints, getMinimumComponentSize, getOrientationValue, getPercentData, getPlatformAdapter, getPreferredComponentSize, getRowConstraints, getRowCount, getRowGroups, getSizeHandler, getTotalWeightX, getTotalWeightY, handleMultiSpans, initCell, initDimensions, initFromCollections, isCanShrink, performLayout, performLayout, removeComponent, setCanShrink, setColumnConstraints, setComponentBounds, setPlatformAdapter, setRowConstraints
-
-
-
-
Method Detail
-
getTopMargin
public NumberWithUnit getTopMargin()
Returns the top margin.- Returns:
- the top margin
-
setTopMargin
public void setTopMargin(NumberWithUnit topMargin)
Sets the top margin. This is the space above the buttons.- Parameters:
topMargin
- the top margin (a null reference is converted to a value of 0)
-
getBottomMargin
public NumberWithUnit getBottomMargin()
Returns the bottom margin.- Returns:
- the bottom margin
-
setBottomMargin
public void setBottomMargin(NumberWithUnit bottomMargin)
Sets the bottom margin. This is the space below the buttons.- Parameters:
bottomMargin
- the bottom margin
-
getLeftMargin
public NumberWithUnit getLeftMargin()
Returns the left margin.- Returns:
- the left margin
-
setLeftMargin
public void setLeftMargin(NumberWithUnit leftMargin)
Sets the left margin. This is the space between the window's left edge and the first button. This value is fixed only if the button bar is left aligned; otherwise this space may grow.- Parameters:
leftMargin
- the left margin (a null reference is converted to a value of 0)
-
getRightMargin
public NumberWithUnit getRightMargin()
Returns the right margin.- Returns:
- the right margin
-
setRightMargin
public void setRightMargin(NumberWithUnit rightMargin)
Sets the right margin. This is the space between the window's right edge and the last button. This value is fixed only if the button bar is right aligned; otherwise this space may grow.- Parameters:
rightMargin
- the right margin (a null reference is converted to a value of 0)
-
getGap
public NumberWithUnit getGap()
Returns the width of the gap between the buttons.- Returns:
- the gap
-
setGap
public void setGap(NumberWithUnit gap)
Sets the width of the gap between the buttons.- Parameters:
gap
- the gap's width (a null reference is converted to a value of 0)
-
getAlignment
public ButtonLayout.Alignment getAlignment()
Returns the alignment of the button bar.- Returns:
- the alignment
-
setAlignment
public void setAlignment(ButtonLayout.Alignment alignment)
Sets the alignment of the button bar.- Parameters:
alignment
- the new alignment (must not be null)- Throws:
IllegalArgumentException
- if the alignment is null
-
initCells
protected void initCells(PercentLayoutPlatformAdapter adapter)
Initializes the whole layout. Creates a percent layout based on the current property values and the contained buttons.- Specified by:
initCells
in classPercentLayoutBase
- Parameters:
adapter
- the currently used platform adapter
-
initRowConstraints
protected void initRowConstraints()
Initializes the row constraints.
-
initColumnConstraints
protected void initColumnConstraints(int lastIndex, int buttonCount)
Initializes the column constraints.- Parameters:
lastIndex
- the index of the last columnbuttonCount
- the number of buttons
-
insertButtons
protected void insertButtons(PercentLayoutPlatformAdapter adapter, int buttonCount)
Inserts all buttons into the percent layout.- Parameters:
adapter
- the platform adapterbuttonCount
- the number of available buttons
-
-