bb.gui
Class Strut

java.lang.Object
  extended by java.awt.Component
      extended by bb.gui.Strut
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class Strut
extends Component

This class is a Component that is always a specified length along a specified direction. Unless it is explicitly changed by the programmer (via the setAxis and setStrutLength methods), the strut's orientation and length will always be kept fixed. In particular, attempts to change an instance's length (e.g. via the reshape method) will be rebuffed.

The strut's behavior in the direction perpendicular to the orientation axis is more flexible. First, its extent (max, preferred, and min) along this direction may be specified (either in a constructor or changed later). Secondly, this extent may be changed via the reshape method.

This Component is useful in adding space between other visible Components. The sole purpose of this class is to offer an AWT alternative to the strut methods available in Swing's Box class.

This class was designed to work with Java 1.1 and forward.

Like typical Java GUI code, this class is not multithread safe: it expects to only be called by EventQueue's dispatch thread. This threading limitation is checked in every public method.

Author:
Brent Boyer
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  int axis
          Stores the orientation axis of this strut.
protected  int maxTransverse
          Stores the maximum transverse (i.e. perpendicular direction) extent of this strut.
protected  int minTransverse
          Stores the minimum transverse (i.e. perpendicular direction) extent of this strut.
protected  int preferredTransverse
          Stores the preferred transverse (i.e. perpendicular direction) extent of this strut.
private static long serialVersionUID
           
protected  int strutLength
          Stores the length of this strut along the orientation axis.
static int xAxis
          Specifies the x-axis (i.e. horizontal dimension).
static int yAxis
          Specifies the y-axis (i.e. vertical dimension).
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Strut(int axis, int strutLength)
          Simply calls this(axis, strutLength, 0, null).
Strut(int axis, int strutLength, int preferredTransverse, Color color)
          Simply calls this(axis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color).
Strut(int axis, int strutLength, int maxTransverse, int preferredTransverse, int minTransverse, Color color)
          Constructs a new Strut instance with the specified strut orientation axis, length, max-preferred-minimum transverse sizes, and color.
 
Method Summary
 Dimension getMaximumSize()
          Returns new Dimension(strutLength, maxTransverse) (if axis == xAxis) or new Dimension(maxTransverse, strutLength) (if axis == yAxis).
 Dimension getMinimumSize()
          Returns new Dimension(strutLength, minTransverse) (if axis == xAxis) or new Dimension(minTransverse, strutLength) (if axis == yAxis).
 Dimension getPreferredSize()
          Returns new Dimension(preferredTransverse, strutLength).
static Strut inX(int strutLength)
          Reurns a new horizontal (x-axis oriented) Strut instance with the specified length.
static Strut inX(int strutLength, int preferredTransverse, Color color)
          Reurns a new horizontal (x-axis oriented) Strut instance with the specified length, preferred transverse size, and color.
static Strut inY(int strutLength)
          Reurns a new vertical (y-axis oriented) Strut instance with the specified length.
static Strut inY(int strutLength, int preferredTransverse, Color color)
          Reurns a new vertical (y-axis oriented) Strut instance with the specified length, preferred transverse size, and color.
 boolean isLightweight()
          Returns true: this Component is peerless.
 void paint(Graphics g)
          Since this is a lightweight (has no peer) gui object that is a direct subclass of Component, this method must be implemented.
 void setAxis(int axis)
          Mutator for the axis field.
 void setBounds(int x, int y, int width, int height)
          Overrides superclass implementation to enforce the fixed strut length requirement: if axis == xAxis, then the width arg is replaced by strutLength in a call to super.reshape; else if axis == yAxis, then the height arg is replaced by strutLength in a call to super.reshape.
 void setMaxTransverse(int maxTransverse)
          Mutator for the maxTransverse field.
 void setMinTransverse(int minTransverse)
          Mutator for the minTransverse field.
 void setPreferredTransverse(int preferredTransverse)
          Mutator for the preferredTransverse field.
 void setStrutLength(int strutLength)
          Mutator for the strutLength field.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

xAxis

public static final int xAxis
Specifies the x-axis (i.e. horizontal dimension).

See Also:
Constant Field Values

yAxis

public static final int yAxis
Specifies the y-axis (i.e. vertical dimension).

See Also:
Constant Field Values

axis

protected int axis
Stores the orientation axis of this strut.


strutLength

protected int strutLength
Stores the length of this strut along the orientation axis.


maxTransverse

protected int maxTransverse
Stores the maximum transverse (i.e. perpendicular direction) extent of this strut.


preferredTransverse

protected int preferredTransverse
Stores the preferred transverse (i.e. perpendicular direction) extent of this strut.


minTransverse

protected int minTransverse
Stores the minimum transverse (i.e. perpendicular direction) extent of this strut.

Constructor Detail

Strut

public Strut(int axis,
             int strutLength)
      throws IllegalArgumentException
Simply calls this(axis, strutLength, 0, null).

Throws:
IllegalArgumentException

Strut

public Strut(int axis,
             int strutLength,
             int preferredTransverse,
             Color color)
      throws IllegalArgumentException
Simply calls this(axis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color).

Throws:
IllegalArgumentException

