Example usage for org.eclipse.jface.resource JFaceResources TEXT_FONT

List of usage examples for org.eclipse.jface.resource JFaceResources TEXT_FONT

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources TEXT_FONT.

Prototype

String TEXT_FONT

To view the source code for org.eclipse.jface.resource JFaceResources TEXT_FONT.

Click Source Link

Document

The symbolic font name for the text font (value "org.eclipse.jface.textfont").

Usage

From source file:org.eclipse.ui.tests.preferences.FontPreferenceTestCase.java

License:Open Source License

protected void doSetUp() throws Exception {
    super.doSetUp();
    AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
    preferenceStore = plugin.getPreferenceStore();

    //Set up the bogus entry for the bad first test
    FontData bogusData = new FontData();
    bogusData.setName("BadData");
    bogusData.setHeight(11);//  w  ww . j a  va2 s. co m
    FontData[] storedValue = new FontData[2];

    //We assume here that the text font is OK
    storedValue[0] = bogusData;
    storedValue[1] = (PreferenceConverter.getDefaultFontDataArray(preferenceStore,
            JFaceResources.TEXT_FONT))[0];
    PreferenceConverter.setValue(preferenceStore, TEST_FONT_ID, storedValue);
    PreferenceConverter.setDefault(preferenceStore, TEST_FONT_ID, storedValue);

}

From source file:org.eclipse.ui.tests.preferences.FontPreferenceTestCase.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 w  w  . jav  a  2s  . c  o m*/

public void testGoodFontDefinition() {

    FontRegistry fontRegistry = JFaceResources.getFontRegistry();
    FontData[] currentTextFonts = PreferenceConverter.getFontDataArray(preferenceStore,
            JFaceResources.TEXT_FONT);
    FontData[] bestFont = fontRegistry.bestDataArray(currentTextFonts, Display.getCurrent());

    //Assert that it is the first font that we get as the
    //valid one
    assertEquals(bestFont[0].getName(), currentTextFonts[0].getName());
    assertEquals(bestFont[0].getHeight(), currentTextFonts[0].getHeight());
}

From source file:org.eclipse.ui.tests.preferences.ZoomAndPreferencesFontTest.java

License:Open Source License

@Test
public void testThemeAPIvsPreferences() {
    int targetHeight = 17; // Whatever > 0 and not default size/10
    FontRegistry registry = editor.getSite().getWorkbenchWindow().getWorkbench().getThemeManager()
            .getCurrentTheme().getFontRegistry();
    FontData[] data = registry.getFontData(JFaceResources.TEXT_FONT);
    FontDescriptor desc = FontDescriptor.createFrom(data).setHeight(targetHeight);
    registry.put(JFaceResources.TEXT_FONT, desc.getFontData());
    Assert.assertEquals(targetHeight, text.getFont().getFontData()[0].getHeight());
    restoreAndCheckDefaults();/*from   www .ja va  2 s  . c  o m*/
}

From source file:org.eclipse.ui.texteditor.AbstractTextEditor.java

License:Open Source License

/**
 * Initializes the given viewer's font./*from   ww  w .  j a  v  a2s .  com*/
 *
 * @param viewer the viewer
 * @since 2.0
 */
private void initializeViewerFont(ISourceViewer viewer) {

    boolean isSharedFont = true;
    Font font = null;
    String symbolicFontName = getSymbolicFontName();

    if (symbolicFontName != null)
        font = JFaceResources.getFont(symbolicFontName);
    else if (fPreferenceStore != null) {
        // Backward compatibility
        if (fPreferenceStore.contains(JFaceResources.TEXT_FONT)
                && !fPreferenceStore.isDefault(JFaceResources.TEXT_FONT)) {
            FontData data = PreferenceConverter.getFontData(fPreferenceStore, JFaceResources.TEXT_FONT);

            if (data != null) {
                isSharedFont = false;
                font = new Font(viewer.getTextWidget().getDisplay(), data);
            }
        }
    }
    if (font == null)
        font = JFaceResources.getTextFont();

    if (!font.equals(fSourceViewer.getTextWidget().getFont())) {
        setFont(viewer, font);

        disposeFont();
        if (!isSharedFont)
            fFont = font;
    } else if (!isSharedFont) {
        font.dispose();
    }
}

From source file:org.eclipse.ui.texteditor.AbstractTextEditor.java

License:Open Source License

