Search in sources :

Example 36 with TextAttribute

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

the class CSSSyntaxColoringPage method activate.

// activate controls based on the given local color type
private void activate(String namedStyle) {
    Color foreground = fDefaultForeground;
    Color background = fDefaultBackground;
    if (namedStyle == null) {
        fClearStyle.setEnabled(false);
        fBold.setEnabled(false);
        fItalic.setEnabled(false);
        fStrike.setEnabled(false);
        fUnderline.setEnabled(false);
        fForegroundLabel.setEnabled(false);
        fBackgroundLabel.setEnabled(false);
        fForegroundColorEditor.setEnabled(false);
        fBackgroundColorEditor.setEnabled(false);
        fBold.setSelection(false);
        fItalic.setSelection(false);
        fStrike.setSelection(false);
        fUnderline.setSelection(false);
    } else {
        TextAttribute attribute = getAttributeFor(namedStyle);
        fClearStyle.setEnabled(true);
        fBold.setEnabled(true);
        fItalic.setEnabled(true);
        fStrike.setEnabled(true);
        fUnderline.setEnabled(true);
        fForegroundLabel.setEnabled(true);
        fBackgroundLabel.setEnabled(true);
        fForegroundColorEditor.setEnabled(true);
        fBackgroundColorEditor.setEnabled(true);
        fBold.setSelection((attribute.getStyle() & SWT.BOLD) != 0);
        fItalic.setSelection((attribute.getStyle() & SWT.ITALIC) != 0);
        fStrike.setSelection((attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0);
        fUnderline.setSelection((attribute.getStyle() & TextAttribute.UNDERLINE) != 0);
        if (attribute.getForeground() != null) {
            foreground = attribute.getForeground();
        }
        if (attribute.getBackground() != null) {
            background = attribute.getBackground();
        }
    }
    fForegroundColorEditor.setColorValue(foreground.getRGB());
    fBackgroundColorEditor.setColorValue(background.getRGB());
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color)

Example 37 with TextAttribute

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

the class CSSSyntaxColoringPage 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)

Example 38 with TextAttribute

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

the class WordRuleTest method testBug175712_1.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
public void testBug175712_1() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((( \n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument)

Example 39 with TextAttribute

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

the class WordRuleTest method testBug175712_2.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
public void testBug175712_2() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((\n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument)

Example 40 with TextAttribute

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

the class JSONSyntaxColoringPage 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