javax.swing

Class 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

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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

UNSET

public static final int UNSET
Indicates a not-set value. *
Field Value:
-2147483648

Constructor Details

Spring

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

Method Details

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.

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

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.

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

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.

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

Spring.java -- Copyright (C) 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.