de.frag.umlplugin.guilayout
Class FlexLayout

java.lang.Object
  extended by de.frag.umlplugin.guilayout.FlexLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2

public abstract class FlexLayout
extends java.lang.Object
implements java.awt.LayoutManager2

FlexLayout is a layout manager, that behaves similarly to GridBagLayout, but is much simpler to use and a little bit less flexible. Complex GUI designs must not be constructed by using FlexLayout directly, but can be created by using the LayoutBuilder. There are two main types of FlexLayout: horizontal and vertical arrangement of components. A FlexLayout is constructed by calling one of the factory methods createHorizontalLayout and createVerticalLayout. Then components are filled into a unregularly rectangular raster with each component associated to a FlexConstraint object, that describes how to arrange and resize the corresponding component.

See Also:
FlexConstraints, LayoutBuilder

Nested Class Summary
protected  class FlexLayout.Element
          An Element is a component and its associated FlexConstraints object.
protected static interface FlexLayout.SizeGetter
          A SizeGetter gets size information from a component and is a simple hook to get different size information in the same way (minimum size, maximum size and preferred size).
 
Field Summary
protected  int columns
           
protected  java.util.List<FlexLayout.Element> components
           
protected  int rows
           
 
Constructor Summary
protected FlexLayout()
          Protected constructor to prevend it from being called directly.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Add one more component to the layouter.
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Add a component to the layouter using default FlexConstraints.
protected abstract  FlexLayout.Element[][] createGrid()
          Create a grid of elements with respect to the type of layouter (horizontal or vertical).
static FlexLayout createHorizontalLayout(int columns)
          Create a new horizontal arranging FlexLayout manager.
static FlexLayout createVerticalLayout(int rows)
          Create a new vertical arranging FlexLayout manager.
 float getLayoutAlignmentX(java.awt.Container target)
           
 float getLayoutAlignmentY(java.awt.Container target)
           
protected  java.awt.Dimension getLayoutSize(java.awt.Container target, FlexLayout.SizeGetter getter)
          Generic layout size calculator to compute values for minimum size, maximum size and preferred size.
 FlexConstraints getParentConstraints()
          Get the constraints, that should be used to add a container with this layouter to a parent container, that uses FlexLayout, too.
 void invalidateLayout(java.awt.Container target)
           
 void layoutContainer(java.awt.Container parent)
          Compute the layout for all components, that reside within the container with respect to the bounds of the parent container.
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Get the maximum size of the target container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Get the minimum size of the target container.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Get the preferred size of the target container.
 void removeLayoutComponent(java.awt.Component comp)
          Remove the given component from the layouter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

components

protected final java.util.List<FlexLayout.Element> components

columns

protected int columns

rows

protected int rows
Constructor Detail

FlexLayout

protected FlexLayout()
Protected constructor to prevend it from being called directly. FlexLayouts should be constructed by calling one of the factory methods createHorizontalLayout and createVerticalLayout.

Method Detail

createHorizontalLayout

public static FlexLayout createHorizontalLayout(int columns)
Create a new horizontal arranging FlexLayout manager. Components will be added from left to right until the given number of columns is reached and a new row of components is created. A horizontal layout has always the given number of columns and an arbitrary number of rows.

Parameters:
columns - number of columns
Returns:
constructed layout manager

createVerticalLayout

public static FlexLayout createVerticalLayout(int rows)
Create a new vertical arranging FlexLayout manager. Components will be added from top to bottom until the given number of rows is reached and a new column of components is created. A vertical layout has always the given number of rows and an arbitrary number of columns.

Parameters:
rows - number of rows
Returns:
constructed layout manager

addLayoutComponent

public void addLayoutComponent(@NotNull
                               java.awt.Component comp,
                               @NotNull
                               java.lang.Object constraints)
Add one more component to the layouter.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - component to add
constraints - layout constraints for the given component. This must be of type FlexConstraints.

addLayoutComponent

public void addLayoutComponent(@NotNull
                               java.lang.String name,
                               @NotNull
                               java.awt.Component comp)
Add a component to the layouter using default FlexConstraints.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
name - name of the component (will be ignored)
comp - component to add

removeLayoutComponent

public void removeLayoutComponent(@NotNull
                                  java.awt.Component comp)
Remove the given component from the layouter.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
comp - component to remove

getLayoutAlignmentX

public float getLayoutAlignmentX(@NotNull
                                 java.awt.Container target)
Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(@NotNull
                                 java.awt.Container target)
Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2

invalidateLayout

public void invalidateLayout(@NotNull
                             java.awt.Container target)
Specified by:
invalidateLayout in interface java.awt.LayoutManager2

getParentConstraints

@NotNull
public FlexConstraints getParentConstraints()
Get the constraints, that should be used to add a container with this layouter to a parent container, that uses FlexLayout, too.

Returns:
constraints to use for adding this container to its parent

createGrid

@NotNull
protected abstract FlexLayout.Element[][] createGrid()
Create a grid of elements with respect to the type of layouter (horizontal or vertical).

Returns:
elements on grid

getLayoutSize

@NotNull
protected java.awt.Dimension getLayoutSize(@NotNull
                                                   java.awt.Container target,
                                                   @NotNull
                                                   FlexLayout.SizeGetter getter)
Generic layout size calculator to compute values for minimum size, maximum size and preferred size.

Parameters:
target - container to compute layout size for
getter - size getter to get size information of a component
Returns:
computed dimension

maximumLayoutSize

@NotNull
public java.awt.Dimension maximumLayoutSize(@NotNull
                                                    java.awt.Container target)
Get the maximum size of the target container.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - container to compute maximum size for
Returns:
maximum size of the container

minimumLayoutSize

@NotNull
public java.awt.Dimension minimumLayoutSize(@NotNull
                                                    java.awt.Container parent)
Get the minimum size of the target container.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - container to compute minimum size for
Returns:
minimum size of the container

preferredLayoutSize

@NotNull
public java.awt.Dimension preferredLayoutSize(@NotNull
                                                      java.awt.Container parent)
Get the preferred size of the target container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - container to compute preferred size for
Returns:
preferred size of the container

layoutContainer

public void layoutContainer(@NotNull
                            java.awt.Container parent)
Compute the layout for all components, that reside within the container with respect to the bounds of the parent container.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - parent container information