jas2.util.layout
Class PnutsLayout
- java.lang.Object
-
- jas2.util.layout.PnutsLayout
-
- All Implemented Interfaces:
- java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable
public class PnutsLayout extends java.lang.Object implements java.awt.LayoutManager2, java.io.SerializableThe 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" "" - See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intBOTTOMstatic intCENTERstatic intH_FITstatic intLEFTstatic intRIGHTstatic intTOPstatic intV_FIT
-
Constructor Summary
Constructors Constructor and Description PnutsLayout()construct a PnutsLayoutPnutsLayout(int cols)construct a PnutsLayout with specified number of columnsPnutsLayout(int cols, int padx, int pady)construct a PnutsLayoutPnutsLayout(java.lang.String str)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddLayoutComponent(java.awt.Component comp, java.lang.Object obj)Adds the specified component to the layout, using the specified constraint object.voidaddLayoutComponent(java.lang.String name, java.awt.Component comp)Adds the specified component with the specified name to the layout.intgetCols()Get the number of columnsintgetColspan(java.awt.Component comp)java.util.HashtablegetConstraints(java.awt.Component comp)get a Hashtable of constraint for the specified componentjava.lang.StringgetConstraintString(java.awt.Component comp)get a string representaion of constraint for the specified componentjava.lang.StringgetExpand(java.awt.Component comp)java.awt.PointgetGridPoint(java.awt.Container target, int x, int y)get left-top point of the component(x,y)java.awt.RectanglegetGridRectangle(java.awt.Container target, int idx)get bounding-box for idx'th componentjava.lang.StringgetHAlign(java.awt.Component comp)intgetIPadX(java.awt.Component comp)intgetIPadY(java.awt.Component comp)floatgetLayoutAlignmentX(java.awt.Container target)Returns the alignment along the x axis.floatgetLayoutAlignmentY(java.awt.Container target)Returns the alignment along the y axis.intgetPadX(java.awt.Component comp)intgetPadY(java.awt.Component comp)intgetRows()get the number of rowsintgetRowspan(java.awt.Component comp)boolean[]getUniform()get "uniform" propertyjava.lang.StringgetVAlign(java.awt.Component comp)voidinvalidateLayout(java.awt.Container target)Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.voidlayoutContainer(java.awt.Container target)Lays out the container.java.awt.DimensionmaximumLayoutSize(java.awt.Container target)Returns the maximum size of this component.java.awt.DimensionminimumLayoutSize(java.awt.Container target)Returns the minimum dimensions needed to layout the components contained in the specified target container.java.awt.DimensionpreferredLayoutSize(java.awt.Container target)Returns the preferred dimensions for this layout given the components in the specified target container.voidremoveLayoutComponent(java.awt.Component comp)Removes the specified component from the layout.voidsetCols(int cols)Set the number of columnsvoidsetColspan(java.awt.Component comp, int colspan)voidsetConstraints(java.awt.Component comp, java.util.Hashtable table)Specify layout constraints with HashtablevoidsetConstraints(java.awt.Component comp, java.lang.String str)Specify layout constraints with comma-separated list of "= ". voidsetExpand(java.awt.Component comp, java.lang.String ex)voidsetHAlign(java.awt.Component comp, java.lang.String s)voidsetIPadding(java.awt.Component comp, int x, int y)voidsetPadding(java.awt.Component comp, int x, int y)voidsetRowspan(java.awt.Component comp, int rowspan)voidsetUniform(boolean x, boolean y)set "uniform" propertyvoidsetVAlign(java.awt.Component comp, java.lang.String s)java.lang.StringtoString()
-
-
-
Field Detail
-
CENTER
public static final int CENTER
- See Also:
- Constant Field Values
-
TOP
public static final int TOP
- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOM
- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
- See Also:
- Constant Field Values
-
V_FIT
public static final int V_FIT
- See Also:
- Constant Field Values
-
H_FIT
public static final int H_FIT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 columnspadx- default external paddingpady- default external padding
-
PnutsLayout
public PnutsLayout(java.lang.String str)
-
-
Method Detail
-
addLayoutComponent
public void addLayoutComponent(java.awt.Component comp, java.lang.Object obj)Adds the specified component to the layout, using the specified constraint object.- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager2- 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(java.awt.Component comp, java.lang.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 componentstr- a string that describes how the component is added to the layout.
-
setConstraints
public void setConstraints(java.awt.Component comp, java.util.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 java.lang.String getConstraintString(java.awt.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 java.util.Hashtable getConstraints(java.awt.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(java.lang.String name, java.awt.Component comp)Adds the specified component with the specified name to the layout.- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager- Parameters:
name- the component namecomp- the component to be added
-
removeLayoutComponent
public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout.- Specified by:
removeLayoutComponentin interfacejava.awt.LayoutManager- Parameters:
comp- the component ot be removed
-
maximumLayoutSize
public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum size of this component.- Specified by:
maximumLayoutSizein interfacejava.awt.LayoutManager2- See Also:
Component.getMinimumSize(),Component.getPreferredSize(),LayoutManager
-
getLayoutAlignmentX
public float getLayoutAlignmentX(java.awt.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.- Specified by:
getLayoutAlignmentXin interfacejava.awt.LayoutManager2
-
getLayoutAlignmentY
public float getLayoutAlignmentY(java.awt.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.- Specified by:
getLayoutAlignmentYin interfacejava.awt.LayoutManager2
-
invalidateLayout
public void invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.- Specified by:
invalidateLayoutin interfacejava.awt.LayoutManager2- 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 directiony- uniform property for vertical direction
-
getUniform
public boolean[] getUniform()
get "uniform" property- Returns:
- boolean array of "uniform property"
-
setColspan
public void setColspan(java.awt.Component comp, int colspan)- Parameters:
comp- the component of which you want to change colspancolspan- the number of columns the component occupies
-
getColspan
public int getColspan(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get colspan- Returns:
- the value of "colspan" property
-
setRowspan
public void setRowspan(java.awt.Component comp, int rowspan)- Parameters:
comp- the component of which you want to change rowspanrowspan- the number of rows the component occupies
-
getRowspan
public int getRowspan(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get rowspan- Returns:
- the value of "rowspan" property
-
setHAlign
public void setHAlign(java.awt.Component comp, java.lang.String s)- Parameters:
comp- the component of which you want to change alignmentalign- "left", "right", "fill", "center"
-
setVAlign
public void setVAlign(java.awt.Component comp, java.lang.String s)- Parameters:
comp- the component of which you want to change alignmentalign- "top", "bottom", "fill", "center"
-
getHAlign
public java.lang.String getHAlign(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get alignment- Returns:
- "fill" | "left" | "right" | "center"
-
getVAlign
public java.lang.String getVAlign(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get alignment- Returns:
- "fill" | "top" | "bottom" | "center"
-
setExpand
public void setExpand(java.awt.Component comp, java.lang.String ex)- Parameters:
comp- the component of which you want to set "expand"
-
getExpand
public java.lang.String getExpand(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get "expand"- Returns:
- "x" | "y" | "xy" | ""
-
setPadding
public void setPadding(java.awt.Component comp, int x, int y)- Parameters:
comp- the component of which you want to change alignmentx- "padx" propertyy- "pady" property
-
getPadX
public int getPadX(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get "padx"- Returns:
- the value of "padx" property
-
getPadY
public int getPadY(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get "pady"- Returns:
- the value of "pady" property
-
setIPadding
public void setIPadding(java.awt.Component comp, int x, int y)- Parameters:
comp- the component of which you want to change alignmentx- "ipadx" propertyy- "ipady" property
-
getIPadX
public int getIPadX(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get "ipadx"- Returns:
- the value of "ipadx" property
-
getIPadY
public int getIPadY(java.awt.Component comp)
- Parameters:
comp- the component of which you want to get "ipady"- Returns:
- the value of "ipady" property
-
preferredLayoutSize
public java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Returns the preferred dimensions for this layout given the components in the specified target container.- Specified by:
preferredLayoutSizein interfacejava.awt.LayoutManager- Parameters:
target- the component which needs to be laid out- See Also:
Container,minimumLayoutSize(java.awt.Container)
-
minimumLayoutSize
public java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Returns the minimum dimensions needed to layout the components contained in the specified target container.- Specified by:
minimumLayoutSizein interfacejava.awt.LayoutManager- Parameters:
target- the component which needs to be laid out- See Also:
preferredLayoutSize(java.awt.Container)
-
layoutContainer
public void layoutContainer(java.awt.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.- Specified by:
layoutContainerin interfacejava.awt.LayoutManager- 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 java.awt.Point getGridPoint(java.awt.Container target, int x, int y)get left-top point of the component(x,y)- Parameters:
x- the index of columny- the index of row- Returns:
- left-top point of the component
-
getGridRectangle
public java.awt.Rectangle getGridRectangle(java.awt.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- the String representation of this PnutsLayout's values.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG