Search in sources :

Example 26 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project usbdm-eclipse-plugins by podonoghue.

the class ViewConfiguration method getCodeScanner.

protected RuleBasedScanner getCodeScanner() {
    if (codeScanner == null) {
        codeScanner = new CodeScanner(colorManager);
        codeScanner.setDefaultReturnToken(new Token(new TextAttribute(colorManager.getColor(ColorConstants.DEFAULT))));
    }
    return codeScanner;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Token(org.eclipse.jface.text.rules.Token)

Example 27 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project egit by eclipse.

the class DiffViewer method refreshDiffStyles.

private void refreshDiffStyles() {
    ColorRegistry col = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
    FontRegistry reg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
    // We do the foreground via syntax coloring and the background via a
    // line background listener. If we did the background also via the
    // TextAttributes, this would take precedence over the line background
    // resulting in strange display if the current line is highlighted:
    // that highlighting would appear only beyond the end of the actual
    // text content (i.e., beyond the end-of-line), while actual text
    // would still get the background from the attribute.
    tokens.put(IDocument.DEFAULT_CONTENT_TYPE, new Token(null));
    tokens.put(DiffDocument.HEADLINE_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffHeadlineForegroundColor), null, SWT.NORMAL, reg.get(THEME_DiffHeadlineFont))));
    tokens.put(DiffDocument.HUNK_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffHunkForegroundColor))));
    tokens.put(DiffDocument.ADDED_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffAddForegroundColor))));
    tokens.put(DiffDocument.REMOVED_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffRemoveForegroundColor))));
    backgroundColors.put(DiffDocument.HEADLINE_CONTENT_TYPE, col.get(THEME_DiffHeadlineBackgroundColor));
    backgroundColors.put(DiffDocument.HUNK_CONTENT_TYPE, col.get(THEME_DiffHunkBackgroundColor));
    backgroundColors.put(DiffDocument.ADDED_CONTENT_TYPE, col.get(THEME_DiffAddBackgroundColor));
    backgroundColors.put(DiffDocument.REMOVED_CONTENT_TYPE, col.get(THEME_DiffRemoveBackgroundColor));
}
Also used : ColorRegistry(org.eclipse.jface.resource.ColorRegistry) TextAttribute(org.eclipse.jface.text.TextAttribute) FontRegistry(org.eclipse.jface.resource.FontRegistry) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token)

Example 28 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project statecharts by Yakindu.

the class StyleRanges method getRanges.

public List<StyleRange> getRanges(String expression) {
    final List<StyleRange> ranges = Lists.newArrayList();
    DocumentEvent event = new DocumentEvent();
    event.fDocument = new DummyDocument(expression);
    DocumentTokenSource tokenSource = tokenSourceProvider.get();
    tokenSource.updateStructure(event);
    Iterator<ILexerTokenRegion> iterator = tokenSource.getTokenInfos().iterator();
    while (iterator.hasNext()) {
        ILexerTokenRegion next = iterator.next();
        TextAttribute attribute = attributeProvider.getAttribute(tokenTypeMapper.getId(next.getLexerTokenType()));
        StyleRange range = new StyleRange(next.getOffset(), next.getLength(), attribute.getForeground(), attribute.getBackground());
        range.font = attribute.getFont();
        range.fontStyle = attribute.getStyle();
        ranges.add(range);
    }
    return ranges;
}
Also used : DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange) ILexerTokenRegion(org.eclipse.xtext.ui.editor.model.ILexerTokenRegion) DocumentEvent(org.eclipse.jface.text.DocumentEvent)

Example 29 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project tdq-studio-se by Talend.

the class AbstractSQLScanner method adaptToColorChange.

private void adaptToColorChange(Token token, PropertyChangeEvent event) {
    RGB rgb = null;
    Object value = event.getNewValue();
    if (value instanceof RGB)
        rgb = (RGB) value;
    else if (value instanceof String)
        rgb = StringConverter.asRGB((String) value);
    if (rgb != null) {
        String property = event.getProperty();
        if (fColorManager instanceof IColorManagerExtension) {
            IColorManagerExtension ext = (IColorManagerExtension) fColorManager;
            ext.unbindColor(property);
            ext.bindColor(property, rgb);
        }
        Object data = token.getData();
        if (data instanceof TextAttribute) {
            TextAttribute oldAttr = (TextAttribute) data;
            token.setData(new TextAttribute(fColorManager.getColor(property), oldAttr.getBackground(), oldAttr.getStyle()));
        }
    }
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) RGB(org.eclipse.swt.graphics.RGB)

Example 30 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project titan.EclipsePlug-ins by eclipse.

the class ColorManager method createAttributeFromPreference.

/**
 * Creates a TextAttribute out of a 'preference group' 's name.
 * <p>
 * Actually 3 preference names are use which are postfixed to get the
 * actual ones needed.
 *
 * @see #getBackgroundColor(String)
 * @see #getForegroundColor(String)
 * @see #createTokenFromPreference(String)
 * @see PreferenceConstants
 *
 * @param key
 *                The 'preference group' 's name.
 * @return The TextAttribute created.
 */
public TextAttribute createAttributeFromPreference(final String key) {
    Color foregroundColor = getForegroundColor(key + PreferenceConstants.FOREGROUND);
    Color backgroundColor;
    if (Activator.getDefault().getPreferenceStore().getBoolean(key + PreferenceConstants.USEBACKGROUNDCOLOR)) {
        backgroundColor = getBackgroundColor(key + PreferenceConstants.BACKGROUND);
    } else {
        backgroundColor = null;
    }
    boolean isBold = Activator.getDefault().getPreferenceStore().getBoolean(key + PreferenceConstants.BOLD);
    return new TextAttribute(foregroundColor, backgroundColor, isBold ? SWT.BOLD : SWT.NORMAL);
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color)

Aggregations

TextAttribute (org.eclipse.jface.text.TextAttribute)142 Token (org.eclipse.jface.text.rules.Token)45 RGB (org.eclipse.swt.graphics.RGB)37 Color (org.eclipse.swt.graphics.Color)36 IToken (org.eclipse.jface.text.rules.IToken)23 StyleRange (org.eclipse.swt.custom.StyleRange)20 IPresentationReconciler (org.eclipse.jface.text.presentation.IPresentationReconciler)16 PresentationReconciler (org.eclipse.jface.text.presentation.PresentationReconciler)16 DefaultDamagerRepairer (org.eclipse.jface.text.rules.DefaultDamagerRepairer)14 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)12 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)12 IRule (org.eclipse.jface.text.rules.IRule)10 RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)9 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)8 ArrayList (java.util.ArrayList)7 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 ColorRegistry (org.eclipse.jface.resource.ColorRegistry)5 Document (org.eclipse.jface.text.Document)4 IDocument (org.eclipse.jface.text.IDocument)4 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)4