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");
 
propertythe meaningdefault
colsnumber of columns1
uniformif width and/or height of each columns are all same, "x", "y" or "xy"""
colspannumber of columns the component occupies1
rowspannumber of rows the component occupies1
padxexternal padding (x)0
padyexternal padding (y)0
ipadxinternal padding (x)0
ipadyinternal padding (y)0
halignalignment of x. One of "left", "right", "center", "fill"center
valignalignment of y. One of "top", "bottom", "center", "fill"center
expandexpand as the size of container changes. one of "x", "y", "xy"""


Variable Index

 o align
default align
 o BOTTOM
 o CENTER
 o cols
The number of columns
 o H_FIT
 o ipadx
default ipadx
 o ipady
default ipady
 o LEFT
 o padx
default padx
 o pady
default pady
 o RIGHT
 o rows
The number of rows
 o TOP
 o V_FIT
 o xfix
 o yfix

Constructor Index

 o PnutsLayout()
construct a PnutsLayout
 o PnutsLayout(int)
construct a PnutsLayout with specified number of columns
 o PnutsLayout(int, int, int)
construct a PnutsLayout
 o PnutsLayout(String)

Method Index

 o addLayoutComponent(Component, Object)
Adds the specified component to the layout, using the specified constraint object.
 o addLayoutComponent(String, Component)
Adds the specified component with the specified name to the layout.
 o getCols()
Get the number of columns
 o getColspan(Component)
 o getConstraints(Component)
get a Hashtable of constraint for the specified component
 o getConstraintString(Component)
get a string representaion of constraint for the specified component
 o getExpand(Component)
 o getGridPoint(Container, int, int)
get left-top point of the component(x,y)
 o getGridRectangle(Container, int)
get bounding-box for idx'th component
 o getHAlign(Component)
 o getIPadX(Component)
 o getIPadY(Component)
 o getLayoutAlignmentX(Container)
Returns the alignment along the x axis.
 o getLayoutAlignmentY(Container)
Returns the alignment along the y axis.
 o getPadX(Component)
 o getPadY(Component)
 o getRows()
get the number of rows
 o getRowspan(Component)
 o getUniform()
get "uniform" property
 o getVAlign(Component)
 o invalidateLayout(Container)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 o layoutContainer(Container)
Lays out the container.
 o maximumLayoutSize(Container)
Returns the maximum size of this component.
 o minimumLayoutSize(Container)
Returns the minimum dimensions needed to layout the components contained in the specified target container.
 o preferredLayoutSize(Container)
Returns the preferred dimensions for this layout given the components in the specified target container.
 o removeLayoutComponent(Component)
Removes the specified component from the layout.
 o setCols(int)
Set the number of columns
 o setColspan(Component, int)
 o setConstraints(Component, Hashtable)
Specify layout constraints with Hashtable
 o setConstraints(Component, String)
Specify layout constraints with comma-separated list of "=".
 o setExpand(Component, String)
 o setHAlign(Component, String)
 o setIPadding(Component, int, int)
 o setPadding(Component, int, int)
 o setRowspan(Component, int)
 o setUniform(boolean, boolean)
set "uniform" property
 o setVAlign(Component, String)
 o toString()

Variables

 o CENTER
 public static final int CENTER
 o TOP
 public static final int TOP
 o BOTTOM
 public static final int BOTTOM
 o LEFT
 public static final int LEFT
 o RIGHT
 public static final int RIGHT
 o V_FIT
 public static final int V_FIT
 o H_FIT
 public static final int H_FIT
 o align
 protected int align
default align

 o padx
 protected int padx
default padx

 o pady
 protected int pady
default pady

 o ipadx
 protected int ipadx
default ipadx

 o ipady
 protected int ipady
default ipady

 o cols
 protected int cols
The number of columns

 o rows
 protected int rows
The number of rows

 o xfix
 protected boolean xfix
 o yfix
 protected boolean yfix

Constructors

 o PnutsLayout
 public PnutsLayout()
construct a PnutsLayout

 o PnutsLayout
 public PnutsLayout(int cols)
construct a PnutsLayout with specified number of columns

Parameters:
cols - the number of columns
 o 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
 o PnutsLayout
 public PnutsLayout(String str)

Methods

 o 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});
 o 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.
 o 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.
 o 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
 o 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
 o 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
 o removeLayoutComponent
 public void removeLayoutComponent(Component comp)
Removes the specified component from the layout.

Parameters:
comp - the component ot be removed
 o maximumLayoutSize
 public Dimension maximumLayoutSize(Container target)
Returns the maximum size of this component.

See Also:
getMinimumSize, getPreferredSize, LayoutManager
 o 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.

 o 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.

 o 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
 o setCols
 public void setCols(int cols)
Set the number of columns

Parameters:
cols - the number of columns
 o setUniform
 public void setUniform(boolean x,
                        boolean y)
set "uniform" property

Parameters:
x - uniform property for horizontal direction
y - uniform property for vertical direction
 o getUniform
 public boolean[] getUniform()
get "uniform" property

Returns:
boolean array of "uniform property"
 o 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
 o getColspan
 public int getColspan(Component comp)
Parameters:
comp - the component of which you want to get colspan
Returns:
the value of "colspan" property
 o 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
 o getRowspan
 public int getRowspan(Component comp)
Parameters:
comp - the component of which you want to get rowspan
Returns:
the value of "rowspan" property
 o setHAlign
 public void setHAlign(Component comp,
                       String s)
Parameters:
comp - the component of which you want to change alignment
align - "left", "right", "fill", "center"
 o setVAlign
 public void setVAlign(Component comp,
                       String s)
Parameters:
comp - the component of which you want to change alignment
align - "top", "bottom", "fill", "center"
 o getHAlign
 public String getHAlign(Component comp)
Parameters:
comp - the component of which you want to get alignment
Returns:
"fill" | "left" | "right" | "center"
 o getVAlign
 public String getVAlign(Component comp)
Parameters:
comp - the component of which you want to get alignment
Returns:
"fill" | "top" | "bottom" | "center"
 o setExpand
 public void setExpand(Component comp,
                       String ex)
Parameters:
comp - the component of which you want to set "expand"
 o getExpand
 public String getExpand(Component comp)
Parameters:
comp - the component of which you want to get "expand"
Returns:
"x" | "y" | "xy" | ""
 o 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
 o getPadX
 public int getPadX(Component comp)
Parameters:
comp - the component of which you want to get "padx"
Returns:
the value of "padx" property
 o getPadY
 public int getPadY(Component comp)
Parameters:
comp - the component of which you want to get "pady"
Returns:
the value of "pady" property
 o 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
 o getIPadX
 public int getIPadX(Component comp)
Parameters:
comp - the component of which you want to get "ipadx"
Returns:
the value of "ipadx" property
 o getIPadY
 public int getIPadY(Component comp)
Parameters:
comp - the component of which you want to get "ipady"
Returns:
the value of "ipady" property
 o 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
 o 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
 o 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
 o getCols
 public int getCols()
Get the number of columns

Returns:
the number of columns
 o getRows
 public int getRows()
get the number of rows

Returns:
the number of rows
 o 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
 o 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
 o toString
 public String toString()
Returns:
the String representation of this PnutsLayout's values.

All Packages  Class Hierarchy  This Package  Previous  Next  Index