[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform] Re: How to get default font in Table

Tom,

It's easy, though not self evident. I suppose it's documented somewhere in that documentation I never read. :-)

It also seems a little dangerous to use a global registry for a particular column viewer. You'd certainly need to be careful to create a key that's unique to this particular column viewer wouldn't you? (Especially for code that might be reused a lot and have different fonts in different places.) And then I'm not certain if this registry gets cleaned up when my viewer is deleted, so it might accumulate viewer-specific garbage.

I'll bet there isn't a single IFontLabelProvider implementation that doesn't need to keep track of the default font for what it's viewing, so I would have hoped for something more "built-in". One problem I see in this regard is that while an IContentProvider has an inputChanged so it knows the viewer that's using it, the ILabelProvider has no such mechanism (that I know of).


Tom Schindl wrote:
Ed,

public MyFontProvider(ColumnViewer viewer) {

    JFaceResources.getFontRegistry().put("MY_FONT",
        viewer.getControl().getFont()
    );
}

public Font getFont() {
    return JFaceResources.getFontRegistry().getItalic("MY_FONT");
}


Isn't that easy enough?

Tom

Ed Merks schrieb:
Prasad,

I found it a bit frustrating when prototyping https://bugs.eclipse.org/bugs/show_bug.cgi?id=95934 that the basic design doesn't include access to the default font since the typical requirement is to change the existing font of the viewer to bold or italic rather than to specify a font from scratch. So it's necessary to know the font being used by the target and to do that you need to set that up yourself using Control.getFont for the Table and passing that in to your specialized label provider.


prasad wrote:
Hi

How can I get the default font used in the table. I am using ITabelFontProvider in TableLableProvider. I want to make some rows bold.
Thanks
Prasad