APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public abstract Class Spring

extends Object
Class Inheritance
Known Direct Subclasses
javax.swing.Spring.AbstractSpring, javax.swing.Spring.NegativeSpring, javax.swing.Spring.ScaleSpring, javax.swing.Spring.SpringMap, javax.swing.SpringLayout.SpringProxy
Imports
java.awt.Component

An instance of the Spring class holds three properties that characterize its behavior: the minimum, preferred, and maximum values. Each of these properties may be involved in defining its fourth, value, property based on a series of rules.

An instance of the Spring class can be visualized as a mechanical spring that provides a corrective force as the spring is compressed or stretched away from its preferred value. This force is modelled as linear function of the distance from the preferred value, but with two different constants -- one for the compressional force and one for the tensional one. Those constants are specified by the minimum and maximum values of the spring such that a spring at its minimum value produces an equal and opposite force to that which is created when it is at its maximum value. The difference between the preferred and minimum values, therefore, represents the ease with which the spring can be compressed and the difference between its maximum and preferred values, indicates the ease with which the Spring can be extended. See the sum method for details.

By defining simple arithmetic operations on Springs, the behavior of a collection of Springs can be reduced to that of an ordinary (non-compound) Spring. We define the "+", "-", max, and min operators on Springs so that, in each case, the result is a Spring whose characteristics bear a useful mathematical relationship to its constituent springs.

A Spring can be treated as a pair of intervals with a single common point: the preferred value. The following rules define some of the arithmetic operators that can be applied to intervals ([a, b] refers to the interval from a to b, where a <= b).

         [a1, b1] + [a2, b2] = [a1 + a2, b1 + b2]

                     -[a, b] = [-b, -a]

     max([a1, b1], [a2, b2]) = [max(a1, a2), max(b1, b2)]
 

If we denote Springs as [a, b, c], where a <= b <= c, we can define the same arithmetic operators on Springs:

         [a1, b1, c1] + [a2, b2, c2] = [a1 + a2, b1 + b2, c1 + c2]

                          -[a, b, c] = [-c, -b, -a]

     max([a1, b1, c1], [a2, b2, c2]) = [max(a1, a2), max(b1, b2), max(c1, c2)]
 

With both intervals and Springs we can define "-" and min in terms of negation:

     X - Y = X + (-Y)

     min(X, Y) = -max(-X, -Y)
 

For the static methods in this class that embody the arithmetic operators, we do not actually perform the operation in question as that would snapshot the values of the properties of the method's arguments at the time the static method is called. Instead, the static methods create a new Spring instance containing references to the method's arguments so that the characteristics of the new spring track the potentially changing characteristics of the springs from which it was made. This is a little like the idea of a lazy value in a functional language.

If you are implementing a SpringLayout you can find further information and examples in How to Use SpringLayout, a section in The Java Tutorial.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Philip Milne
Since
1.4
See Also
SpringLayout, SpringLayout.Constraints

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
pack-priv abstract static class
pack-priv static class
private static class
private static class
private static class
pack-priv abstract static class
private static class
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
public static final int
UNSET

An integer value signifying that a property value has not yet been calculated.

Constructor Summary

AccessConstructor and Description
protected
Spring()

Used by factory methods to create a Spring.

Method Summary

Modifier and TypeMethod and Description
private static void
checkArg(Object s)

If s is null, this throws an NullPointerException.

public static Spring

Returns:

a spring whose minimum, preferred, and maximum values each have the value pref
constant
(int
the minimum, preferred, and maximum values of the new spring
pref
)

Returns a strut -- a spring whose minimum, preferred, and maximum values each have the value pref.

public static Spring

Returns:

a spring whose minimum, preferred, and maximum values have the values: min, pref, and max respectively
constant
(int
the minimum value of the new spring
min
,
int
the preferred value of the new spring
pref
,
int
the maximum value of the new spring
max
)

Returns a spring whose minimum, preferred, and maximum values have the values: min, pref, and max respectively.

pack-priv static Spring
public abstract int

Returns:

the maximumValue property of this Spring
getMaximumValue
()

Returns the maximum value of this Spring.

public abstract int

Returns:

the minimumValue property of this Spring
getMinimumValue
()

Returns the minimum value of this Spring.

public abstract int

Returns:

the preferredValue of this Spring
getPreferredValue
()

Returns the preferred value of this Spring.

pack-priv double
public abstract int

Returns:

the value property of this Spring
getValue
()

Returns the current value of this Spring.

public static Spring

Returns:

a spring whose properties are defined by the vertical component of the component's size methods.
height
(Component
Component used for calculating size
c
)

Returns a spring whose minimum, preferred, maximum and value properties are defined by the heights of the minimumSize, preferredSize, maximumSize and size properties of the supplied component.

pack-priv boolean
public static Spring

Returns:

max(s1, s2): a spring whose value is always greater than (or equal to) the values of both s1 and s2
max
(Spring
a Spring object
s1
,
Spring
a Spring object
s2
)

Returns max(s1, s2): a spring whose value is always greater than (or equal to) the values of both s1 and s2.

public static Spring

Returns:

-s: a spring running in the opposite direction to s
minus
(Spring
a Spring object
s
)

Returns -s: a spring running in the opposite direction to s.

private double
range(boolean contract)

public static Spring

Returns:

a spring whose properties are those of the input spring s multiplied by factor
scale
(Spring
the spring to scale
s
,
float
amount to scale by.
factor
)

Returns a spring whose minimum, preferred, maximum and value properties are each multiples of the properties of the argument spring, s.

pack-priv void
setStrain(double strain)

public abstract void
setValue(int
the new setting of the value property
value
)

Sets the current value of this Spring to value.

public static Spring

Returns:

s1+s2: a spring representing s1 and s2 in series
sum
(Spring
a Spring object
s1
,
Spring
a Spring object
s2
)

Returns s1+s2: a spring representing s1 and s2 in series.

public static Spring

Returns:

a spring whose properties are defined by the horizontal component of the component's size methods.
width
(Component
Component used for calculating size
c
)

Returns a spring whose minimum, preferred, maximum and value properties are defined by the widths of the minimumSize, preferredSize, maximumSize and size properties of the supplied component.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait