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

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

Introduction

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

Prototype

public static Font getFont(String symbolicName) 

Source Link

Document

Returns the font in JFace's font registry with the given symbolic font name.

Usage

From source file:org.eclipse.wst.xsl.ui.internal.wizards.NewXSLFileTemplatesWizardPage.java

License:Open Source License

private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {
        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXSL();

        @Override//from  ww  w .  j a  v a  2 s .co  m
        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        @Override
        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    IStructuredModel scratchModel = StructuredModelManager.getModelManager()
            .createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}

From source file:org.eclipse.xtext.xbase.ui.hover.XbaseInformationControl.java

License:Open Source License

/**
 * Xbase - modification//from  w  ww . ja va  2s. c o m
 */
@Override
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
    if (fSymbolicFontName == null)
        return null;

    GC gc = new GC(fBrowser);
    Font font = JFaceResources.getFont(fSymbolicFontName);
    gc.setFont(font);
    int width = gc.getFontMetrics().getAverageCharWidth();
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    return new Point(widthInChars * width, heightInChars * height);
}

From source file:org.eclipse.xtext.xbase.ui.hover.XbaseInformationControl.java

License:Open Source License

/**
 * Creates and initializes the text layout used to compute the size hint.
 * /*  ww  w.j  av  a 2 s .c om*/
 * @since 3.2
 */
private void createTextLayout() {
    fTextLayout = new TextLayout(fSashForm.getDisplay());

    // Initialize fonts
    String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
    Font font = JFaceResources.getFont(symbolicFontName);
    fTextLayout.setFont(font);
    fTextLayout.setWidth(-1);
    font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
    fBoldStyle = new TextStyle(font, null, null);

    // Compute and set tab width
    fTextLayout.setText("    "); //$NON-NLS-1$
    int tabWidth = fTextLayout.getBounds().width;
    fTextLayout.setTabs(new int[] { tabWidth });
    fTextLayout.setText(""); //$NON-NLS-1$
}

From source file:org.ect.reo.mcrl2.properties.MCRL2StyledTextAdapter.java

License:Open Source License

/**
 * Default constructor.//from w  w w . j av a  2s .c o m
 * @param text Text with mCRL2 code.
 */
public MCRL2StyledTextAdapter(StyledText text) {
    this.text = text;

    // Try to use the Java Editor font:
    Font font = JFaceResources.getFont("org.eclipse.jdt.ui.editors.textfont");
    if (font != null)
        text.setFont(font);

    // Listen to modify events:
    text.addModifyListener(this);
}

From source file:org.emftext.language.xpath2.resource.xpath2.ui.Xpath2BrowserInformationControl.java

License:Open Source License

/**
 * Creates and initializes the text layout used to compute the size hint.
 * /*from  w  ww.java  2  s  .  co m*/
 * @since 3.2
 */
private void createTextLayout() {
    fTextLayout = new TextLayout(fBrowser.getDisplay());

    // Initialize fonts
    String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
    Font font = JFaceResources.getFont(symbolicFontName);
    fTextLayout.setFont(font);
    fTextLayout.setWidth(-1);
    font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
    fBoldStyle = new TextStyle(font, null, null);

    // Compute and set tab width
    fTextLayout.setText("    ");
    int tabWidth = fTextLayout.getBounds().width;
    fTextLayout.setTabs(new int[] { tabWidth });

    fTextLayout.setText("");
}

From source file:org.emftext.language.xpath2.resource.xpath2.ui.Xpath2BrowserInformationControl.java

License:Open Source License

/**
 * /*from  ww w. ja  v  a 2 s.  co  m*/
 * @see
 * org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int,
 * int)
 */
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
    if (fSymbolicFontName == null) {
        return null;
    }

    GC gc = new GC(fBrowser);
    Font font = fSymbolicFontName == null ? JFaceResources.getDialogFont()
            : JFaceResources.getFont(fSymbolicFontName);
    gc.setFont(font);
    int width = gc.getFontMetrics().getAverageCharWidth();
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    return new Point(widthInChars * width, heightInChars * height);
}

From source file:org.erlide.ui.prefs.plugin.ColoringPreferencePage.java

License:Open Source License

