edu.stanford.hci.r3.util.layout
Class RiverLayout

java.lang.Object
  extended by java.awt.FlowLayout
      extended by edu.stanford.hci.r3.util.layout.RiverLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.io.Serializable

public class RiverLayout
extends java.awt.FlowLayout
implements java.awt.LayoutManager, java.io.Serializable

RiverLayout makes it very simple to construct user interfaces as components are laid out similar to how text is added to a word processor (Components flow like a "river". RiverLayout is however much more powerful than FlowLayout: Components added with the add() method generally gets laid out horizontally, but one may add a string before the component being added to specify "constraints" like this: add("br hfill", new JTextField("Your name here"); The code above forces a "line break" and extends the added component horizontally. Without the "hfill" constraint, the component would take on its preferred size.

List of constraints:

RiverLayout is LGPL licensed - use it freely in free and commercial programs

See Also:
Serialized Form

Field Summary
static java.lang.String CENTER_ALIGN
           
static java.lang.String HFILL
           
static java.lang.String LEFT_ALIGN
           
static java.lang.String LINE_BREAK
           
static java.lang.String PARAGRAPH_BREAK
           
static java.lang.String RIGHT_ALIGN
           
static java.lang.String TAB_STOP
           
static java.lang.String VCENTER
           
static java.lang.String VFILL
           
static java.lang.String VTOP
           
 
Fields inherited from class java.awt.FlowLayout
CENTER, LEADING, LEFT, RIGHT, TRAILING
 
Constructor Summary
RiverLayout()
           
RiverLayout(int hgap, int vgap)
           
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
           
protected  void adjustAlignment(java.awt.Component m)
           
protected  edu.stanford.hci.r3.util.layout.Ruler calcTabs(java.awt.Container target)
          Figure out tab stop x-positions
 java.awt.Insets getExtraInsets()
           
 int getHgap()
          Gets the horizontal gap between components.
protected  java.awt.Insets getInsets(java.awt.Container target)
           
 int getVgap()
          Gets the vertical gap between components.
 void layoutContainer(java.awt.Container target)
          Lays out the container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container target)
          Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
protected  void moveComponents(java.awt.Container target, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr, edu.stanford.hci.r3.util.layout.Ruler ruler)
          Centers the elements in the specified row, if there is any slack.
 java.awt.Dimension preferredLayoutSize(java.awt.Container target)
          Returns the preferred dimensions for this layout given the visible components in the specified target container.
protected  void relMove(java.awt.Container target, int dx, int dy, int rowStart, int rowEnd)
           
 void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component from the layout.
 void setExtraInsets(java.awt.Insets newExtraInsets)
           
 void setHgap(int hgap)
          Sets the horizontal gap between components.
 void setVgap(int vgap)
          Sets the vertical gap between components.
 
Methods inherited from class java.awt.FlowLayout
getAlignment, getAlignOnBaseline, setAlignment, setAlignOnBaseline, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CENTER_ALIGN

public static final java.lang.String CENTER_ALIGN
See Also:
Constant Field Values

HFILL

public static final java.lang.String HFILL
See Also:
Constant Field Values

LEFT_ALIGN

public static final java.lang.String LEFT_ALIGN
See Also:
Constant Field Values

LINE_BREAK

public static final java.lang.String LINE_BREAK
See Also:
Constant Field Values

PARAGRAPH_BREAK

public static final java.lang.String PARAGRAPH_BREAK
See Also:
Constant Field Values

RIGHT_ALIGN

public static final java.lang.String RIGHT_ALIGN
See Also:
Constant Field Values

TAB_STOP

public static final java.lang.String TAB_STOP
See Also:
Constant Field Values

VCENTER

public static final java.lang.String VCENTER
See Also:
Constant Field Values

VFILL

public static final java.lang.String VFILL
See Also:
Constant Field Values

VTOP

public static final java.lang.String VTOP
See Also:
Constant Field Values
Constructor Detail

RiverLayout

public RiverLayout()

RiverLayout

public RiverLayout(int hgap,
                   int vgap)
Method Detail

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Overrides:
addLayoutComponent in class java.awt.FlowLayout
Parameters:
name - the name of the component
comp - the component to be added

adjustAlignment

protected void adjustAlignment(java.awt.Component m)

calcTabs

protected edu.stanford.hci.r3.util.layout.Ruler calcTabs(java.awt.Container target)
Figure out tab stop x-positions


getExtraInsets

public java.awt.Insets getExtraInsets()

getHgap

public int getHgap()
Gets the horizontal gap between components.

Overrides:
getHgap in class java.awt.FlowLayout

getInsets

protected java.awt.Insets getInsets(java.awt.Container target)

getVgap

public int getVgap()
Gets the vertical gap between components.

Overrides:
getVgap in class java.awt.FlowLayout

layoutContainer

public void layoutContainer(java.awt.Container target)
Lays out the container. This method lets each component take its preferred size by reshaping the components in the target container in order to satisfy the constraints of this FlowLayout object.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Overrides:
layoutContainer in class java.awt.FlowLayout
Parameters:
target - the specified component being laid out
See Also:
Container, Container.doLayout()

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Returns the minimum dimensions needed to layout the visible components contained in the specified target container.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Overrides:
minimumLayoutSize in class java.awt.FlowLayout
Parameters:
target - the component which needs to be laid out
Returns:
the minimum dimensions to lay out the subcomponents of the specified container
See Also:
preferredLayoutSize(java.awt.Container), Container, Container.doLayout()

moveComponents

protected void moveComponents(java.awt.Container target,
                              int x,
                              int y,
                              int width,
                              int height,
                              int rowStart,
                              int rowEnd,
                              boolean ltr,
                              edu.stanford.hci.r3.util.layout.Ruler ruler)
Centers the elements in the specified row, if there is any slack.

Parameters:
target - the component which needs to be moved
x - the x coordinate
y - the y coordinate
width - the width dimensions
height - the height dimensions
rowStart - the beginning of the row
rowEnd - the the ending of the row

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Returns the preferred dimensions for this layout given the visible components in the specified target container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Overrides:
preferredLayoutSize in class java.awt.FlowLayout
Parameters:
target - the component which needs to be laid out
Returns:
the preferred dimensions to lay out the subcomponents of the specified container
See Also:
Container, minimumLayoutSize(java.awt.Container), Container.getPreferredSize()

relMove

protected void relMove(java.awt.Container target,
                       int dx,
                       int dy,
                       int rowStart,
                       int rowEnd)

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout. Not used by this class.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Overrides:
removeLayoutComponent in class java.awt.FlowLayout
Parameters:
comp - the component to remove
See Also:
Container.removeAll()

setExtraInsets

public void setExtraInsets(java.awt.Insets newExtraInsets)

setHgap

public void setHgap(int hgap)
Sets the horizontal gap between components.

Overrides:
setHgap in class java.awt.FlowLayout

setVgap

public void setVgap(int vgap)
Sets the vertical gap between components.

Overrides:
setVgap in class java.awt.FlowLayout

Copyright 2006 Stanford University