de.frag.umlplugin.guilayout
Class LayoutBuilder

java.lang.Object
  extended by de.frag.umlplugin.guilayout.LayoutBuilder

public class LayoutBuilder
extends java.lang.Object

The LayoutBuilder is a convenience class for building hierarchical FlexLayout GUI layouts. The following example should illustrate the basic functionality:

FlexDemo application window snapshot

To create this GUI the following code does all the layout after the GUI elements itself are created.

   LayoutBuilder builder = new LayoutBuilder ();
   builder.setDefaultInsets (new Insets (2, 2, 2, 2));
   JPanel root = builder.beginV ();
     builder.beginH ();    // selection area
       builder.beginV ();  // box with available computers
         builder.add (availableLabel,    CENTER);
         builder.add (availableScroller, STRETCH_XY);
       builder.end ();
       builder.beginV ();  // buttons to add/remove computers
         builder.add (add,    FILL_X);
         builder.add (remove, FILL_X);
       builder.end ();
       builder.beginV ();  // box with selected computers
         builder.add (selectedLabel,    CENTER);
         builder.add (selectedScroller, STRETCH_XY);
       builder.end ();
     builder.end ();       // end of selection area
     builder.beginH (4);
       builder.add (hostLabel, LABEL);
       builder.add (hostField, STRETCH_X);
       builder.add (ipLabel,   LABEL);
       builder.add (ipField,   STRETCH_X);
       builder.add (osLabel,   LABEL);
       builder.add (osField,   STRETCH_X);
       builder.add (roomLabel, LABEL);
       builder.add (roomField, STRETCH_X);
     builder.end ();
     builder.beginH ();
       builder.add (okButton,     MAX_X);
       builder.addHSpace ();
       builder.add (cancelButton, MAX_X);
     builder.end ();
   builder.end ();
 

This is a simple example, that uses a border layout:

   JPanel root = new JPanel (new BorderLayout ());
   root.add (north,  BorderLayout.NORTH);
   root.add (south,  BorderLayout.SOUTH);
   root.add (west,   BorderLayout.WEST);
   root.add (east,   BorderLayout.EAST);
   root.add (center, BorderLayout.CENTER);
 
The following code simulates this border layout using FlexLayout:
   LayoutBuilder builder = new LayoutBuilder ();
   JPanel root = builder.beginV ();
     builder.add (north, STRETCH_X);
     builder.beginH ();
       builder.add (west,   STRETCH_Y);
       builder.add (center, STRETCH_XY);
       builder.add (east,   STRETCH_Y);
     builder.end ();
     builder.add (south, STRETCH_X);
   builder.end ();
 


Constructor Summary
LayoutBuilder()
          Construct a new LayoutBuilder.
LayoutBuilder(java.awt.Container root, FlexLayout layout)
          Create a new LayoutBuilder, that sets a the specified FlexLayout as layout manager for the given container and then uses the given Container as root container.
 
Method Summary
 void add(java.awt.Component component, java.lang.Object constraints)
          Add the given component to the current container using the given constraints.
 void addHSpace()
          Add some horizontal flexible space to create a gap between other components.
 void addHSpace(int pixels)
          Add some horizontal fixed space to create a gap between other components.
 void addVSpace()
          Add some vertical flexible space to create a gap between other components.
 void addVSpace(int pixels)
          Add some vertical fixed space to create a gap between other components.
 javax.swing.JPanel beginBorder()
          Begin a new border layout hierarchy level of components.
 javax.swing.JPanel beginH()
          Begin a new horizontal hierarchy level of components.
 javax.swing.JPanel beginH(int columns)
          Begin a new horizontal hierarchy level of components.
 javax.swing.JPanel beginV()
          Begin a new vertical hierarchy level of components.
 javax.swing.JPanel beginV(int rows)
          Begin a new vertical hierarchy level of components.
 void end()
          Leave the current container hierarchy level.
 void end(java.lang.Object constraints)
          Leave the current container hierarchy level.
 java.awt.Insets getDefaultComponentInsets()
          Get the default insets, that are used for all components, that are added with null insets.
 java.awt.Insets getDefaultContainerInsets()
          Get the default insets, that are used for all containers, that are added with null insets.
 void setDefaultComponentInsets(java.awt.Insets insets)
          Set the default insets, that will be used for all components, that are added with null insets.
 void setDefaultContainerInsets(java.awt.Insets insets)
          Set the default insets, that will be used for all containers, that are added with null insets.
 void setDefaultInsets(java.awt.Insets insets)
          Set the default insets, that will be used for all components or containers, that are added with null insets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayoutBuilder

