ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui
Class ButtonAreaLayout

java.lang.Object
  extended by com.ehsbe.commons.gui.ButtonAreaLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class ButtonAreaLayout
extends Object
implements LayoutManager2

ButtonAreaLayout behaves in a similar manner to FlowLayout. It lays out all components per default from left to right. If syncAllWidths is true, the width of each component will be set to the largest preferred size width. Per default, all buttons will have a minimum width of 80 pixels. If syncAllHeights is true, the height of each component will be set to the largest preferred size height. If it is false, all components will have their preferred height and are vertically centered in their container. Per default, all buttons will have a minimum height of 20 pixels.

If the preferred size of a component is less than the minimum size, the minimum size will be used instead.


Constructor Summary
ButtonAreaLayout()
          Create a new standard ButtonLayout.
ButtonAreaLayout(boolean syncAllWidths, boolean syncAllHeights, int padding, int orientation, boolean reverseButtons, Dimension minSize)
          Create a new ButtonLayouter.
ButtonAreaLayout(boolean syncAllSizes, int padding)
          Create a new ButtonLayout.
ButtonAreaLayout(boolean syncAllSizes, int padding, int orientation)
          Create a new ButtonLayouter.
ButtonAreaLayout(boolean syncAllSizes, int padding, int orientation, boolean reverseButtons, Dimension minSize)
          Create a new ButtonLayouter.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          
 void addLayoutComponent(String name, Component comp)
          
 float getLayoutAlignmentX(Container container)
          
 float getLayoutAlignmentY(Container container)
          
 Dimension getMinButtonSize()
          Get the minimum size, a button should have.
 int getOrientation(Container container)
          Get the orientation used for button layout wrt. the given container.
 boolean getPackButtons()
          Check, whether buttons get packed on centered orientation, so that the distance between the buttons is exactly the value of padding.
 int getPadding()
          Get the padding distance between buttons.
 boolean getReverse()
          Check, whether buttons are layed out in reverse order wrt. to their index in the container's component list
 boolean getSyncAllHeights()
          Check, whether all buttons will have the same height.
 boolean getSyncAllWidths()
          Check, whether all buttons will have the same width.
 void invalidateLayout(Container target)
          
 void layoutContainer(Container container)
          
 Dimension maximumLayoutSize(Container container)
          
 Dimension minimumLayoutSize(Container container)
          
 Dimension preferredLayoutSize(Container container)
          
 void removeLayoutComponent(Component comp)
          
 void setMinButtonSize(Dimension minButtonSize)
          Set the minimum size, a button should have.
 void setOrientation(int orientation)
          Set the orientation to use for button layout wrt. a left-to-right oriented container.
 void setPackButtons(boolean packButtons)
          Set, whether buttons should be packed, i.e. distance between them is the value of padding, or whether the distance between the buttons is the left space in the container equally distributed to all button distances.
 void setPadding(int newPadding)
          Set the padding distance between buttons in pixels
 void setReverse(boolean newValue)
          Set, whether to layout the buttons in reverse order wrt. to their index in the container's component list Per default, this property is set to false.
 void setSyncAllHeights(boolean newValue)
          Set, whether to make all buttons the same height.
 void setSyncAllWidths(boolean newValue)
          Set, whether to make all buttons the same witdth.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ButtonAreaLayout

public ButtonAreaLayout()
Create a new standard ButtonLayout.

UIManager properties used: OptionPane.sameSizeButtons, OptionPane.buttonPadding, OptionPane.buttonOrientation


ButtonAreaLayout

public ButtonAreaLayout(boolean syncAllSizes,
                        int padding)
Create a new ButtonLayout.

UIManager properties used: OptionPane.buttonOrientation

Parameters:
syncAllSizes - If true, make the size of all buttons equal to the width of the widest button and the height to the height of the button with the biggest height.
padding - padding to use between the buttons.

ButtonAreaLayout

public ButtonAreaLayout(boolean syncAllSizes,
                        int padding,
                        int orientation)
Create a new ButtonLayouter.

Parameters:
syncAllSizes - If true, make the size of all buttons equal to the width of the widest button and the height to the height of the button with the biggest height.
padding - padding to use between the buttons.
orientation - SwingConstants.LEFT || SwingConstants.CENTER || SwingConstants.RIGHT

ButtonAreaLayout

public ButtonAreaLayout(boolean syncAllSizes,
                        int padding,
                        int orientation,
                        boolean reverseButtons,
                        Dimension minSize)
Create a new ButtonLayouter.

Parameters:
syncAllSizes - If true, make the size of all buttons equal to the width of the widest button and the height to the height of the button with the biggest height.
padding - padding to use between the buttons.
orientation - SwingConstants.LEFT || SwingConstants.CENTER || SwingConstants.RIGHT
reverseButtons - if true, layout the buttons in reverse order wrt. to their index in the container's component list
minSize - the minimum size of the buttons

ButtonAreaLayout

public ButtonAreaLayout(boolean syncAllWidths,
                        boolean syncAllHeights,
                        int padding,
                        int orientation,
                        boolean reverseButtons,
                        Dimension minSize)
Create a new ButtonLayouter.

Parameters:
syncAllWidths - If true, make the width of all buttons equal to the width of the widest button.
syncAllHeights - If true, make the height of all buttons equal to the height of the button with the biggest height.
padding - padding to use between the buttons.
orientation - SwingConstants.LEFT || SwingConstants.CENTER || SwingConstants.RIGHT
reverseButtons - if true, layout the buttons in reverse order wrt. to their index in the container's component list
minSize - the minimum size of the buttons
Method Detail

setReverse

public void setReverse(boolean newValue)
Set, whether to layout the buttons in reverse order wrt. to their index in the container's component list

Per default, this property is set to false.

Parameters:
newValue - if true, layout in reverse order

getReverse

public boolean getReverse()
Check, whether buttons are layed out in reverse order wrt. to their index in the container's component list

Returns:
if true, layout in reverse order

setSyncAllWidths

public void setSyncAllWidths(boolean newValue)
Set, whether to make all buttons the same witdth.

Parameters:
newValue - if true, equalize the width of all buttons

getSyncAllWidths

public boolean getSyncAllWidths()
Check, whether all buttons will have the same width.

Returns:
true if all buttons are equalized wrt. their width

setSyncAllHeights

public void setSyncAllHeights(boolean newValue)
Set, whether to make all buttons the same height.

Parameters:
newValue - if true, equalize the height of all buttons

getSyncAllHeights

public boolean getSyncAllHeights()
Check, whether all buttons will have the same height.

Returns:
true if all buttons are equalized wrt. their height

setPadding

public void setPadding(int newPadding)
Set the padding distance between buttons in pixels

Parameters:
newPadding - the new padding distance

getPadding

public int getPadding()
Get the padding distance between buttons.

Returns:
the padding distance between buttons

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)

Specified by:
addLayoutComponent in interface LayoutManager2

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)

Specified by:
addLayoutComponent in interface LayoutManager

removeLayoutComponent

public void removeLayoutComponent(Component comp)

Specified by:
removeLayoutComponent in interface LayoutManager

invalidateLayout

public void invalidateLayout(Container target)

Specified by:
invalidateLayout in interface LayoutManager2

maximumLayoutSize

public Dimension maximumLayoutSize(Container container)

Specified by:
maximumLayoutSize in interface LayoutManager2

preferredLayoutSize

public Dimension preferredLayoutSize(Container container)

Specified by:
preferredLayoutSize in interface LayoutManager

minimumLayoutSize

public Dimension minimumLayoutSize(Container container)

Specified by:
minimumLayoutSize in interface LayoutManager

setOrientation

public void setOrientation(int orientation)
Set the orientation to use for button layout wrt. a left-to-right oriented container.

Parameters:
orientation - SwingConstants.LEFT || SwingConstants.CENTER || SwingConstants.RIGHT

getOrientation

public int getOrientation(Container container)
Get the orientation used for button layout wrt. the given container.

Parameters:
container - container, whoms orientation should be taken into account. Might be null - in this case a left-to-right oriented container is assumed. The parameter is ignored, if the current orientation strategy of the layout manager is set to SwingConstants#CENTER.
Returns:
SwingConstants.LEFT || SwingConstants.CENTER || SwingConstants.RIGHT

layoutContainer

public void layoutContainer(Container container)

Specified by:
layoutContainer in interface LayoutManager

getLayoutAlignmentX

public float getLayoutAlignmentX(Container container)

Specified by:
getLayoutAlignmentX in interface LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(Container container)

Specified by:
getLayoutAlignmentY in interface LayoutManager2

getPackButtons

public boolean getPackButtons()
Check, whether buttons get packed on centered orientation, so that the distance between the buttons is exactly the value of padding.

E.g. packed:

     +-------------------------------+
     |        Button1 Button2        |
     +-------------------------------+
 
unpacked (padding is ignored):
     +-------------------------------+
     |Button1                 Button2|
     +-------------------------------+
 

Returns:
true, if the buttons are packed together.
See Also:
getPadding(), setPadding(int)

setPackButtons

public void setPackButtons(boolean packButtons)
Set, whether buttons should be packed, i.e. distance between them is the value of padding, or whether the distance between the buttons is the left space in the container equally distributed to all button distances.

Per default, all buttons are packed.

Parameters:
packButtons - if true, pack buttons.

getMinButtonSize

public Dimension getMinButtonSize()
Get the minimum size, a button should have.

Returns:
always a none null size

setMinButtonSize

public void setMinButtonSize(Dimension minButtonSize)
Set the minimum size, a button should have.

Parameters:
minButtonSize - if null, the default of 80 for width and 20 for height will be used.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.