Jump to: navigation, search

AbstractTextEditor Font Management

Revision as of 18:50, 5 February 2009 by Bimargulies.gmail.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The AbstractTextEditor class is the base class of all the textual editors in Eclipse. If you want to build a plugin that displays text in the main editor area, you will inevitably end up looking at the class as the basis of your work.

By and large, it's pretty straightforward to create your own text editor. The API to this class gives you opportunities to take comprehensive control. One area that is a bit convoluted, however, is font management.

AbstractTextEditor implements a font scheme tied to the org.eclipse.ui.editors extension point. When you define an editor, one of the attributes of the editor extension is a symbolicFontName. If you leave it blank, it defaults to the value of JFaceResources.TEXT_FONT.

The symbolic font name is a key into the font resources defined in org.eclipse.ui.themes. Users can bind specific fonts to these symbolic names in the 'Fonts and Colors' preferences page.

The scheme, then, is as follows:

If you leave symbolicFontName blank, your editor will share the generic Text Editor font.

If you don't want to share the generic Text Editor font, you must define a symbolic font name via an extension in org.eclipse.ui.themes. Then you put that ID into the symbolicFontName. Now users can choose a font that will be applied to all instances of your editor.