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.imp.editor.UniversalEditor.java

License:Open Source License

private void setSourceFontFromPreference() {
    String fontName = null;/*from  w  ww.j a  v a 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.eclipse.jdt.internal.debug.ui.JDISourceViewer.java

License:Open Source License

/**
 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
 *//*from www.  jav a 2 s .co  m*/
public void propertyChange(PropertyChangeEvent event) {
    IContentAssistant assistant = getContentAssistant();
    if (assistant instanceof ContentAssistant) {
        JDIContentAssistPreference.changeConfiguration((ContentAssistant) assistant, event);
    }
    String property = event.getProperty();

    if (JFaceResources.TEXT_FONT.equals(property)) {
        updateViewerFont();
    }
    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.linuxtools.internal.perf.ui.ReportComparisonView.java

License:Open Source License

/**
 * Set properties for StlyedText widget.
 * @param input String StyledText content.
 *//*w w w .ja va 2s. co m*/
private void setStyledText(String input) {
    result.setText(input);
    result.setJustify(true);
    result.setAlignment(SWT.LEFT);

    result.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    List<StyleRange> styles = new ArrayList<>();
    int ptr = 0;
    String[] lines = input.split("\n"); //$NON-NLS-1$

    for (String line : lines) {
        if (Pattern.matches(DIFF_ENTRY, line)) {
            Matcher m = Pattern.compile(DIFF_ENTRY).matcher(line);
            if (m.matches() && m.group(1) != null && m.group(3) != null) {
                try {
                    float baseline = Float.parseFloat(m.group(1).trim());
                    float delta = Float.parseFloat(m.group(3).trim());
                    if (baseline > 1 && Math.abs(delta) > 1) {
                        StyleRange curStyleRange;
                        if (delta < 0) {
                            curStyleRange = delta < -5 ? new StyleRange(ptr, line.length(), LIGHT_GREEN, null)
                                    : new StyleRange(ptr, line.length(), GREEN, null);
                        } else {
                            curStyleRange = delta < 5 ? new StyleRange(ptr, line.length(), ORANGE, null)
                                    : new StyleRange(ptr, line.length(), RED, null);
                        }
                        styles.add(curStyleRange);
                    }
                } catch (NumberFormatException e) {
                    // set no StyleRange
                }
            }
        }
        // + 1 to skip over the '\n' at EOL that the tokenizer eats
        ptr += line.length() + 1;
    }

    result.setStyleRanges(styles.toArray(new StyleRange[0]));
}

From source file:org.eclipse.linuxtools.internal.perf.ui.StatComparisonView.java

License:Open Source License

/**
 * Set String input in text display. Adapted from
 * org.eclipse.linuxtools.internal.perf.ui.SourceDisassemblyView.
 *
 * @param input text to display/* w ww.ja  v  a 2  s . c  o m*/
 */
private void setStyledText(String input) {
    text.setText(input);
    text.setAlignment(SWT.LEFT);
    // set default TextConsole font (monospaced).
    text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    List<StyleRange> styles = new ArrayList<>();
    int ptr = 0;

    String[] lines = input.split("\n"); //$NON-NLS-1$

    for (String line : lines) {
        if (Pattern.matches(OCCURRENCE, line)) {
            Matcher m = Pattern.compile(OCCURRENCE).matcher(line);
            if (m.matches() && m.group(1) != null) {
                try {
                    float occurrence = StatComparisonData.toFloat(m.group(1).trim());
                    if (occurrence > 0) {
                        styles.add(new StyleRange(ptr, line.length(), RED, null));
                    } else if (occurrence < 0) {
                        styles.add(new StyleRange(ptr, line.length(), GREEN, null));
                    }
                } catch (NumberFormatException e) {
                    // set no StyleRange
                }
            }
        }
        // + 1 to skip over the '\n' at EOL that the tokenizer eats
        ptr += line.length() + 1;
    }

    text.setStyleRanges(styles.toArray(new StyleRange[0]));
}

From source file:org.eclipse.linuxtools.internal.perf.ui.StatView.java

License:Open Source License

private void setStyledText(String input) {
    text.setText(input);/*from w  w w .  ja  v  a  2  s  .co  m*/

    // the default TextConsole font (we want monospaced)
    text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
}

From source file:org.eclipse.m2m.internal.qvt.oml.editor.ui.colorer.QVTColorsConfigurationBlock.java

License:Open Source License

private void hookPreviewUpdater(final SourceViewer viewer, final IPreferenceStore preferenceStore,
        final QVTColorManager colorManager) {
    final org.eclipse.jface.util.IPropertyChangeListener fontChangeListener = new org.eclipse.jface.util.IPropertyChangeListener() {
        /*/*from www .j a v a  2 s .co m*/
         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(JFaceResources.TEXT_FONT)) {
                Font font = JFaceResources.getTextFont();
                viewer.getTextWidget().setFont(font);
            }
        }
    };

    final org.eclipse.jface.util.IPropertyChangeListener propertyChangeListener = new org.eclipse.jface.util.IPropertyChangeListener() {
        /*
         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
         */
        public void propertyChange(final PropertyChangeEvent event) {
            colorManager.propertyChange(event);
            viewer.invalidateTextPresentation();
        }
    };
    viewer.getTextWidget().addDisposeListener(new DisposeListener() {
        /*
         * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
         */
        public void widgetDisposed(DisposeEvent e) {
            preferenceStore.removePropertyChangeListener(propertyChangeListener);
            JFaceResources.getFontRegistry().removeListener(fontChangeListener);
        }
    });

    JFaceResources.getFontRegistry().addListener(fontChangeListener);
    preferenceStore.addPropertyChangeListener(propertyChangeListener);
}