/**
 * Returns the property preference key for the editor font.
 * <p>/*w ww. j  a v  a2  s .  c o m*/
 * If the editor is defined with a <code>symbolicFontName </code> then this name is returned and
 * the font is looked up in the JFace resource registry. Otherwise,
 * {@link JFaceResources#TEXT_FONT} is returned and the font is looked up in this editor's
 * preference store.
 * </p>
 * 
 * @return a String with the key
 * @since 2.1
 */
protected final String getFontPropertyPreferenceKey() {
    String symbolicFontName = getSymbolicFontName();
    if (symbolicFontName != null)
        return symbolicFontName;
    return JFaceResources.TEXT_FONT;
}

From source file:org.eclipse.ui.texteditor.AbstractTextZoomHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    AbstractTextEditor textEditor = getActiveTextEditor(event);
    if (textEditor == null) {
        return null;
    }/*from w  w w  .ja  v  a  2s  . c  o  m*/
    FontRegistry fontRegistry = textEditor.getSite().getWorkbenchWindow().getWorkbench().getThemeManager()
            .getCurrentTheme().getFontRegistry();
    String fontProperty = textEditor.getSymbolicFontName();
    if (fontProperty == null) {
        fontProperty = JFaceResources.TEXT_FONT;
    }
    Set<String> fontsToSet = getAffectedFontNames(fontProperty, fontRegistry);
    FontData[] initialFontData = null;
    String currentFontName = fontProperty;
    while (currentFontName != null && (initialFontData = fontRegistry.getFontData(currentFontName)) == null) {
        currentFontName = fgFontToDefault.get(currentFontName);
    }

    FontData[] newFontData = createFontDescriptor(initialFontData).getFontData();
    if (newFontData != null) {
        fontsToSet.stream().forEach(fontName -> fontRegistry.put(fontName, newFontData));
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.ui.texteditor.WorkbenchChainedTextFontFieldEditor.java

License:Open Source License

/**
 * Starts the propagation of the text font preference set in the workbench
 * to given target preference store using the given preference key.
 *
 * @param target the target preference store
 * @param targetKey the key to be used in the target preference store
 *//* w  w  w.j a  v  a  2s  .c o m*/
public static void startPropagate(IPreferenceStore target, String targetKey) {
    Plugin plugin = Platform.getPlugin("org.eclipse.ui.workbench"); //$NON-NLS-1$
    if (plugin instanceof AbstractUIPlugin) {
        AbstractUIPlugin uiPlugin = (AbstractUIPlugin) plugin;
        IPreferenceStore store = uiPlugin.getPreferenceStore();
        if (store != null)
            PropagatingFontFieldEditor.startPropagate(store, JFaceResources.TEXT_FONT, target, targetKey);
    }
}

From source file:org.eclipse.vjet.eclipse.internal.ui.preferences.formatting.JavaPreview.java

License:Open Source License

/**
 * Create a new Java preview/*from   ww  w. j  av a2 s. c  o  m*/
 * @param workingValues
 * @param parent
 */
public JavaPreview(Map workingValues, Composite parent) {
    VjoTextTools tools = VjetUIPlugin.getDefault().getTextTools();
    fPreviewDocument = new Document();
    fWorkingValues = workingValues;
    tools.setupDocumentPartitioner(fPreviewDocument, IJavaScriptPartitions.JAVA_PARTITIONING);

    PreferenceStore prioritizedSettings = new PreferenceStore();
    prioritizedSettings.setValue(VjetPlugin.COMPILER_SOURCE, VjetPlugin.VERSION_1_5);
    prioritizedSettings.setValue(VjetPlugin.COMPILER_COMPLIANCE, VjetPlugin.VERSION_1_5);
    prioritizedSettings.setValue(VjetPlugin.COMPILER_CODEGEN_TARGET_PLATFORM, VjetPlugin.VERSION_1_5);
    prioritizedSettings.setValue(VjetPlugin.COMPILER_PB_ASSERT_IDENTIFIER, VjetPlugin.ERROR);

    IPreferenceStore[] chain = { prioritizedSettings, VjetUIPlugin.getDefault().getPreferenceStore(),
            EditorsUI.getPreferenceStore() };
    fPreferenceStore = new ChainedPreferenceStore(chain);
    fSourceViewer = new JavaSourceViewer(parent, null, null, false,
            SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore);
    fViewerConfiguration = new SimpleJavascriptSourceViewerConfiguration(tools.getColorManager(),
            fPreferenceStore, null, IJavaScriptPartitions.JAVA_PARTITIONING, true);
    fSourceViewer.configure(fViewerConfiguration);
    fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    fMarginPainter = new MarginPainter(fSourceViewer);
    final RGB rgb = PreferenceConverter.getColor(fPreferenceStore,
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR);
    fMarginPainter.setMarginRulerColor(tools.getColorManager().getColor(rgb));
    fSourceViewer.addPainter(fMarginPainter);

    new JavaSourcePreviewerUpdater();
    fSourceViewer.setDocument(fPreviewDocument);
}

From source file:org.eclipse.wst.jsdt.debug.internal.ui.source.JavaScriptSourceViewer.java

License:Open Source License

public void propertyChange(PropertyChangeEvent event) {
    String property = event.getProperty();

    if (JFaceResources.TEXT_FONT.equals(property)) {
        updateViewerFont();/* w  w w .jav a  2 s  . c o m*/
    }
    if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property)
            || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property)
            || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND.equals(property)
            || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)) {
        updateViewerColors();
    }
    if (fConfiguration != null) {
        if (fConfiguration.affectsTextPresentation(event)) {
            fConfiguration.handlePropertyChangeEvent(event);
            invalidateTextPresentation();
        }
    }
}

