Class FlexibleLayout

java.lang.Object
  |
  +--FlexibleLayout

public class FlexibleLayout
extends java.lang.Object
implements java.awt.LayoutManager2, FlexibleConstants

Flexible layout manager that allows components to be positionned either at an absolute or at a relative location. Component size can also adapt itself to the container size. Once positionned, the component can be newly laid out using FlexibleConstraints methods.

See Also:
FlexibleConstraints

Fields inherited from interface FlexibleConstants
BOTTOM_MASK, BOTTOMCENTER, BOTTOMCENTER_RELATIVE, BOTTOMLEFT, BOTTOMLEFT_RELATIVE, BOTTOMRIGHT, BOTTOMRIGHT_RELATIVE, CENTER, CENTER_RELATIVE, CENTERLEFT, CENTERLEFT_RELATIVE, CENTERRIGHT, CENTERRIGHT_RELATIVE, HEIGHT_RELATIVE, HORIZONTALCENTER_MASK, LEFT_MASK, RELATIVE, RIGHT_MASK, SCALABLE, SCALABLE_HEIGHT, SCALABLE_WIDTH, SIZE_RELATIVE, TOP_MASK, TOPCENTER, TOPCENTER_RELATIVE, TOPLEFT, TOPLEFT_RELATIVE, TOPRIGHT, TOPRIGHT_RELATIVE, VERTICALCENTER_MASK, WIDTH_RELATIVE
 
Constructor Summary
FlexibleLayout()
          Creates a new FlexibleLayout instance with no size specified.
FlexibleLayout(java.awt.Container target)
          Creates a new FlexibleLayout instance to lay out the specified target container.
FlexibleLayout(java.awt.Dimension size)
          Creates a new FlexibleLayout instance with size.
FlexibleLayout(java.awt.Dimension size, java.awt.Insets insets)
          Creates a new FlexibleLayout instance with size.
FlexibleLayout(int width, int height)
          Creates a new FlexibleLayout instance with size.
FlexibleLayout(int width, int height, java.awt.Insets insets)
          Creates a new FlexibleLayout instance with size.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
           
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
           
 FlexibleConstraints getConstraints(java.awt.Component comp)
          Gets the constraints for the specified component in this layout.
 float getLayoutAlignmentX(java.awt.Container target)
           
 float getLayoutAlignmentY(java.awt.Container target)
           
 java.awt.Dimension getSize()
          Gets this layout size.
 void invalidateLayout(java.awt.Container target)
           
 void layoutContainer(java.awt.Container parent)
          Lays out the container using this FlexibleLayout rules.
 java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
           
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
           
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Calculates the preferred size dimensions for the specified container given the components in the specified parent container.
 void removeLayoutComponent(java.awt.Component comp)
           
 void setConstraints(java.awt.Component comp, FlexibleConstraints cons)
          Specifies new constraints for the specified component in this layout.
 void setSize(java.awt.Dimension size)
          Specifies this layout size.
 void setSize(int width, int height)
          Specifies this layout size.
 void setTarget(java.awt.Container target)
          Sets this layout size so to lay out the specified target container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlexibleLayout

public FlexibleLayout()
Creates a new FlexibleLayout instance with no size specified.

FlexibleLayout

public FlexibleLayout(java.awt.Dimension size)
Creates a new FlexibleLayout instance with size.

This is the layout default size, and it defines the number of rows and columns to use for relative layout.

Parameters:
size - The size to use for layout.
See Also:
setSize(java.awt.Dimension)

FlexibleLayout

public FlexibleLayout(int width,
                      int height)
Creates a new FlexibleLayout instance with size.

This is the layout default size, and it defines the number of rows and columns to use for relative layout.

Parameters:
width - The width to use for layout.
height - The height to use for layout.
See Also:
setSize(java.awt.Dimension)

FlexibleLayout

public FlexibleLayout(java.awt.Dimension size,
                      java.awt.Insets insets)
Creates a new FlexibleLayout instance with size.

This is the layout default size, and it defines the number of rows and columns to use for relative layout.

Parameters:
size - The size to use for layout.
See Also:
setSize(java.awt.Dimension)

FlexibleLayout

public FlexibleLayout(int width,
                      int height,
                      java.awt.Insets insets)
Creates a new FlexibleLayout instance with size.

This is the layout default size, and it defines the number of rows and columns to use for relative layout.

Parameters:
width - The width to use for layout.
height - The height to use for layout.
See Also:
setSize(java.awt.Dimension)

FlexibleLayout

public FlexibleLayout(java.awt.Container target)
Creates a new FlexibleLayout instance to lay out the specified target container.

This layout size is set according to target client area, that is the container size without its insets.
NB: There is no drawback in using this layout for other containers too.

Parameters:
target - the target container.
See Also:
setTarget(java.awt.Container)
Method Detail

addLayoutComponent

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

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Calculates the preferred size dimensions for the specified container given the components in the specified parent container.

Fixed: Preferred size calculation was corrected in this version.

Parameters:
parent - the container to be laid out.
See Also:
minimumLayoutSize(java.awt.Container)

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)

maximumLayoutSize

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

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lays out the container using this FlexibleLayout rules.

Components that were not added to the container using FlexibleConstraints constraints (or null constraints) aren't laid out.

Most applications do not call this method directly.

Parameters:
parent - the container in which to do the layout
See Also:
FlexibleConstraints, Container, Container.doLayout()

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

setConstraints

public void setConstraints(java.awt.Component comp,
                           FlexibleConstraints cons)
Specifies new constraints for the specified component in this layout.
Parameters:
component - the component to be modified.
constraints - the constraints to be applied.

getConstraints

public FlexibleConstraints getConstraints(java.awt.Component comp)
Gets the constraints for the specified component in this layout.
Parameters:
component - the component to be queried.

setSize

public void setSize(java.awt.Dimension size)
Specifies this layout size.

This is the layout default size, and it defines the number of rows and columns to use for relative layout.

Parameters:
size - The size to use for layout.
See Also:
getSize(), setTarget(java.awt.Container), FlexibleConstants.RELATIVE

setSize

public void setSize(int width,
                    int height)
Specifies this layout size.

This is the layout default size, and it defines the number of rows and columns to use for relative layout.

Parameters:
width - The width to use for layout.
height - The height to use for layout.
See Also:
getSize(), setTarget(java.awt.Container), FlexibleConstants.RELATIVE

setTarget

public void setTarget(java.awt.Container target)
Sets this layout size so to lay out the specified target container.

This layout size is set according to target client area, that is the target size without its insets.

Parameters:
target - the target container.
See Also:
setSize(java.awt.Dimension)

getSize

public java.awt.Dimension getSize()
Gets this layout size.

When not null, this is the layout preferred size, and it defines the number of rows and columns to use for relative layout.

Returns:
This layout size.
See Also:
setSize(java.awt.Dimension), FlexibleConstants.RELATIVE