From source file:org.eclipse.mat.ui.snapshot.panes.OQLPane.java

License:Open Source License

public void createPartControl(Composite parent) {
    SashForm sash = new SashForm(parent, SWT.VERTICAL | SWT.SMOOTH);

    queryViewer = new SourceViewer(sash, null, SWT.MULTI | SWT.WRAP);
    queryString = queryViewer.getTextWidget();
    queryString.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    Color background = queryString.getBackground();
    IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
    ITheme current = themeManager.getCurrentTheme();
    ColorRegistry colorRegistry = current.getColorRegistry();
    commentCol = colorRegistry.get(ColorProvider.COMMENT_COLOR_PREF);
    keywordCol = colorRegistry.get(ColorProvider.KEYWORD_COLOR_PREF);
    IDocument d = createDocument();//from w  ww .  j a v a2 s .  c  o m
    d.set(Messages.OQLPane_F1ForHelp);

    queryViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateActions();
        }
    });

    queryViewer.setDocument(d);
    queryViewer.configure(new OQLTextViewerConfiguration(getSnapshot(), commentCol, keywordCol));
    // Eclipse 4 seems to need this otherwise in high contrast mode the background is white
    queryString.setBackground(background);
    queryString.selectAll();

    PlatformUI.getWorkbench().getHelpSystem().setHelp(queryString, "org.eclipse.mat.ui.help.oql"); //$NON-NLS-1$
    queryString.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == '\r' && (e.stateMask & SWT.MOD1) != 0) {
                executeAction.run();
                e.doit = false;
            } else if (e.keyCode == ' ' && (e.stateMask & SWT.CTRL) != 0) {
                //ctrl space combination for content assist
                contentAssistAction.run();
            } else if (e.keyCode == SWT.F5) {
                executeAction.run();
                e.doit = false;
            }
        }

    });

    queryString.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            IActionBars actionBars = getEditor().getEditorSite().getActionBars();
            actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyQueryStringAction);
            actionBars.updateActionBars();
        }

        public void focusLost(FocusEvent e) {
        }

    });
    queryString.setFocus();

    createContainer(sash);

    sash.setWeights(new int[] { 1, 4 });

    makeActions();
    hookContextMenu();

}

From source file:org.eclipse.mylyn.internal.tasks.ui.editors.RichTextEditor.java

License:Open Source License

public SourceViewer getDefaultViewer() {
    if (defaultViewer == null) {
        defaultViewer = createDefaultEditor(editorComposite, style);
        configure(defaultViewer, new Document(getText()), isReadOnly());

        // fixed font size
        defaultViewer.getTextWidget().setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
        // adapt maximize action
        defaultViewer.getControl().setData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION,
                editorViewer.getControl().getData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION));
        // adapt menu to the new viewer
        installMenu(defaultViewer.getControl(), editorViewer.getControl().getMenu());
    }/*from   w  ww .java2s  . c om*/
    return defaultViewer;
}

