[cp-patches] FYI: Component.setName() fix

David Gilbert david.gilbert at object-refinery.com
Tue Jun 27 15:36:38 UTC 2006


This patch (committed) fixes a bug in the setName() method in the Component class. 
In addition, the Mauve test I wrote for this showed that the automatic name 
generating mechanism is missing from the Label class, so I copied the same thing 
over from the Button class:

2006-06-27  David Gilbert  <david.gilbert at object-refinery.com>

	* java/awt/Component.java
	(setName): Fire required PropertyChangeEvent,
	* java/awt/Label.java
	(getText): Removed redundant brackets,
	(generateName): New method (override),
	(nextLabelNumber): New field,
	(getUniqueLong): New method.

This fixes a test case from the Intel test suite and some new Mauve tests that I 
will commit shortly.

Regards,

Dave
-------------- next part --------------
Index: java/awt/Component.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.125
diff -u -r1.125 Component.java
--- java/awt/Component.java	27 Jun 2006 13:38:29 -0000	1.125
+++ java/awt/Component.java	27 Jun 2006 15:28:56 -0000
@@ -632,16 +632,19 @@
   }
 
   /**
-   * Sets the name of this component to the specified name.
+   * Sets the name of this component to the specified name (this is a bound
+   * property with the name 'name').
    *
-   * @param name the new name of this component
+   * @param name the new name (<code>null</code> permitted).
    * @see #getName()
    * @since 1.1
    */
   public void setName(String name)
   {
     nameExplicitlySet = true;
+    String old = this.name;
     this.name = name;
+    firePropertyChange("name", old, name);
   }
 
   /**
Index: java/awt/Label.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/Label.java,v
retrieving revision 1.22
diff -u -r1.22 Label.java
--- java/awt/Label.java	27 Jun 2006 15:05:20 -0000	1.22
+++ java/awt/Label.java	27 Jun 2006 15:28:56 -0000
@@ -167,7 +167,7 @@
    */
   public String getText()
   {
-    return(text);
+    return text;
   }
 
   /**
@@ -271,5 +271,25 @@
     return accessibleContext;
   }
 
+  /**
+   * Generate a unique name for this button.
+   *
+   * @return A unique name for this button.
+   */
+  String generateName()
+  {
+    return "label" + getUniqueLong();
+  }
+  
+  /**
+   * The number used to generate the name returned by getName.
+   */
+  private static transient long nextLabelNumber;
+
+  private static synchronized long getUniqueLong()
+  {
+    return nextLabelNumber++;
+  }
+
 }
 


More information about the Classpath-patches mailing list