classpath-patches
[Top][All Lists]
Advanced

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

Re: [cp-patches] Proposed: javax.swing.UIManager patch


From: David Gilbert
Subject: Re: [cp-patches] Proposed: javax.swing.UIManager patch
Date: Tue, 23 Aug 2005 15:33:04 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

Roman Kennke wrote:

Am Dienstag, den 23.08.2005, 13:27 +0000 schrieb David Gilbert:
This patch does two things primarily:

(1) corrects a problem where every call to "get" a default value ends up calling the getDefaults() method in the current LookAndFeel, which *creates* a new table of defaults each time it is called (the API docs say it should only be called once - a better name for the method would be createDefaults()). The solution is to retain a reference to the UIDefaults for the current look and feel, and use that reference in getLookAndFeelDefaults() (and change all the get methods to use getLookAndFeelDefaults());

Sounds reasonable.

(2) implements the property change mechanism in UIManager using the SwingPropertyChangeSupport class.

Dito.

I've also added API doc comments. If the patch is too messy, I'll take some more time to split it into the relevant pieces.

I think many people prefer to have documentation changes and code
changes separate. It would be nice to have this split up. Besides that,
please go ahead and commit.


/Roman

OK, I've committed the first part that implements the property change listener mechanism:

2005-08-23  David Gilbert  <address@hidden>

   * javax/swing/UIManager.java:
   (addPropertyChangeListener): implemented,
   (removePropertyChangeListener): likewise,
   (getPropertyChangeListeners): likewise,
   (setLookAndFeel): fire a property change event.

More to follow.

Regards,

Dave Gilbert

Index: javax/swing/UIManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/UIManager.java,v
retrieving revision 1.22
diff -u -r1.22 UIManager.java
--- javax/swing/UIManager.java  22 Aug 2005 13:28:44 -0000      1.22
+++ javax/swing/UIManager.java  23 Aug 2005 14:23:41 -0000
@@ -47,6 +47,7 @@
 import java.util.Locale;
 
 import javax.swing.border.Border;
+import javax.swing.event.SwingPropertyChangeSupport;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.metal.MetalLookAndFeel;
 
@@ -101,6 +102,10 @@
   
   static LookAndFeel look_and_feel = new MetalLookAndFeel();
 
+  /** Property change listener mechanism. */
+  static SwingPropertyChangeSupport listeners 
+      = new SwingPropertyChangeSupport(UIManager.class);
+
   static
   {
     String defaultlaf = System.getProperty("swing.defaultlaf");
@@ -132,7 +137,7 @@
    */
   public static void addPropertyChangeListener(PropertyChangeListener listener)
   {
-    // FIXME
+    listeners.addPropertyChangeListener(listener);
   }
 
   /**
@@ -140,9 +145,10 @@
    *
    * @param listener the listener to remove
    */
-  public static void removePropertyChangeListener(PropertyChangeListener 
listener)
+  public static void removePropertyChangeListener(PropertyChangeListener 
+          listener)
   {
-    // FIXME
+    listeners.removePropertyChangeListener(listener);
   }
 
   /**
@@ -154,8 +160,7 @@
    */
   public static PropertyChangeListener[] getPropertyChangeListeners()
   {
-    // FIXME
-    throw new Error ("Not implemented");
+    return listeners.getPropertyChangeListeners();
   }
 
   /**
@@ -463,16 +468,18 @@
   public static void setLookAndFeel(LookAndFeel newLookAndFeel)
     throws UnsupportedLookAndFeelException
   {
-    if (! newLookAndFeel.isSupportedLookAndFeel())
+    if (newLookAndFeel != null && ! newLookAndFeel.isSupportedLookAndFeel())
       throw new UnsupportedLookAndFeelException(newLookAndFeel.getName());
     
-    if (look_and_feel != null)
-      look_and_feel.uninitialize();
+    LookAndFeel oldLookAndFeel = look_and_feel;
+    if (oldLookAndFeel != null)
+      oldLookAndFeel.uninitialize();
 
     // Set the current default look and feel using a LookAndFeel object. 
     look_and_feel = newLookAndFeel;
     look_and_feel.initialize();
        
+    listeners.firePropertyChange("lookAndFeel", oldLookAndFeel, 
newLookAndFeel);
     //revalidate();
     //repaint();
   }

reply via email to

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