Search in sources :

Example 31 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project soot by Sable.

the class JimpleConfiguration method getJimpleScanner.

protected JimpleScanner getJimpleScanner() {
    if (scanner == null) {
        scanner = new JimpleScanner(colorManager);
        scanner.setDefaultReturnToken(new Token(new TextAttribute(colorManager.getColor(IJimpleColorConstants.JIMPLE_DEFAULT))));
    }
    return scanner;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Token(org.eclipse.jface.text.rules.Token)

Example 32 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.

the class AbstractLineStyleProvider method prepareTextRegion.

/**
 * @param region
 * @param start
 * @param length
 * @param holdResults
 * @return
 */
private boolean prepareTextRegion(ITextRegionCollection blockedRegion, int partitionStartOffset, int partitionLength, Collection holdResults) {
    boolean handled = false;
    final int partitionEndOffset = partitionStartOffset + partitionLength - 1;
    ITextRegion region = null;
    ITextRegionList regions = blockedRegion.getRegions();
    int nRegions = regions.size();
    StyleRange styleRange = null;
    for (int i = 0; i < nRegions; i++) {
        region = regions.get(i);
        TextAttribute attr = null;
        TextAttribute previousAttr = null;
        if (blockedRegion.getStartOffset(region) > partitionEndOffset)
            break;
        if (blockedRegion.getEndOffset(region) <= partitionStartOffset)
            continue;
        if (region instanceof ITextRegionCollection) {
            handled = prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults);
        } else {
            attr = getAttributeFor(blockedRegion, region);
            if (attr != null) {
                handled = true;
                // regions correctly
                if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) {
                    styleRange.length += region.getLength();
                } else {
                    styleRange = createStyleRange(blockedRegion, region, attr, partitionStartOffset, partitionLength);
                    holdResults.add(styleRange);
                    // technically speaking, we don't need to update
                    // previousAttr
                    // in the other case, because the other case is when
                    // it hasn't changed
                    previousAttr = attr;
                }
            } else {
                previousAttr = null;
            }
        }
    }
    return handled;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 33 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.

the class StyledTextColorPicker method getAttribute.

protected TextAttribute getAttribute(String namedStyle) {
    TextAttribute ta = new TextAttribute(getDefaultForeground(), getDefaultBackground(), SWT.NORMAL);
    if (namedStyle != null && getPreferenceStore() != null) {
        String prefString = getPreferenceStore().getString(namedStyle);
        String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
        if (stylePrefs != null) {
            RGB foreground = ColorHelper.toRGB(stylePrefs[0]);
            RGB background = ColorHelper.toRGB(stylePrefs[1]);
            int fontModifier = SWT.NORMAL;
            boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue();
            if (bold)
                fontModifier = fontModifier | SWT.BOLD;
            if (showItalic) {
                boolean italic = Boolean.valueOf(stylePrefs[3]).booleanValue();
                if (italic)
                    fontModifier = fontModifier | SWT.ITALIC;
            }
            ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier);
        }
    }
    return ta;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) RGB(org.eclipse.swt.graphics.RGB)

Example 34 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.

the class StyledTextColorPicker method applyStyles.

protected void applyStyles() {
    if (fText == null || fText.isDisposed() || fInput == null || fInput.length() == 0)
        return;
    // List regions = fParser.getRegions();
    IStructuredDocumentRegion node = fNodes;
    while (node != null) {
        ITextRegionList regions = node.getRegions();
        for (int i = 0; i < regions.size(); i++) {
            ITextRegion currentRegion = regions.get(i);
            // lookup the local coloring type and apply it
            String namedStyle = (String) getContextStyleMap().get(currentRegion.getType());
            if (namedStyle == null)
                continue;
            TextAttribute attribute = getAttribute(namedStyle);
            if (attribute == null)
                continue;
            StyleRange style = new StyleRange(node.getStartOffset(currentRegion), currentRegion.getLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
            fText.setStyleRange(style);
        }
        node = node.getNext();
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 35 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.

the class HTMLSyntaxColoringPage method getAttributeFor.

private TextAttribute getAttributeFor(String namedStyle) {
    TextAttribute ta = new TextAttribute(fDefaultForeground, fDefaultBackground, SWT.NORMAL);
    if (namedStyle != null && fOverlayStore != null) {
        // note: "namedStyle" *is* the preference key
        String prefString = getOverlayStore().getString(namedStyle);
        String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
        if (stylePrefs != null) {
            RGB foreground = ColorHelper.toRGB(stylePrefs[0]);
            RGB background = ColorHelper.toRGB(stylePrefs[1]);
            int fontModifier = SWT.NORMAL;
            if (stylePrefs.length > 2) {
                boolean on = Boolean.valueOf(stylePrefs[2]).booleanValue();
                if (on)
                    fontModifier = fontModifier | SWT.BOLD;
            }
            if (stylePrefs.length > 3) {
                boolean on = Boolean.valueOf(stylePrefs[3]).booleanValue();
                if (on)
                    fontModifier = fontModifier | SWT.ITALIC;
            }
            if (stylePrefs.length > 4) {
                boolean on = Boolean.valueOf(stylePrefs[4]).booleanValue();
                if (on)
                    fontModifier = fontModifier | TextAttribute.STRIKETHROUGH;
            }
            if (stylePrefs.length > 5) {
                boolean on = Boolean.valueOf(stylePrefs[5]).booleanValue();
                if (on)
                    fontModifier = fontModifier | TextAttribute.UNDERLINE;
            }
            ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier);
        }
    }
    return ta;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) RGB(org.eclipse.swt.graphics.RGB)

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