Class 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 a PercentLayoutPlatformAdapter implementation is available.

    Version:
    $Id: ButtonLayout.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    See Also:
    Serialized Form
    • Constructor Detail

      • ButtonLayout

        public ButtonLayout()
        Creates a new instance of ButtonLayout. All properties are set to default values.
    • 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 class PercentLayoutBase
        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 column
        buttonCount - the number of buttons
      • insertButtons

        protected void insertButtons​(PercentLayoutPlatformAdapter adapter,
                                     int buttonCount)
        Inserts all buttons into the percent layout.
        Parameters:
        adapter - the platform adapter
        buttonCount - the number of available buttons