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.console.TextConsole.java

License:Open Source License

/**
 * Returns the default text font.
 * 
 * @return the default text font
 */
private Font getDefaultFont() {
    return JFaceResources.getFont(JFaceResources.TEXT_FONT);
}

From source file:org.eclipse.ui.editors.text.TextEditorPreferencePage.java

License:Open Source License

public void createFieldEditors() {
    addField(new FontFieldEditor(JFaceResources.TEXT_FONT, TextEditorMessages.PreferencePage_fontEditor,
            getFieldEditorParent()));
}

From source file:org.eclipse.ui.editors.text.TextEditorPreferencePage.java

License:Open Source License

/**
 * Initializes the defaults for the given store.
 *
 * @param store the preference store/*from   www  . j a va  2  s  .com*/
 * @since 2.0
 */
public static void initDefaults(IPreferenceStore store) {

    if (fgInitialized)
        return;

    fgInitialized = true;

    Font font = JFaceResources.getTextFont();
    if (font != null) {
        FontData[] data = font.getFontData();
        if (data != null && data.length > 0)
            PreferenceConverter.setDefault(store, JFaceResources.TEXT_FONT, data[0]);
    }

    Display display = Display.getDefault();
    Color color = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    PreferenceConverter.setDefault(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, color.getRGB());
    store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, true);

    color = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    PreferenceConverter.setDefault(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, color.getRGB());
    store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true);
}

From source file:org.eclipse.ui.internal.editors.text.TextEditorDefaultsPreferencePage.java

License:Open Source License