public static SourceViewer createErlangPreviewer(final Composite parent, IColorManager colorManager,
        Map<TokenHighlight, HighlightStyle> colors, final String content) {
    // TODO we should move this method, to a utility class (or maybe create
    // an ErlangPreviewSourceViewer class)
    if (colorManager == null) {
        colorManager = new ColorManager();
    }//from  w  w w  .  java2  s.  co m
    if (colors == null) {
        colors = new HashMap<TokenHighlight, HighlightStyle>();
        for (final TokenHighlight th : TokenHighlight.values()) {
            colors.put(th, th.getDefaultData());
        }
    }

    final IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
    final IPreferenceStore store = new ChainedPreferenceStore(
            new IPreferenceStore[] { createTemporaryCorePreferenceStore(), generalTextStore });
    final SourceViewer v = new ProjectionViewer(parent, null, null, false,
            SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    final SyntaxColorPreviewEditorConfiguration configuration = new SyntaxColorPreviewEditorConfiguration(store,
            colorManager, colors);
    v.configure(configuration);

    final Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
    v.getTextWidget().setFont(font);
    new ErlangSourceViewerUpdater(v, configuration, store);
    v.setEditable(false);

    final IDocument document = new Document(content);
    v.setDocument(document);

    return v;
}

From source file:org.erlide.ui.prefs.plugin.internal.ErlangSourceViewerUpdater.java

License:Open Source License

/**
 * Creates an Erlang source preview updater for the given viewer,
 * configuration and preference store./*from   w  w  w .  j a  v a 2 s  .co m*/
 * 
 * @param viewer
 *            the viewer
 * @param configuration
 *            the configuration
 * @param preferenceStore
 *            the preference store
 */
public ErlangSourceViewerUpdater(final ISourceViewer viewer,
        final ErlangSourceViewerConfiguration configuration, final IPreferenceStore preferenceStore) {
    Assert.isNotNull(viewer);
    Assert.isNotNull(configuration);
    Assert.isNotNull(preferenceStore);
    final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() {

        /*
         * @see
         * org.eclipse.jface.util.IPropertyChangeListener#propertyChange
         * (org.eclipse.jface.util.PropertyChangeEvent)
         */
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty())) {
                final Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
                viewer.getTextWidget().setFont(font);
            }
        }
    };
    final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {

        /*
         * @see
         * org.eclipse.jface.util.IPropertyChangeListener#propertyChange
         * (org.eclipse.jface.util.PropertyChangeEvent)
         */
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            // if (configuration.affectsTextPresentation(event)) {
            // configuration.handlePropertyChangeEvent(event);
            // viewer.invalidateTextPresentation();
            // }
        }
    };
    viewer.getTextWidget().addDisposeListener(new DisposeListener() {

        /*
         * @see
         * org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse
         * .swt.events.DisposeEvent)
         */
        @Override
        public void widgetDisposed(final DisposeEvent e) {
            preferenceStore.removePropertyChangeListener(propertyChangeListener);
            JFaceResources.getFontRegistry().removeListener(fontChangeListener);
        }
    });
    JFaceResources.getFontRegistry().addListener(fontChangeListener);
    preferenceStore.addPropertyChangeListener(propertyChangeListener);
}

From source file:org.erlide.ui.util.eclipse.text.BrowserInformationControl.java

License:Open Source License

/**
 * Creates and initializes the text layout used to compute the size hint.
 * //from w w  w.  jav a2  s  . co  m
 * @since 3.2
 */
private void createTextLayout() {
    fTextLayout = new TextLayout(fBrowser.getDisplay());

    // Initialize fonts
    Font font = fSymbolicFontName == null ? JFaceResources.getDialogFont()
            : JFaceResources.getFont(fSymbolicFontName);
    fTextLayout.setFont(font);
    fTextLayout.setWidth(-1);
    final FontData[] fontData = font.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setStyle(SWT.BOLD);
    }
    font = new Font(getShell().getDisplay(), fontData);
    fBoldStyle = new TextStyle(font, null, null);

    // Compute and set tab width
    fTextLayout.setText("    "); //$NON-NLS-1$
    final int tabWidth = fTextLayout.getBounds().width;
    fTextLayout.setTabs(new int[] { tabWidth });

    fTextLayout.setText(""); //$NON-NLS-1$
}

From source file:org.erlide.ui.util.eclipse.text.BrowserInformationControl.java

License:Open Source License

@Override
public Point computeSizeConstraints(final int widthInChars, final int heightInChars) {
    if (fSymbolicFontName == null) {
        return null;
    }//from w ww  . j av a2  s  .  c  om

    final GC gc = new GC(fBrowser);
    final Font font = JFaceResources.getFont(fSymbolicFontName);
    gc.setFont(font);
    final int width = gc.getFontMetrics().getAverageCharWidth();
    final int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    return new Point(widthInChars * width, heightInChars * height);
}