List of usage examples for org.eclipse.jface.preference PreferenceConverter basicGetFontData
public static FontData[] basicGetFontData(String value)
FontData from the given string. From source file:eu.numberfour.n4js.ui.textzoom.TextZoomHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { boolean zoomIn = ZOOM_IN_ID.equals(event.getCommand().getId()); int delta = zoomIn ? +1 : -1; IPreferencesService preferencesService = Platform.getPreferencesService(); String value = preferencesService.getString(QUALIFIER, JFaceResources.TEXT_FONT, null, null); FontData fontData[] = PreferenceConverter.basicGetFontData(value); FontData fontdata = fontData[0];/*ww w .j a v a 2 s . co m*/ fontdata.setHeight(fontdata.getHeight() + delta); Preferences preferences = preferencesService.getRootNode().node("/instance/" + QUALIFIER); preferences.put(JFaceResources.TEXT_FONT, fontdata.toString()); try { preferences.flush(); } catch (BackingStoreException e) { // ignore } return null; }
From source file:io.usethesource.impulse.preferences.fields.FontFieldEditor.java
License:Open Source License
protected void doLoad() { if (changeFontButton == null) { return;/*from www .ja va2 s . c o m*/ } updateFont( PreferenceConverter.basicGetFontData(preferencesService.getStringPreference(getPreferenceName()))); }
From source file:io.usethesource.impulse.preferences.fields.FontFieldEditor.java
License:Open Source License
protected void doLoadDefault() { if (changeFontButton == null) { return;/*w w w . j a v a2 s . co m*/ } String fontPref = preferencesService.getStringPreference(IPreferencesService.DEFAULT_LEVEL, getPreferenceName()); updateFont(PreferenceConverter.basicGetFontData(fontPref)); }
From source file:io.usethesource.impulse.preferences.fields.FontFieldEditor.java
License:Open Source License
@Override protected void doLoadLevel(String level) { if (valueControl != null) { String value = preferencesService.getStringPreference(level, getPreferenceName()); updateFont(PreferenceConverter.basicGetFontData(value)); }//from w ww . j ava 2 s . c o m }
From source file:io.usethesource.impulse.preferences.fields.FontFieldEditor.java
License:Open Source License
@Override protected String doLoadWithInheritance() { String levelLoaded = null;//from w ww. j av a 2s . c o m String[] levels = IPreferencesService.levels; // If we're loading with inheritance for some field that is // not attached to a preferences level then assume that we // should just search from the bottom up int startingLevelIdx = (preferencesLevel == null) ? 0 : PREFS_LEVELS_AS_LIST.indexOf(preferencesLevel); int levelAtWhichFound = -1; String encodedFontValue = null; // Search up levels starting from the level of this field for (int level = startingLevelIdx; level < levels.length; level++) { encodedFontValue = preferencesService.getRawStringPreference(levels[level], getPreferenceName()); if (encodedFontValue != null) { levelAtWhichFound = level; levelLoaded = levels[levelAtWhichFound]; break; } } if (encodedFontValue == null) { encodedFontValue = DEFAULT_FONT_DESCRIPTOR; } // TODO should this be calling updateFont() instead of the following? levelFromWhichLoaded = levelLoaded; setInherited(startingLevelIdx != levelAtWhichFound); setPresentsDefaultValue(IPreferencesService.DEFAULT_LEVEL.equals(levelFromWhichLoaded)); fieldModified = true; // valueChanged(); // should not be called when field set from preference store previousValue = chosenFont; // not clear whether this needs to be done on initial load from store chosenFont = PreferenceConverter.basicGetFontData(encodedFontValue); if (valueControl != null) { valueControl.setText(StringConverter.asString(chosenFont[0])); } if (previewer != null) { previewer.setFont(chosenFont); } return levelLoaded; }
From source file:org.eclipse.ui.internal.themes.Theme.java
License:Open Source License
/** * Listener that is responsible for responding to preference changes. * /*from ww w .j a va 2s . co m*/ * @return the property change listener */ private IPropertyChangeListener getPropertyListener() { if (propertyListener == null) { propertyListener = new IPropertyChangeListener() { /* (non-Javadoc) * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { String[] split = ThemeElementHelper.splitPropertyName(Theme.this, event.getProperty()); String key = split[1]; String theme = split[0]; if (key.equals(IWorkbenchPreferenceConstants.CURRENT_THEME_ID)) { return; } try { String thisTheme = getId(); if (Util.equals(thisTheme, theme)) { if (getFontRegistry().hasValueFor(key)) { FontData[] data = PreferenceConverter .basicGetFontData((String) event.getNewValue()); getFontRegistry().put(key, data); processDefaultsTo(key, data); return; } else if (getColorRegistry().hasValueFor(key)) { RGB rgb = StringConverter.asRGB((String) event.getNewValue()); getColorRegistry().put(key, rgb); processDefaultsTo(key, rgb); return; } } } catch (DataFormatException e) { //no-op } } /** * Process all fonts that default to the given ID. * * @param key the font ID * @param fd the new FontData for defaulted fonts */ private void processDefaultsTo(String key, FontData[] fd) { FontDefinition[] defs = WorkbenchPlugin.getDefault().getThemeRegistry().getFontsFor(getId()); for (int i = 0; i < defs.length; i++) { String defaultsTo = defs[i].getDefaultsTo(); if (defaultsTo != null && defaultsTo.equals(key)) { IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); if (store.isDefault( ThemeElementHelper.createPreferenceKey(Theme.this, defs[i].getId()))) { getFontRegistry().put(defs[i].getId(), fd); processDefaultsTo(defs[i].getId(), fd); } } } } /** * Process all colors that default to the given ID. * * @param key the color ID * @param rgb the new RGB value for defaulted colors */ private void processDefaultsTo(String key, RGB rgb) { ColorDefinition[] defs = WorkbenchPlugin.getDefault().getThemeRegistry().getColorsFor(getId()); for (int i = 0; i < defs.length; i++) { String defaultsTo = defs[i].getDefaultsTo(); if (defaultsTo != null && defaultsTo.equals(key)) { IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); if (store.isDefault( ThemeElementHelper.createPreferenceKey(Theme.this, defs[i].getId()))) { getColorRegistry().put(defs[i].getId(), rgb); processDefaultsTo(defs[i].getId(), rgb); } } } } }; } return propertyListener; }
From source file:org.eclipse.xtext.ui.editor.utils.EditorUtils.java
License:Open Source License
public static Font fontFromFontData(FontData[] fontDataArray) { if (fontDataArray != null && fontDataArray.length > 0) { String fontData = PreferenceConverter.getStoredRepresentation(fontDataArray); if (!JFaceResources.getFontRegistry().hasValueFor(fontData)) { FontData[] fData = PreferenceConverter.basicGetFontData(fontData); JFaceResources.getFontRegistry().put(fontData, fData); }//w ww .ja v a2 s . co m Font font = JFaceResources.getFontRegistry().get(fontData); return font; } return null; }
From source file:tarlog.eclipse.plugins.handlers.FontUtils.java
License:Apache License
private static void changeFont(String qualifier, String key, int changeBy) { IPreferencesService preferencesService = Platform.getPreferencesService(); String value = preferencesService.getString(qualifier, key, null, null); FontData fontData[] = PreferenceConverter.basicGetFontData(value); FontData fontdata = fontData[0];//from ww w .ja v a 2 s. c o m fontdata.setHeight(fontdata.getHeight() + changeBy); Preferences preferences = preferencesService.getRootNode().node("/instance/" + qualifier); preferences.put(key, fontdata.toString()); try { preferences.flush(); } catch (BackingStoreException e) { } }