List of usage examples for org.eclipse.jface.resource FontRegistry filterData
public FontData[] filterData(FontData[] fonts, Display display)
From source file:org.eclipse.ui.internal.themes.ThemeElementHelper.java
License:Open Source License
/** * Installs the given font in the preference store and optionally the font * registry./*w w w .j av a 2s . c o m*/ * * @param definition * the font definition * @param registry * the font registry * @param store * the preference store from which to set and obtain font data * @param setInRegistry * whether the color should be put into the registry as well as * having its default preference set */ private static void installFont(FontDefinition definition, ITheme theme, IPreferenceStore store, boolean setInRegistry) { FontRegistry registry = theme.getFontRegistry(); String id = definition.getId(); String key = createPreferenceKey(theme, id); FontData[] prefFont = store != null ? PreferenceConverter.getFontDataArray(store, key) : null; FontData[] defaultFont = null; if (definition.getValue() != null) { defaultFont = definition.getValue(); } else if (definition.getDefaultsTo() != null) { defaultFont = registry.filterData(registry.getFontData(definition.getDefaultsTo()), PlatformUI.getWorkbench().getDisplay()); } else { // values pushed in from jface property files. Very ugly. Display display = PlatformUI.getWorkbench().getDisplay(); //If in high contrast, ignore the defaults in jface and use the default (system) font. //This is a hack to address bug #205474. See bug #228207 for a future fix. FontData[] fontData = JFaceResources.getFontRegistry() .getFontData(display.getHighContrast() ? JFaceResources.DEFAULT_FONT : id); defaultFont = registry.bestDataArray(fontData, display); } if (setInRegistry) { if (prefFont == null || prefFont == PreferenceConverter.FONTDATA_ARRAY_DEFAULT_DEFAULT) { prefFont = defaultFont; } if (prefFont != null) { registry.put(id, prefFont); } } if (defaultFont != null && store != null) { PreferenceConverter.setDefault(store, key, defaultFont); } }
From source file:org.eclipse.ui.tests.preferences.DeprecatedFontPreferenceTestCase.java
License:Open Source License
/** * Test for a valid font like the test font. The first good one * we should find should be the first one in the list. *///w ww . j av a 2s.c om public void testGoodFontDefinition() { FontRegistry fontRegistry = JFaceResources.getFontRegistry(); FontData[] currentTextFonts = PreferenceConverter.getFontDataArray(preferenceStore, JFaceResources.TEXT_FONT); FontData bestFont = fontRegistry.filterData(currentTextFonts, Display.getCurrent())[0]; //Assert that it is the first font that we get as the //valid one assertEquals(bestFont.getName(), currentTextFonts[0].getName()); assertEquals(bestFont.getHeight(), currentTextFonts[0].getHeight()); }
From source file:org.eclipse.ui.tests.preferences.DeprecatedFontPreferenceTestCase.java
License:Open Source License
/** * Test that if the first font in the list is bad that the * second one comes back as valid.//w w w. j ava 2s . co m */ public void testBadFirstFontDefinition() { FontRegistry fontRegistry = JFaceResources.getFontRegistry(); FontData[] currentTestFonts = PreferenceConverter.getFontDataArray(preferenceStore, TEST_FONT_ID); FontData bestFont = fontRegistry.filterData(currentTestFonts, Display.getCurrent())[0]; //Assert that it is the second font that we get as the //valid one assertEquals(bestFont.getName(), currentTestFonts[1].getName()); assertEquals(bestFont.getHeight(), currentTestFonts[1].getHeight()); }
From source file:org.eclipse.ui.tests.preferences.DeprecatedFontPreferenceTestCase.java
License:Open Source License
/** * Test that the no valid font is returned when the entry * is missing.// w ww.j av a 2 s.c o m */ public void testNoFontDefinition() { FontRegistry fontRegistry = JFaceResources.getFontRegistry(); FontData[] currentTestFonts = PreferenceConverter.getFontDataArray(preferenceStore, MISSING_FONT_ID); FontData bestFont = fontRegistry.filterData(currentTestFonts, Display.getCurrent())[0]; FontData[] systemFontData = Display.getCurrent().getSystemFont().getFontData(); //Assert that the first font is the system font assertEquals(bestFont.getName(), systemFontData[0].getName()); assertEquals(bestFont.getHeight(), systemFontData[0].getHeight()); }
From source file:org.eclipse.ui.tests.preferences.FontPreferenceTestCase.java
License:Open Source License
/** * Test that if the first font in the list is bad that the * second one comes back as valid.// w w w. j ava 2 s. c o m */ public void testBadFirstFontDefinition() { FontRegistry fontRegistry = JFaceResources.getFontRegistry(); FontData[] currentTestFonts = PreferenceConverter.getFontDataArray(preferenceStore, TEST_FONT_ID); FontData[] bestFont = fontRegistry.filterData(currentTestFonts, Display.getCurrent()); //Assert that it is the second font that we get as the //valid one assertEquals(bestFont[0].getName(), currentTestFonts[1].getName()); assertEquals(bestFont[0].getHeight(), currentTestFonts[1].getHeight()); }
From source file:org.eclipse.ui.tests.preferences.FontPreferenceTestCase.java
License:Open Source License
/** * Test that the no valid font is returned when the entry * is missing.//from ww w .java 2 s.c om */ public void testNoFontDefinition() { FontRegistry fontRegistry = JFaceResources.getFontRegistry(); FontData[] currentTestFonts = PreferenceConverter.getFontDataArray(preferenceStore, MISSING_FONT_ID); FontData[] bestFont = fontRegistry.filterData(currentTestFonts, Display.getCurrent()); FontData[] systemFontData = Display.getCurrent().getSystemFont().getFontData(); //Assert that the first font is the system font assertEquals(bestFont[0].getName(), systemFontData[0].getName()); assertEquals(bestFont[0].getHeight(), systemFontData[0].getHeight()); }