diff options
author | David Gilbert <david.gilbert@object-refinery.com> | 2006-06-27 13:38:28 +0000 |
---|---|---|
committer | David Gilbert <david.gilbert@object-refinery.com> | 2006-06-27 13:38:28 +0000 |
commit | 978dd5a56bcd7bd1ce93b883ee4b6fc487c05057 (patch) | |
tree | 63953eef202de73fbd66f0715d05bc5f9841dd53 /java | |
parent | a9be9ad2bd3eff0234d4f02fcfe26db9e98b2879 (diff) | |
download | classpath-978dd5a56bcd7bd1ce93b883ee4b6fc487c05057.tar.gz |
2006-06-27 David Gilbert <david.gilbert@object-refinery.com>
* java/awt/Component.java
(minSizeSet): New field,
(maxSize): Likewise,
(maxSizeSet): Likewise,
(isMaximumSizeSet): Implemented,
(isMinimumSizeSet): Likewise,
(isPreferredSizeSet): Likewise,
(setMaximumSize): Likewise,
(setMinimumSize): Likewise,
(setPreferredSize): Likewise.
Diffstat (limited to 'java')
-rw-r--r-- | java/awt/Component.java | 135 |
1 files changed, 133 insertions, 2 deletions
diff --git a/java/awt/Component.java b/java/awt/Component.java index 41fbb0151..e45e294aa 100644 --- a/java/awt/Component.java +++ b/java/awt/Component.java @@ -70,6 +70,7 @@ import java.awt.image.ImageProducer; import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; import java.awt.peer.LightweightPeer; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.IOException; @@ -427,6 +428,24 @@ public abstract class Component Dimension minSize; /** + * Flag indicating whether the minimum size for the component has been set + * by a call to {@link #setMinimumSize(Dimension)} with a non-null value. + */ + boolean minSizeSet; + + /** + * The maximum size for the component. + * @see #setMaximumSize(Dimension) + */ + Dimension maxSize; + + /** + * A flag indicating whether the maximum size for the component has been set + * by a call to {@link #setMaximumSize(Dimension)} with a non-null value. + */ + boolean maxSizeSet; + + /** * Cached information on the preferred size. Should have been transient. * * @serial ignore @@ -434,6 +453,12 @@ public abstract class Component Dimension prefSize; /** + * Flag indicating whether the preferred size for the component has been set + * by a call to {@link #setPreferredSize(Dimension)} with a non-null value. + */ + boolean prefSizeSet; + + /** * Set to true if an event is to be handled by this component, false if * it is to be passed up the hierarcy. * @@ -1584,6 +1609,7 @@ public abstract class Component * * @return the component's preferred size * @see #getMinimumSize() + * @see #setPreferredSize(Dimension) * @see LayoutManager */ public Dimension getPreferredSize() @@ -1592,6 +1618,40 @@ public abstract class Component } /** + * Sets the preferred size that will be returned by + * {@link #getPreferredSize()} always, and sends a + * {@link PropertyChangeEvent} (with the property name 'preferredSize') to + * all registered listeners. + * + * @param size the preferred size (<code>null</code> permitted). + * + * @since 1.5 + * + * @see #getPreferredSize() + */ + public void setPreferredSize(Dimension size) + { + Dimension old = prefSizeSet ? prefSize : null; + prefSize = size; + prefSizeSet = (size != null); + firePropertyChange("preferredSize", old, size); + } + + /** + * Returns <code>true</code> if the current preferred size is not + * <code>null</code> and was set by a call to + * {@link #setPreferredSize(Dimension)}, otherwise returns <code>false</code>. + * + * @return A boolean. + * + * @since 1.5 + */ + public boolean isPreferredSizeSet() + { + return prefSizeSet; + } + + /** * Returns the component's preferred size. * * @return the component's preferred size @@ -1599,7 +1659,7 @@ public abstract class Component */ public Dimension preferredSize() { - if (prefSize == null) + if (!prefSizeSet) { if (peer == null) prefSize = minimumSize(); @@ -1614,6 +1674,7 @@ public abstract class Component * * @return the component's minimum size * @see #getPreferredSize() + * @see #setMinimumSize(Dimension) * @see LayoutManager */ public Dimension getMinimumSize() @@ -1622,6 +1683,39 @@ public abstract class Component } /** + * Sets the minimum size that will be returned by {@link #getMinimumSize()} + * always, and sends a {@link PropertyChangeEvent} (with the property name + * 'minimumSize') to all registered listeners. + * + * @param size the minimum size (<code>null</code> permitted). + * + * @since 1.5 + * + * @see #getMinimumSize() + */ + public void setMinimumSize(Dimension size) + { + Dimension old = minSizeSet ? minSize : null; + minSize = size; + minSizeSet = (size != null); + firePropertyChange("minimumSize", old, size); + } + + /** + * Returns <code>true</code> if the current minimum size is not + * <code>null</code> and was set by a call to + * {@link #setMinimumSize(Dimension)}, otherwise returns <code>false</code>. + * + * @return A boolean. + * + * @since 1.5 + */ + public boolean isMinimumSizeSet() + { + return minSizeSet; + } + + /** * Returns the component's minimum size. * * @return the component's minimum size @@ -1640,15 +1734,52 @@ public abstract class Component * * @return the component's maximum size * @see #getMinimumSize() + * @see #setMaximumSize(Dimension) * @see #getPreferredSize() * @see LayoutManager */ public Dimension getMaximumSize() { - return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); + if (maxSizeSet) + return maxSize; + else + return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); } /** + * Sets the maximum size that will be returned by {@link #getMaximumSize()} + * always, and sends a {@link PropertyChangeEvent} (with the property name + * 'maximumSize') to all registered listeners. + * + * @param size the maximum size (<code>null</code> permitted). + * + * @since 1.5 + * + * @see #getMaximumSize() + */ + public void setMaximumSize(Dimension size) + { + Dimension old = maxSizeSet ? maxSize : null; + maxSize = size; + maxSizeSet = (size != null); + firePropertyChange("maximumSize", old, size); + } + + /** + * Returns <code>true</code> if the current maximum size is not + * <code>null</code> and was set by a call to + * {@link #setMaximumSize(Dimension)}, otherwise returns <code>false</code>. + * + * @return A boolean. + * + * @since 1.5 + */ + public boolean isMaximumSizeSet() + { + return maxSizeSet; + } + + /** * Returns the preferred horizontal alignment of this component. The value * returned will be between {@link #LEFT_ALIGNMENT} and * {@link #RIGHT_ALIGNMENT}, inclusive. |