In JComponent we handle pref/min/max size specially. However, since JDK1.5, we have the same stuff in Component (setBlahSize(), isBlahSizeSet()). I adjusted the JComponent impl to use the super impl when appropriate. This should improve memory footprint as it avoids the doubled space for the pref/min/max size fields.

Note that I removed the isBlahSizeSet() and setBlahSize() methods. They seems to be spec'ed in JComponent, however, I can't see why they should do anything else than their super impl. So I took them out for efficiency. I suppose Sun only left them in for the API docs or so.

2006-08-22  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/JComponent.java
        (preferredSize): Removed field.
        (maximumSize): Removed field.
        (minimumSize): Removed field.
        (getMaximumSize): Adjusted to delegate to Component, rather
        then managing the size in JComponent.
        (getMinimumSize): Adjusted to delegate to Component, rather
        then managing the size in JComponent.
        (getPreferredSize): Adjusted to delegate to Component, rather
        then managing the size in JComponent.
        (isMaximumSizeSet): Removed.
        (isMinimumSizeSet): Removed.
        (isPreferredSizeSet): Removed.
        (setMaximumSize): Removed.
        (setMinimumSize): Removed
        (setPreferredSize): Removed.

/Roman
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.143
diff -u -1 -2 -r1.143 JComponent.java
--- javax/swing/JComponent.java	17 Aug 2006 15:11:54 -0000	1.143
+++ javax/swing/JComponent.java	22 Aug 2006 12:47:59 -0000
@@ -494,45 +494,24 @@
      * <code>null</code> if the component does not support key bindings.
      *
      * @return the keybindings associated with this accessible component
      */
     public AccessibleKeyBinding getAccessibleKeyBinding()
     {
       // The reference implementation seems to always return null here,
       // independent of the key bindings of the JComponent. So do we.
       return null;
     }
   }
 
