ucar.unidata.ui
Class GraphPaperLayout

java.lang.Object
  extended by ucar.unidata.ui.GraphPaperLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class GraphPaperLayout
extends Object
implements LayoutManager2

The GraphPaperLayout class is a layout manager that lays out a container's components in a rectangular grid, similar to GridLayout. Unlike GridLayout, however, components can take up multiple rows and/or columns. The layout manager acts as a sheet of graph paper. When a component is added to the layout manager, the location and relative size of the component are simply supplied by the constraints as a Rectangle.

 import java.awt.*;
 import java.applet.Applet;
 public class ButtonGrid extends Applet {
     public void init() {
         setLayout(new GraphPaperLayout(new Dimension(5,5)));
         // Add a 1x1 Rect at (0,0)
         add(new Button("1"), new Rectangle(0,0,1,1));
         // Add a 2x1 Rect at (2,0)
         add(new Button("2"), new Rectangle(2,0,2,1));
         // Add a 1x2 Rect at (1,1)
         add(new Button("3"), new Rectangle(1,1,1,2));
         // Add a 2x2 Rect at (3,2)
         add(new Button("4"), new Rectangle(3,2,2,2));
         // Add a 1x1 Rect at (0,4)
         add(new Button("5"), new Rectangle(0,4,1,1));
         // Add a 1x2 Rect at (2,3)
         add(new Button("6"), new Rectangle(2,3,1,2));
     }
 }
 

Author:
Michael Martak

Nested Class Summary
static class GraphPaperLayout.EditPanel
          Class EditPanel _more_
static class GraphPaperLayout.Location
          Class Location _more_
 
Constructor Summary
GraphPaperLayout()
          Creates a graph paper layout with a default of a 1 x 1 graph, with no vertical or horizontal padding.
GraphPaperLayout(Dimension gridSize)
          Creates a graph paper layout with the given grid size, with no vertical or horizontal padding.
GraphPaperLayout(Dimension gridSize, int hgap, int vgap)
          Creates a graph paper layout with the given grid size and padding.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void addLayoutComponent(String name, Component comp)
          Adds the specified component with the specified name to the layout.
static Dimension getDimensions(List locations)
          _more_
 Dimension getGridSize()
           
protected  Dimension getLargestCellSize(Container parent, boolean isPreferred)
          Algorithm for calculating the largest minimum or preferred cell size.
 float getLayoutAlignmentX(Container target)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(Container target)
          Returns the alignment along the y axis.
protected  Dimension getLayoutSize(Container parent, boolean isPreferred)
          Algorithm for calculating layout size (minimum or preferred).
 void invalidateLayout(Container target)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
static JComponent layout(List locations)
          _more_
 void layoutContainer(Container parent)
          Lays out the container in the specified container.
static void main(String[] args)
          _more_
 Dimension maximumLayoutSize(Container target)
          Returns the maximum size of this component.
 Dimension minimumLayoutSize(Container parent)
          Calculates the minimum size dimensions for the specified panel given the components in the specified parent container.
 Dimension preferredLayoutSize(Container parent)
          Calculates the preferred size dimensions for the specified panel given the components in the specified parent container.
 void removeLayoutComponent(Component comp)
          Removes the specified component from the layout.
 void setConstraints(Component comp, Rectangle constraints)
          _more_
 void setGridSize(Dimension d)
          Set the size of the graph paper in logical units (n x m)
 void setGridSize(int width, int height)
          Set the size of the graph paper in logical units (n x m)
static void showDialog(List locations, String title)
          _more_
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphPaperLayout

public GraphPaperLayout()
Creates a graph paper layout with a default of a 1 x 1 graph, with no vertical or horizontal padding.


GraphPaperLayout

public GraphPaperLayout(Dimension gridSize)
Creates a graph paper layout with the given grid size, with no vertical or horizontal padding.

Parameters:
gridSize -

GraphPaperLayout

