|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjas.util.layout.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" | "" |
| Field Summary | |
|---|---|
protected int |
align
default align |
static int |
BOTTOM
|
static int |
CENTER
|
protected int |
cols
The number of columns |
static int |
H_FIT
|
protected int |
ipadx
default ipadx |
protected int |
ipady
default ipady |
static int |
LEFT
|
protected int |
padx
default padx |
protected int |
pady
default pady |
static int |
RIGHT
|
protected int |
rows
The number of rows |
static int |
TOP
|
static int |
V_FIT
|
protected boolean |
xfix
|
protected boolean |
yfix
|
| Constructor Summary | |
|---|---|
PnutsLayout()
construct a PnutsLayout |
|
PnutsLayout(int cols)
construct a PnutsLayout with specified number of columns |
|
PnutsLayout(int cols,
int padx,
int pady)
construct a PnutsLayout |
|
PnutsLayout(String str)
|
|
| Method Summary | |
|---|---|
void |
addLayoutComponent(Component comp,
Object obj)
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. |
int |
getCols()
Get the number of columns |
int |
getColspan(Component comp)
|
Hashtable |
getConstraints(Component comp)
get a Hashtable of constraint for the specified component |
String |
getConstraintString(Component comp)
get a string representaion of constraint for the specified component |
String |
getExpand(Component comp)
|
Point |
getGridPoint(Container target,
int x,
int y)
get left-top point of the component(x,y) |
Rectangle |
getGridRectangle(Container target,
int idx)
get bounding-box for idx'th component |
String |
getHAlign(Component comp)
|
int |
getIPadX(Component comp)
|
int |
getIPadY(Component comp)
|
float |
getLayoutAlignmentX(Container target)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. |
int |
getPadX(Component comp)
|
int |
getPadY(Component comp)
|
int |
getRows()
get the number of rows |
int |
getRowspan(Component comp)
|
boolean[] |
getUniform()
get "uniform" property |
String |
getVAlign(Component comp)
|
void |
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
void |
layoutContainer(Container target)
Lays out the container. |
Dimension |
maximumLayoutSize(Container target)
Returns the maximum size of this component. |
Dimension |
minimumLayoutSize(Container target)
Returns the minimum dimensions needed to layout the components contained in the specified target container. |
Dimension |
preferredLayoutSize(Container target)
Returns the preferred dimensions for this layout given the components in the specified target container. |
void |
removeLayoutComponent(Component comp)
Removes the specified component from the layout. |
void |
setCols(int cols)
Set the number of columns |
void |
setColspan(Component comp,
int colspan)
|
void |
setConstraints(Component comp,
Hashtable table)
Specify layout constraints with Hashtable |
void |
setConstraints(Component comp,
String str)
Specify layout constraints with comma-separated list of " |
void |
setExpand(Component comp,
String ex)
|
void |
setHAlign(Component comp,
String s)
|
void |
setIPadding(Component comp,
int x,
int y)
|
void |
setPadding(Component comp,
int x,
int y)
|
void |
setRowspan(Component comp,
int rowspan)
|
void |
setUniform(boolean x,
boolean y)
set "uniform" property |
void |
setVAlign(Component comp,
String s)
|
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int CENTER
public static final int TOP
public static final int BOTTOM
public static final int LEFT
public static final int RIGHT
public static final int V_FIT
public static final int H_FIT
protected int align
protected int padx
protected int pady
protected int ipadx
protected int ipady
protected int cols
protected int rows
protected boolean xfix
protected boolean yfix
| Constructor Detail |
|---|
public PnutsLayout()
public PnutsLayout(int cols)
cols - the number of columns
public PnutsLayout(int cols,
int padx,
int pady)
cols - the number of columnspadx - default external paddingpady - default external paddingpublic PnutsLayout(String str)
| Method Detail |
|---|
public void addLayoutComponent(Component comp,
Object obj)
addLayoutComponent in interface LayoutManager2comp - 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});
public void setConstraints(Component comp,
String str)
comp - the componentstr - a string that describes how
the component is added to the layout.
public void setConstraints(Component comp,
Hashtable table)
comp - the component to be set the constraint.table - a Hashtable that describes how
the component is added to the layout.public String getConstraintString(Component comp)
comp - the component to be investigate
public Hashtable getConstraints(Component comp)
comp - the component to be investigate
public void addLayoutComponent(String name,
Component comp)
addLayoutComponent in interface LayoutManagername - the component namecomp - the component to be addedpublic void removeLayoutComponent(Component comp)
removeLayoutComponent in interface LayoutManagercomp - the component ot be removedpublic Dimension maximumLayoutSize(Container target)
maximumLayoutSize in interface LayoutManager2Component.getMinimumSize(),
Component.getPreferredSize(),
LayoutManagerpublic float getLayoutAlignmentX(Container target)
getLayoutAlignmentX in interface LayoutManager2public float getLayoutAlignmentY(Container target)
getLayoutAlignmentY in interface LayoutManager2public void invalidateLayout(Container target)
invalidateLayout in interface LayoutManager2target - container to invalidate the layoutpublic void setCols(int cols)
cols - the number of columns
public void setUniform(boolean x,
boolean y)
x - uniform property for horizontal directiony - uniform property for vertical directionpublic boolean[] getUniform()
public void setColspan(Component comp,
int colspan)
comp - the component of which you want to change colspancolspan - the number of columns the component occupiespublic int getColspan(Component comp)
comp - the component of which you want to get colspan
public void setRowspan(Component comp,
int rowspan)
comp - the component of which you want to change rowspanrowspan - the number of rows the component occupiespublic int getRowspan(Component comp)
comp - the component of which you want to get rowspan
public void setHAlign(Component comp,
String s)
comp - the component of which you want to change alignmentalign - "left", "right", "fill", "center"
public void setVAlign(Component comp,
String s)
comp - the component of which you want to change alignmentalign - "top", "bottom", "fill", "center"public String getHAlign(Component comp)
comp - the component of which you want to get alignment
public String getVAlign(Component comp)
comp - the component of which you want to get alignment
public void setExpand(Component comp,
String ex)
comp - the component of which you want to set "expand"public String getExpand(Component comp)
comp - the component of which you want to get "expand"
public void setPadding(Component comp,
int x,
int y)
comp - the component of which you want to change alignmentx - "padx" propertyy - "pady" propertypublic int getPadX(Component comp)
comp - the component of which you want to get "padx"
public int getPadY(Component comp)
comp - the component of which you want to get "pady"
public void setIPadding(Component comp,
int x,
int y)
comp - the component of which you want to change alignmentx - "ipadx" propertyy - "ipady" propertypublic int getIPadX(Component comp)
comp - the component of which you want to get "ipadx"
public int getIPadY(Component comp)
comp - the component of which you want to get "ipady"
public Dimension preferredLayoutSize(Container target)
preferredLayoutSize in interface LayoutManagertarget - the component which needs to be laid outContainer,
minimumLayoutSize(java.awt.Container)public Dimension minimumLayoutSize(Container target)
minimumLayoutSize in interface LayoutManagertarget - the component which needs to be laid outpreferredLayoutSize(java.awt.Container)public void layoutContainer(Container target)
layoutContainer in interface LayoutManagertarget - the specified component being laid out.Containerpublic int getCols()
public int getRows()
public Point getGridPoint(Container target,
int x,
int y)
x - the index of columny - the index of row
public Rectangle getGridRectangle(Container target,
int idx)
idx - the index of the component
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||