org.springframework.richclient.layout
Class GridBagLayoutBuilder

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.layout.GridBagLayoutBuilder
All Implemented Interfaces:
LayoutBuilder
Direct Known Subclasses:
GridBagLayoutFormBuilder.FormModelAwareGridBagLayoutBuilder

public class GridBagLayoutBuilder
extends Object
implements LayoutBuilder

This provides an easy way to create panels using a GridBagLayout.

Usage is:

 GridBagLayoutBuilder builder = new GridBagLayoutBuilder();

 builder.appendRightLabel("label.field1").appendField(field1);
 builder.appendRightLabel("label.field2").appendField(field2);
 builder.nextLine();

 builder.appendRightLabel("label.field3").appendField(field3);
 // because "field3" is the last component on this line, but the panel has
 // 4 columns, "field3" will span 3 columns
 builder.nextLine();

 // once everything's been put into the builder, ask it to build a panel
 // to use in the UI.
 JPanel panel = builder.getPanel();
 

Author:
Jim Moore
See Also:
setAutoSpanLastComponent(boolean), setShowGuidelines(boolean), setComponentFactory(ComponentFactory)

Constructor Summary
GridBagLayoutBuilder()
           
 
Method Summary
 GridBagLayoutBuilder append(Component component)
          Appends the given component to the end of the current line, using the default insets and no expansion
 GridBagLayoutBuilder append(Component component, int colSpan, int rowSpan)
          Appends the given component to the end of the current line, using the default insets and no expansion
 GridBagLayoutBuilder append(Component component, int colSpan, int rowSpan, boolean expandX, boolean expandY)
          Appends the given component to the end of the current line, using the default insets
 GridBagLayoutBuilder append(Component component, int colSpan, int rowSpan, boolean expandX, boolean expandY, Insets insets)
          Appends the given component to the end of the current line
 GridBagLayoutBuilder append(Component component, int colSpan, int rowSpan, double xweight, double yweight)
          Appends the given component to the end of the current line, using the default insets
 GridBagLayoutBuilder append(Component component, int colSpan, int rowSpan, double xweight, double yweight, Insets insets)
          Appends the given component to the end of the current line
 GridBagLayoutBuilder append(Component component, int x, int y, int colSpan, int rowSpan, boolean expandX, boolean expandY, Insets insets)
          Appends the given component to the end of the current line
 GridBagLayoutBuilder append(Component component, int x, int y, int colSpan, int rowSpan, double xweight, double yweight, Insets insets)
          Appends the given component to the end of the current line
 GridBagLayoutBuilder appendField(Component component)
          Appends the given component to the end of the current line.
 GridBagLayoutBuilder appendField(Component component, int colSpan)
          Appends the given component to the end of the current line.
 GridBagLayoutBuilder appendLabel(JLabel label)
          Appends the given label to the end of the current line.
 GridBagLayoutBuilder appendLabel(JLabel label, int colSpan)
          Appends the given label to the end of the current line.
 GridBagLayoutBuilder appendLabeledField(JLabel label, JComponent field, LabelOrientation labelOrientation, int colSpan, int rowSpan, boolean expandX, boolean expandY)
          Appends a label and field to the end of the current line.

The label will be to the left of the field, and be right-justified.
The field will "grow" horizontally as space allows.

 GridBagLayoutBuilder appendLabeledField(String propertyName, JComponent field, LabelOrientation labelOrientation)
          Appends a label and field to the end of the current line.
 GridBagLayoutBuilder appendLabeledField(String propertyName, JComponent field, LabelOrientation labelOrientation, int colSpan)
          Appends a label and field to the end of the current line.
 GridBagLayoutBuilder appendLabeledField(String propertyName, JComponent field, LabelOrientation labelOrientation, int colSpan, int rowSpan, boolean expandX, boolean expandY)
          Appends a label and field to the end of the current line.

The label will be to the left of the field, and be right-justified.
The field will "grow" horizontally as space allows.

 GridBagLayoutBuilder appendLeftLabel(String labelKey)
          Appends a left-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.
 GridBagLayoutBuilder appendLeftLabel(String labelKey, int colSpan)
          Appends a left-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.
 GridBagLayoutBuilder appendRightLabel(String labelKey)
          Appends a right-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.
 GridBagLayoutBuilder appendRightLabel(String labelKey, int colSpan)
          Appends a right-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.
 GridBagLayoutBuilder appendSeparator()
          Appends a seperator (usually a horizonal line).
 GridBagLayoutBuilder appendSeparator(String labelKey)
          Appends a seperator (usually a horizonal line) using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to put along with the seperator.
protected  JLabel createLabel(String propertyName)
           
 ComponentFactory getComponentFactory()
           
 int getCurrentCol()
          Returns the current column (zero-based) that the builder is putting components in
 int getCurrentRow()
          Returns the current row (zero-based) that the builder is putting components in
 Insets getDefaultInsets()
          Returns the default Insetsused when adding components
 JPanel getPanel()
          Creates and returns a JPanel with all the given components in it, using the "hints" that were provided to the builder.
 GridBagLayoutBuilder nextLine()
          Ends the current line and starts a new one
 void setAutoSpanLastComponent(boolean autoSpanLastComponent)
          Should the last column before a nextLine()automaticly span to the end of the panel?

For example, if you have

 void setComponentFactory(ComponentFactory componentFactory)
           
 void setDefaultInsets(Insets defaultInsets)
          Sets the default Insetsused when adding components
 void setShowGuidelines(boolean showGuidelines)
          Should this show "guidelines"? Useful for debugging layouts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridBagLayoutBuilder

public GridBagLayoutBuilder()
Method Detail

getDefaultInsets

public Insets getDefaultInsets()
Returns the default Insetsused when adding components


setDefaultInsets

public void setDefaultInsets(Insets defaultInsets)
Sets the default Insetsused when adding components


getCurrentRow

public int getCurrentRow()
Returns the current row (zero-based) that the builder is putting components in


getCurrentCol

public int getCurrentCol()
Returns the current column (zero-based) that the builder is putting components in


getComponentFactory

public ComponentFactory getComponentFactory()

setComponentFactory

public void setComponentFactory(ComponentFactory componentFactory)

append

public GridBagLayoutBuilder append(Component component)
Appends the given component to the end of the current line, using the default insets and no expansion

Parameters:
component - the component to add to the current line
Returns:
"this" to make it easier to string together append calls

append

public GridBagLayoutBuilder append(Component component,
                                   int colSpan,
                                   int rowSpan)
Appends the given component to the end of the current line, using the default insets and no expansion

Parameters:
component - the component to add to the current line
colSpan - the number of columns to span
rowSpan - the number of rows to span
Returns:
"this" to make it easier to string together append calls

append

public GridBagLayoutBuilder append(Component component,
                                   int colSpan,
                                   int rowSpan,
                                   boolean expandX,
                                   boolean expandY)
Appends the given component to the end of the current line, using the default insets

Parameters:
component - the component to add to the current line
colSpan - the number of columns to span
rowSpan - the number of rows to span
expandX - should the component "grow" horrizontally?
expandY - should the component "grow" vertically?
Returns:
"this" to make it easier to string together append calls

append

public GridBagLayoutBuilder append(Component component,
                                   int colSpan,
                                   int rowSpan,
                                   boolean expandX,
                                   boolean expandY,
                                   Insets insets)
Appends the given component to the end of the current line

Parameters:
component - the component to add to the current line
colSpan - the number of columns to span
rowSpan - the number of rows to span
expandX - should the component "grow" horrizontally?
expandY - should the component "grow" vertically?
insets - the insets to use for this component
Returns:
"this" to make it easier to string together append calls

append

