Patch: GLightweightPeer,LightweightPeer,Toolkit allow creation and display of lightweight components

Scott Gilbertson scottg@mantatest.com
Wed Jan 15 19:54:00 GMT 2003


> Scott> These changes allow creation and display of lighweight
> Scott> components by directly subclassing java.awt.Component and
> Scott> java.awt.Container.
Tom> I'm not so sure about this change.  I'll look at it a little later
Tom> today and see what is going on.

Neither am I, but I couldn't immediately see any other way to create a
functional lightweight container, and the change works.
Note that the javadoc for java.awt.Toolkit.createComponent in j2sdk 1.4.0
says "Creates a peer for a component or container. This peer is windowless
and allows the Component and Container classes to be extended directly to
create windowless components that are defined entirely in java."  The
comment in the libjava implementation doesn't mention containers.  I should
have changed it to match.

> Scott> gcc/libjava/java/awt/Toolkit.java
> Scott>  protected LightweightPeer
> Scott>  createComponent(Component target)
> Scott>  {
> Scott> -  return null;
> Scott> +  return gnu.java.awt.GLightweightPeer.INSTANCE;
> Scott>  }
Tom> This change we definitely can't put in.  This makes the
Tom> platform-independent Toolkit class depend directly on a particular
Tom> lightweight peer implementation.  It seems to me that this function
Tom> should be overridden in the platform-specific Toolkit, for instance
Tom> XToolkit.  What do you think about that?

We could have XLightweightPeer (new class, initially identical to
GLightweightPeer) returned from XToolkit.createComponent, but the reason
java.awt.Toolkit.createComponent isn't abstract is to allow the base Tookit
class to return a trivial peer.  I claim lightweights can be
non-platform-specific ("windowless components that are defined entirely in
java" in the earlier quote), which if true would eliminate the "particular
lightweight peer implementation" problem.

Tom> That said, I don't understand why the GLightweightPeer class is in
Tom> gnu.java.awt and not somewhere else.  So, I'm a little confused.

Perhaps it's because that's more-or-less how Sun does it
(sun.awt.NullComponentPeer returned from java.awt.Toolkit.getComponent), but
I guess I'm not supposed to look at that (good thing they didn't include
NullComponentPeer source in the JDK, or I'd be tempted).




More information about the Java-patches mailing list