summaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java')
-rw-r--r--libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java64
1 files changed, 53 insertions, 11 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java
index 4f535f653cc..458f10204f0 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicPanelUI.java
@@ -1,5 +1,5 @@
/* BasicPanelUI.java
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,33 +44,68 @@ import javax.swing.LookAndFeel;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.PanelUI;
+/**
+ * A UI delegate for the {@link JPanel} component.
+ */
public class BasicPanelUI extends PanelUI
{
- public static ComponentUI createUI(JComponent x)
+ /**
+ * A UI delegate that can be shared by all panels (because the delegate is
+ * stateless).
+ */
+ static BasicPanelUI sharedUI;
+
+ /**
+ * Returns a UI delegate for the specified component.
+ *
+ * @param panel the panel.
+ */
+ public static ComponentUI createUI(JComponent panel)
{
- return new BasicPanelUI();
+ if (sharedUI == null)
+ sharedUI = new BasicPanelUI();
+ return sharedUI;
}
+ /**
+ * Installs this UI delegate in the specified component.
+ *
+ * @param c the component (should be a {@link JPanel}, <code>null</code> not
+ * permitted).
+ */
public void installUI(JComponent c)
{
super.installUI(c);
if (c instanceof JPanel)
{
- JPanel p = (JPanel) c;
- installDefaults(p);
+ JPanel p = (JPanel) c;
+ installDefaults(p);
}
}
+ /**
+ * Installs the defaults for this UI delegate in the specified panel.
+ *
+ * @param p the panel (<code>null</code> not permitted).
+ */
protected void installDefaults(JPanel p)
{
LookAndFeel.installColorsAndFont(p, "Panel.background", "Panel.foreground",
"Panel.font");
+
+ // A test against the reference implementation shows that this method will
+ // install a border if one is defined in the UIDefaults table (even though
+ // the BasicLookAndFeel doesn't actually define a "Panel.border"). This
+ // test was written after discovering that a null argument to
+ // uninstallDefaults throws a NullPointerException in
+ // LookAndFeel.uninstallBorder()...
+ LookAndFeel.installBorder(p, "Panel.border");
}
/**
- * Uninstalls this UI from the JPanel.
+ * Uninstalls this UI delegate from the specified component.
*
- * @param c the JPanel from which to uninstall this UI
+ * @param c the component (<code>null</code> not permitted).
*/
public void uninstallUI(JComponent c)
{
@@ -78,13 +113,20 @@ public class BasicPanelUI extends PanelUI
}
/**
- * Uninstalls the UI defaults that have been install through
- * {@link #installDefaults}.
+ * Uninstalls the UI defaults for the specified panel.
*
- * @param p the panel from which to uninstall the UI defaults
+ * @param p the panel (<code>null</code> not permitted).
*/
protected void uninstallDefaults(JPanel p)
{
- // Nothing to do here.
+ // Tests on the reference implementation showed this method:
+ // (1) doesn't actually remove the installed colors and font installed
+ // by installDefaults(), it isn't necessary;
+ // (2) throws a NullPointerException in LookAndFeel.uninstallBorder() if
+ // p is null. Strangely, no border is installed by the
+ // BasicLookAndFeel - perhaps this is needed by another LAF?
+
+ LookAndFeel.uninstallBorder(p);
}
+
}