classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: javax.swing.plaf.metal.MetalTextFieldUI fix


From: Roman Kennke
Subject: [cp-patches] FYI: javax.swing.plaf.metal.MetalTextFieldUI fix
Date: Mon, 25 Apr 2005 10:35:46 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

I committed the attached patch that fixes MetalTextFieldUI. createUI() must not return a shared instance of MetalTextFieldUI because the UI class is stateful.

2005-04-25  Roman Kennke  <address@hidden>

       * javax/swing/plaf/metal/MetalTextFieldUI.java
       (createUI): Return one instance per Component instead of a
       shared instance.

/Roman

Index: javax/swing/plaf/metal/MetalTextFieldUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTextFieldUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalTextFieldUI.java
--- javax/swing/plaf/metal/MetalTextFieldUI.java        14 Apr 2005 18:00:46 
-0000      1.1
+++ javax/swing/plaf/metal/MetalTextFieldUI.java        25 Apr 2005 08:32:29 
-0000
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicTextFieldUI;
@@ -46,9 +48,8 @@
   extends BasicTextFieldUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
-  /** The shared UI instance for MetalTextFieldUIs */
-  private static MetalTextFieldUI instance = null;
+  /** The UI instances for MetalTextFieldUIs */
+  private static HashMap instances = null;
 
   /**
    * Constructs a new instance of MetalTextFieldUI.
@@ -67,8 +68,19 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalTextFieldUI();
+    if (instances == null)
+      instances = new HashMap();
+
+    Object o = instances.get(component);
+    MetalTextFieldUI instance;
+    if (o == null)
+      {
+       instance = new MetalTextFieldUI();
+       instances.put(component, instance);
+      }
+    else
+      instance = (MetalTextFieldUI) o;
+
     return instance;
   }
 }

reply via email to

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