ise.java.awt
Class KappaLayout

java.lang.Object
  extended by ise.java.awt.KappaLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable
Direct Known Subclasses:
LambdaLayout

public class KappaLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable

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:

Parameters may be omitted (default values will be used), e.g., p.add(new Button("OK), "1,4,,,w,");
which means put the button at column 1, row 4, default 1 column wide, default 1 row tall, stretch to fit width of column, no padding.
Spaces in the parameter string are ignored, so these are identical:
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.

Author:
Dale Anson
See Also:
Serialized Form

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

_preferred_width

protected int _preferred_width

_preferred_height

protected int _preferred_height

_size_unknown

protected boolean _size_unknown

_col_count

protected int _col_count

_row_count

protected int _row_count

_constraints

protected java.util.Hashtable _constraints

_table

protected java.util.Hashtable _table

_0dim

protected java.awt.Dimension _0dim

_components

protected java.util.Hashtable _components

_col_widths

protected int[] _col_widths

_row_heights

protected int[] _row_heights

_same_width_cols

protected java.util.Vector _same_width_cols

_same_height_rows

protected java.util.Vector _same_height_rows

_stretch

protected boolean _stretch

N

public static final int N
For alignment constraint (a), align component to North in cell.

See Also:
Constant Field Values

NE

public static final int NE
For alignment constraint (a), align component to NorthEast in cell.

See Also:
Constant Field Values

E

public static final int E
For alignment constraint (a), align component to East in cell.

See Also:
Constant Field Values

SE

public static final int SE
For alignment constraint (a), align component to SouthEast in cell.

See Also:
Constant Field Values

S

public static final int S
For alignment constraint (a), align component to South in cell.

See Also:
Constant Field Values

SW

public static final int SW
For alignment constraint (a), align component to SouthWest in cell.

See Also:
Constant Field Values

W

public static final int W
For alignment constraint (a), align component to West in cell.

See Also:
Constant Field Values

NW

public static final int NW
For alignment constraint (a), align component to NorthWest in cell.

See Also:
Constant Field Values

R

public static final int R
Convenience setting for width (w) or height (h), causes component to use Remaining cells.

See Also:
Constant Field Values
Constructor Detail

KappaLayout

public KappaLayout()
Default constructor, no stretching.


KappaLayout

public KappaLayout(boolean s)
Constructor, allows stretching.

Parameters:
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

toString

public java.lang.String toString()
Useful for debugging a layout. Call after components are showing to make sure all data is available.

Overrides:
toString in class java.lang.Object
Returns:
a String with lots of useful info about the layout.

addLayoutComponent

public void addLayoutComponent(java.lang.String n,
                               java.awt.Component c)
Required by LayoutManager, simply calls addLayoutComponent(Component, Object).

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component c)
Required by LayoutManager.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Required by LayoutManager.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Required by LayoutManager.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Returns:
preferredLayoutSize(parent)

layoutContainer

public void layoutContainer(java.awt.Container parent)
Required by LayoutManager, does all the real layout work.

Specified by:
layoutContainer in interface java.awt.LayoutManager

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraint)
Required by LayoutManager2. Will NOT add component if either component or constraints are null, or if constraints is not a String or Kappa/LambdaLayout.Constraint.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container c)
Required by LayoutManager2.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Returns:
preferredLayoutSize(parent)

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container c)
Required by LayoutManager2.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2
Returns:
0.5f

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container c)
Required by LayoutManager2.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2
Returns:
0.5f

invalidateLayout

public void invalidateLayout(java.awt.Container c)
Required by LayoutManager2.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2

calculateDimensions

protected void calculateDimensions()
Calculate preferred size and other dimensions.


makeColumnsSameWidth

public void makeColumnsSameWidth(int column1,
                                 int column2)
Makes two columns be the same width. The actual width will be the larger of the preferred widths of these columns.

Parameters:
column1 - column number
column2 - column number

makeColumnsSameWidth

public void makeColumnsSameWidth(int[] columns)
Makes several columns be the same width. The actual width will be the largest preferred width of these columns.

Parameters:
columns - array of column numbers to make the same width.

makeColumnsSameWidth

public void makeColumnsSameWidth()
Makes all columns be the same width. The actual width will be the largest preferred width of these columns.


makeRowsSameHeight

public void makeRowsSameHeight(int row1,
                               int row2)
Makes two rows be the same height. The actual height will be the larger of the preferred heights of these rows.

Parameters:
row1 - row number
row2 - row number

makeRowsSameHeight

public void makeRowsSameHeight(int[] rows)
Makes several rows be the same height. The actual height will be the largest preferred height of these rows.

Parameters:
rows - array of row numbers to make the same height.

makeRowsSameHeight

public void makeRowsSameHeight()
Makes all rows be the same height. The actual height will be the largest preferred height of these rows.


setColumnWidth

public void setColumnWidth(int column,
                           int width)
Sets a column to a specific width. Use care with this method, components wider than the set width will be truncated.

Parameters:
column - column number
width - width in pixels

setRowHeight

public void setRowHeight(int row,
                         int height)
Sets a row to a specific height. Use care with this method, components taller than the set height will be truncated.

Parameters:
row - row number
height - height in pixels

createConstraint

public static KappaLayout.Constraints createConstraint()
Creates a Constraints for direct manipulation.

Returns:
a Constraints object for direct manipulation.

createHorizontalStrut

public static java.awt.Component createHorizontalStrut(int width)
Useful for holding an otherwise empty column to a minimum width.

Parameters:
width - desired width of component
Returns:
a component with some width but no height

createHorizontalStrut

public static java.awt.Component createHorizontalStrut(int width,
                                                       boolean rigid)
Useful for holding a column to a fixed width.

Parameters:
width - desired width of component
rigid - if true, will not stretch
Returns:
a component with some width but no height

createVerticalStrut

public static java.awt.Component createVerticalStrut(int height)
Useful for holding an otherwise empty row to a minimum height.

Parameters:
height - desired height of component
Returns:
a component with some height but no width

createVerticalStrut

public static java.awt.Component createVerticalStrut(int height,
                                                     boolean rigid)
Useful for holding a row to a fixed height.

Parameters:
height - desired height of component
rigid - if true, will not stretch
Returns:
a component with some height but no width

createStrut

public static java.awt.Component createStrut(int width,
                                             int height)
Useful for setting an otherwise blank cell to a minimum width and height.

Parameters:
width - desired width of component
height - desired height of component
Returns:
a component with some height and width

createStrut

public static java.awt.Component createStrut(int width,
                                             int height,
                                             boolean rigid)
Useful for setting a row and column to a fixed width and height.

Parameters:
width - desired width of component
height - desired height of component
Returns:
a component with some height and width


Copyright © 2000 Dale Anson, All Rights Reserved.
KappaLayout Home Page