Package uk.ac.starlink.util.gui

# Class GridBagLayouter

java.lang.Object
uk.ac.starlink.util.gui.GridBagLayouter

public class GridBagLayouter extends Object
Utility class for laying out UI components using a GridBagLayout with fixed schemes of various kinds.. See the various schemes (SCHEME[1-]) for what layouts are supported.

A typical usage pattern is:

        GridBagLayouter layouter = new GridBagLayouter( pane, GridBagLayouter.SCHEME3 );
        layouter.add( "Label:", false );
        layouter.add( new JComponent(), true );         // End of this line
        ... more components ...
        layouter.eatSpare();                            // End of all components

Version:
  $Id$
Author:
  Peter W. Draper

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`SCHEME1`
Simple row by row layout.
`static final int`
`SCHEME2`
Simple row by row layout, but this time with three components, weighted 0.15 to 0 to 0.85, so that most space is kept by right component.
`static final int`
`SCHEME3`
Simple row by row layout.
`static final int`
`SCHEME4`
Simple row by row layout, as in SCHEME3, but with the occasional component that fills vertically too.
`static final int`
`SCHEME5`
Simple row by row layout.

## Constructor Summary

Constructors
Constructor
Description
`GridBagLayouter(Container container)`
Create an instance with the default layout scheme (SCHEME1).
`GridBagLayouter(Container container, int scheme)`
Create an instance with a given layout scheme.

## Method Summary

Modifier and Type
Method
Description
`void`
`add(Component component, boolean complete)`
Add a control using the current scheme.
`void`
`add(Component component, GridBagConstraints gbc)`
Add a control using given GridBagContraints.
`void`
`add(String label)`
Add a JLabel using the current scheme.
`void`
`add(String label, boolean complete)`
Add a JLabel using the current scheme.
`void`
`eatLine()`
Eat to end of current line.
`void`
`eatSpare()`
Finish adding by "eating" all remaining space (makes components move to top of container).
`Container`
`getContainer()`
Get the container we're adding to.
`void`
`setInsets(Insets insets)`
Set the GridBagLayout Insets.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### SCHEME1

public static final int SCHEME1
Simple row by row layout. Everything packed to the left, labels right justified, no fills. Typical usage:

        label: [input component]
        label: [input component]
        ....

See Also:
  - Constant Field Values

### SCHEME2

public static final int SCHEME2
Simple row by row layout, but this time with three components, weighted 0.15 to 0 to 0.85, so that most space is kept by right component. Typical usage:

        [minor input component] label [main input component]
        [minor input component] label [main input component]
        ....

See Also:
  - Constant Field Values

### SCHEME3

public static final int SCHEME3
Simple row by row layout. Everything packed to the left, labels right justified, last component uses all remaining space. Typical usage:

        label: [long text input component            ]
        label: [long text input component            ]
        ....

See Also:
  - Constant Field Values

### SCHEME4

public static final int SCHEME4
Simple row by row layout, as in SCHEME3, but with the occasional component that fills vertically too. Typical usage:

        label: [long text input component            ]
        label: [long text input component            ]
        [text/display area                           ]
        [....                                        ]
        [....                                        ]
        ....

a filled area is indicated by a single item on a line.

See Also:
  - Constant Field Values

### SCHEME5

public static final int SCHEME5
Simple row by row layout. Everything packed to the left, labels left justified, no fills. Typical usage:

     label
     [input component] [input component]
     label
     [input component] [input component]
        ....

See Also:
  - Constant Field Values

## Constructor Details

### GridBagLayouter

public GridBagLayouter(Container container)
Create an instance with the default layout scheme (SCHEME1). Note that container gains a GridBagLayout.

Parameters:
  `container` - the container

### GridBagLayouter

public GridBagLayouter(Container container, int scheme)
Create an instance with a given layout scheme. Note that container gains a GridBagLayout.

Parameters:
  `container` - the container
  `scheme` - one of the available schemes (SCHEME[1-]).

## Method Details

### add

public void add(String label, boolean complete)
Add a JLabel using the current scheme.

Parameters:
  `label` - the string for the JLabel
  `complete` - whether the line is now completed

### add

public void add(String label)
Add a JLabel using the current scheme. Assumes complete is false.

Parameters:
  `label` - the string for the JLabel

### add

public void add(Component component, boolean complete)
Add a control using the current scheme.

Parameters:
  `component` - the component to add
  `complete` - whether the line is now completed

### setInsets

public void setInsets(Insets insets)
Set the GridBagLayout Insets. Overrides the default.

### add

public void add(Component component, GridBagConstraints gbc)
Add a control using given GridBagContraints. This does not use any of the builtin schemes.

### eatLine

public void eatLine()
Eat to end of current line.

### eatSpare

public void eatSpare()
Finish adding by "eating" all remaining space (makes components move to top of container).

### getContainer

public Container getContainer()
Get the container we're adding to.