In Eclipse, I need to access "Preferences > General > Appearance > Colors and Fonts" programmatically.
How can I do it?
答案 0 :(得分:1)
此首选项页面定义当前主题颜色和字体注册表中的条目。
获取当前主题:
ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
获取注册表:
ColorRegistry colorRegistry = currentTheme.getColorRegistry();
FontRegistry fontRegistry = currentTheme.getFontRegistry();
使用org.eclipse.ui.themes
colorDefinition
或fontDefinition
条目中定义的密钥访问各种颜色和字体。一些最常见的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();