|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
bb.gui.Strut
public class Strut
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.
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.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
public static final int xAxis
public static final int yAxis
protected int axis
protected int strutLength
orientation axis
.
protected int maxTransverse
protected int preferredTransverse
protected int minTransverse
Constructor Detail |
---|
public Strut(int axis, int strutLength) throws IllegalArgumentException
this(axis, strutLength, 0, null)
.
IllegalArgumentException
public Strut(int axis, int strutLength, int preferredTransverse, Color color) throws IllegalArgumentException
this(axis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color)
.
IllegalArgumentException
public Strut(int axis, int strutLength, int maxTransverse, int preferredTransverse, int minTransverse, Color color) throws IllegalArgumentException, IllegalStateException
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 axismaxTransverse
- the maximum transverse (i.e. perpendicular direction) extent of this strutpreferredTransverse
- the preferred transverse (i.e. perpendicular direction) extent of this strutminTransverse
- the minimum transverse (i.e. perpendicular direction) extent of this strutcolor
- the foreground Color of this strut; if null its parent's foreground Color will be used
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 |
---|
public static Strut inX(int strutLength, int preferredTransverse, Color color) throws IllegalStateException
new Strut(xAxis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color)
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public static Strut inX(int strutLength) throws IllegalStateException
inX(strutLength, 0, null)
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public static Strut inY(int strutLength, int preferredTransverse, Color color) throws IllegalStateException
new Strut(yAxis, strutLength, Integer.MAX_VALUE, preferredTransverse, 0, color)
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public static Strut inY(int strutLength) throws IllegalStateException
inY(strutLength, 0, null)
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void setAxis(int axis) throws IllegalArgumentException, IllegalStateException
IllegalArgumentException
- if axis is neither xAxis nor yAxis
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void setStrutLength(int strutLength) throws IllegalArgumentException, IllegalStateException
IllegalArgumentException
- if strutLength is < 0
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void setMaxTransverse(int maxTransverse) throws IllegalArgumentException, IllegalStateException
IllegalArgumentException
- if maxTransverse is < 0
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void setPreferredTransverse(int preferredTransverse) throws IllegalArgumentException, IllegalStateException
IllegalArgumentException
- if preferredTransverse is < 0
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void setMinTransverse(int minTransverse) throws IllegalArgumentException, IllegalStateException
IllegalArgumentException
- if minTransverse is < 0
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public Dimension getMaximumSize() throws IllegalStateException
new Dimension(strutLength, maxTransverse)
(if axis == xAxis)
or new Dimension(maxTransverse, strutLength)
(if axis == yAxis).
getMaximumSize
in class Component
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public Dimension getPreferredSize() throws IllegalStateException
new Dimension(preferredTransverse, strutLength)
.
getPreferredSize
in class Component
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public Dimension getMinimumSize() throws IllegalStateException
new Dimension(strutLength, minTransverse)
(if axis == xAxis)
or new Dimension(minTransverse, strutLength)
(if axis == yAxis).
getMinimumSize
in class Component
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public boolean isLightweight() throws IllegalStateException
isLightweight
in class Component
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void paint(Graphics g) throws IllegalStateException
paint
in class Component
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
public void setBounds(int x, int y, int width, int height) throws IllegalStateException
setBounds
in class Component
IllegalStateException
- if calling thread is not EventQueue
's dispatch thread
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |