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:
- Button1, Button2, Button3:
weightx=1.0
- Button4:
weightx=1.0,
gridwidth=GadgetGridBagConstraints.REMAINDER
- Button5:
gridwidth=GadgetGridBagConstraints.REMAINDER
- Button6:
gridwidth=GadgetGridBagConstraints.RELATIVE
- Button7:
gridwidth=GadgetGridBagConstraints.REMAINDER
- Button8:
gridheight=2, weighty=1.0,
- Button9, Button 10:
gridwidth=GadgetGridBagConstraints.REMAINDER
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 );;
}
}
-
columnWeights
-
-
columnWidths
-
-
defaultConstraints
-
-
gadgettable
-
-
layoutInfo
-
-
MAXGRIDSIZE
-
-
MINSIZE
-
-
PREFERREDSIZE
-
-
rowHeights
-
-
rowWeights
-
-
GadgetGridBagLayout()
- Creates a gridbag layout.
-
addLayoutGadget(String, Gadget)
- Adds the specified gadget with the specified name to the layout.
-
AdjustForGravity(GadgetGridBagConstraints, Rectangle)
-
-
ArrangeGadgetGrid(ContainerGadget)
-
-
childrenCanOverlap()
- returns true if children can overlap each other.
-
getConstraints(Gadget)
- Retrieves the constraints for the specified gadget.
-
getLayoutDimensions()
- gets the layout dimensions
-
GetLayoutInfo(ContainerGadget, int)
- Gets the layout information
-
getLayoutOrigin()
- getLayoutOrigin
-
getLayoutWeights()
- getLayoutWeights
-
GetMinSize(ContainerGadget, GadgetGridBagLayoutInfo)
-
-
getUseMinimum()
-
-
layoutContainerGadget(ContainerGadget)
- Lays out the container in the specified panel.
-
location(int, int)
- location
-
lookupConstraints(Gadget)
- Retrieves the constraints for the specified gadget.
-
minimumLayoutSize(ContainerGadget)
- Returns the minimum dimensions needed to layout the gadgets
contained in the specified panel.
-
preferredLayoutSize(ContainerGadget)
- Returns the preferred dimensions for this layout given the gadgets
in the specified panel.
-
removeLayoutGadget(Gadget)
- Removes the specified gadget from the layout.
-
setConstraints(Gadget, GadgetGridBagConstraints)
- Sets the constraints for the specified gadget.
-
setUseMinimum(boolean)
-
-
toString()
- Returns the String representation of this GadgetGridLayout's values.
MAXGRIDSIZE
protected static final int MAXGRIDSIZE
MINSIZE
protected static final int MINSIZE
PREFERREDSIZE
protected static final int PREFERREDSIZE
gadgettable
protected Hashtable gadgettable
defaultConstraints
protected GadgetGridBagConstraints defaultConstraints
layoutInfo
protected GadgetGridBagLayoutInfo layoutInfo
columnWidths
public int columnWidths[]
rowHeights
public int rowHeights[]
columnWeights
public double columnWeights[]
rowWeights
public double rowWeights[]
GadgetGridBagLayout
public GadgetGridBagLayout()
- Creates a gridbag layout.
setUseMinimum
public void setUseMinimum(boolean useMinimum)
getUseMinimum
public boolean getUseMinimum()
childrenCanOverlap
public boolean childrenCanOverlap()
- returns true if children can overlap each other.
- Returns:
- false
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
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
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
getLayoutOrigin
public Point getLayoutOrigin()
- getLayoutOrigin
- Returns:
- Point
getLayoutDimensions
public int[][] getLayoutDimensions()
- gets the layout dimensions
- Returns:
- int [][]
getLayoutWeights
public double[][] getLayoutWeights()
- getLayoutWeights
- Returns:
- double [][]
location
public Point location(int x,
int y)
- location
- Parameters:
- x - - TBD
- y - - TBD
- Returns:
- Point
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
removeLayoutGadget
public void removeLayoutGadget(Gadget gadget)
- Removes the specified gadget from the layout. Does not apply.
- Parameters:
- gadget - the gadget to be removed
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
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
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
toString
public String toString()
- Returns the String representation of this GadgetGridLayout's values.
- Returns:
- String
- Overrides:
- toString in class Object
GetLayoutInfo
protected GadgetGridBagLayoutInfo GetLayoutInfo(ContainerGadget parent,
int sizeflag)
- Gets the layout information
- Parameters:
- parent - - TBD
- sizeflag - - TBD
- Returns:
- GadgetGridBagLayoutInfo
AdjustForGravity
protected void AdjustForGravity(GadgetGridBagConstraints constraints,
Rectangle r)
GetMinSize
protected Dimension GetMinSize(ContainerGadget parent,
GadgetGridBagLayoutInfo info)
ArrangeGadgetGrid
protected void ArrangeGadgetGrid(ContainerGadget parent)
All Packages Class Hierarchy This Package Previous Next Index