summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/awt/Component.java
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2005-09-23 21:31:04 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2005-09-23 21:31:04 +0000
commit947b8814056ea2fba6bbcfab86591f74bffc0311 (patch)
tree3ca4b2e68dc14c3128b9c781d23f1d0b1f2bee49 /libjava/classpath/java/awt/Component.java
parent49792907376493f0939563eb0219b96a48f1ae3b (diff)
downloadppe42-gcc-947b8814056ea2fba6bbcfab86591f74bffc0311.tar.gz
ppe42-gcc-947b8814056ea2fba6bbcfab86591f74bffc0311.zip
Imported Classpath 0.18.
* sources.am, Makefile.in: Updated. * Makefile.am (nat_source_files): Removed natProxy.cc. * java/lang/reflect/natProxy.cc: Removed. * gnu/classpath/jdwp/VMFrame.java, gnu/classpath/jdwp/VMIdManager.java, gnu/classpath/jdwp/VMVirtualMachine.java, java/lang/reflect/VMProxy.java: New files. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * scripts/makemake.tcl (verbose): Add gnu/java/awt/peer/qt to BC list. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/net/DefaultContentHandlerFactory.java (getContent): Remove ClasspathToolkit references. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/awt/xlib/XCanvasPeer.java: Add new peer methods. * gnu/awt/xlib/XFramePeer.java: Likewise. * gnu/awt/xlib/XGraphicsConfiguration.java: Likewise. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * Makefile.am (libgcjawt_la_SOURCES): Remove jawt.c. Add classpath/native/jawt/jawt.c. * Makefile.in: Regenerate. * jawt.c: Remove file. * include/Makefile.am (tool_include__HEADERS): Remove jawt.h and jawt_md.h. Add ../classpath/include/jawt.h and ../classpath/include/jawt_md.h. * include/Makefile.in: Regenerate. * include/jawt.h: Regenerate. * include/jawt_md.h: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@104586 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/awt/Component.java')
-rw-r--r--libjava/classpath/java/awt/Component.java179
1 files changed, 122 insertions, 57 deletions
diff --git a/libjava/classpath/java/awt/Component.java b/libjava/classpath/java/awt/Component.java
index 4491904d0a4..0ae1ffa7d0b 100644
--- a/libjava/classpath/java/awt/Component.java
+++ b/libjava/classpath/java/awt/Component.java
@@ -897,9 +897,21 @@ public abstract class Component
if(!isVisible())
{
this.visible = true;
- if (peer != null)
- peer.setVisible(true);
- invalidate();
+ // Avoid NullPointerExceptions by creating a local reference.
+ ComponentPeer currentPeer=peer;
+ if (currentPeer != null)
+ currentPeer.setVisible(true);
+
+ // Invalidate the parent if we have one. The component itself must
+ // not be invalidated. We also avoid NullPointerException with
+ // a local reference here.
+ Container currentParent = parent;
+ if (currentParent != null)
+ {
+ currentParent.invalidate();
+ currentParent.repaint();
+ }
+
ComponentEvent ce =
new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
getToolkit().getSystemEventQueue().postEvent(ce);
@@ -930,10 +942,23 @@ public abstract class Component
{
if (isVisible())
{
- if (peer != null)
- peer.setVisible(false);
+ // Avoid NullPointerExceptions by creating a local reference.
+ ComponentPeer currentPeer=peer;
+ if (currentPeer != null)
+ currentPeer.setVisible(false);
+
this.visible = false;
- invalidate();
+
+ // Invalidate the parent if we have one. The component itself must
+ // not be invalidated. We also avoid NullPointerException with
+ // a local reference here.
+ Container currentParent = parent;
+ if (currentParent != null)
+ {
+ currentParent.invalidate();
+ currentParent.repaint();
+ }
+
ComponentEvent ce =
new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
getToolkit().getSystemEventQueue().postEvent(ce);
@@ -963,10 +988,12 @@ public abstract class Component
*/
public void setForeground(Color c)
{
- firePropertyChange("foreground", foreground, c);
if (peer != null)
peer.setForeground(c);
+
+ Color previous = foreground;
foreground = c;
+ firePropertyChange("foreground", previous, c);
}
/**
@@ -992,7 +1019,7 @@ public abstract class Component
{
if (background != null)
return background;
- return parent == null ? SystemColor.window : parent.getBackground();
+ return parent == null ? null : parent.getBackground();
}
/**
@@ -1006,16 +1033,18 @@ public abstract class Component
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);
}
/**
@@ -1039,13 +1068,15 @@ public abstract class Component
*/
public Font getFont()
{
- if (font != null)
- return font;
+ Font f = font;
+ if (f != null)
+ return f;
- if (parent != null)
- return parent.getFont ();
+ Component p = parent;
+ if (p != null)
+ return p.getFont();
else
- return new Font ("Dialog", Font.PLAIN, 12);
+ return new Font("Dialog", Font.PLAIN, 12);
}
/**
@@ -1058,15 +1089,16 @@ public abstract class Component
*/
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();
+ }
}
/**
@@ -1372,9 +1404,6 @@ public abstract class Component
// Erase old bounds and repaint new bounds for lightweights.
if (isLightweight() && isShowing ())
{
- boolean shouldRepaintParent = false;
- boolean shouldRepaintSelf = false;
-
if (parent != null)
{
Rectangle parentBounds = parent.getBounds();
@@ -1384,14 +1413,11 @@ public abstract class Component
Rectangle newBounds = new Rectangle(parent.getX() + x,
parent.getY() + y,
width, height);
- shouldRepaintParent = parentBounds.intersects(oldBounds);
- shouldRepaintSelf = parentBounds.intersects(newBounds);
+ Rectangle destroyed = oldBounds.union(newBounds);
+ if (!destroyed.isEmpty())
+ parent.repaint(0, destroyed.x, destroyed.y, destroyed.width,
+ destroyed.height);
}
-
- if (shouldRepaintParent && parent != null)
- parent.repaint(oldx, oldy, oldwidth, oldheight);
- if (shouldRepaintSelf)
- repaint();
}
// Only post event if this component is visible and has changed size.
@@ -1798,9 +1824,8 @@ public abstract class Component
*/
public void paint(Graphics g)
{
- // Paint the heavyweight peer
- if (!isLightweight() && peer != null)
- peer.paint(g);
+ // This is a callback method and is meant to be overridden by subclasses
+ // that want to perform custom painting.
}
/**
@@ -1816,10 +1841,20 @@ public abstract class Component
*
* @see #paint(Graphics)
* @see #repaint()
+ *
+ * @specnote In contrast to what the spec says, tests show that the exact
+ * behaviour is to clear the background on lightweight and
+ * top-level components only. Heavyweight components are not
+ * affected by this method and only call paint().
*/
public void update(Graphics g)
{
- if (!isLightweight())
+ // Tests show that the clearing of the background is only done in
+ // two cases:
+ // - If the component is lightweight (yes this is in contrast to the spec).
+ // or
+ // - If the component is a toplevel container.
+ if (isLightweight() || getParent() == null)
{
Rectangle clip = g.getClipBounds();
if (clip == null)
@@ -1827,7 +1862,6 @@ public abstract class Component
else
g.clearRect(clip.x, clip.y, clip.width, clip.height);
}
-
paint(g);
}
@@ -1854,7 +1888,14 @@ public abstract class Component
*/
public void repaint()
{
- repaint(0, 0, 0, width, height);
+ if(!isShowing())
+ {
+ Component p = parent;
+ if (p != null)
+ p.repaint(0, getX(), getY(), width, height);
+ }
+ else
+ repaint(0, 0, 0, width, height);
}
/**
@@ -1868,7 +1909,14 @@ public abstract class Component
*/
public void repaint(long tm)
{
- repaint(tm, 0, 0, width, height);
+ if(!isShowing())
+ {
+ Component p = parent;
+ if (p != null)
+ p.repaint(tm, getX(), getY(), width, height);
+ }
+ else
+ repaint(tm, 0, 0, width, height);
}
/**
@@ -1885,7 +1933,14 @@ public abstract class Component
*/
public void repaint(int x, int y, int w, int h)
{
- repaint(0, x, y, w, h);
+ if(!isShowing())
+ {
+ Component p = parent;
+ if (p != null)
+ p.repaint(0, x + getX(), y + getY(), width, height);
+ }
+ else
+ repaint(0, x, y, w, h);
}
/**
@@ -1903,14 +1958,18 @@ public abstract class Component
*/
public void repaint(long tm, int x, int y, int width, int height)
{
- // Handle lightweight repainting by forwarding to native parent
- if (isLightweight() && parent != null)
+ if(!isShowing())
{
- if (parent != null)
- parent.repaint(tm, x + getX(), y + getY(), width, height);
+ Component p = parent;
+ if (p != null)
+ p.repaint(tm, x + getX(), y + getY(), width, height);
+ }
+ else
+ {
+ ComponentPeer p = peer;
+ if (p != null)
+ p.repaint(tm, x, y, width, height);
}
- else if (peer != null)
- peer.repaint(tm, x, y, width, height);
}
/**
@@ -1971,7 +2030,7 @@ public abstract class Component
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
{
if ((flags & (FRAMEBITS | ALLBITS)) != 0)
- repaint ();
+ repaint();
else if ((flags & SOMEBITS) != 0)
{
if (incrementalDraw)
@@ -1981,10 +2040,10 @@ public abstract class Component
long tm = redrawRate.longValue();
if (tm < 0)
tm = 0;
- repaint (tm);
+ repaint(tm);
}
else
- repaint (100);
+ repaint(100);
}
}
return (flags & (ALLBITS | ABORT | ERROR)) == 0;
@@ -2282,8 +2341,6 @@ public abstract class Component
// Some subclasses in the AWT package need to override this behavior,
// hence the use of dispatchEventImpl().
dispatchEventImpl(e);
- if (peer != null && ! e.consumed)
- peer.handleEvent(e);
}
/**
@@ -4183,6 +4240,10 @@ public abstract class Component
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();
}
@@ -4742,7 +4803,7 @@ p * <li>the set of backward traversal keys
* @param e the event to dispatch
*/
- void dispatchEventImpl (AWTEvent e)
+ void dispatchEventImpl(AWTEvent e)
{
Event oldEvent = translateEvent (e);
@@ -4776,8 +4837,12 @@ p * <li>the set of backward traversal keys
break;
}
}
- processEvent (e);
+ if (e.id != PaintEvent.PAINT && e.id != PaintEvent.UPDATE)
+ processEvent(e);
}
+
+ if (peer != null)
+ peer.handleEvent(e);
}
/**
OpenPOWER on IntegriCloud