public GridBagLayoutBuilder append(Component component,
                                   int x,
                                   int y,
                                   int colSpan,
                                   int rowSpan,
                                   boolean expandX,
                                   boolean expandY,
                                   Insets insets)
Appends the given component to the end of the current line

Parameters:
component - the component to add to the current line
x - the column to put the component
y - the row to put the component
colSpan - the number of columns to span
rowSpan - the number of rows to span
expandX - should the component "grow" horrizontally?
expandY - should the component "grow" vertically?
insets - the insets to use for this component
Returns:
"this" to make it easier to string together append calls

append

public GridBagLayoutBuilder append(Component component,
                                   int colSpan,
                                   int rowSpan,
                                   double xweight,
                                   double yweight)
Appends the given component to the end of the current line, using the default insets

Parameters:
component - the component to add to the current line
colSpan - the number of columns to span
rowSpan - the number of rows to span
xweight - the "growth weight" horrizontally
yweight - the "growth weight" horrizontally
Returns:
"this" to make it easier to string together append calls
See Also:
GridBagConstraints.weightx, GridBagConstraints.weighty

append

public GridBagLayoutBuilder append(Component component,
                                   int colSpan,
                                   int rowSpan,
                                   double xweight,
                                   double yweight,
                                   Insets insets)
Appends the given component to the end of the current line

Parameters:
component - the component to add to the current line
colSpan - the number of columns to span
rowSpan - the number of rows to span
xweight - the "growth weight" horrizontally
yweight - the "growth weight" horrizontally
insets - the insets to use for this component
Returns:
"this" to make it easier to string together append calls
See Also:
GridBagConstraints.weightx, GridBagConstraints.weighty

appendLabeledField

public GridBagLayoutBuilder appendLabeledField(String propertyName,
                                               JComponent field,
                                               LabelOrientation labelOrientation)
Appends a label and field to the end of the current line.

The label will be to the left of the field, and be right-justified.
The field will "grow" horizontally as space allows.

Parameters:
propertyName - the name of the property to create the controls for
Returns:
"this" to make it easier to string together append calls

appendLabeledField

public GridBagLayoutBuilder appendLabeledField(String propertyName,
                                               JComponent field,
                                               LabelOrientation labelOrientation,
                                               int colSpan)
Appends a label and field to the end of the current line.

The label will be to the left of the field, and be right-justified.
The field will "grow" horizontally as space allows.

Parameters:
propertyName - the name of the property to create the controls for
colSpan - the number of columns the field should span
Returns:
"this" to make it easier to string together append calls

appendLabeledField

public GridBagLayoutBuilder appendLabeledField(String propertyName,
                                               JComponent field,
                                               LabelOrientation labelOrientation,
                                               int colSpan,
                                               int rowSpan,
                                               boolean expandX,
                                               boolean expandY)
Appends a label and field to the end of the current line.

The label will be to the left of the field, and be right-justified.
The field will "grow" horizontally as space allows.

Parameters:
propertyName - the name of the property to create the controls for
colSpan - the number of columns the field should span
Returns:
"this" to make it easier to string together append calls

createLabel

protected JLabel createLabel(String propertyName)

appendLabeledField

public GridBagLayoutBuilder appendLabeledField(JLabel label,
                                               JComponent field,
                                               LabelOrientation labelOrientation,
                                               int colSpan,
                                               int rowSpan,
                                               boolean expandX,
                                               boolean expandY)
Appends a label and field to the end of the current line.

The label will be to the left of the field, and be right-justified.
The field will "grow" horizontally as space allows.

Parameters:
label - the label to associate and layout with the field
colSpan - the number of columns the field should span
Returns:
"this" to make it easier to string together append calls

append

public GridBagLayoutBuilder append(Component component,
                                   int x,
                                   int y,
                                   int colSpan,
                                   int rowSpan,
                                   double xweight,
                                   double yweight,
                                   Insets insets)
Appends the given component to the end of the current line

