|
From: | David Gilbert |
Subject: | Re: [cp-patches] Proposed: javax.swing.UIManager patch |
Date: | Tue, 23 Aug 2005 16:27:00 +0000 |
User-agent: | Mozilla Thunderbird 1.0.6 (X11/20050728) |
David Gilbert wrote:
And the fourth and final part (committed) which fixes some problems with the auxiliary look and feel methods:David Gilbert wrote:Here is the third part (committed) of the patch - it is the API doc additions:David Gilbert wrote:Here is the second part (committed) that caches the UIDefaults from the current look and feel when it is first set:Roman Kennke wrote:OK, I've committed the first part that implements the property change listener mechanism: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 codechanges separate. It would be nice to have this split up. Besides that,please go ahead and commit. /Roman2005-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 Gilbert2005-08-23 David Gilbert <address@hidden> * javax/swing/UIManager.java: (look_and_feel): renamed currentLookAndFeel, (currentUIDefaults): new field, (get(Object)): access cached UIDefaults, (get(Object, Locale)): likewise, (getBoolean(Object)): likewise, (getBoolean(Object, Locale)): likewise, (getBorder(Object)): likewise, (getBorder(Object, Locale)): likewise, (getColor(Object)): likewise, (getColor(Object, Locale)): likewise,(getDefaults): return reference to UIDefaults from current look andfeel rather than recreating them every time, (getDimension(Object)): access local defaults, (getDimension(Object, Locale)): likewise, (getFont(Object)): likewise, (getFont(Object, Locale)): likewise, (getIcon(Object)): likewise, (getIcon(Object, Locale)): likewise, (getInsets(Object)): likewise, (getInsets(Object, Locale)): likewise, (getInt(Object)): likewise, (getInt(Object, Locale)): likewise, (getLookAndFeel): renamed attribute, (getLookAndFeelDefaults): return reference to UIDefaults from current look and feel rather than recreating them every time, (getString(Object)): access local defaults, (getString(Object, Locale)): likewise, (getUI(JComponent)): likewise, (installLookAndFeel(String, String)): implemented by delegation, (put(Object, Object)): update local defaults, (setLookAndFeel): create and retain reference to UIDefaults. Regards, Dave2005-08-23 David Gilbert <address@hidden> * javax/swing/UIManager.java: added API docs all over. One more to follow. Regards, Dave Gilbert
2005-08-23 David Gilbert <address@hidden>* javax/swing/UIManager.java: (addAuxiliaryLookAndFeel): renamed field, added check for null
argument, (removeAuxiliaryLookAndFeel): reimplemented, (getAuxiliaryLookAndFeels): renamed field, (installLookAndFeel): implemented by delegation. I also added some tests to Mauve to cover these changes. Regards, Dave
Index: javax/swing/UIManager.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/UIManager.java,v retrieving revision 1.25 diff -u -r1.25 UIManager.java --- javax/swing/UIManager.java 23 Aug 2005 15:11:13 -0000 1.25 +++ javax/swing/UIManager.java 23 Aug 2005 15:19:55 -0000 @@ -125,7 +125,7 @@ }; /** The installed auxiliary look and feels. */ - static LookAndFeel[] aux_installed; + static LookAndFeel[] auxLookAndFeels; /** The current look and feel. */ static LookAndFeel currentLookAndFeel; @@ -210,19 +210,21 @@ * * @see #getAuxiliaryLookAndFeels() */ - public static void addAuxiliaryLookAndFeel (LookAndFeel l) + public static void addAuxiliaryLookAndFeel(LookAndFeel laf) { - if (aux_installed == null) + if (laf == null) + throw new NullPointerException("Null 'laf' argument."); + if (auxLookAndFeels == null) { - aux_installed = new LookAndFeel[1]; - aux_installed[0] = l; + auxLookAndFeels = new LookAndFeel[1]; + auxLookAndFeels[0] = laf; return; } - LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ]; - System.arraycopy(aux_installed, 0, T, 0, aux_installed.length); - aux_installed = T; - aux_installed[aux_installed.length-1] = l; + LookAndFeel[] temp = new LookAndFeel[auxLookAndFeels.length + 1]; + System.arraycopy(auxLookAndFeels, 0, temp, 0, auxLookAndFeels.length); + auxLookAndFeels = temp; + auxLookAndFeels[auxLookAndFeels.length - 1] = laf; } /** @@ -235,17 +237,34 @@ */ public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf) { - if (aux_installed == null) + if (auxLookAndFeels == null) return false; - - for (int i=0;i<aux_installed.length;i++) + int count = auxLookAndFeels.length; + if (count == 1 && auxLookAndFeels[0] == laf) + { + auxLookAndFeels = null; + return true; + } + for (int i = 0; i < count; i++) { - if (aux_installed[i] == laf) + if (auxLookAndFeels[i] == laf) { - aux_installed[ i ] = aux_installed[aux_installed.length-1]; - LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ]; - System.arraycopy (aux_installed, 0, T, 0, aux_installed.length-1); - aux_installed = T; + LookAndFeel[] temp = new LookAndFeel[auxLookAndFeels.length - 1]; + if (i == 0) + { + System.arraycopy(auxLookAndFeels, 1, temp, 0, count - 1); + } + else if (i == count - 1) + { + System.arraycopy(auxLookAndFeels, 0, temp, 0, count - 1); + } + else + { + System.arraycopy(auxLookAndFeels, 0, temp, 0, i); + System.arraycopy(auxLookAndFeels, i + 1, temp, i, + count - i - 1); + } + auxLookAndFeels = temp; return true; } } @@ -261,9 +280,9 @@ * * @see #addAuxiliaryLookAndFeel(LookAndFeel) */ - public static LookAndFeel[] getAuxiliaryLookAndFeels() + public static LookAndFeel[] getAuxiliaryLookAndFeels() { - return aux_installed; + return auxLookAndFeels; } /** @@ -545,6 +564,7 @@ */ public static void installLookAndFeel(String name, String className) { + installLookAndFeel(new LookAndFeelInfo(name, className)); } /**
[Prev in Thread] | Current Thread | [Next in Thread] |