All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class dtai.gwt.GadgetGridBagLayout

java.lang.Object
   |
   +----dtai.gwt.GadgetGridBagLayout

public class GadgetGridBagLayout
extends Object
implements GadgetLayoutManager
GadgetGridBagLayout is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be the same size. Each GadgetGridBagLayout uses a rectangular grid of cells, with each component occupying one or more cells (called its display area). Each component managed by a GadgetGridBagLayout is associated with a GadgetGridBagConstraints instance that specifies how the component is laid out within its display area. How a GadgetGridBagLayout places a set of components depends on each component's GadgetGridBagConstraints and minimum size, as well as the preferred size of the components' container.

To use a GadgetGridBagLayout effectively, you must customize one or more of its components' GadgetGridBagConstraints. You customize a GadgetGridBagConstraints object by setting one or more of its instance variables:

gridx, gridy
Specifies the cell at the upper left of the component's display area, where the upper-left-most cell has address gridx=0, gridy=0. Use GadgetGridBagConstraints.RELATIVE (the default value) to specify that the component be just placed just to the right of (for gridx) or just below (for gridy) the component that was added to the container just before this component was added.
gridwidth, gridheight
Specifies the number of cells in a row (for gridwidth) or column (for gridheight) in the component's display area. The default value is 1. Use GadgetGridBagConstraints.REMAINDER to specify that the component be the last one in its row (for gridwidth) or column (for gridheight). Use GadgetGridBagConstraints.RELATIVE to specify that the component be the next to last one in its row (for gridwidth) or column (for gridheight).
fill
Used when the component's display area is larger than the component's requested size to determine whether (and how) to resize the component. Valid values are GadgetGridBagConstraint.NONE (the default), GadgetGridBagConstraint.HORIZONTAL (make the component wide enough to fill its display area horizontally, but don't change its height), GadgetGridBagConstraint.VERTICAL (make the component tall enough to fill its display area vertically, but don't change its width), and GadgetGridBagConstraint.BOTH (make the component fill its display area entirely).
ipadx, ipady
Specifies the internal padding: how much to add to the minimum size of the component. The width of the component will be at least its minimum width plus ipadx*2 pixels (since the padding applies to both sides of the component). Similarly, the height of the component will be at least the minimum height plus ipady*2 pixels.
insets
Specifies the external padding of the component -- the minimum amount of space between the component and the edges of its display area.
anchor
Used when the component is smaller than its display area to determine where (within the area) to place the component. Valid values are GadgetGridBagConstraints.CENTER (the default), GadgetGridBagConstraints.NORTH, GadgetGridBagConstraints.NORTHEAST, GadgetGridBagConstraints.EAST, GadgetGridBagConstraints.SOUTHEAST, GadgetGridBagConstraints.SOUTH, GadgetGridBagConstraints.SOUTHWEST, GadgetGridBagConstraints.WEST, and GadgetGridBagConstraints.NORTHWEST.
weightx, weighty
Used to determine how to distribute space; this is important for specifying resizing behavior. Unless you specify a weight for at least one component in a row (weightx) and column (weighty), all the components clump together in the center of their container. This is because when the weight is zero (the default), the GadgetGridBagLayout puts any extra space between its grid of cells and the edges of the container.
The following figure shows ten components (all buttons) managed by a GadgetGridBagLayout:
All the components have fill=GadgetGridBagConstraints.BOTH. In addition, the components have the following non-default constraints: Here is the code that implements the example shown above:
public class GadgetGridBagEx1 extends Applet {
protected void makebutton(String name,
GadgetGridBagLayout gridbag,
GadgetGridBagConstraints c) {
Button button = new Button(name);
gridbag.setConstraints(button, c);
add(button);
}
public void init() {
GadgetGridBagLayout gridbag = new GadgetGridBagLayout();
GadgetGridBagConstraints c = new GadgetGridBagConstraints();
setFont(new Font("Helvetica", Font.PLAIN, 14));
setLayout(gridbag);
c.fill = GadgetGridBagConstraints.BOTH;
c.weightx = 1.0;
makebutton("Button1", gridbag, c);
makebutton("Button2", gridbag, c);
makebutton("Button3", gridbag, c);
c.gridwidth = GadgetGridBagConstraints.REMAINDER; //end row
makebutton("Button4", gridbag, c);
c.weightx = 0.0;		   //reset to the default
makebutton("Button5", gridbag, c); //another row
c.gridwidth = GadgetGridBagConstraints.RELATIVE; //next-to-last in row
makebutton("Button6", gridbag, c);
c.gridwidth = GadgetGridBagConstraints.REMAINDER; //end row
makebutton("Button7", gridbag, c);
c.gridwidth = 1;	   	   //reset to the default
c.gridheight = 2;
c.weighty = 1.0;
makebutton("Button8", gridbag, c);
c.weighty = 0.0;		   //reset to the default
c.gridwidth = GadgetGridBagConstraints.REMAINDER; //end row
c.gridheight = 1;		   //reset to the default
makebutton("Button9", gridbag, c);
makebutton("Button10", gridbag, c);
resize(300, 100);
}
public static void main(String args[]) {
Frame f = new Frame("GadgetGridBag Layout Example");
GadgetGridBagEx1 ex1 = new GadgetGridBagEx1();
ex1.init();
f.add("Center", ex1);
f.pack();
f.resize(f.preferredSize());
f.setVisible( true );;
}
}


