diff options
| author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-10 21:46:48 +0000 | 
|---|---|---|
| committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-10 21:46:48 +0000 | 
| commit | ce57ab760f69de6db452def7ffbf5b114a2d8694 (patch) | |
| tree | ea38c56431c5d4528fb54254c3f8e50f517bede3 /libjava/classpath/javax/swing/Spring.java | |
| parent | 50996fe55769882de3f410896032c887f0ff0d04 (diff) | |
| download | ppe42-gcc-ce57ab760f69de6db452def7ffbf5b114a2d8694.tar.gz ppe42-gcc-ce57ab760f69de6db452def7ffbf5b114a2d8694.zip  | |
       Imported GNU Classpath 0.90
       * scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
       * gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
       * java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
       * java/lang/Math.java: New override file.
       * java/lang/Character.java: Merged from Classpath.
       (start, end): Now 'int's.
       (canonicalName): New field.
       (CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
       (UnicodeBlock): Added argument.
       (of): New overload.
       (forName): New method.
       Updated unicode blocks.
       (sets): Updated.
       * sources.am: Regenerated.
       * Makefile.in: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111942 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/javax/swing/Spring.java')
| -rw-r--r-- | libjava/classpath/javax/swing/Spring.java | 136 | 
1 files changed, 136 insertions, 0 deletions
diff --git a/libjava/classpath/javax/swing/Spring.java b/libjava/classpath/javax/swing/Spring.java index 8f7105d496d..b9890c7147f 100644 --- a/libjava/classpath/javax/swing/Spring.java +++ b/libjava/classpath/javax/swing/Spring.java @@ -37,6 +37,9 @@ exception statement from your version. */  package javax.swing; +import java.awt.Component; +import java.awt.Dimension; +  /**   * Calculates the space between component edges, that are layed out by   * {@link SpringLayout}. @@ -168,6 +171,139 @@ public abstract class Spring    }    /** +   * 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. +   * @param spring the spring to track +   * @param factor the factor by which to scale +   * @return a new multiplicative Spring +   * @since 1.5 +   */ +  public static Spring scale(final Spring spring, final float factor) +  { +    if (spring == null) +      throw new NullPointerException("spring argument is null"); +    return new Spring() +    { +      public int getMaximumValue() +      { +        return (int) ((factor < 0 ? spring.getMinimumValue() +                            : spring.getMaximumValue()) +                      * factor); +      } + +      public int getMinimumValue() +      { +        return (int) ((factor < 0 ? spring.getMaximumValue() +                                  : spring.getMinimumValue()) +                            * factor); +      } + +      public int getPreferredValue() +      { +        return (int) (spring.getPreferredValue() * factor); +      } + +      public int getValue() +      { +        return (int) (spring.getValue() * factor); +      } + +      public void setValue(int value) +      { +        spring.setValue((int) (value / factor)); +      } +    }; +  } + +  /** +   * 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. +   * @param component the component +   * @return a new Spring which tracks the component's width +   * @since 1.5 +   */ +  public static Spring width(final Component component) +  { +    return new Spring() +    { +      public int getMaximumValue() +      { +        return component.getMaximumSize().width; +      } + +      public int getMinimumValue() +      { +        return component.getMinimumSize().width; +      } + +      public int getPreferredValue() +      { +        return component.getPreferredSize().width; +      } + +      public int getValue() +      { +        return component.getSize().width; +      } + +      public void setValue(int value) +      { +        Dimension d = component.getSize(); +        component.setSize(value, d.height); +      } +    }; +  } + +  /** +   * 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. +   * @param component the component +   * @return a new Spring which tracks the component's height +   * @since 1.5 +   */ +  public static Spring height(final Component component) +  { +    return new Spring() +    { +      public int getMaximumValue() +      { +        return component.getMaximumSize().height; +      } + +      public int getMinimumValue() +      { +        return component.getMinimumSize().height; +      } + +      public int getPreferredValue() +      { +        return component.getPreferredSize().height; +      } + +      public int getValue() +      { +        return component.getSize().height; +      } + +      public void setValue(int value) +      { +        Dimension d = component.getSize(); +        component.setSize(d.width, value); +      } +    }; +  } + +  /**     * A simple Spring, that holds constant values for min, pref and max.     *     * @author Roman Kennke (roman@ontographics.com)  | 