From source file:org.eclipse.ocl.examples.interpreter.console.OCLConsolePage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    // force left-to-right text direction in the console, because it
    //    works with OCL text and the OCL language is based on English
    page = new SashForm(parent, SWT.VERTICAL | SWT.LEFT_TO_RIGHT);

    output = new TextViewer(page, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    output.getTextWidget().setLayoutData(new GridData(GridData.FILL_BOTH));
    output.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    output.setEditable(false);/* w  w  w .ja va 2 s.c om*/
    output.setDocument(new Document());

    colorManager = new ColorManager();
    document = new OCLDocument();
    document.setOCLFactory(oclFactory);
    document.setModelingLevel(modelingLevel);

    input = new OCLSourceViewer(page, colorManager, SWT.BORDER | SWT.MULTI);
    input.setDocument(document);
    input.getTextWidget().addKeyListener(new InputKeyListener());

    selectionListener = new ISelectionListener() {
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            OCLConsolePage.this.selectionChanged(selection);
        }
    };
    selectionService = getSite().getWorkbenchWindow().getSelectionService();
    selectionService.addPostSelectionListener(selectionListener);

    // get current selection
    ISelection selection = selectionService.getSelection();
    if (selection == null) {
        selection = getActiveSelection();
    }
    selectionChanged(selection);

    ((SashForm) page).setWeights(new int[] { 2, 1 });

    ClearOutputAction clear = new ClearOutputAction(output);
    CloseAction close = new CloseAction();
    SaveAction save = new SaveAction();
    LoadAction load = new LoadAction();

    IMenuManager menu = getSite().getActionBars().getMenuManager();
    menu.add(load);
    menu.add(save);
    menu.add(clear);
    menu.add(close);

    IMenuManager metamodelMenu = new MenuManager(OCLInterpreterMessages.console_metamodelMenu,
            "org.eclipse.ocl.examples.interpreter.metamodel"); //$NON-NLS-1$
    menu.add(metamodelMenu);
    DropDownAction metamodelAction = new DropDownAction();
    metamodelAction.setToolTipText(OCLInterpreterMessages.console_metamodelTip);
    addMetamodelActions(metamodelMenu, metamodelAction);

    IMenuManager levelMenu = new MenuManager(OCLInterpreterMessages.console_modelingLevel);
    menu.add(levelMenu);
    DropDownAction levelAction = new DropDownAction();
    levelAction.setToolTipText(OCLInterpreterMessages.console_modelingLevelTip);
    IAction m2 = new ModelingLevelAction(ModelingLevel.M2);
    m2.setChecked(true);
    levelMenu.add(m2);
    levelAction.addAction(m2);
    IAction m1 = new ModelingLevelAction(ModelingLevel.M1);
    levelMenu.add(m1);
    levelAction.addAction(m1);

    ActionContributionItem metamodelItem = new ActionContributionItem(metamodelAction);
    metamodelItem.setMode(ActionContributionItem.MODE_FORCE_TEXT);

    IToolBarManager toolbar = getSite().getActionBars().getToolBarManager();
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, metamodelItem);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, levelAction);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, load);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, save);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, clear);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, close);
}

