|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ise.java.awt.KappaLayout
public class KappaLayout
KappaLayout, a Java layout manager.
Copyright (C) 2000, Dale Anson
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
KappaLayout -- similar to others, but this one's simpler and easier to use.
Example use:
This will put a button on a panel in the top of its cell, stretched to
fill the cell width, with a 3 pixel pad:
Panel p = new Panel(new KappaLayout());
Button b = new Button("OK");
p.add(b, "0, 0, 1, 2, 2, w, 3");
The constraints string has this layout:
"x, y, w, h, a, s, p"
defined as follows:
By popular request, the alignment constraint can also be represented as:
NW N NE
W 0 E
SW S SE
which are compass directions for alignment within the cell.
p.add(new Button("OK), "1,4,,,w,");
p.add(new Button("OK), "1,4,,,w,");
p.add(new Button("OK), " 1, 4, , , w");
Rather than use a constraints string, a Constraints object may be used
directly, similar to how GridBag uses a GridBagConstraint. E.g,
Panel p = new Panel();
KappaLayout tl = new KappaLayout();
p.setLayout(tl);
KappaLayout.Constraints con = tl.getConstraint();
con.x = 1;
con.y = 2;
con.w = 2;
con.h = 2;
con.s = "wh";
panel.add(new Button("OK"), con);
con.x = 3;
panel.add(new Button("Cancel"), con);
Note that the same Constraints can be reused, thereby reducing the number of
objects created.
Nested Class Summary | |
---|---|
static class |
KappaLayout.Constraints
This class is cloneable so that users may create and reuse a Constraints object similar to how one would use a GridBagConstraints rather than the string parameters. |
static class |
KappaLayout.Strut
Simple component that is invisible. |
Field Summary | |
---|---|
protected java.awt.Dimension |
_0dim
|
protected int |
_col_count
|
protected int[] |
_col_widths
|
protected java.util.Hashtable |
_components
|
protected java.util.Hashtable |
_constraints
|
protected int |
_preferred_height
|
protected int |
_preferred_width
|
protected int |
_row_count
|
protected int[] |
_row_heights
|
protected java.util.Vector |
_same_height_rows
|
protected java.util.Vector |
_same_width_cols
|
protected boolean |
_size_unknown
|
protected boolean |
_stretch
|
protected java.util.Hashtable |
_table
|
static int |
E
For alignment constraint (a), align component to East in cell. |
static int |
N
For alignment constraint (a), align component to North in cell. |
static int |
NE
For alignment constraint (a), align component to NorthEast in cell. |
static int |
NW
For alignment constraint (a), align component to NorthWest in cell. |
static int |
R
Convenience setting for width (w) or height (h), causes component to use Remaining cells. |
static int |
S
For alignment constraint (a), align component to South in cell. |
static int |
SE
For alignment constraint (a), align component to SouthEast in cell. |
static int |
SW
For alignment constraint (a), align component to SouthWest in cell. |
static int |
W
For alignment constraint (a), align component to West in cell. |
Constructor Summary | |
---|---|
KappaLayout()
Default constructor, no stretching. |
|
KappaLayout(boolean s)
Constructor, allows stretching. |
Method Summary | |
---|---|
void |
addLayoutComponent(java.awt.Component comp,
java.lang.Object constraint)
Required by LayoutManager2. |
void |
addLayoutComponent(java.lang.String n,
java.awt.Component c)
Required by LayoutManager, simply calls addLayoutComponent(Component, Object) . |
protected void |
calculateDimensions()
Calculate preferred size and other dimensions. |
static KappaLayout.Constraints |
createConstraint()
Creates a Constraints for direct manipulation. |
static java.awt.Component |
createHorizontalStrut(int width)
Useful for holding an otherwise empty column to a minimum width. |
static java.awt.Component |
createHorizontalStrut(int width,
boolean rigid)
Useful for holding a column to a fixed width. |
static java.awt.Component |
createStrut(int width,
int height)
Useful for setting an otherwise blank cell to a minimum width and height. |
static java.awt.Component |
createStrut(int width,
int height,
boolean rigid)
Useful for setting a row and column to a fixed width and height. |
static java.awt.Component |
createVerticalStrut(int height)
Useful for holding an otherwise empty row to a minimum height. |
static java.awt.Component |
createVerticalStrut(int height,
boolean rigid)
Useful for holding a row to a fixed height. |
float |
getLayoutAlignmentX(java.awt.Container c)
Required by LayoutManager2. |
float |
getLayoutAlignmentY(java.awt.Container c)
Required by LayoutManager2. |
void |
invalidateLayout(java.awt.Container c)
Required by LayoutManager2. |
void |
layoutContainer(java.awt.Container parent)
Required by LayoutManager, does all the real layout work. |
void |
makeColumnsSameWidth()
Makes all columns be the same width. |
void |
makeColumnsSameWidth(int[] columns)
Makes several columns be the same width. |
void |
makeColumnsSameWidth(int column1,
int column2)
Makes two columns be the same width. |
void |
makeRowsSameHeight()
Makes all rows be the same height. |
void |
makeRowsSameHeight(int[] rows)
Makes several rows be the same height. |
void |
makeRowsSameHeight(int row1,
int row2)
Makes two rows be the same height. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container c)
Required by LayoutManager2. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Required by LayoutManager. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Required by LayoutManager. |
void |
removeLayoutComponent(java.awt.Component c)
Required by LayoutManager. |
void |
setColumnWidth(int column,
int width)
Sets a column to a specific width. |
void |
setRowHeight(int row,
int height)
Sets a row to a specific height. |
java.lang.String |
toString()
Useful for debugging a layout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int _preferred_width
protected int _preferred_height
protected boolean _size_unknown
protected int _col_count
protected int _row_count
protected java.util.Hashtable _constraints
protected java.util.Hashtable _table
protected java.awt.Dimension _0dim
protected java.util.Hashtable _components
protected int[] _col_widths
protected int[] _row_heights
protected java.util.Vector _same_width_cols
protected java.util.Vector _same_height_rows
protected boolean _stretch
public static final int N
public static final int NE
public static final int E
public static final int SE
public static final int S
public static final int SW
public static final int W
public static final int NW
public static final int R
Constructor Detail |
---|
public KappaLayout()
public KappaLayout(boolean s)
s
- if true, stretches layout to fill container by adding extra space
between components, does not stretch the components, just the space between them.Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public void addLayoutComponent(java.lang.String n, java.awt.Component c)
addLayoutComponent(Component, Object)
.
addLayoutComponent
in interface java.awt.LayoutManager
public void removeLayoutComponent(java.awt.Component c)
removeLayoutComponent
in interface java.awt.LayoutManager
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize
in interface java.awt.LayoutManager
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize
in interface java.awt.LayoutManager
preferredLayoutSize(parent)
public void layoutContainer(java.awt.Container parent)
layoutContainer
in interface java.awt.LayoutManager
public void addLayoutComponent(java.awt.Component comp, java.lang.Object constraint)
addLayoutComponent
in interface java.awt.LayoutManager2
public java.awt.Dimension maximumLayoutSize(java.awt.Container c)
maximumLayoutSize
in interface java.awt.LayoutManager2
preferredLayoutSize(parent)
public float getLayoutAlignmentX(java.awt.Container c)
getLayoutAlignmentX
in interface java.awt.LayoutManager2
public float getLayoutAlignmentY(java.awt.Container c)
getLayoutAlignmentY
in interface java.awt.LayoutManager2
public void invalidateLayout(java.awt.Container c)
invalidateLayout
in interface java.awt.LayoutManager2
protected void calculateDimensions()
public void makeColumnsSameWidth(int column1, int column2)
column1
- column numbercolumn2
- column numberpublic void makeColumnsSameWidth(int[] columns)
columns
- array of column numbers to make the same width.public void makeColumnsSameWidth()
public void makeRowsSameHeight(int row1, int row2)
row1
- row numberrow2
- row numberpublic void makeRowsSameHeight(int[] rows)
rows
- array of row numbers to make the same height.public void makeRowsSameHeight()
public void setColumnWidth(int column, int width)
column
- column numberwidth
- width in pixelspublic void setRowHeight(int row, int height)
row
- row numberheight
- height in pixelspublic static KappaLayout.Constraints createConstraint()
public static java.awt.Component createHorizontalStrut(int width)
width
- desired width of component
public static java.awt.Component createHorizontalStrut(int width, boolean rigid)
width
- desired width of componentrigid
- if true, will not stretch
public static java.awt.Component createVerticalStrut(int height)
height
- desired height of component
public static java.awt.Component createVerticalStrut(int height, boolean rigid)
height
- desired height of componentrigid
- if true, will not stretch
public static java.awt.Component createStrut(int width, int height)
width
- desired width of componentheight
- desired height of component
public static java.awt.Component createStrut(int width, int height, boolean rigid)
width
- desired width of componentheight
- desired height of component
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |