Vladimir Kozhaev
Vladimir Kozhaev

Reputation: 97

Eclipse plug-ins. How to programmatically access to workspace preferences?

In Eclipse, I need to access "Preferences > General > Appearance > Colors and Fonts" programmatically.

How can I do it?

Upvotes: 2

Views: 853

Answers (1)

greg-449
greg-449

Reputation: 111142

This preference page defines entries in the current theme color and font registries.

Get the current theme with:

ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();

Get the registries with:

ColorRegistry colorRegistry = currentTheme.getColorRegistry();

FontRegistry fontRegistry = currentTheme.getFontRegistry();

Individual colors and fonts are accessed using the key defined in the org.eclipse.ui.themes colorDefinition or fontDefinition entry. Some of the most common ids are defined in JFaceResources:

Color color = colorRegistry.get("color id");

Font dialogFont = colorRegistry.get(JFaceResources.DIALOG_FONT);

You can also get the set of defined keys:

Set<String> fontIdKeys = fontRegistry.getKeySet();

You get the font name from the FontData for the font:

FontData [] fontData = dialogFont.getFontData();

String fontName = fontData[0].getName();

Upvotes: 3

Related Questions