Variable Index

 o columnWeights
 o columnWidths
 o defaultConstraints
 o gadgettable
 o layoutInfo
 o MAXGRIDSIZE
 o MINSIZE
 o PREFERREDSIZE
 o rowHeights
 o rowWeights

Constructor Index

 o GadgetGridBagLayout()
Creates a gridbag layout.

Method Index

 o addLayoutGadget(String, Gadget)
Adds the specified gadget with the specified name to the layout.
 o AdjustForGravity(GadgetGridBagConstraints, Rectangle)
 o ArrangeGadgetGrid(ContainerGadget)
 o childrenCanOverlap()
returns true if children can overlap each other.
 o getConstraints(Gadget)
Retrieves the constraints for the specified gadget.
 o getLayoutDimensions()
gets the layout dimensions
 o GetLayoutInfo(ContainerGadget, int)
Gets the layout information
 o getLayoutOrigin()
getLayoutOrigin
 o getLayoutWeights()
getLayoutWeights
 o GetMinSize(ContainerGadget, GadgetGridBagLayoutInfo)
 o getUseMinimum()
 o layoutContainerGadget(ContainerGadget)
Lays out the container in the specified panel.
 o location(int, int)
location
 o lookupConstraints(Gadget)
Retrieves the constraints for the specified gadget.
 o minimumLayoutSize(ContainerGadget)
Returns the minimum dimensions needed to layout the gadgets contained in the specified panel.
 o preferredLayoutSize(ContainerGadget)
Returns the preferred dimensions for this layout given the gadgets in the specified panel.
 o removeLayoutGadget(Gadget)
Removes the specified gadget from the layout.
 o setConstraints(Gadget, GadgetGridBagConstraints)
Sets the constraints for the specified gadget.
 o setUseMinimum(boolean)
 o toString()
Returns the String representation of this GadgetGridLayout's values.

Variables

 o MAXGRIDSIZE
 protected static final int MAXGRIDSIZE
 o MINSIZE
 protected static final int MINSIZE
 o PREFERREDSIZE
 protected static final int PREFERREDSIZE
 o gadgettable
 protected Hashtable gadgettable
 o defaultConstraints
 protected GadgetGridBagConstraints defaultConstraints
 o layoutInfo
 protected GadgetGridBagLayoutInfo layoutInfo
 o columnWidths
 public int columnWidths[]
 o rowHeights
 public int rowHeights[]
 o columnWeights
 public double columnWeights[]
 o rowWeights
 public double rowWeights[]

