The GLightweightPeer normally does nothing (as the actions)and most
methods are implemented to return null or so. However, we might still
end up in it for one reason (crappy apps doing nasty stuff) or another
(crap in Classpath). I implemented some methods to do something
reasonable in such a case.
2006-11-14 Roman Kennke <[EMAIL PROTECTED]>
* gnu/java/awt/peer/GLightweightPeer.java
(handleEvent): Try to do something reasonable and trigger
painting
for the lightweight component.
(getFontMetrics): Fetch and return a font metrics object from
the Toolkit.
/Roman
Index: gnu/java/awt/peer/GLightweightPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/GLightweightPeer.java,v
retrieving revision 1.10
diff -u -1 -5 -r1.10 GLightweightPeer.java
--- gnu/java/awt/peer/GLightweightPeer.java 28 Jul 2006 10:07:39 -0000 1.10
+++ gnu/java/awt/peer/GLightweightPeer.java 14 Nov 2006 10:13:28 -0000
@@ -151,32 +151,34 @@
}
public void enable()
{
// Nothing to do here for lightweights.
}
public GraphicsConfiguration getGraphicsConfiguration()
{
// Nothing to do here for lightweights.
return null;
}
public FontMetrics getFontMetrics(Font f)
{
- // Nothing to do here for lightweights.
- return null;
+ // We shouldn't end up here, but if we do we can still try do something
+ // reasonable.
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ return tk.getFontMetrics(f);
}
/* Returning null here tells the Component object that called us to
* use its parent's Graphics. */
public Graphics getGraphics()
{
// Nothing to do here for lightweights.
return null;
}
public Point getLocationOnScreen()
{
// Nothing to do here for lightweights.
return null;
}
@@ -189,31 +191,55 @@
public Dimension getPreferredSize()
{
return preferredSize();
}
/* Returning null here tells the Component object that called us to
* use its parent's Toolkit. */
public Toolkit getToolkit()
{
// Nothing to do here for lightweights.
return null;
}
public void handleEvent(AWTEvent e)
{
- // Nothing to do here for lightweights.
+ // This can only happen when an application posts a PaintEvent for
+ // a lightweight component directly. We still support painting for
+ // this case.
+ if (e instanceof PaintEvent)
+ {
+ PaintEvent pe = (PaintEvent) e;
+ Component target = (Component) e.getSource();
+ if (target != null && target.isShowing())
+ {
+ Graphics g = target.getGraphics();
+ if (g != null)
+ {
+ try
+ {
+ Rectangle clip = pe.getUpdateRect();
+ g.setClip(clip);
+ target.paint(g);
+ }
+ finally
+ {
+ g.dispose();
+ }
+ }
+ }
+ }
}
public void hide()
{
// Nothing to do here for lightweights.
}
public boolean isFocusable()
{
// Nothing to do here for lightweights.
return false;
}
public boolean isFocusTraversable()
{