From source file:org.eclipse.ocl.examples.xtext.console.OCLConsolePage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    // force left-to-right text direction in the console, because it
    //    works with OCL text and the OCL language is based on English
    page = new SashForm(parent, SWT.VERTICAL | SWT.LEFT_TO_RIGHT);

    output = new TextViewer(page, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    output.getTextWidget().setLayoutData(new GridData(GridData.FILL_BOTH));
    output.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    output.setEditable(false);/*  w  w w  . j a v a 2 s .  c  om*/
    output.setDocument(new Document());

    colorManager = new ColorManager();
    //      document.setOCLFactory(oclFactory);
    //      document.setModelingLevel(modelingLevel);

    createEditor(page);
    input = editor.getViewer();
    input.getTextWidget().addKeyListener(new InputKeyListener());
    input.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    selectionListener = new ISelectionListener() {
        public void selectionChanged(IWorkbenchPart part, final ISelection selection) {
            //            System.out.println("selectionChanged: ");
            if (part instanceof IConsoleView) {
                IConsole console = ((IConsoleView) part).getConsole();
                if (console instanceof OCLConsole) {
                    return;
                }
            }
            if (part instanceof ContentOutline) {
                ContentOutline contentOutline = (ContentOutline) part;
                IPage currentPage = contentOutline.getCurrentPage();
                if (currentPage instanceof OutlinePage) {
                    OutlinePage outlinePage = (OutlinePage) currentPage;
                    IXtextDocument xtextDocument = outlinePage.getXtextDocument();
                    Element pivotElement = xtextDocument.readOnly(new IUnitOfWork<Element, XtextResource>() {
                        public Element exec(XtextResource state) throws Exception {
                            if (selection instanceof IStructuredSelection) {
                                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                                if (structuredSelection.size() == 1) {
                                    Object selectedObject = structuredSelection.getFirstElement();
                                    if (selectedObject instanceof EObjectNode) {
                                        EObjectNode eObjectNode = (EObjectNode) selectedObject;
                                        URI uri = eObjectNode.getEObjectURI();
                                        EObject csObject = state.getEObject(uri.fragment());
                                        if (csObject instanceof Pivotable) {
                                            Element pivotObject = ((Pivotable) csObject).getPivot();
                                            if (pivotObject != null) {
                                                return pivotObject;
                                            }
                                        }
                                    }
                                }
                            }
                            return null;
                        }
                    });
                    if (pivotElement != null) {
                        OCLConsolePage.this.selectionChanged(new StructuredSelection(pivotElement));
                        return;
                    }
                }
            }
            OCLConsolePage.this.selectionChanged(selection);
        }
    };
    selectionService = getSite().getWorkbenchWindow().getSelectionService();
    selectionService.addPostSelectionListener(selectionListener);

    // get current selection
    //      ISelection selection = selectionService.getSelection();         // Doesn't have a value preceding console start
    ISelection selection = BaseUIUtil.getActiveSelection(getSite());
    selectionChanged(selection);

    ((SashForm) page).setWeights(new int[] { 2, 1 });

    ClearOutputAction clear = new ClearOutputAction(output);
    CloseAction close = new CloseAction();
    SaveExpressionAction saveExpression = new SaveExpressionAction(this);
    LoadExpressionAction loadExpression = new LoadExpressionAction(this);

    IMenuManager menu = getSite().getActionBars().getMenuManager();
    menu.add(loadExpression);
    menu.add(saveExpression);
    menu.add(clear);
    menu.add(close);

    //      IMenuManager metamodelMenu = new MenuManager(
    //          OCLInterpreterMessages.console_metamodelMenu,
    //          "org.eclipse.ocl.examples.xtext.console.metamodel"); //$NON-NLS-1$
    //      menu.add(metamodelMenu);
    //      DropDownAction metamodelAction = new DropDownAction();
    //      metamodelAction.setToolTipText(OCLInterpreterMessages.console_metamodelTip);
    //      addMetamodelActions(metamodelMenu, metamodelAction);

    //      IMenuManager levelMenu = new MenuManager(OCLInterpreterMessages.console_modelingLevel);
    //      menu.add(levelMenu);
    //        DropDownAction levelAction = new DropDownAction();
    //        levelAction.setToolTipText(OCLInterpreterMessages.console_modelingLevelTip);
    //      IAction m2 = new ModelingLevelAction(ModelingLevel.M2);
    //      m2.setChecked(true);
    //      levelMenu.add(m2);
    //      levelAction.addAction(m2);
    //      IAction m1 = new ModelingLevelAction(ModelingLevel.M1);
    //      levelMenu.add(m1);
    //      levelAction.addAction(m1);

    //      ActionContributionItem metamodelItem = new ActionContributionItem(
    //          metamodelAction);
    //      metamodelItem.setMode(ActionContributionItem.MODE_FORCE_TEXT);

    IToolBarManager toolbar = getSite().getActionBars().getToolBarManager();
    //        toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, metamodelItem);
    //        toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, levelAction);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, loadExpression);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, saveExpression);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, clear);
    toolbar.appendToGroup(IConsoleConstants.OUTPUT_GROUP, close);
}