Constructors

 o GadgetGridBagLayout
 public GadgetGridBagLayout()
Creates a gridbag layout.

Methods

 o setUseMinimum
 public void setUseMinimum(boolean useMinimum)
 o getUseMinimum
 public boolean getUseMinimum()
 o childrenCanOverlap
 public boolean childrenCanOverlap()
returns true if children can overlap each other.

Returns:
false
 o setConstraints
 public void setConstraints(Gadget gadget,
                            GadgetGridBagConstraints constraints)
Sets the constraints for the specified gadget.

Parameters:
gadget - the gadget to be modified
constraints - the constraints to be applied
 o getConstraints
 public GadgetGridBagConstraints getConstraints(Gadget gadget)
Retrieves the constraints for the specified gadget. A copy of the constraints is returned.

Parameters:
gadget - the gadget to be queried
Returns:
GadgetGridBagConstraints
 o lookupConstraints
 protected GadgetGridBagConstraints lookupConstraints(Gadget gadget)
Retrieves the constraints for the specified gadget. The return value is not a copy, but is the actual constraints class used by the layout mechanism.

Parameters:
gadget - the gadget to be queried
constraints - - TBD
Returns:
GadgetGridBagConstraints
 o getLayoutOrigin
 public Point getLayoutOrigin()
getLayoutOrigin

Returns:
Point
 o getLayoutDimensions
 public int[][] getLayoutDimensions()
gets the layout dimensions

Returns:
int [][]
 o getLayoutWeights
 public double[][] getLayoutWeights()
getLayoutWeights

Returns:
double [][]
 o location
 public Point location(int x,
                       int y)
location

Parameters:
x - - TBD
y - - TBD
Returns:
Point
 o addLayoutGadget
 public void addLayoutGadget(String name,
                             Gadget gadget)
Adds the specified gadget with the specified name to the layout.

Parameters:
name - the name of the gadget
gadget - the gadget to be added
 o removeLayoutGadget
 public void removeLayoutGadget(Gadget gadget)
Removes the specified gadget from the layout. Does not apply.

Parameters:
gadget - the gadget to be removed
 o preferredLayoutSize
 public Dimension preferredLayoutSize(ContainerGadget parent)
Returns the preferred dimensions for this layout given the gadgets in the specified panel.

Parameters:
parent - the gadget which needs to be laid out
Returns:
Dimension
See Also:
minimumLayoutSize
 o minimumLayoutSize
 public Dimension minimumLayoutSize(ContainerGadget parent)
Returns the minimum dimensions needed to layout the gadgets contained in the specified panel.

Parameters:
parent - the gadget which needs to be laid out
Returns:
Dimension
See Also:
preferredLayoutSize
 o layoutContainerGadget
 public void layoutContainerGadget(ContainerGadget parent)
Lays out the container in the specified panel.

Parameters:
parent - the specified gadget being laid out
See Also:
ContainerGadget
 o toString
 public String toString()
Returns the String representation of this GadgetGridLayout's values.

Returns:
String
Overrides:
toString in class Object
 o GetLayoutInfo
 protected GadgetGridBagLayoutInfo GetLayoutInfo(ContainerGadget parent,
                                                 int sizeflag)
Gets the layout information

Parameters:
parent - - TBD
sizeflag - - TBD
Returns:
GadgetGridBagLayoutInfo
 o AdjustForGravity
 protected void AdjustForGravity(GadgetGridBagConstraints constraints,
                                 Rectangle r)
 o GetMinSize
 protected Dimension GetMinSize(ContainerGadget parent,
                                GadgetGridBagLayoutInfo info)
 o ArrangeGadgetGrid
 protected void ArrangeGadgetGrid(ContainerGadget parent)

All Packages  Class Hierarchy  This Package  Previous  Next  Index