private Control createAppearancePage(Composite parent) {

    Composite appearanceComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;/*from  w w  w .j  a va 2s.  c om*/
    layout.marginHeight = 0;
    layout.marginWidth = 0;

    appearanceComposite.setLayout(layout);

    Link fontLink = new Link(appearanceComposite, SWT.NONE);
    fontLink.setText(TextEditorMessages.TextEditorPreferencePage_Font_link);
    fontLink.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(getShell(),
                    "org.eclipse.ui.preferencePages.ColorsAndFonts", null, //$NON-NLS-1$
                    "selectFont:" + JFaceResources.TEXT_FONT); //$NON-NLS-1$
        }
    });
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    fontLink.setLayoutData(gd);

    addFiller(appearanceComposite, 2);

    String label = TextEditorMessages.TextEditorPreferencePage_undoHistorySize;
    Preference undoHistorySize = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNDO_HISTORY_SIZE, label, null);
    IntegerDomain undoHistorySizeDomain = new IntegerDomain(0, 99999);
    addTextField(appearanceComposite, undoHistorySize, undoHistorySizeDomain, 15, 0);

    label = TextEditorMessages.TextEditorPreferencePage_displayedTabWidth;
    Preference tabWidth = new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, label,
            null);
    IntegerDomain tabWidthDomain = new IntegerDomain(1, 16);
    addTextField(appearanceComposite, tabWidth, tabWidthDomain, 15, 0);

    label = TextEditorMessages.TextEditorPreferencePage_convertTabsToSpaces;
    Preference spacesForTabs = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, label, null);
    addCheckBox(appearanceComposite, spacesForTabs, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorPreferencePage_highlightCurrentLine;
    Preference highlightCurrentLine = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, label, null);
    addCheckBox(appearanceComposite, highlightCurrentLine, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorPreferencePage_showPrintMargin;
    Preference showPrintMargin = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, label, null);
    final Button showPrintMarginButton = addCheckBox(appearanceComposite, showPrintMargin, new BooleanDomain(),
            0);

    label = TextEditorMessages.TextEditorPreferencePage_printMarginColumn;
    Preference printMarginColumn = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, label, null);
    final IntegerDomain printMarginDomain = new IntegerDomain(20, 200);
    final Control[] printMarginControls = addTextField(appearanceComposite, printMarginColumn,
            printMarginDomain, 15, 20);
    createDependency(showPrintMarginButton, showPrintMargin, printMarginControls);

    showPrintMarginButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateStatus(printMarginDomain);
        }
    });

    label = TextEditorMessages.TextEditorPreferencePage_showLineNumbers;
    Preference showLineNumbers = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, label, null);
    addCheckBox(appearanceComposite, showLineNumbers, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorDefaultsPreferencePage_range_indicator;
    Preference showMagnet = new Preference(AbstractDecoratedTextEditorPreferenceConstants.SHOW_RANGE_INDICATOR,
            label, null);
    addCheckBox(appearanceComposite, showMagnet, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorDefaultsPreferencePage_showWhitespaceCharacters;
    String linkText = TextEditorMessages.TextEditorDefaultsPreferencePage_showWhitespaceCharactersLinkText;
    Preference showWhitespaceCharacters = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_WHITESPACE_CHARACTERS, label, null);
    addCheckBoxWithLink(appearanceComposite, showWhitespaceCharacters, linkText, new BooleanDomain(), 0,
            new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    Dialog dialog = new WhitespaceCharacterPainterOptionsDialog(
                            Display.getDefault().getActiveShell(), fOverlayStore);
                    dialog.open();
                }
            });

    label = TextEditorMessages.TextEditorPreferencePage_showAffordance;
    Preference showAffordance = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, label, null);
    addCheckBox(appearanceComposite, showAffordance, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorDefaultsPreferencePage_enrichHoverMode;
    Preference hoverReplace = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HOVER_ENRICH_MODE, label, null);
    EnumeratedDomain hoverReplaceDomain = new EnumeratedDomain();
    hoverReplaceDomain.addValue(
            new EnumValue(-1, TextEditorMessages.TextEditorDefaultsPreferencePage_enrichHover_disabled));
    hoverReplaceDomain.addValue(
            new EnumValue(1, TextEditorMessages.TextEditorDefaultsPreferencePage_enrichHover_immediately));
    hoverReplaceDomain.addValue(
            new EnumValue(0, TextEditorMessages.TextEditorDefaultsPreferencePage_enrichHover_afterDelay));
    hoverReplaceDomain.addValue(
            new EnumValue(2, TextEditorMessages.TextEditorDefaultsPreferencePage_enrichHover_onClick));
    addCombo(appearanceComposite, hoverReplace, hoverReplaceDomain, 0);

    label = TextEditorMessages.TextEditorDefaultsPreferencePage_textDragAndDrop;
    Preference textDragAndDrop = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TEXT_DRAG_AND_DROP_ENABLED, label, null);
    addCheckBox(appearanceComposite, textDragAndDrop, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorDefaultsPreferencePage_warn_if_derived;
    Preference warnIfDerived = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED, label, null);
    addCheckBox(appearanceComposite, warnIfDerived, new BooleanDomain(), 0);

    label = TextEditorMessages.TextEditorDefaultsPreferencePage_smartHomeEnd;
    Preference smartHomeEnd = new Preference(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SMART_HOME_END, label, null);
    addCheckBox(appearanceComposite, smartHomeEnd, new BooleanDomain(), 0);

    addFiller(appearanceComposite, 2);

    Label l = new Label(appearanceComposite, SWT.LEFT);
    l.setText(TextEditorMessages.TextEditorPreferencePage_appearanceOptions);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    l.setLayoutData(gd);

    Composite editorComposite = new Composite(appearanceComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
    gd.horizontalSpan = 2;
    editorComposite.setLayoutData(gd);

    fAppearanceColorList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH);
    gd.heightHint = fAppearanceColorList.getItemHeight() * 8;
    fAppearanceColorList.setLayoutData(gd);

    Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    l = new Label(stylesComposite, SWT.LEFT);
    l.setText(TextEditorMessages.TextEditorPreferencePage_color);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    l.setLayoutData(gd);

    fAppearanceColorEditor = new ColorSelector(stylesComposite);
    Button foregroundColorButton = fAppearanceColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);

    SelectionListener colorDefaultSelectionListener = new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            boolean systemDefault = fAppearanceColorDefault.getSelection();
            fAppearanceColorEditor.getButton().setEnabled(!systemDefault);

            int i = fAppearanceColorList.getSelectionIndex();
            if (i == -1)
                return;

            String key = fAppearanceColorListModel[i][2];
            if (key != null)
                fOverlayStore.setValue(key, systemDefault);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };

    fAppearanceColorDefault = new Button(stylesComposite, SWT.CHECK);
    fAppearanceColorDefault.setText(TextEditorMessages.TextEditorPreferencePage_systemDefault);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fAppearanceColorDefault.setLayoutData(gd);
    fAppearanceColorDefault.setVisible(false);
    fAppearanceColorDefault.addSelectionListener(colorDefaultSelectionListener);

    fAppearanceColorList.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            handleAppearanceColorListSelection();
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            int i = fAppearanceColorList.getSelectionIndex();
            if (i == -1)
                return;

            String key = fAppearanceColorListModel[i][1];
            PreferenceConverter.setValue(fOverlayStore, key, fAppearanceColorEditor.getColorValue());
        }
    });

    Link link = new Link(appearanceComposite, SWT.NONE);
    link.setText(TextEditorMessages.TextEditorPreferencePage_colorsAndFonts_link);
    link.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(getShell(),
                    "org.eclipse.ui.preferencePages.ColorsAndFonts", null, //$NON-NLS-1$
                    "selectCategory:org.eclipse.ui.workbenchMisc"); //$NON-NLS-1$
        }
    });

    GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gridData.widthHint = 150; // only expand further if anyone else requires it
    gridData.horizontalSpan = 2;
    link.setLayoutData(gridData);

    addFiller(appearanceComposite, 2);

    appearanceComposite.layout();

    return appearanceComposite;
}

