[Top][All Lists]
[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 16:19:26 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.6 (X11/20050728) |
David Gilbert wrote:
David Gilbert wrote:
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
Here is the second part (committed) that caches the UIDefaults from
the current look and feel when it is first set:
2005-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
and
feel 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,
Dave
Here is the third part (committed) of the patch - it is the API doc
additions:
2005-08-23 David Gilbert <address@hidden>
* javax/swing/UIManager.java: added API docs all over.
One more to follow.
Regards,
Dave Gilbert
Index: javax/swing/UIManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/UIManager.java,v
retrieving revision 1.24
diff -u -r1.24 UIManager.java
--- javax/swing/UIManager.java 23 Aug 2005 14:55:27 -0000 1.24
+++ javax/swing/UIManager.java 23 Aug 2005 15:08:54 -0000
@@ -51,12 +51,27 @@
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.metal.MetalLookAndFeel;
+/**
+ * Manages the current address@hidden LookAndFeel} and any auxiliary
address@hidden LookAndFeel}
+ * instances.
+ */
public class UIManager implements Serializable
{
+ /**
+ * Represents the basic information about a address@hidden LookAndFeel}
(LAF), so
+ * that a list of installed LAFs can be presented without actually loading
+ * the LAF class(es).
+ */
public static class LookAndFeelInfo
{
String name, clazz;
+ /**
+ * Creates a new instance.
+ *
+ * @param name the look and feel name.
+ * @param clazz the look and feel class name.
+ */
public LookAndFeelInfo(String name,
String clazz)
{
@@ -64,11 +79,21 @@
this.clazz = clazz;
}
+ /**
+ * Returns the name of the look and feel.
+ *
+ * @return The name of the look and feel.
+ */
public String getName()
{
return name;
}
+ /**
+ * Returns the fully qualified class name for the address@hidden
LookAndFeel}.
+ *
+ * @return The fully qualified class name for the address@hidden
LookAndFeel}.
+ */
public String getClassName()
{
return clazz;
@@ -94,12 +119,15 @@
private static final long serialVersionUID = -5547433830339189365L;
+ /** The installed look and feel(s). */
static LookAndFeelInfo [] installed = {
- new LookAndFeelInfo ("Metal", "javax.swing.plaf.metal.MetalLookAndFeel")
+ new LookAndFeelInfo("Metal", "javax.swing.plaf.metal.MetalLookAndFeel")
};
+ /** The installed auxiliary look and feels. */
static LookAndFeel[] aux_installed;
+ /** The current look and feel. */
static LookAndFeel currentLookAndFeel;
static UIDefaults currentUIDefaults;
@@ -131,6 +159,10 @@
}
+ /**
+ * Creates a new instance of the <code>UIManager</code>. There is no need
+ * to construct an instance of this class, since all methods are static.
+ */
public UIManager()
{
// Do nothing here.
@@ -170,7 +202,13 @@
}
/**
- * Add a LookAndFeel to the list of auxiliary look and feels.
+ * Add a address@hidden LookAndFeel} to the list of auxiliary look and feels.
+ *
+ * @param laf the auxiliary look and feel (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>laf</code> is <code>null</code>.
+ *
+ * @see #getAuxiliaryLookAndFeels()
*/
public static void addAuxiliaryLookAndFeel (LookAndFeel l)
{
@@ -187,6 +225,14 @@
aux_installed[aux_installed.length-1] = l;
}
+ /**
+ * Removes a address@hidden LookAndFeel} (LAF) from the list of auxiliary
LAFs.
+ *
+ * @param laf the LAF to remove.
+ *
+ * @return <code>true</code> if the LAF was removed, and <code>false</code>
+ * otherwise.
+ */
public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
{
if (aux_installed == null)
@@ -206,16 +252,41 @@
return false;
}
+ /**
+ * Returns an array (possibly <code>null</code>) containing the auxiliary
+ * address@hidden LookAndFeel}s that are in use. These are used by the
+ * address@hidden javax.swing.plaf.multi.MultiLookAndFeel} class.
+ *
+ * @return The auxiliary look and feels (possibly <code>null</code>).
+ *
+ * @see #addAuxiliaryLookAndFeel(LookAndFeel)
+ */
public static LookAndFeel[] getAuxiliaryLookAndFeels()
{
return aux_installed;
}
+ /**
+ * Returns an object from the address@hidden UIDefaults} table for the
current
+ * address@hidden LookAndFeel}.
+ *
+ * @param key the key.
+ *
+ * @return The object.
+ */
public static Object get(Object key)
{
return getLookAndFeelDefaults().get(key);
}
+ /**
+ * Returns an object from the address@hidden UIDefaults} table for the
current
+ * address@hidden LookAndFeel}.
+ *
+ * @param key the key.
+ *
+ * @return The object.
+ */
public static Object get(Object key, Locale locale)
{
return getLookAndFeelDefaults().get(key ,locale);
@@ -280,7 +351,10 @@
}
/**
- * this string can be passed to Class.forName()
+ * The fully qualified class name of the cross platform (Metal) look and
feel.
+ * This string can be passed to Class.forName()
+ *
+ * @return <code>"javax.swing.plaf.metal.MetalLookAndFeel"</code>
*/
public static String getCrossPlatformLookAndFeelClassName()
{
@@ -289,6 +363,8 @@
/**
* Returns the default values for this look and feel.
+ *
+ * @return The address@hidden UIDefaults} for the current address@hidden
LookAndFeel}.
*/
public static UIDefaults getDefaults()
{
@@ -369,6 +445,12 @@
return getLookAndFeelDefaults().getInsets(key, locale);
}
+ /**
+ * Returns an array containing information about the address@hidden
LookAndFeel}s
+ * that are installed.
+ *
+ * @return A list of the look and feels that are available (installed).
+ */
public static LookAndFeelInfo[] getInstalledLookAndFeels()
{
return installed;
@@ -390,6 +472,13 @@
return x.intValue();
}
+ /**
+ * Returns the current look and feel (which may be <code>null</code>).
+ *
+ * @return The current look and feel.
+ *
+ * @see #setLookAndFeel(LookAndFeel)
+ */
public static LookAndFeel getLookAndFeel()
{
return currentLookAndFeel;
@@ -398,6 +487,8 @@
/**
* Returns the <code>UIDefaults</code> table of the currently active
* look and feel.
+ *
+ * @return The address@hidden UIDefaults} for the current address@hidden
LookAndFeel}.
*/
public static UIDefaults getLookAndFeelDefaults()
{
@@ -421,9 +512,13 @@
}
/**
- * Returns the name of the LookAndFeel class that implements the
+ * Returns the name of the address@hidden LookAndFeel} class that implements
the
* native systems look and feel if there is one, otherwise the name
* of the default cross platform LookAndFeel class.
+ *
+ * @return The fully qualified class name for the system look and feel.
+ *
+ * @see #getCrossPlatformLookAndFeelClassName()
*/
public static String getSystemLookAndFeelClassName()
{
@@ -431,7 +526,10 @@
}
/**
- * Returns the Look and Feel object that renders the target component.
+ * Returns UI delegate from the current address@hidden LookAndFeel} that
renders the
+ * target component.
+ *
+ * @param target the target component.
*/
public static ComponentUI getUI(JComponent target)
{
@@ -440,6 +538,10 @@
/**
* Creates a new look and feel and adds it to the current array.
+ *
+ * @param name the look and feel name.
+ * @param className the fully qualified name of the class that implements
the
+ * look and feel.
*/
public static void installLookAndFeel(String name, String className)
{
@@ -451,6 +553,7 @@
*/
public static void installLookAndFeel(LookAndFeelInfo info)
{
+ // FIXME: not yet implemented
}
/**
@@ -466,10 +569,18 @@
*/
public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[]
infos)
{
+ // FIXME: not yet implemented.
}
/**
- * Set the current default look.
+ * Sets the current address@hidden LookAndFeel}.
+ *
+ * @param newLookAndFeel the new look and feel (<code>null</code>
permitted).
+ *
+ * @throws UnsupportedLookAndFeelException if the look and feel is not
+ * supported on the current platform.
+ *
+ * @see LookAndFeel#isSupportedLookAndFeel()
*/
public static void setLookAndFeel(LookAndFeel newLookAndFeel)
throws UnsupportedLookAndFeelException
@@ -499,8 +610,15 @@
/**
* Set the current default look and feel using a class name.
+ *
+ * @param className the look and feel class name.
+ *
+ * @throws UnsupportedLookAndFeelException if the look and feel is not
+ * supported on the current platform.
+ *
+ * @see LookAndFeel#isSupportedLookAndFeel()
*/
- public static void setLookAndFeel (String className)
+ public static void setLookAndFeel(String className)
throws ClassNotFoundException, InstantiationException,
IllegalAccessException,
UnsupportedLookAndFeelException
{