Strut

public Strut(int axis,
             int strutLength,
             int maxTransverse,
             int preferredTransverse,
             int minTransverse,
             Color color)
      throws IllegalArgumentException,
             IllegalStateException
Constructs a new Strut instance with the specified strut orientation axis, length, max-preferred-minimum transverse sizes, and color.

Parameters:
axis - the orientation axis of this strut (i.e. the direction in which it will be held rigid)
strutLength - the length of the strut along the orientation axis
maxTransverse - the maximum transverse (i.e. perpendicular direction) extent of this strut
preferredTransverse - the preferred transverse (i.e. perpendicular direction) extent of this strut
minTransverse - the minimum transverse (i.e. perpendicular direction) extent of this strut
color - the foreground Color of this strut; if null its parent's foreground Color will be used
Throws:
IllegalArgumentException - if axis is neither xAxis nor yAxis; strutLength, maxTransverse, preferredTransverse, or minTransverse are < 0
IllegalStateException - if calling thread is not EventQueue's dispatch thread
Method Detail

inX

public static Strut inX(int strutLength,
                        int preferredTransverse,
                        Color color)
                 throws IllegalStateException
Reurns a new horizontal (x-axis oriented) Strut instance with the specified length, preferred transverse size, and color.

Returns:
new Strut(xAxis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color)
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

inX

public static Strut inX(int strutLength)
                 throws IllegalStateException
Reurns a new horizontal (x-axis oriented) Strut instance with the specified length.

Returns:
inX(strutLength, 0, null)
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

inY

public static Strut inY(int strutLength,
                        int preferredTransverse,
                        Color color)
                 throws IllegalStateException
Reurns a new vertical (y-axis oriented) Strut instance with the specified length, preferred transverse size, and color.

Returns:
new Strut(yAxis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color)
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

inY

public static Strut inY(int strutLength)
                 throws IllegalStateException
Reurns a new vertical (y-axis oriented) Strut instance with the specified length.

Returns:
inY(strutLength, 0, null)
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

setAxis

public void setAxis(int axis)
             throws IllegalArgumentException,
                    IllegalStateException
Mutator for the axis field.

Throws:
IllegalArgumentException - if axis is neither xAxis nor yAxis
IllegalStateException - if calling thread is not EventQueue's dispatch thread

setStrutLength

public void setStrutLength(int strutLength)
                    throws IllegalArgumentException,
                           IllegalStateException
Mutator for the strutLength field.

Throws:
IllegalArgumentException - if strutLength is < 0
IllegalStateException - if calling thread is not EventQueue's dispatch thread

setMaxTransverse

public void setMaxTransverse(int maxTransverse)
                      throws IllegalArgumentException,
                             IllegalStateException
Mutator for the maxTransverse field.

Throws:
IllegalArgumentException - if maxTransverse is < 0
IllegalStateException - if calling thread is not EventQueue's dispatch thread

setPreferredTransverse

public void setPreferredTransverse(int preferredTransverse)
                            throws IllegalArgumentException,
                                   IllegalStateException
Mutator for the preferredTransverse field.

Throws:
IllegalArgumentException - if preferredTransverse is < 0
IllegalStateException - if calling thread is not EventQueue's dispatch thread

setMinTransverse

public void setMinTransverse(int minTransverse)
                      throws IllegalArgumentException,
                             IllegalStateException
Mutator for the minTransverse field.

Throws:
IllegalArgumentException - if minTransverse is < 0
IllegalStateException - if calling thread is not EventQueue's dispatch thread

getMaximumSize

public Dimension getMaximumSize()
                         throws IllegalStateException
Returns new Dimension(strutLength, maxTransverse) (if axis == xAxis) or new Dimension(maxTransverse, strutLength) (if axis == yAxis).

Overrides:
getMaximumSize in class Component
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

getPreferredSize

public Dimension getPreferredSize()
                           throws IllegalStateException
Returns new Dimension(preferredTransverse, strutLength).

Overrides:
getPreferredSize in class Component
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

getMinimumSize

public Dimension getMinimumSize()
                         throws IllegalStateException
Returns new Dimension(strutLength, minTransverse) (if axis == xAxis) or new Dimension(minTransverse, strutLength) (if axis == yAxis).

Overrides:
getMinimumSize in class Component
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

isLightweight

public boolean isLightweight()
                      throws IllegalStateException
Returns true: this Component is peerless.

Overrides:
isLightweight in class Component
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread

paint

public void paint(Graphics g)
           throws IllegalStateException
Since this is a lightweight (has no peer) gui object that is a direct subclass of Component, this method must be implemented. The code here merely fills in this Component's rectangular (length & width) dimensions with its foreground Color.

Overrides:
paint in class Component
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread
See Also:
Painting in AWT and Swing

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
               throws IllegalStateException
Overrides superclass implementation to enforce the fixed strut length requirement: if axis == xAxis, then the width arg is replaced by strutLength in a call to super.reshape; else if axis == yAxis, then the height arg is replaced by strutLength in a call to super.reshape.

Overrides:
setBounds in class Component
Throws:
IllegalStateException - if calling thread is not EventQueue's dispatch thread