From source file:org.eclipse.ui.internal.texteditor.AbstractZoomTextHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    AbstractTextEditor textEditor = getActiveTextEditor();
    if (textEditor == null) {
        return null;
    }// www  .j  a  v  a  2  s  . c  o m
    FontRegistry fontRegistry = textEditor.getSite().getWorkbenchWindow().getWorkbench().getThemeManager()
            .getCurrentTheme().getFontRegistry();
    FontData[] initialFontData = fontRegistry.getFontData(JFaceResources.TEXT_FONT);
    int destFontSize = initialFontData[0].getHeight() + this.fontDiff;
    if (destFontSize <= 0) {
        return null;
    }
    FontDescriptor newFontDescriptor = FontDescriptor.createFrom(initialFontData).setHeight(destFontSize);
    fontRegistry.put(JFaceResources.TEXT_FONT, newFontDescriptor.getFontData());
    PlatformUI.getPreferenceStore().setValue(JFaceResources.TEXT_FONT,
            PreferenceConverter.getStoredRepresentation(newFontDescriptor.getFontData()));
    WorkbenchPlugin.getDefault().getPreferenceStore().setValue(JFaceResources.TEXT_FONT,
            PreferenceConverter.getStoredRepresentation(newFontDescriptor.getFontData()));
    return newFontDescriptor;
}

From source file:org.eclipse.ui.internal.texteditor.TextChangeHover.java

License:Open Source License

public IInformationControlCreator getHoverControlCreator() {
    return new IInformationControlCreator() {
        public IInformationControl createInformationControl(Shell parent) {
            SourceViewerInformationControl control = new SourceViewerInformationControl(parent, false,
                    JFaceResources.TEXT_FONT, EditorsUI.getTooltipAffordanceString());
            control.setHorizontalScrollPixel(fLastScrollIndex);
            return control;
        }/*from   ww  w  .j  a va2s.c  om*/
    };
}

From source file:org.eclipse.ui.internal.texteditor.TextChangeHover.java

License:Open Source License

public IInformationControlCreator getInformationPresenterControlCreator() {
    return new IInformationControlCreator() {
        public IInformationControl createInformationControl(Shell parent) {
            return new SourceViewerInformationControl(parent, true, JFaceResources.TEXT_FONT, null);
        }/*from  w w  w  . j  av  a 2  s.co  m*/
    };
}

From source file:org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView.java

License:Open Source License

public void createPartControl(Composite parent) {
    control = parent;/* ww w . j a  va 2  s .c o  m*/

    Composite buttonBar = new Composite(parent, SWT.NONE);
    {
        GridDataFactory buttonData = GridDataFactory.fillDefaults().grab(true, false);

        Button applyButton = new Button(buttonBar, SWT.PUSH);
        applyButton.setText("Apply");
        applyButton.addSelectionListener(new SelectionAdapter() {
            /* (non-Javadoc)
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            public void widgetSelected(SelectionEvent e) {
                applyPressed();
            }
        });
        buttonData.applyTo(applyButton);

        Button clearButton = new Button(buttonBar, SWT.PUSH);
        clearButton.setText("Reset");
        clearButton.addSelectionListener(new SelectionAdapter() {
            /* (non-Javadoc)
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            public void widgetSelected(SelectionEvent e) {
                minWidthText.setText("");
                maxWidthText.setText("");
                quantizedWidthText.setText("");
                minHeightText.setText("");
                maxHeightText.setText("");
                quantizedHeightText.setText("");
                fixedAreaText.setText("");
                applyPressed();
            }
        });
        buttonData.applyTo(clearButton);

        Button newViewButton = new Button(buttonBar, SWT.PUSH);
        newViewButton.setText("New View");
        newViewButton.addSelectionListener(new SelectionAdapter() {
            /* (non-Javadoc)
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            public void widgetSelected(SelectionEvent e) {
                try {
                    getSite().getPage().showView(
                            "org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView",
                            "" + System.currentTimeMillis(), IWorkbenchPage.VIEW_ACTIVATE);
                } catch (PartInitException e1) {
                    MessageDialog.openError(getSite().getShell(), "Error opening view", "Unable to open view.");
                }
            }
        });
        buttonData.applyTo(newViewButton);

        GridLayoutFactory.fillDefaults().equalWidth(true).numColumns(3).applyTo(buttonBar);
    }
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(buttonBar);

    new Label(parent, SWT.NONE).setText("Min Width");
    minWidthText = createText(parent);

    new Label(parent, SWT.NONE).setText("Max Width (blank = unbounded)");
    maxWidthText = createText(parent);

    new Label(parent, SWT.NONE).setText("Quantized Width (blank = none)");
    quantizedWidthText = createText(parent);

    new Label(parent, SWT.NONE).setText("Min Height");
    minHeightText = createText(parent);

    new Label(parent, SWT.NONE).setText("Max Height (blank = unbounded)");
    maxHeightText = createText(parent);

    new Label(parent, SWT.NONE).setText("Quantized Height (blank = none)");
    quantizedHeightText = createText(parent);

    new Label(parent, SWT.NONE).setText("Fixed Area (blank = none");
    fixedAreaText = createText(parent);

    sampleImplementation = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sampleImplementation.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    sampleImplementation.setTabs(4);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(sampleImplementation);

    GridLayoutFactory.fillDefaults().numColumns(2).margins(LayoutConstants.getMargins()).generateLayout(parent);

    applyPressed();

}

From source file:org.eclipse.ui.tests.preferences.DeprecatedFontPreferenceTestCase.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);/*from   www .j av  a2 s. c  o  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.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.
 *//*from  w w w  . j  a  va2 s  . 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());
}