All Packages Class Hierarchy This Package Previous Next Index
Class pnuts.awt.PnutsLayout
pnuts.awt.PnutsLayout
- public class PnutsLayout
The PnutsLayout is a general purpose geometry manager.
It is more user-friendly than any LayoutManager out there
and as flexible as GridBagLayout.
e.g.
setLayout(new PnutsLayout("cols = 3"));
add(button1, "ipadx = 20, ipady = 20");
add(button2, "padx = 20, pady = 20");
add(button3, "colspan = 2");
add(button4, "rowspan = 2");
add(button3, "halign = left, valign = top");
add(button3, "halign = right, valign = bottom");
add(button3, "halign = center, valign = fill");
property | the meaning | default |
cols | number of columns | 1 |
uniform | if width and/or height of each columns are all same, "x", "y" or "xy" | "" |
colspan | number of columns the component occupies | 1 |
rowspan | number of rows the component occupies | 1 |
padx | external padding (x) | 0 |
pady | external padding (y) | 0 |
ipadx | internal padding (x) | 0 |
ipady | internal padding (y) | 0 |
halign | alignment of x. One of "left", "right", "center", "fill" | center |
valign | alignment of y. One of "top", "bottom", "center", "fill" | center |
expand | expand as the size of container changes. one of "x", "y", "xy" | "" |
-
align
- default align
-
BOTTOM
-
-
CENTER
-
-
cols
- The number of columns
-
H_FIT
-
-
ipadx
- default ipadx
-
ipady
- default ipady
-
LEFT
-
-
padx
- default padx
-
pady
- default pady
-
RIGHT
-
-
rows
- The number of rows
-
TOP
-
-
V_FIT
-
-
xfix
-
-
yfix
-
-
PnutsLayout()
- construct a PnutsLayout
-
PnutsLayout(int)
- construct a PnutsLayout with specified number of columns
-
PnutsLayout(int, int, int)
- construct a PnutsLayout
-
PnutsLayout(String)
-
-
addLayoutComponent(Component, Object)
- Adds the specified component to the layout, using the specified
constraint object.
-
addLayoutComponent(String, Component)
- Adds the specified component with the specified name to
the layout.
-
getCols()
- Get the number of columns
-
getColspan(Component)
-
-
getConstraints(Component)
- get a Hashtable of constraint for the specified component
-
getConstraintString(Component)
- get a string representaion of constraint for the
specified component
-
getExpand(Component)
-
-
getGridPoint(Container, int, int)
- get left-top point of the component(x,y)
-
getGridRectangle(Container, int)
- get bounding-box for idx'th component
-
getHAlign(Component)
-
-
getIPadX(Component)
-
-
getIPadY(Component)
-
-
getLayoutAlignmentX(Container)
- Returns the alignment along the x axis.
-
getLayoutAlignmentY(Container)
- Returns the alignment along the y axis.
-
getPadX(Component)
-
-
getPadY(Component)
-
-
getRows()
- get the number of rows
-
getRowspan(Component)
-
-
getUniform()
- get "uniform" property
-
getVAlign(Component)
-
-
invalidateLayout(Container)
- Invalidates the layout, indicating that if the layout manager
has cached information it should be discarded.
-
layoutContainer(Container)
- Lays out the container.
-
maximumLayoutSize(Container)
-
Returns the maximum size of this component.
-
minimumLayoutSize(Container)
- Returns the minimum dimensions needed to layout the components
contained in the specified target container.
-
preferredLayoutSize(Container)
- Returns the preferred dimensions for this layout given the components
in the specified target container.
-
removeLayoutComponent(Component)
- Removes the specified component from the layout.
-
setCols(int)
- Set the number of columns
-
setColspan(Component, int)
-
-
setConstraints(Component, Hashtable)
- Specify layout constraints with Hashtable
-
setConstraints(Component, String)
- Specify layout constraints with comma-separated list of
"=".
-
setExpand(Component, String)
-
-
setHAlign(Component, String)
-
-
setIPadding(Component, int, int)
-
-
setPadding(Component, int, int)
-
-
setRowspan(Component, int)
-
-
setUniform(boolean, boolean)
- set "uniform" property
-
setVAlign(Component, String)
-
-
toString()
-
CENTER
public static final int CENTER
TOP
public static final int TOP
BOTTOM
public static final int BOTTOM
LEFT
public static final int LEFT
RIGHT
public static final int RIGHT
V_FIT
public static final int V_FIT
H_FIT
public static final int H_FIT
align
protected int align
- default align
padx
protected int padx
- default padx
pady
protected int pady
- default pady
ipadx
protected int ipadx
- default ipadx
ipady
protected int ipady
- default ipady
cols
protected int cols
- The number of columns
rows
protected int rows
- The number of rows
xfix
protected boolean xfix
yfix
protected boolean yfix
PnutsLayout
public PnutsLayout()
- construct a PnutsLayout
PnutsLayout
public PnutsLayout(int cols)
- construct a PnutsLayout with specified number of columns
- Parameters:
- cols - the number of columns
PnutsLayout
public PnutsLayout(int cols,
int padx,
int pady)
- construct a PnutsLayout
- Parameters:
- cols - the number of columns
- padx - default external padding
- pady - default external padding
PnutsLayout
public PnutsLayout(String str)
addLayoutComponent
public void addLayoutComponent(Component comp,
Object obj)
- Adds the specified component to the layout, using the specified
constraint object.
- Parameters:
- comp - the component to be added.
- obj - an object that determines how
the component is added to the layout.
Usage:
container.add(component, new Object[]{align, colspan, rowspan});
setConstraints
public void setConstraints(Component comp,
String str)
- Specify layout constraints with comma-separated list of
"=".
halign ::= left | right | center | fill
valign ::= top | bottom | center | fill
expand ::= x | y | xy
- Parameters:
- comp - the component
- str - a string that describes how
the component is added to the layout.
setConstraints
public void setConstraints(Component comp,
Hashtable table)
- Specify layout constraints with Hashtable
- Parameters:
- comp - the component to be set the constraint.
- table - a Hashtable that describes how
the component is added to the layout.
getConstraintString
public String getConstraintString(Component comp)
- get a string representaion of constraint for the
specified component
- Parameters:
- comp - the component to be investigate
- Returns:
- string representaion of the constraint
getConstraints
public Hashtable getConstraints(Component comp)
- get a Hashtable of constraint for the specified component
- Parameters:
- comp - the component to be investigate
- Returns:
- the constraints as Hashtable
addLayoutComponent
public void addLayoutComponent(String name,
Component comp)
- Adds the specified component with the specified name to
the layout.
- Parameters:
- name - the component name
- comp - the component to be added
removeLayoutComponent
public void removeLayoutComponent(Component comp)
- Removes the specified component from the layout.
- Parameters:
- comp - the component ot be removed
maximumLayoutSize
public Dimension maximumLayoutSize(Container target)
- Returns the maximum size of this component.
- See Also:
- getMinimumSize, 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.
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.
invalidateLayout
public void invalidateLayout(Container target)
- Invalidates the layout, indicating that if the layout manager
has cached information it should be discarded.
- Parameters:
- target - container to invalidate the layout
setCols
public void setCols(int cols)
- Set the number of columns
- Parameters:
- cols - the number of columns
setUniform
public void setUniform(boolean x,
boolean y)
- set "uniform" property
- Parameters:
- x - uniform property for horizontal direction
- y - uniform property for vertical direction
getUniform
public boolean[] getUniform()
- get "uniform" property
- Returns:
- boolean array of "uniform property"
setColspan
public void setColspan(Component comp,
int colspan)
- Parameters:
- comp - the component of which you want to change colspan
- colspan - the number of columns the component occupies
getColspan
public int getColspan(Component comp)
- Parameters:
- comp - the component of which you want to get colspan
- Returns:
- the value of "colspan" property
setRowspan
public void setRowspan(Component comp,
int rowspan)
- Parameters:
- comp - the component of which you want to change rowspan
- rowspan - the number of rows the component occupies
getRowspan
public int getRowspan(Component comp)
- Parameters:
- comp - the component of which you want to get rowspan
- Returns:
- the value of "rowspan" property
setHAlign
public void setHAlign(Component comp,
String s)
- Parameters:
- comp - the component of which you want to change alignment
- align - "left", "right", "fill", "center"
setVAlign
public void setVAlign(Component comp,
String s)
- Parameters:
- comp - the component of which you want to change alignment
- align - "top", "bottom", "fill", "center"
getHAlign
public String getHAlign(Component comp)
- Parameters:
- comp - the component of which you want to get alignment
- Returns:
- "fill" | "left" | "right" | "center"
getVAlign
public String getVAlign(Component comp)
- Parameters:
- comp - the component of which you want to get alignment
- Returns:
- "fill" | "top" | "bottom" | "center"
setExpand
public void setExpand(Component comp,
String ex)
- Parameters:
- comp - the component of which you want to set "expand"
getExpand
public String getExpand(Component comp)
- Parameters:
- comp - the component of which you want to get "expand"
- Returns:
- "x" | "y" | "xy" | ""
setPadding
public void setPadding(Component comp,
int x,
int y)
- Parameters:
- comp - the component of which you want to change alignment
- x - "padx" property
- y - "pady" property
getPadX
public int getPadX(Component comp)
- Parameters:
- comp - the component of which you want to get "padx"
- Returns:
- the value of "padx" property
getPadY
public int getPadY(Component comp)
- Parameters:
- comp - the component of which you want to get "pady"
- Returns:
- the value of "pady" property
setIPadding
public void setIPadding(Component comp,
int x,
int y)
- Parameters:
- comp - the component of which you want to change alignment
- x - "ipadx" property
- y - "ipady" property
getIPadX
public int getIPadX(Component comp)
- Parameters:
- comp - the component of which you want to get "ipadx"
- Returns:
- the value of "ipadx" property
getIPadY
public int getIPadY(Component comp)
- Parameters:
- comp - the component of which you want to get "ipady"
- Returns:
- the value of "ipady" property
preferredLayoutSize
public Dimension preferredLayoutSize(Container target)
- Returns the preferred dimensions for this layout given the components
in the specified target container.
- Parameters:
- target - the component which needs to be laid out
- See Also:
- Container, minimumLayoutSize
minimumLayoutSize
public Dimension minimumLayoutSize(Container target)
- Returns the minimum dimensions needed to layout the components
contained in the specified target container.
- Parameters:
- target - the component which needs to be laid out
- See Also:
- preferredLayoutSize
layoutContainer
public void layoutContainer(Container target)
- Lays out the container. This method will actually reshape the
components in the target in order to satisfy the constraints of
the BorderLayout object.
- Parameters:
- target - the specified component being laid out.
- See Also:
- Container
getCols
public int getCols()
- Get the number of columns
- Returns:
- the number of columns
getRows
public int getRows()
- get the number of rows
- Returns:
- the number of rows
getGridPoint
public Point getGridPoint(Container target,
int x,
int y)
- get left-top point of the component(x,y)
- Parameters:
- x - the index of column
- y - the index of row
- Returns:
- left-top point of the component
getGridRectangle
public Rectangle getGridRectangle(Container target,
int idx)
- get bounding-box for idx'th component
- Parameters:
- idx - the index of the component
- Returns:
- bounding-box as Rectangle object
toString
public String toString()
- Returns:
- the String representation of this PnutsLayout's values.
All Packages Class Hierarchy This Package Previous Next Index