Example usage for org.eclipse.jface.preference PreferenceConverter readFontData

List of usage examples for org.eclipse.jface.preference PreferenceConverter readFontData

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceConverter readFontData.

Prototype

public static FontData[] readFontData(String fontDataValue) 

Source Link

Document

Reads the supplied string and returns its corresponding FontData.

Usage

From source file:com.redhat.ceylon.eclipse.code.editor.CeylonEditor.java

License:Open Source License

private void setSourceFontFromPreference() {
    String fontName = WorkbenchPlugin.getDefault().getPreferenceStore().getString(JFaceResources.TEXT_FONT);
    FontRegistry fontRegistry = CeylonPlugin.getInstance().getFontRegistry();
    if (!fontRegistry.hasValueFor(fontName)) {
        fontRegistry.put(fontName, PreferenceConverter.readFontData(fontName));
    }/*from  w  w  w.j a  va2 s. c o m*/
    Font sourceFont = fontRegistry.get(fontName);
    if (sourceFont != null) {
        getSourceViewer().getTextWidget().setFont(sourceFont);
    }
}

From source file:org.eclipse.imp.editor.UniversalEditor.java

License:Open Source License

private void setupSourcePrefListeners() {
    // If there are no language-specific preferences, use the settings on the IMP preferences page
    if (fLangSpecificPrefs == null || !fLangSpecificPrefs.isDefined(PreferenceConstants.P_SOURCE_FONT)
            || !fLangSpecificPrefs.isDefined(PreferenceConstants.P_TAB_WIDTH)
            || !fLangSpecificPrefs.isDefined(PreferenceConstants.P_SPACES_FOR_TABS)) {
        fPropertyListener = new IPropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(PreferenceConstants.P_SOURCE_FONT)
                        && !fLangSpecificPrefs.isDefined(PreferenceConstants.P_SOURCE_FONT)) {
                    FontData[] newValue = (FontData[]) event.getNewValue();
                    String fontDescriptor = newValue[0].toString();

                    handleFontChange(newValue, fontDescriptor);
                } else if (event.getProperty().equals(PreferenceConstants.P_TAB_WIDTH)
                        && !fLangSpecificPrefs.isDefined(PreferenceConstants.P_TAB_WIDTH)) {
                    handleTabsChange(((Integer) event.getNewValue()).intValue());
                } else if (event.getProperty().equals(PreferenceConstants.P_SPACES_FOR_TABS)
                        && !fLangSpecificPrefs.isDefined(PreferenceConstants.P_SPACES_FOR_TABS)) {
                    handleSpacesForTabsChange(((Boolean) event.getNewValue()).booleanValue());
                }/*from www  . ja  v a 2 s  .  c o m*/
            }
        };
        RuntimePlugin.getInstance().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
    }
    // TODO Perhaps add a flavor of IMP PreferenceListener that notifies for a change to any preference key?
    // Then the following listeners could become just one, at the expense of casting the pref values.
    if (fLangSpecificPrefs != null) {
        fFontListener = new StringPreferenceListener(fLangSpecificPrefs, PreferenceConstants.P_SOURCE_FONT) {
            @Override
            public void changed(String oldValue, String newValue) {
                FontData[] fontData = PreferenceConverter.readFontData(newValue);
                handleFontChange(fontData, newValue);
            }
        };
    }
    if (fLangSpecificPrefs != null) {
        fTabListener = new IntegerPreferenceListener(fLangSpecificPrefs, PreferenceConstants.P_TAB_WIDTH) {
            @Override
            public void changed(int oldValue, int newValue) {
                handleTabsChange(newValue);
            }
        };
    }
    if (fLangSpecificPrefs != null) {
        fSpacesForTabsListener = new BooleanPreferenceListener(fLangSpecificPrefs,
                PreferenceConstants.P_SPACES_FOR_TABS) {
            @Override
            public void changed(boolean oldValue, boolean newValue) {
                handleSpacesForTabsChange(newValue);
            }
        };
    }
}

From source file:org.eclipse.imp.editor.UniversalEditor.java

License:Open Source License

private void setSourceFontFromPreference() {
    String fontName = null;//from w w w  .java  2  s  .co  m
    if (fLangSpecificPrefs != null) {
        fontName = fLangSpecificPrefs.getStringPreference(PreferenceConstants.P_SOURCE_FONT);
    }
    if (fontName == null) {
        // Don't use the IMP SourceFont pref key on the IMP RuntimePlugin's preference
        // store; use the JFaceResources TEXT_FONT pref key on the WorkbenchPlugin's
        // preference store. This way, the workbench-wide setting in "General" ->
        // "Appearance" => "Colors and Fonts" will have the desired effect, in the
        // absence of a language-specific setting.
        //          IPreferenceStore prefStore= RuntimePlugin.getInstance().getPreferenceStore();
        //
        //          fontName= prefStore.getString(PreferenceConstants.P_SOURCE_FONT);

        IPreferenceStore prefStore = WorkbenchPlugin.getDefault().getPreferenceStore();

        fontName = prefStore.getString(JFaceResources.TEXT_FONT);
    }
    FontRegistry fontRegistry = RuntimePlugin.getInstance().getFontRegistry();

    if (!fontRegistry.hasValueFor(fontName)) {
        fontRegistry.put(fontName, PreferenceConverter.readFontData(fontName));
    }
    Font sourceFont = fontRegistry.get(fontName);

    if (sourceFont != null) {
        getSourceViewer().getTextWidget().setFont(sourceFont);
    }
}

From source file:org.rascalmpl.eclipse.console.internal.OutputWidget.java

License:Open Source License

private void setFont() {
    final FontRegistry fontRegistry = RuntimePlugin.getInstance().getFontRegistry();
    final String fontDescriptor = RuntimePlugin.getInstance().getPreferenceStore()
            .getString(PreferenceConstants.P_SOURCE_FONT);

    if (fontDescriptor != null) {
        if (!fontRegistry.hasValueFor(fontDescriptor)) {
            FontData[] fontData = PreferenceConverter.readFontData(fontDescriptor);
            fontRegistry.put(fontDescriptor, fontData);
        }/*from   www  .  j  a  v a2s.  c  o m*/

        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                Font sourceFont = fontRegistry.get(fontDescriptor);
                text.setFont(sourceFont);
            }
        });
    }
}