-  /** 
-   * An explicit value for the component's preferred size; if not set by a
-   * user, this is calculated on the fly by delegating to the [EMAIL PROTECTED]
-   * ComponentUI#getPreferredSize} method on the [EMAIL PROTECTED] #ui} property. 
-   */
-  Dimension preferredSize;
-
-  /** 
-   * An explicit value for the component's minimum size; if not set by a
-   * user, this is calculated on the fly by delegating to the [EMAIL PROTECTED]
-   * ComponentUI#getMinimumSize} method on the [EMAIL PROTECTED] #ui} property. 
-   */
-  Dimension minimumSize;
-
-  /** 
-   * An explicit value for the component's maximum size; if not set by a
-   * user, this is calculated on the fly by delegating to the [EMAIL PROTECTED]
-   * ComponentUI#getMaximumSize} method on the [EMAIL PROTECTED] #ui} property.
-   */
-  Dimension maximumSize;
-
   /**
    * A value between 0.0 and 1.0 indicating the preferred horizontal
    * alignment of the component, relative to its siblings. The values
    * [EMAIL PROTECTED] #LEFT_ALIGNMENT}, [EMAIL PROTECTED] #CENTER_ALIGNMENT}, and [EMAIL PROTECTED]
    * #RIGHT_ALIGNMENT} can also be used, as synonyms for <code>0.0</code>,
    * <code>0.5</code>, and <code>1.0</code>, respectively. Not all layout
    * managers use this property.
    *
    * @see #getAlignmentX
    * @see #setAlignmentX
    * @see javax.swing.OverlayLayout
    * @see javax.swing.BoxLayout
@@ -1261,153 +1240,114 @@
    * @return The component's current location
    */
   public Point getLocation(Point rv)
   {
     if (rv == null)
       return new Point(getX(), getY());
 
     rv.setLocation(getX(), getY());
     return rv;
   }
 
   /**
-   * Get the component's maximum size. If the [EMAIL PROTECTED] #maximumSize} property
-   * has been explicitly set, it is returned. If the [EMAIL PROTECTED] #maximumSize}
+   * Get the component's maximum size. If the <code>maximumSize</code> property
+   * has been explicitly set, it is returned. If the <code>maximumSize</code>
    * property has not been set but the [EMAIL PROTECTED] #ui} property has been, the
    * result of [EMAIL PROTECTED] ComponentUI#getMaximumSize} is returned. If neither
    * property has been set, the result of [EMAIL PROTECTED] Container#getMaximumSize}
    * is returned.
    *
-   * @return The maximum size of the component
+   * @return the maximum size of the component
    *
-   * @see #maximumSize
-   * @see #setMaximumSize
+   * @see Component#setMaximumSize
+   * @see Component#getMaximumSize()
+   * @see Component#isMaximumSizeSet()
+   * @see ComponentUI#getMaximumSize(JComponent)
    */
   public Dimension getMaximumSize()
   {
-    if (maximumSize != null)
-      return maximumSize;
-
-    if (ui != null)
+    Dimension size = null; 
+    if (isMaximumSizeSet())
+      size = super.getMaximumSize();
+    else
       {
-        Dimension s = ui.getMaximumSize(this);
-        if (s != null)
-          return s;
+        if (ui != null)
+          size = ui.getMaximumSize(this);
+        if (size == null)
+          size = super.getMaximumSize();
       }
-
-    Dimension p = super.getMaximumSize();
-    return p;
+    return size;
   }
 
   /**
-   * Get the component's minimum size. If the [EMAIL PROTECTED] #minimumSize} property
-   * has been explicitly set, it is returned. If the [EMAIL PROTECTED] #minimumSize}
+   * Get the component's minimum size. If the <code>minimumSize</code> property
+   * has been explicitly set, it is returned. If the <code>minimumSize</code>
    * property has not been set but the [EMAIL PROTECTED] #ui} property has been, the
    * result of [EMAIL PROTECTED] ComponentUI#getMinimumSize} is returned. If neither
    * property has been set, the result of [EMAIL PROTECTED] Container#getMinimumSize}
    * is returned.
    *
    * @return The minimum size of the component
    *
-   * @see #minimumSize
-   * @see #setMinimumSize
+   * @see Component#setMinimumSize
+   * @see Component#getMinimumSize()
+   * @see Component#isMinimumSizeSet()
+   * @see ComponentUI#getMinimumSize(JComponent)
    */
   public Dimension getMinimumSize()
   {
-    if (minimumSize != null)
-      return minimumSize;
-
-    if (ui != null)
+    Dimension size = null; 
+    if (isMinimumSizeSet())
+      size = super.getMinimumSize();
+    else
       {
-        Dimension s = ui.getMinimumSize(this);
-        if (s != null)
-          return s;
+        if (ui != null)
+          size = ui.getMinimumSize(this);
+        if (size == null)
+          size = super.getMinimumSize();
       }
-
-    Dimension p = super.getMinimumSize();
-    return p;
+    return size;
   }
 
   /**
-   * Get the component's preferred size. If the [EMAIL PROTECTED] #preferredSize}
-   * property has been explicitly set, it is returned. If the [EMAIL PROTECTED]
-   * #preferredSize} property has not been set but the [EMAIL PROTECTED] #ui} property
-   * has been, the result of [EMAIL PROTECTED] ComponentUI#getPreferredSize} is
+   * Get the component's preferred size. If the <code>preferredSize</code>
+   * property has been explicitly set, it is returned. If the
+   * <code>preferredSize</code> property has not been set but the [EMAIL PROTECTED] #ui}
+   * property has been, the result of [EMAIL PROTECTED] ComponentUI#getPreferredSize} is
    * returned. If neither property has been set, the result of [EMAIL PROTECTED]
    * Container#getPreferredSize} is returned.
    *
    * @return The preferred size of the component
    *
-   * @see #preferredSize
-   * @see #setPreferredSize
+   * @see Component#setPreferredSize
+   * @see Component#getPreferredSize()
+   * @see Component#isPreferredSizeSet()
+   * @see ComponentUI#getPreferredSize(JComponent)
    */
   public Dimension getPreferredSize()
   {
-    Dimension prefSize = null;
-    if (preferredSize != null)
-      prefSize = new Dimension(preferredSize);
-
-    else if (ui != null)
+    Dimension size = null; 
+    if (isPreferredSizeSet())
+      size = super.getPreferredSize();
+    else
       {
-        Dimension s = ui.getPreferredSize(this);
-        if (s != null)
-          prefSize = s;
+        if (ui != null)
+          size = ui.getPreferredSize(this);
+        if (size == null)
+          size = super.getPreferredSize();
       }
-
-    if (prefSize == null)
-      prefSize = super.getPreferredSize();
-
-    return prefSize;
-  }
-
-  /**
-   * Checks if a maximum size was explicitely set on the component.
-   *
-   * @return <code>true</code> if a maximum size was set,
-   * <code>false</code> otherwise
-   * 
-   * @since 1.3
-   */
-  public boolean isMaximumSizeSet()
-  {
-    return maximumSize != null;
-  }
-
-  /**
-   * Checks if a minimum size was explicitely set on the component.
-   *
-   * @return <code>true</code> if a minimum size was set,
-   * <code>false</code> otherwise
-   * 
-   * @since 1.3
-   */
-  public boolean isMinimumSizeSet()
-  {
-    return minimumSize != null;
+    return size;
   }
 
   /**
-   * Checks if a preferred size was explicitely set on the component.
-   *
-   * @return <code>true</code> if a preferred size was set,
-   * <code>false</code> otherwise
-   * 
-   * @since 1.3
-   */
-  public boolean isPreferredSizeSet()
-  {
-    return preferredSize != null;
-  }
-  
-  /**
    * Return the value of the <code>nextFocusableComponent</code> property.
    *
    * @return The current value of the property, or <code>null</code>
    * if none has been set.
    * 
    * @deprecated See [EMAIL PROTECTED] java.awt.FocusTraversalPolicy}
    */
   public Component getNextFocusableComponent()
   {
     Container focusRoot = this;
     if (! this.isFocusCycleRoot())
       focusRoot = getFocusCycleRootAncestor();
@@ -2869,75 +2809,24 @@
    *
    * @param fg The new value of the property
    */
   public void setForeground(Color fg)
   {
     if (fg == getForeground())
       return;
     super.setForeground(fg);
     repaint();
   }
 
   /**
-   * Set the value of the [EMAIL PROTECTED] #maximumSize} property. The passed value is
-   * copied, the later direct changes on the argument have no effect on the
-   * property value.
-   *
-   * @param max The new value of the property
-   */
-  public void setMaximumSize(Dimension max)
-  {
-    Dimension oldMaximumSize = maximumSize;
-    if (max != null) 
-      maximumSize = new Dimension(max);
-    else
-      maximumSize = null;
-    firePropertyChange("maximumSize", oldMaximumSize, maximumSize);
-  }
-
-  /**
-   * Set the value of the [EMAIL PROTECTED] #minimumSize} property. The passed value is
-   * copied, the later direct changes on the argument have no effect on the
-   * property value.
-   *
-   * @param min The new value of the property
-   */
-  public void setMinimumSize(Dimension min)
-  {
-    Dimension oldMinimumSize = minimumSize;
-    if (min != null)
-      minimumSize = new Dimension(min);
-    else
-      minimumSize = null;
-    firePropertyChange("minimumSize", oldMinimumSize, minimumSize);
-  }
-
-  /**
-   * Set the value of the [EMAIL PROTECTED] #preferredSize} property. The passed value is
-   * copied, the later direct changes on the argument have no effect on the
-   * property value.
-   *
-   * @param pref The new value of the property
-   */
-  public void setPreferredSize(Dimension pref)
-  {
-    Dimension oldPreferredSize = preferredSize;
-    if (pref != null)
-      preferredSize = new Dimension(pref);
-    else
-      preferredSize = null;
-    firePropertyChange("preferredSize", oldPreferredSize, preferredSize);
-  }
-
-  /**
    * Set the specified component to be the next component in the 
    * focus cycle, overriding the [EMAIL PROTECTED] FocusTraversalPolicy} for
    * this component.
    *
    * @param aComponent The component to set as the next focusable
    *
    * @deprecated Use FocusTraversalPolicy instead
    */
   public void setNextFocusableComponent(Component aComponent)
   {
     Container focusRoot = this;
     if (! this.isFocusCycleRoot())

Reply via email to