From source file:org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin.java

License:Open Source License

/**
 * Installs backwards compatibility for the preference store.
 *//*from   w  w  w  . ja  va 2  s  . c  om*/
private void ensurePreferenceStoreBackwardsCompatibility() {

    IPreferenceStore store = getPreferenceStore();

    // must add here to guarantee that it is the first in the listener list
    fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
    fMembersOrderPreferenceCache.install(store);

    /*
     * Installs backwards compatibility: propagate the Java editor font from a
     * pre-2.1 plug-in to the Platform UI's preference store to preserve
     * the Java editor font from a pre-2.1 workspace. This is done only
     * once.
     */
    String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
    if (store.contains(JFaceResources.TEXT_FONT) && !store.isDefault(JFaceResources.TEXT_FONT)) {
        if (!store.getBoolean(fontPropagatedKey))
            PreferenceConverter.setValue(getDeprecatedWorkbenchPreferenceStore(),
                    PreferenceConstants.EDITOR_TEXT_FONT,
                    PreferenceConverter.getFontDataArray(store, JFaceResources.TEXT_FONT));
    }
    store.setValue(fontPropagatedKey, true);

    /*
     * Backwards compatibility: set the Java editor font in this plug-in's
     * preference store to let older versions access it. Since 2.1 the
     * Java editor font is managed by the workbench font preference page.
     */
    PreferenceConverter.putValue(store, JFaceResources.TEXT_FONT,
            JFaceResources.getFontRegistry().getFontData(PreferenceConstants.EDITOR_TEXT_FONT));

    fFontPropertyChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
                PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT,
                        JFaceResources.getFontRegistry().getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
        }
    };
    JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);

    /*
     * Backwards compatibility: propagate the Java editor tab width from a
     * pre-3.0 plug-in to the new preference key. This is done only once.
     */
    final String oldTabWidthKey = DEPRECATED_EDITOR_TAB_WIDTH;
    final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
    String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
    if (store.contains(oldTabWidthKey) && !store.isDefault(oldTabWidthKey)) {
        if (!store.getBoolean(tabWidthPropagatedKey))
            store.setValue(newTabWidthKey, store.getInt(oldTabWidthKey));
    }
    store.setValue(tabWidthPropagatedKey, true);

    /*
     * Backwards compatibility: set the Java editor tab width in this plug-in's
     * preference store with the old key to let older versions access it.
     * Since 3.0 the tab width is managed by the extended text editor and
     * uses a new key.
     */
    store.putValue(oldTabWidthKey, store.getString(newTabWidthKey));

    fPropertyChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (newTabWidthKey.equals(event.getProperty())) {
                IPreferenceStore prefStore = getPreferenceStore();
                prefStore.putValue(oldTabWidthKey, prefStore.getString(newTabWidthKey));
            }
        }
    };
    store.addPropertyChangeListener(fPropertyChangeListener);

    /*
     * Backward compatibility for the refactoring preference key. 
     */
    //      store.setValue(
    //         PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD, 
    //         RefactoringCore.getConditionCheckingFailedSeverity());

    // The commented call above triggers the eager loading of the LTK core plug-in
    // Since the condition checking failed severity is guaranteed to be of RefactoringStatus.SEVERITY_WARNING,
    // we directly insert the inlined value of this constant
    store.setToDefault(DEPRECATED_REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD);

    if (!store.getBoolean(JavaDocLocations.PREF_JAVADOCLOCATIONS_MIGRATED)) {
        JavaDocLocations.migrateToClasspathAttributes();
    }

    FormatterProfileStore.checkCurrentOptionsVersion();

    /*
     * Backward compatibility: migrate "alphabetic ordering" preference to point the sorter
     * preference to the alphabetic sorter.
     */
    String proposalOrderMigrated = "proposalOrderMigrated"; //$NON-NLS-1$

    if (store.contains(DEPRECATED_CODEASSIST_ORDER_PROPOSALS)) {
        if (!store.getBoolean(proposalOrderMigrated)) {
            boolean alphabetic = store.getBoolean(DEPRECATED_CODEASSIST_ORDER_PROPOSALS);
            if (alphabetic)
                store.setValue(PreferenceConstants.CODEASSIST_SORTER,
                        "org.eclipse.wst.jsdt.ui.AlphabeticSorter"); //$NON-NLS-1$
        }
    }
    store.setValue(proposalOrderMigrated, true);

}