[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: some fixlets for java.awt.Component
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: some fixlets for java.awt.Component |
Date: |
Fri, 22 Jul 2005 16:35:47 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
Hi,
while merging java.awt.Component with the Aicas java.awt.Component, I
found the following optimizations and fixlets for Component:
2005-07-22 Roman Kennke <address@hidden>
* java/awt/Component.java
(setForeground): Fire PropertyChangeEvent after the foreground
has actually changed, instead of before.
(setBackground): Fire PropertyChangeEvent after the foreground
has actually changed, instead of before. Avoid one comparison
at the beginning of method.
(getBackground): If background is null and parent is null,
return
null, instead of SystemColor.window. This is what it's supposed
to do.
(getFont): Avoid NPE by creating a local reference. Return
static final DEFAULT_FONT instead of creating a new font every
time
we and our parents have no font set.
(setFont): Made check for font equality more precise.
(paramString): Added parent in paramString.
I've committed these, since these are minor fixes and will do no harm.
/Roman
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.62
diff -u -r1.62 Component.java
--- java/awt/Component.java 22 Jul 2005 11:12:41 -0000 1.62
+++ java/awt/Component.java 22 Jul 2005 14:24:54 -0000
@@ -211,6 +211,12 @@
*/
static final Object treeLock = new String("AWT_TREE_LOCK");
+ /**
+ * Preallocated default font returned by getFont() if no font was
+ * set explicitly.
+ */
+ private static final Font DEFAULT_FONT = new Font ("Dialog", Font.PLAIN, 12);
+
// Serialized fields from the serialization spec.
/**
@@ -988,10 +994,12 @@
*/
public void setForeground(Color c)
{
- firePropertyChange("foreground", foreground, c);
if (peer != null)
peer.setForeground(c);
+
+ Color previous = foreground;
foreground = c;
+ firePropertyChange("foreground", previous, c);
}
/**
@@ -1017,7 +1025,7 @@
{
if (background != null)
return background;
- return parent == null ? SystemColor.window : parent.getBackground();
+ return parent == null ? null : parent.getBackground();
}
/**
@@ -1031,16 +1039,18 @@
public void setBackground(Color c)
{
// return if the background is already set to that color.
- if (background != null && c != null)
- if (background.equals(c))
- return;
+ if ((c != null) && c.equals(background))
+ return;
+
// If c is null, inherit from closest ancestor whose bg is set.
if (c == null && parent != null)
c = parent.getBackground();
- firePropertyChange("background", background, c);
if (peer != null && c != null)
peer.setBackground(c);
+
+ Color previous = background;
background = c;
+ firePropertyChange("background", previous, c);
}
/**
@@ -1064,13 +1074,15 @@
*/
public Font getFont()
{
- if (font != null)
- return font;
-
- if (parent != null)
- return parent.getFont ();
+ Font f = font;
+ if (f != null)
+ return f;
+
+ Component p = parent;
+ if (p != null)
+ return p.getFont ();
else
- return new Font ("Dialog", Font.PLAIN, 12);
+ return DEFAULT_FONT;
}
/**
@@ -1083,15 +1095,16 @@
*/
public void setFont(Font newFont)
{
- if (font == newFont)
- return;
-
- Font oldFont = font;
- font = newFont;
- if (peer != null)
- peer.setFont(font);
- firePropertyChange("font", oldFont, newFont);
- invalidate();
+ if((newFont != null && (font == null || !font.equals(newFont)))
+ || newFont == null)
+ {
+ Font oldFont = font;
+ font = newFont;
+ if (peer != null)
+ peer.setFont(font);
+ firePropertyChange("font", oldFont, newFont);
+ invalidate();
+ }
}
/**
@@ -4208,6 +4221,10 @@
param.append(",translucent");
if (isDoubleBuffered())
param.append(",doublebuffered");
+ if (parent == null)
+ param.append(",parent==null");
+ else
+ param.append(",parent==").append(parent.getName());
return param.toString();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: some fixlets for java.awt.Component,
Roman Kennke <=