javax.swing
Class Spring

java.lang.Object
  extended by javax.swing.Spring

public abstract class Spring
extends Object

Calculates the space between component edges, that are layed out by SpringLayout.

A Spring defines a minimum, preferred and maximum distance for each edge (north, east, south, west) of a component.

However, springs are not static, their actual values are computed at runtime. That means, if a Spring C is defined as the sum of Spring A and Spring B, then the values (min, pref and max) are not calculated at creation of Spring C, but instead always when getValue() is called. So, when Spring A or Spring B changes, this is reflected in Spring C.


Field Summary
static int UNSET
          Indicates a not-set value.
 
Constructor Summary
protected Spring()
          Creates a new Spring object.
 
Method Summary
static Spring constant(int val)
          Creates a Spring which min, pref and max values are all the same.
static Spring constant(int min, int pref, int max)
          Creates a Spring which min, pref and max values are constants.
abstract  int getMaximumValue()
          Returns the maximum value of the Spring.
abstract  int getMinimumValue()
          Returns the minimum value of this Spring.
abstract  int getPreferredValue()
          Return the preferred value of this Spring.
abstract  int getValue()
          Return the actual value of this Spring.
static Spring height(Component component)
          Return a new Spring which takes its values from the specified Component.
static Spring max(Spring s1, Spring s2)
          Creates and returns a Spring, which always has the maximum values min = max(min_s1, min_s2), pref = max(pref_s1, pref_s2), max = max(max_s1, max_s2).
static Spring minus(Spring s)
          Creates and returns a Spring, which is always the negation of s.
static Spring scale(Spring spring, float factor)
          Return a new Spring which computes its values by scaling the values of another spring by a constant factor.
abstract  void setValue(int value)
          Sets the actual value.
static Spring sum(Spring s1, Spring s2)
          Creates and returns a Spring, which is always the sum of s1 and s2.
static Spring width(Component component)
          Return a new Spring which takes its values from the specified Component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNSET

public static final int UNSET
Indicates a not-set value.

See Also:
Constant Field Values
Constructor Detail

Spring

protected Spring()
Creates a new Spring object. This constructor is used by the static methods which create Springs.

Method Detail

constant

public static Spring constant(int val)
Creates a Spring which min, pref and max values are all the same. These kind of Springs are 'struts'.

Parameters:
val - the constant for min, pref and max values.
Returns:
a Spring object with constant values for min, pref and max.

constant

public static Spring constant(int min,
                              int pref,
                              int max)
Creates a Spring which min, pref and max values are constants.

Parameters:
min - the constant for the minimum value.
pref - the constant for the preferred value.
max - the constant for the maximum value.
Returns:
a Spring object with constant values for min, pref and max.

getMaximumValue

public abstract int getMaximumValue()
Returns the maximum value of the Spring.

Returns:
the maximum value.

getMinimumValue

public abstract int getMinimumValue()
Returns the minimum value of this Spring.

Returns:
the minimum value.

getPreferredValue

public abstract int getPreferredValue()
Return the preferred value of this Spring.

Returns:
the preferred value.

getValue

public abstract int getValue()
Return the actual value of this Spring.

Returns:
the actual value of this Spring.

max

public static Spring max(Spring s1,
                         Spring s2)
Creates and returns a Spring, which always has the maximum values min = max(min_s1, min_s2), pref = max(pref_s1, pref_s2), max = max(max_s1, max_s2).

Parameters:
s1 - the first summand of the max Spring.
s2 - the second summand of the max Spring.
Returns:
a Spring which is max(s1, s2).

minus

public static Spring minus(Spring s)
Creates and returns a Spring, which is always the negation of s. min = -min_s, pref = -pref_s, max = -max_pref.

Parameters:
s - the Spring to be negated.
Returns:
the negative of s.

setValue

public abstract void setValue(int value)
Sets the actual value. If value is out of the (min, max) bounds, then the value is adjusted, so that is inside these bounds.

Parameters:
value - the value to be set.

sum

public static Spring sum(Spring s1,
                         Spring s2)
Creates and returns a Spring, which is always the sum of s1 and s2. min_sum = min_s1 + min_s2, pref_sum = pref_s1 + pref_s2, max_sum = max_s1 + max_s2.

Parameters:
s1 - the 1st summand of the sum Spring.
s2 - the 2nd summand of the sum Spring.
Returns:
a sum which is s1 + s2.

scale

public static Spring scale(Spring spring,
                           float factor)
Return a new Spring which computes its values by scaling the values of another spring by a constant factor. If the factor is negative, the minimum and maximum values of the argument spring will be interchanged.

Parameters:
spring - the spring to track
factor - the factor by which to scale
Returns:
a new multiplicative Spring
Since:
1.5

width

public static Spring width(Component component)
Return a new Spring which takes its values from the specified Component. In particular, the maximum value is taken from the maximumSize, the minimum value is taken from the minimumSize, the preferred value is taken from the preferredSize, and the value is taken from the component's current size. These values change as the component changes size.

Parameters:
component - the component
Returns:
a new Spring which tracks the component's width
Since:
1.5

height

public static Spring height(Component component)
Return a new Spring which takes its values from the specified Component. In particular, the maximum value is taken from the maximumSize, the minimum value is taken from the minimumSize, the preferred value is taken from the preferredSize, and the value is taken from the component's current size. These values change as the component changes size.

Parameters:
component - the component
Returns:
a new Spring which tracks the component's height
Since:
1.5