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

时间:2017-06-09 12:38:02

标签: java eclipse-plugin

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

How can I do it?

1 个答案:

答案 0 :(得分:1)

此首选项页面定义当前主题颜色和字体注册表中的条目。

获取当前主题:

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

获取注册表:

ColorRegistry colorRegistry = currentTheme.getColorRegistry();

FontRegistry fontRegistry = currentTheme.getFontRegistry();

使用org.eclipse.ui.themes colorDefinitionfontDefinition条目中定义的密钥访问各种颜色和字体。一些最常见的ID在JFaceResources

中定义
Color color = colorRegistry.get("color id");

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

您还可以获得一组已定义的键:

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

您可以从FontData获取字体的字体名称:

FontData [] fontData = dialogFont.getFontData();

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