public LayoutBuilder()
Construct a new LayoutBuilder. The first (root) container should be created using one of the begin-methods, so adding of components is possible only after entering the first hierarchy of containers.


LayoutBuilder

public LayoutBuilder(@NotNull
                     java.awt.Container root,
                     @NotNull
                     FlexLayout layout)
Create a new LayoutBuilder, that sets a the specified FlexLayout as layout manager for the given container and then uses the given Container as root container.

Parameters:
root - root container
layout - layout manager to use for the root container
Method Detail

setDefaultInsets

public void setDefaultInsets(@Nullable
                             java.awt.Insets insets)
Set the default insets, that will be used for all components or containers, that are added with null insets.

Parameters:
insets - new default insets

setDefaultComponentInsets

public void setDefaultComponentInsets(@Nullable
                                      java.awt.Insets insets)
Set the default insets, that will be used for all components, that are added with null insets.

Parameters:
insets - new default insets

setDefaultContainerInsets

public void setDefaultContainerInsets(@Nullable
                                      java.awt.Insets insets)
Set the default insets, that will be used for all containers, that are added with null insets.

Parameters:
insets - new default insets

getDefaultComponentInsets

@NotNull
public java.awt.Insets getDefaultComponentInsets()
Get the default insets, that are used for all components, that are added with null insets.

Returns:
default insets

getDefaultContainerInsets

@NotNull
public java.awt.Insets getDefaultContainerInsets()
Get the default insets, that are used for all containers, that are added with null insets.

Returns:
default insets

beginH

@NotNull
public javax.swing.JPanel beginH()
Begin a new horizontal hierarchy level of components. All components, that are added subsequently via calls to add, are arranged horizontally. So the new component hierarchy will be an irregular raster of components with one row and an arbitrary number of columns.

Returns:
the container, that is used as new component hierarchy level

beginH

@NotNull
public javax.swing.JPanel beginH(int columns)
Begin a new horizontal hierarchy level of components. All components, that are added subsequently via calls to add, are arranged horizontally until the specified number of columns is reached and a new row of components is created. So the new component hierarchy will be an irregular raster of components with a fixed number of columns and an arbitrary number of rows.

Parameters:
columns - maximum number of columns
Returns:
the container, that is used as new component hierarchy level

beginV

@NotNull
public javax.swing.JPanel beginV()
Begin a new vertical hierarchy level of components. All components, that are added subsequently via calls to add, are arranged vertically. So the new component hierarchy will be an irregular raster of components with one column and an arbitrary number of rows.

Returns:
the container, that is used as new component hierarchy level

beginV

@NotNull
public javax.swing.JPanel beginV(int rows)
Begin a new vertical hierarchy level of components. All components, that are added subsequently via calls to add, are arranged vertically until the specified number of rows is reached and a new column of components is created. So the new component hierarchy will be an irregular raster of components with a fixed number of rows and an arbitrary number of columns.

Parameters:
rows - maximum number of rows
Returns:
the container, that is used as new component hierarchy level

beginBorder

@NotNull
public javax.swing.JPanel beginBorder()
Begin a new border layout hierarchy level of components. All components, that are added subsequently via calls to add, are arranged using a border layout

Returns:
the container, that is used as new component hierarchy level

end

public void end()
Leave the current container hierarchy level. The current container will be added to its parent container and the parent container will become the current container. If this is called without a matching previous call to of the begin-methods, a java.util.EmptyStackException will be raised.


end

public void end(@Nullable
                java.lang.Object constraints)
Leave the current container hierarchy level. The current container will be added to its parent container and the parent container will become the current container. If this is called without a matching previous call to of the begin-methods, a java.util.EmptyStackException will be raised.

Parameters:
constraints - constraints to use for finished panel

add

public void add(@NotNull
                java.awt.Component component,
                @Nullable
                java.lang.Object constraints)
Add the given component to the current container using the given constraints.

Parameters:
component - component to add
constraints - constraints to use for the given component

addHSpace

public void addHSpace()
Add some horizontal flexible space to create a gap between other components.


addHSpace

public void addHSpace(int pixels)
Add some horizontal fixed space to create a gap between other components.

Parameters:
pixels - width of space in pixels

addVSpace

public void addVSpace()
Add some vertical flexible space to create a gap between other components.


addVSpace

public void addVSpace(int pixels)
Add some vertical fixed space to create a gap between other components.

Parameters:
pixels - height of space in pixels