gui
Class AbstractSizer

java.lang.Object
  extended by gui.AbstractSizer

public abstract class AbstractSizer
extends java.lang.Object

The AbstractSizer class is the base class for classes that manage resizing components such as text panes that can lay out their contents differently depending on available space.

The setWidth() and setHeight() methods are TemplateMethods in a Template Method design pattern, along with a private method that is invoked whenever the sized component is sized by a layout manager. Subclasses complete the implementation by implementing the primitive operation computePreferredSize().

An AbstractSizer variable may appear to be unused. This is because its methods are not always invoked directly. They may be only invoked through the ComponentListener that it installs on its component.


Constructor Summary
AbstractSizer(javax.swing.JComponent c)
          new AbstractSizer(c) returns a new sizer whosed sized component is c.
 
Method Summary
protected abstract  java.awt.Dimension computePreferredSize(java.awt.Dimension sz)
          computePreferredSize(sz) returns a preferred size based on the current actual size sz.
 void setHeight(int h)
          s.setHeight(h) sets the initial heighth of the sized component of s to h.
 void setWidth(int w)
          s.setWidth(w) sets the initial width of the sized component of s to w.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSizer

public AbstractSizer(javax.swing.JComponent c)
new AbstractSizer(c) returns a new sizer whosed sized component is c.

Parameters:
c - the component to be sized
Method Detail

computePreferredSize

protected abstract java.awt.Dimension computePreferredSize(java.awt.Dimension sz)
computePreferredSize(sz) returns a preferred size based on the current actual size sz. Most implementations should return a new size with only one of the dimensions altered.

Returns:
the new preferred size for the component.

setWidth

public void setWidth(int w)
s.setWidth(w) sets the initial width of the sized component of s to w. The initial height will be determined by the computePreferredSize() method.

Parameters:
w - the initial width

setHeight

public void setHeight(int h)
s.setHeight(h) sets the initial heighth of the sized component of s to h. The initial width will be determined by the computePreferredSize() method.

Parameters:
h - the initial width