javax.swing
public abstract class Spring extends Object
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 whengetValue()
is
called. So, when Spring A or Spring B changes, this is reflected in
Spring C.Modifier and Type | Field and Description |
---|---|
static int |
UNSET
Indicates a not-set value.
|
Modifier | Constructor and Description |
---|---|
protected |
Spring()
Creates a new Spring object.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public static final int UNSET
protected Spring()
public static Spring constant(int val)
val
- the constant for min, pref and max values.public static Spring constant(int min, int pref, int max)
min
- the constant for the minimum value.pref
- the constant for the preferred value.max
- the constant for the maximum value.public abstract int getMaximumValue()
public abstract int getMinimumValue()
public abstract int getPreferredValue()
public abstract int getValue()
public static Spring max(Spring s1, Spring s2)
s1
- the first summand of the max Spring.s2
- the second summand of the max Spring.public static Spring minus(Spring s)
s
- the Spring to be negated.s
.public abstract void setValue(int value)
value
is out of the (min, max)
bounds, then the value is adjusted, so that is inside these bounds.value
- the value to be set.public static Spring sum(Spring s1, Spring s2)
s1
- the 1st summand of the sum Spring.s2
- the 2nd summand of the sum Spring.s1 + s2
.public static Spring scale(Spring spring, float factor)
spring
- the spring to trackfactor
- the factor by which to scalepublic static Spring width(Component component)
component
- the componentpublic static Spring height(Component component)
component
- the component