classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: fix for MetalTreeUI


From: Roman Kennke
Subject: [cp-patches] FYI: fix for MetalTreeUI
Date: Tue, 12 Jul 2005 21:27:03 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050331)

I checked in a fix that makes JTrees working in the MetalL&F. The MetalTreeUI.createUI() method used to return a shared instance of itself for all JTrees. This would not work because TreeUIs are stateful, i.e. they keep a reference to the JTree they are responsible for.


2005-07-12  Roman Kennke  <address@hidden>

        * javax/swing/plaf/metal/MetalTreeUI.java
        (createUI): Return a different instance of MetalTreeUI for each
        JTree. The TreeUI is stateful, so a shared instance would not
        work.

/Roman
Index: javax/swing/plaf/metal/MetalTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTreeUI.java,v
retrieving revision 1.2
diff -u -r1.2 MetalTreeUI.java
--- javax/swing/plaf/metal/MetalTreeUI.java     2 Jul 2005 20:32:51 -0000       
1.2
+++ javax/swing/plaf/metal/MetalTreeUI.java     12 Jul 2005 19:24:13 -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.BasicTreeUI;
@@ -46,9 +48,8 @@
   extends BasicTreeUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
-  /** The shared UI instance for MetalTreeUIs */
-  private static MetalTreeUI instance = null;
+  /** The UI instances for MetalTreeUIs */
+  private static HashMap instances = null;
 
   /**
    * Constructs a new instance of MetalTreeUI.
@@ -67,8 +68,19 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalTreeUI();
+    if (instances == null)
+      instances = new HashMap();
+
+    Object o = instances.get(component);
+    MetalTreeUI instance;
+    if (o == null)
+      {
+       instance = new MetalTreeUI();
+       instances.put(component, instance);
+      }
+    else
+      instance = (MetalTreeUI) o;
+
     return instance;
   }
 }

reply via email to

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