Hi Thomas,

> > Some more stuff that I had trouble with Espial/Espresso. This should fix
> > the font handling in AWT.
> 
> [...]
> 
> >    /**
> >     * Called to ensure that the layout for this component is valid. This is
> >     * usually called on containers.
> >     *
> >     * @see #invalidate()
> >     * @see #doLayout()
> >     * @see LayoutManager
> >     * @see Container#validate()
> >     */
> >    public void validate()
> >    {
> > -    valid = true;
> > +    if (! valid)
> > +      {
> > +        // Synchronize on the tree here as this might change the layout
> > +        // of the hierarchy.
> > +        synchronized (getTreeLock())
> > +          {
> > +            // Create local variables for thread safety.
> > +            ComponentPeer p = peer;
> > +            if (p != null)
> > +              {
> > +                // Possibly update the peer's font.
> > +                Font newFont = getFont();
> > +                Font oldFont = peerFont;
> > +                // Only update when the font really changed.
> > +                if (newFont != oldFont
> > +                    && (oldFont == null || ! oldFont.equals(newFont)))
> > +                  {
> > +                    p.setFont(newFont);
> > +                    peerFont = newFont;
> > +                  }
> > +                // Let the peer perform any layout.
> > +                p.layout();
> > +              }
> > +          }
> > +        valid = true;
> > +      }
> >    }
> 
> Does the reference implementation do this font field manipulation in 
> validate? 
> Why is this needed in addition to the setFont part of your patch?

I noticed that the RI updates the peer font when the actual font changes
in a testprogram. Unfortunately, this seems to be hard to integrate into
mauve, because this involves a peer testing environment (own Toolkit and
dummy impls for the peers etc).
The reasoning behind this - afaics - that the font of a component is not
only a local setting, but also can depend on the font settings of the
ancestors of that component. So we fetch the current font via getFont()
and update the peerFont field and the actual peer's font setting _when
they differ_. Maybe I should comment this: The font field represents the
component's font only when it is not null. When this field is null, then
getFont() asks the parent. However, the peerFont field always represents
the component's real font (possibly fetched from the parent) but this
can only be guaranteed when the component is valid.

Regards, Roman



Reply via email to