I have an Eclipse plugin which creates a JavaSourceViewer
to visualize specific source code in a separate view.
I would like to configure the font of the viewer to match the settings of the Java Editor Text Font preference:
JavaSourceViewer textViewer = new JavaSourceViewer(...);
...
// get the SWT component which displays the text
StyledText textControl = textViewer.getTextWidget();
// retrieve the font preference from the theme manager
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
ITheme currentTheme = themeManager.getCurrentTheme();
FontRegistry fontRegistry = currentTheme.getFontRegistry();
Font font = fontRegistry.get(PreferenceConstants.EDITOR_TEXT_FONT);
// set the font on the SWT component
textControl.setFont(font);
My question is especially about the code block which retrieves the font from the theme manager:
- Is this the correct approach to get the font?
- Is there anything else which needs to be considered?