Parameters:
component - the component to add to the current line
x - the column to put the component
y - the row to put the component
colSpan - the number of columns to span
rowSpan - the number of rows to span
xweight - the "growth weight" horrizontally
yweight - the "growth weight" horrizontally
insets - the insets to use for this component
Returns:
"this" to make it easier to string together append calls
See Also:
GridBagConstraints.weightx, GridBagConstraints.weighty

appendLabel

public GridBagLayoutBuilder appendLabel(JLabel label)
Appends the given label to the end of the current line. The label does not "grow."

Parameters:
label - the label to append
Returns:
"this" to make it easier to string together append calls

appendLabel

public GridBagLayoutBuilder appendLabel(JLabel label,
                                        int colSpan)
Appends the given label to the end of the current line. The label does not "grow."

Parameters:
label - the label to append
colSpan - the number of columns to span
Returns:
"this" to make it easier to string together append calls

appendRightLabel

public GridBagLayoutBuilder appendRightLabel(String labelKey)
Appends a right-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.

Parameters:
labelKey - the key into the message bundle; if not found the key is used as the text to display
Returns:
"this" to make it easier to string together append calls

appendRightLabel

public GridBagLayoutBuilder appendRightLabel(String labelKey,
                                             int colSpan)
Appends a right-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.

Parameters:
labelKey - the key into the message bundle; if not found the key is used as the text to display
colSpan - the number of columns to span
Returns:
"this" to make it easier to string together append calls

appendLeftLabel

public GridBagLayoutBuilder appendLeftLabel(String labelKey)
Appends a left-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.

Parameters:
labelKey - the key into the message bundle; if not found the key is used as the text to display
Returns:
"this" to make it easier to string together append calls

appendLeftLabel

public GridBagLayoutBuilder appendLeftLabel(String labelKey,
                                            int colSpan)
Appends a left-justified label to the end of the given line, using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to use.

Parameters:
labelKey - the key into the message bundle; if not found the key is used as the text to display
colSpan - the number of columns to span
Returns:
"this" to make it easier to string together append calls

appendField

public GridBagLayoutBuilder appendField(Component component)
Appends the given component to the end of the current line. The component will "grow" horizontally as space allows.

Parameters:
component - the item to append
Returns:
"this" to make it easier to string together append calls

appendField

public GridBagLayoutBuilder appendField(Component component,
                                        int colSpan)
Appends the given component to the end of the current line. The component will "grow" horizontally as space allows.

Parameters:
component - the item to append
colSpan - the number of columns to span
Returns:
"this" to make it easier to string together append calls

appendSeparator

public GridBagLayoutBuilder appendSeparator()
Appends a seperator (usually a horizonal line). Has an implicit nextLine()before and after it.

Returns:
"this" to make it easier to string together append calls

appendSeparator

public GridBagLayoutBuilder appendSeparator(String labelKey)
Appends a seperator (usually a horizonal line) using the provided string as the key to look in the ComponentFactory'smessage bundle for the text to put along with the seperator. Has an implicit nextLine()before and after it.

Returns:
"this" to make it easier to string together append calls

nextLine

public GridBagLayoutBuilder nextLine()
Ends the current line and starts a new one

Returns:
"this" to make it easier to string together append calls

setShowGuidelines

public void setShowGuidelines(boolean showGuidelines)
Should this show "guidelines"? Useful for debugging layouts.


getPanel

public JPanel getPanel()
Creates and returns a JPanel with all the given components in it, using the "hints" that were provided to the builder.

Specified by:
getPanel in interface LayoutBuilder
Returns:
a new JPanel with the components laid-out in it

setAutoSpanLastComponent

public void setAutoSpanLastComponent(boolean autoSpanLastComponent)
Should the last column before a nextLine()automaticly span to the end of the panel?

For example, if you have

 append(a).append(b).append(c).nextLine();
 append(d).append(e).nextLine();
 
then "e" would automaticly span two columns.

Parameters:
autoSpanLastComponent - default is true


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.