[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] FYI: MetalTabbedPaneUI fix
From: |
Michael Koch |
Subject: |
Re: [cp-patches] FYI: MetalTabbedPaneUI fix |
Date: |
Fri, 15 Apr 2005 11:16:12 +0200 |
User-agent: |
mutt-ng 1.5.9-r243i (Debian) |
On Fri, Apr 15, 2005 at 11:03:45AM +0200, Roman Kennke wrote:
> The following fix lets MetalTabbedPaneUI create one instance of itself
> instead of sharing a singleton.
>
> 2005-04-15 Roman Kennke <address@hidden>
>
> * javax/swing/plaf/metal/MetalTabbedPaneUI.java
> (createUI): Create one MetalTabbedPaneUI per Component instead
> of sharing one instance.
>
>
> /Roman
>
> Index: javax/swing/plaf/metal/MetalTabbedPaneUI.java
> ===================================================================
> RCS file:
> /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java,v
> retrieving revision 1.2
> diff -u -r1.2 MetalTabbedPaneUI.java
> --- javax/swing/plaf/metal/MetalTabbedPaneUI.java 14 Apr 2005 13:58:51
> -0000 1.2
> +++ javax/swing/plaf/metal/MetalTabbedPaneUI.java 15 Apr 2005 09:00:03
> -0000
> @@ -38,6 +38,8 @@
>
> package javax.swing.plaf.metal;
>
> +import java.util.HashMap;
> +import java.util.Map;
> import javax.swing.JComponent;
> import javax.swing.plaf.ComponentUI;
> import javax.swing.plaf.basic.BasicTabbedPaneUI;
> @@ -46,9 +48,8 @@
> extends BasicTabbedPaneUI
> {
>
> - // FIXME: maybe replace by a Map of instances when this becomes stateful
> /** The shared UI instance for JTabbedPanes. */
> - private static MetalTabbedPaneUI instance = null;
> + private static Map instances = null;
As you know this will always contain a HashMap its better to make it a
HashMap as method calls to explicit classes is faster then calling
methods through interfaces. Speed doesnt really matter in this case but
this is a general rule.
> /**
> * Constructs a new instance of MetalTabbedPaneUI.
> @@ -67,8 +68,19 @@
> */
> public static ComponentUI createUI(JComponent component)
> {
> - if (instance == null)
> - instance = new MetalTabbedPaneUI();
> + if (instances == null)
> + instances = new HashMap();
> +
> + Object o = instances.get(component);
> + MetalTabbedPaneUI instance;
> + if (o == null)
> + {
> + instance = new MetalTabbedPaneUI();
> + instances.put(component, instance);
> + }
> + else
> + instance = (MetalTabbedPaneUI) o;
> +
> return instance;
> }
> }
Michael
--
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
Join the community at http://planet.classpath.org/