Working with grids

The Waterloo base module provides Swing containers for display Waterloo plots.

There is no reason for Java programmers to use these. All Waterloo containers extend basic Swing containers and can be used in any custom swing hierarchy. The kcl.waterloo.swing package is provided for convenience only.

Java programmers can also use components in a custom Swing hierarchy e.g. a GCTabbedGridContainer or GCGrdiElement can be housed in any Swing hierarchy - not just in a GCFrame.

The GCGridElement

GCGridElements are used to wrap Waterloo graphics components when adding them to a GCGrid.

GCGridElements are treated specially by the custom layout of a GCGrid to maintain their position within the grid.

Grid elements may overlap: the GCGridElement therefore also contains Z-order information and behaves much as a layer in graphics editing software like Adobe PhotoShop - you can set the order in which elements are drawn to screen.

A GCGridElement is a JPanel with a BorderLayout. Waterloo graphics are always added to the center component of the layout and the EAST, NORTH, WEST and SOUTH components are usually empty - and can therefore be used to add labels, titles, toolbars and legends etc. to the graphics using standard Swing components.

The GCGrid

A GCGrid hosts a collection of GCGridElements and uses a custom layout to support the grid. This layout allows you to set:
  1. the position of the top left corner of each GCGridElement.
  2. the width and height of each GCGridElement.
  3. the Z-order of each GCGridElement.

When adding an element to the GCGridContainer you specify the location of its top left corner as the row and column position together with a height and width. The custom layout updates automatically to support the required number of rows and columns in the panel.

Grids are flexible: the dimensions are not fixed but adapt as more GCGridElements are added.

GCGridContainers and GCTabbedGridContainers

A GCGridContainer is a Swing panel designed to maintain grids of Waterloo charts (and other Swing components).

A GCTabbedGridContainer is a JTabbedPane subclass where each tab can contain a GCGridContainer thus allowing muliple-grids in a single component. Tab elements may also contain non-Waterloo elements e.g. a JTable.

GCFrame

The GCFrame is a JFrame subclass. The createFrame methods in Waterloo generate GCFrames.

A GCFrame instance has one non-standard property: the graphicsContainer. This is a reference to the component used to contain Waterloo charts. It will normally, but does not need to be, the content pane for the GCFrame. Two custom components are provided to act as graphicsContainers: the GCGridContainer and the GCTabbedGridContainer.