use of org.eclipse.ui.internal.themes.FontDefinition in project eclipse.platform.ui by eclipse-platform.
the class FontDefinitionTest method testFontDefinitionWhenNameCategoryIdAndDescriptionOverridden.
@Test
public void testFontDefinitionWhenNameCategoryIdAndDescriptionOverridden() {
// given
engine = createEngine("FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic; font-weight: bold;" + " label:'nameOverridden'; category: '#categoryIdOverridden'; description: 'descriptionOverridden'}", display);
FontDefinition definition = fontDefinition("org.eclipse.jface.bannerfont", "name", "categoryId", "description");
assertNull(definition.getValue());
assertFalse(definition.isOverridden());
// when
engine.applyStyles(definition, true);
// then
assertNotNull(definition.getValue());
assertEquals("Times", definition.getValue()[0].getName());
assertEquals(12, definition.getValue()[0].getHeight());
assertEquals(SWT.ITALIC | SWT.BOLD, definition.getValue()[0].getStyle());
assertEquals("categoryIdOverridden", definition.getCategoryId());
assertEquals("nameOverridden", definition.getName());
assertTrue(definition.getDescription().startsWith("descriptionOverridden"));
assertTrue(definition.isOverridden());
}
use of org.eclipse.ui.internal.themes.FontDefinition in project eclipse.platform.ui by eclipse-platform.
the class Workbench method initializeFonts.
/*
* Initializes the workbench fonts with the stored values.
*/
private void initializeFonts() {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
FontDefinition[] fontDefinitions = WorkbenchPlugin.getDefault().getThemeRegistry().getFonts();
ThemeElementHelper.populateRegistry(getThemeManager().getCurrentTheme(), fontDefinitions, PrefUtil.getInternalPreferenceStore());
final IPropertyChangeListener themeToPreferencesFontSynchronizer = event -> {
if (event.getNewValue() instanceof FontData[]) {
FontData[] fontData = (FontData[]) event.getNewValue();
PrefUtil.getInternalPreferenceStore().setValue(event.getProperty(), PreferenceConverter.getStoredRepresentation(fontData));
}
};
getThemeManager().getCurrentTheme().getFontRegistry().addListener(themeToPreferencesFontSynchronizer);
getThemeManager().addPropertyChangeListener(event -> {
if (IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) {
Object oldValue = event.getOldValue();
if (oldValue != null && oldValue instanceof ITheme) {
((ITheme) oldValue).removePropertyChangeListener(themeToPreferencesFontSynchronizer);
}
Object newValue = event.getNewValue();
if (newValue != null && newValue instanceof ITheme) {
((ITheme) newValue).addPropertyChangeListener(themeToPreferencesFontSynchronizer);
}
}
});
}
});
}
use of org.eclipse.ui.internal.themes.FontDefinition in project eclipse.platform.ui by eclipse-platform.
the class ExtensionEventHandler method loadThemes.
// TODO: confirm
private void loadThemes(IExtension ext) {
ThemeRegistryReader reader = new ThemeRegistryReader();
ThemeRegistry registry = (ThemeRegistry) WorkbenchPlugin.getDefault().getThemeRegistry();
reader.setRegistry(registry);
for (IConfigurationElement configElement : ext.getConfigurationElements()) {
reader.readElement(configElement);
}
Collection<ColorDefinition> colors = reader.getColorDefinitions();
ColorDefinition[] colorDefs = colors.toArray(new ColorDefinition[colors.size()]);
ITheme theme = workbench.getThemeManager().getTheme(IThemeManager.DEFAULT_THEME);
ThemeElementHelper.populateRegistry(theme, colorDefs, PrefUtil.getInternalPreferenceStore());
Collection<FontDefinition> fonts = reader.getFontDefinitions();
FontDefinition[] fontDefs = fonts.toArray(new FontDefinition[fonts.size()]);
ThemeElementHelper.populateRegistry(theme, fontDefs, PrefUtil.getInternalPreferenceStore());
Map<String, String> data = reader.getData();
registry.addData(data);
}
use of org.eclipse.ui.internal.themes.FontDefinition in project eclipse.platform.ui by eclipse-platform.
the class ThemesExtensionTest method testThemesExtension.
@Test
public void testThemesExtension() {
// given
engine = createEngine("ThemesExtension {font-definition: '#org-eclipse-ui-workbench-FONT_DEF_1'," + "'#org-eclipse-ui-workbench-FONT_DEF_2'; color-definition: '#org-eclipse-ui-workbench-COLOR_DEF_1';}", display);
ThemesExtension themesExtention = new ThemesExtension();
// when
engine.applyStyles(themesExtention, true);
// then
assertEquals(3, themesExtention.getDefinitions().size());
assertTrue(themesExtention.getDefinitions().get(0) instanceof FontDefinition);
FontDefinition fontDefinition1 = (FontDefinition) themesExtention.getDefinitions().get(0);
assertTrue(fontDefinition1.isAddedByCss());
assertFalse(fontDefinition1.isOverridden());
assertEquals("org.eclipse.ui.workbench.FONT_DEF_1", fontDefinition1.getId());
assertEquals(ThemesExtension.DEFAULT_CATEGORY_ID, fontDefinition1.getCategoryId());
assertTrue(fontDefinition1.getName().startsWith(FontDefinition.class.getSimpleName()));
assertTrue(fontDefinition1.getName().endsWith(fontDefinition1.getId()));
assertNotNull(fontDefinition1.getDescription());
assertTrue(themesExtention.getDefinitions().get(1) instanceof FontDefinition);
FontDefinition fontDefinition2 = (FontDefinition) themesExtention.getDefinitions().get(1);
assertTrue(fontDefinition2.isAddedByCss());
assertFalse(fontDefinition2.isOverridden());
assertEquals("org.eclipse.ui.workbench.FONT_DEF_2", fontDefinition2.getId());
assertEquals(ThemesExtension.DEFAULT_CATEGORY_ID, fontDefinition1.getCategoryId());
assertTrue(fontDefinition2.getName().startsWith(FontDefinition.class.getSimpleName()));
assertTrue(fontDefinition2.getName().endsWith(fontDefinition2.getId()));
assertNotNull(fontDefinition2.getDescription());
assertTrue(themesExtention.getDefinitions().get(2) instanceof ColorDefinition);
ColorDefinition colorDefinition1 = (ColorDefinition) themesExtention.getDefinitions().get(2);
assertTrue(colorDefinition1.isAddedByCss());
assertFalse(colorDefinition1.isOverridden());
assertEquals("org.eclipse.ui.workbench.COLOR_DEF_1", colorDefinition1.getId());
assertNotNull(colorDefinition1.getDescription());
assertEquals(ThemesExtension.DEFAULT_CATEGORY_ID, colorDefinition1.getCategoryId());
assertTrue(colorDefinition1.getName().startsWith(ColorDefinition.class.getSimpleName()));
assertTrue(colorDefinition1.getName().endsWith(colorDefinition1.getId()));
assertNotNull(colorDefinition1.getDescription());
}
use of org.eclipse.ui.internal.themes.FontDefinition in project eclipse.platform.ui by eclipse-platform.
the class ThemeRegistryModifiedHandlerTest method testHandleEvent.
@Test
public void testHandleEvent() throws Exception {
// given
FontDefinition fontDefinition1 = mock(FontDefinition.class);
doReturn("fontDefinition1").when(fontDefinition1).getId();
doReturn(true).when(fontDefinition1).isOverridden();
FontDefinition fontDefinition2 = mock(FontDefinition.class);
doReturn("fontDefinition2").when(fontDefinition2).getId();
doReturn(false).when(fontDefinition2).isOverridden();
ColorDefinition colorDefinition = mock(ColorDefinition.class);
doReturn("colorDefinition").when(colorDefinition).getId();
doReturn(true).when(colorDefinition).isOverridden();
ThemeRegistry themeRegistry = spy(new ThemeRegistry());
doReturn(new FontDefinition[] { fontDefinition1, fontDefinition2 }).when(themeRegistry).getFonts();
doReturn(new ColorDefinition[] { colorDefinition }).when(themeRegistry).getColors();
FontRegistry fontRegistry = mock(FontRegistry.class);
ColorRegistry colorRegistry = mock(ColorRegistry.class);
ITheme colorsAndFontsTheme = mock(ITheme.class);
doReturn("3.x theme id").when(colorsAndFontsTheme).getId();
org.eclipse.e4.ui.css.swt.theme.ITheme cssTheme = mock(org.eclipse.e4.ui.css.swt.theme.ITheme.class);
doReturn("css theme id").when(cssTheme).getId();
ThemeRegistryModifiedHandlerTestable handler = spy(new ThemeRegistryModifiedHandlerTestable());
doReturn(themeRegistry).when(handler).getThemeRegistry();
doReturn(fontRegistry).when(handler).getFontRegistry();
doReturn(colorRegistry).when(handler).getColorRegistry();
doReturn(colorsAndFontsTheme).when(handler).getColorsAndFontsTheme();
doReturn(cssTheme).when(handler).getTheme();
// when
handler.handleEvent(mock(Event.class));
// then
verify(handler, times(1)).populateThemeRegistries(themeRegistry, fontRegistry, colorRegistry, cssTheme, colorsAndFontsTheme);
verify(handler, times(1)).sendThemeDefinitionChangedEvent();
}
Aggregations