classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Clone parameter Dimension in JComponent setters.


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Clone parameter Dimension in JComponent setters.
Date: Tue, 08 Nov 2005 11:34:33 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Our setMaximumSize, setMinimumSize, setPreferredSize do not clone the passed parameter, assigning it directly. If the user program reuses the passed object (for instance, to set the same property with different values for another component), the modifications both in Classpath and the user code cause the improper work.

Despite the current version produces less garbage, and very simple workaround is possible, Sun seems cloning the values (later changes on parameter have no effect).

This patch makes our behaviour consistent with Sun's.

2005-11-08  Audrius Meskauskas  <address@hidden>

* javax/swing/JComponent.java (setMaximumSize, setMinimumSize, setPreferredSize):
Clone the passed parameter.
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.75
diff -u -r1.75 JComponent.java
--- javax/swing/JComponent.java 2 Nov 2005 19:26:33 -0000       1.75
+++ javax/swing/JComponent.java 8 Nov 2005 10:18:42 -0000
@@ -2435,38 +2435,44 @@
   }
 
   /**
-   * Set the value of the address@hidden #maximumSize} property.
+   * Set the value of the address@hidden #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;
-    maximumSize = max;
+    maximumSize = new Dimension(max);
     firePropertyChange("maximumSize", oldMaximumSize, maximumSize);
   }
 
   /**
-   * Set the value of the address@hidden #minimumSize} property.
+   * Set the value of the address@hidden #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;
-    minimumSize = min;
+    minimumSize = new Dimension(min);
     firePropertyChange("minimumSize", oldMinimumSize, minimumSize);
   }
 
   /**
-   * Set the value of the address@hidden #preferredSize} property.
+   * Set the value of the address@hidden #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;
-    preferredSize = pref;
+    preferredSize = new Dimension(pref);
     firePropertyChange("preferredSize", oldPreferredSize, preferredSize);
   }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]