public GraphPaperLayout(Dimension gridSize,
                        int hgap,
                        int vgap)
Creates a graph paper layout with the given grid size and padding.

Parameters:
gridSize - size of the graph paper in logical units (n x m)
hgap - horizontal padding
vgap - vertical padding
Method Detail

getGridSize

public Dimension getGridSize()
Returns:
the size of the graph paper in logical units (n x m)

setGridSize

public void setGridSize(Dimension d)
Set the size of the graph paper in logical units (n x m)

Parameters:
d -

setGridSize

public void setGridSize(int width,
                        int height)
Set the size of the graph paper in logical units (n x m)

Parameters:
width -
height -

setConstraints

public void setConstraints(Component comp,
                           Rectangle constraints)
_more_

Parameters:
comp -
constraints -

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Adds the specified component with the specified name to the layout. This does nothing in GraphPaperLayout, since constraints are required.

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name -
comp -

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
comp - the component to be removed

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Calculates the preferred size dimensions for the specified panel given the components in the specified parent container.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent - the component to be laid out
Returns:
_more_
See Also:
minimumLayoutSize(java.awt.Container)

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Calculates the minimum size dimensions for the specified panel given the components in the specified parent container.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent - the component to be laid out
Returns:
_more_
See Also:
preferredLayoutSize(java.awt.Container)

getLayoutSize

protected Dimension getLayoutSize(Container parent,
                                  boolean isPreferred)
Algorithm for calculating layout size (minimum or preferred).

The width of a graph paper layout is the largest cell width (calculated in getLargestCellSize() times the number of columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.

The height of a graph paper layout is the largest cell height (calculated in getLargestCellSize() times the number of rows, plus the vertical padding times the number of rows plus one, plus the top and bottom insets of the target container.

Parameters:
parent - the container in which to do the layout.
isPreferred - true for calculating preferred size, false for calculating minimum size.
Returns:
the dimensions to lay out the subcomponents of the specified container.
See Also:
getLargestCellSize(java.awt.Container, boolean)

getLargestCellSize

protected Dimension getLargestCellSize(Container parent,
                                       boolean isPreferred)
Algorithm for calculating the largest minimum or preferred cell size.

Largest cell size is calculated by getting the applicable size of each component and keeping the maximum value, dividing the component's width by the number of columns it is specified to occupy and dividing the component's height by the number of rows it is specified to occupy.

Parameters:
parent - the container in which to do the layout.
isPreferred - true for calculating preferred size, false for calculating minimum size.
Returns:
the largest cell size required.

layoutContainer

public void layoutContainer(Container parent)
Lays out the container in the specified container.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
parent - the component which needs to be laid out

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Adds the specified component to the layout, using the specified constraint object.

Specified by:
addLayoutComponent in interface LayoutManager2
Parameters:
comp - the component to be added
constraints - where/how the component is added to the layout.

maximumLayoutSize

public Dimension maximumLayoutSize(Container target)
Returns the maximum size of this component.

Specified by:
maximumLayoutSize in interface LayoutManager2
Parameters:
target -
Returns:
_more_
See Also:
Component.getMinimumSize(), Component.getPreferredSize(), LayoutManager

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Specified by:
getLayoutAlignmentX in interface LayoutManager2
Parameters:
target -
Returns:
_more_

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Specified by:
getLayoutAlignmentY in interface LayoutManager2
Parameters:
target -
Returns:
_more_

invalidateLayout

public void invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout in interface LayoutManager2
Parameters:
target -

getDimensions

public static Dimension getDimensions(List locations)
_more_

Parameters:
locations - _more_
Returns:
_more_

layout

public static JComponent layout(List locations)
_more_

Parameters:
locations - _more_
Returns:
_more_

showDialog

public static void showDialog(List locations,
                              String title)
_more_

Parameters:
locations - _more_
title - _more_

main

public static void main(String[] args)
_more_

Parameters:
args - _more_