Search in sources :

Example 46 with TextAttribute

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

the class LineStyleProviderForJSPEL method addJavaTextAttribute.

/**
 * Looks up the colorKey in the preference store and adds the style
 * information to list of TextAttributes
 *
 * @param colorKey
 */
private void addJavaTextAttribute(String colorKey) {
    IPreferenceStore store = getJavaColorPreferences();
    if (store != null && colorKey != null) {
        TextAttribute ta = null;
        if (colorKey == IStyleConstantsJSPEL.EL_KEYWORD) {
            // keyword
            RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR);
            boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD);
            boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC);
            boolean strikethrough = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_STRIKETHROUGH);
            boolean underline = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_UNDERLINE);
            int style = SWT.NORMAL;
            if (bold) {
                style = style | SWT.BOLD;
            }
            if (italics) {
                style = style | SWT.ITALIC;
            }
            if (strikethrough) {
                style = style | TextAttribute.STRIKETHROUGH;
            }
            if (underline) {
                style = style | TextAttribute.UNDERLINE;
            }
            ta = createTextAttribute(foreground, null, style);
        } else if (colorKey == IStyleConstantsJSPEL.EL_DEFAULT) {
            // default
            RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR);
            boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD);
            boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC);
            boolean strikethrough = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_STRIKETHROUGH);
            boolean underline = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_UNDERLINE);
            int style = SWT.NORMAL;
            if (bold) {
                style = style | SWT.BOLD;
            }
            if (italics) {
                style = style | SWT.ITALIC;
            }
            if (strikethrough) {
                style = style | TextAttribute.STRIKETHROUGH;
            }
            if (underline) {
                style = style | TextAttribute.UNDERLINE;
            }
            ta = createTextAttribute(foreground, null, style);
        }
        if (ta != null) {
            getTextAttributes().put(colorKey, ta);
            fScanner.setTokenData(colorKey, ta);
        }
    }
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) RGB(org.eclipse.swt.graphics.RGB)

Example 47 with TextAttribute

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

the class JSPSyntaxColoringPage 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 48 with TextAttribute

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

the class JSPSyntaxColoringPage method applyStyles.

/**
 * Color the text in the sample area according to the current preferences
 */
void applyStyles() {
    if (fText == null || fText.isDisposed())
        return;
    IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
    while (documentRegion != null) {
        ITextRegionList regions = documentRegion.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) fContextToStyleMap.get(currentRegion.getType());
            if (namedStyle == null)
                continue;
            TextAttribute attribute = getAttributeFor(namedStyle);
            if (attribute == null)
                continue;
            StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
            style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
            style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0;
            fText.setStyleRange(style);
        }
        documentRegion = documentRegion.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 49 with TextAttribute

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

the class LineStyleProviderForJava method addJavaTextAttribute.

/**
 * Looks up the colorKey in the preference store and adds the style
 * information to list of TextAttributes
 *
 * @param colorKey
 */
private void addJavaTextAttribute(String colorKey) {
    IPreferenceStore store = getJavaColorPreferences();
    if (store != null && colorKey != null) {
        TextAttribute ta = null;
        if (colorKey == IStyleConstantsJSPJava.JAVA_KEYWORD) {
            // keyword
            RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR);
            boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD);
            boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC);
            boolean strikethrough = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_STRIKETHROUGH);
            boolean underline = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_UNDERLINE);
            int style = SWT.NORMAL;
            if (bold) {
                style = style | SWT.BOLD;
            }
            if (italics) {
                style = style | SWT.ITALIC;
            }
            if (strikethrough) {
                style = style | TextAttribute.STRIKETHROUGH;
            }
            if (underline) {
                style = style | TextAttribute.UNDERLINE;
            }
            ta = createTextAttribute(foreground, null, style);
        } else if (colorKey == IStyleConstantsJSPJava.JAVA_STRING) {
            // string
            RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_STRING_COLOR);
            boolean bold = store.getBoolean(PreferenceConstants.EDITOR_STRING_BOLD);
            boolean italics = store.getBoolean(PreferenceConstants.EDITOR_STRING_ITALIC);
            boolean strikethrough = store.getBoolean(PreferenceConstants.EDITOR_STRING_STRIKETHROUGH);
            boolean underline = store.getBoolean(PreferenceConstants.EDITOR_STRING_UNDERLINE);
            int style = SWT.NORMAL;
            if (bold) {
                style = style | SWT.BOLD;
            }
            if (italics) {
                style = style | SWT.ITALIC;
            }
            if (strikethrough) {
                style = style | TextAttribute.STRIKETHROUGH;
            }
            if (underline) {
                style = style | TextAttribute.UNDERLINE;
            }
            ta = createTextAttribute(foreground, null, style);
        } else if (colorKey == IStyleConstantsJSPJava.JAVA_SINGLE_LINE_COMMENT) {
            // single line comment
            RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR);
            boolean bold = store.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD);
            boolean italics = store.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_ITALIC);
            boolean strikethrough = store.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_STRIKETHROUGH);
            boolean underline = store.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_UNDERLINE);
            int style = SWT.NORMAL;
            if (bold) {
                style = style | SWT.BOLD;
            }
            if (italics) {
                style = style | SWT.ITALIC;
            }
            if (strikethrough) {
                style = style | TextAttribute.STRIKETHROUGH;
            }
            if (underline) {
                style = style | TextAttribute.UNDERLINE;
            }
            ta = createTextAttribute(foreground, null, style);
        } else if (colorKey == IStyleConstantsJSPJava.JAVA_DEFAULT) {
            // default
            RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR);
            boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD);
            boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC);
            boolean strikethrough = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_STRIKETHROUGH);
            boolean underline = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_UNDERLINE);
            int style = SWT.NORMAL;
            if (bold) {
                style = style | SWT.BOLD;
            }
            if (italics) {
                style = style | SWT.ITALIC;
            }
            if (strikethrough) {
                style = style | TextAttribute.STRIKETHROUGH;
            }
            if (underline) {
                style = style | TextAttribute.UNDERLINE;
            }
            ta = createTextAttribute(foreground, null, style);
        }
        if (ta != null) {
            getTextAttributes().put(colorKey, ta);
            fScanner.setTokenData(colorKey, ta);
        }
    }
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) RGB(org.eclipse.swt.graphics.RGB)

Example 50 with TextAttribute

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

the class LineStyleProviderForJava method getTokenTextAttribute.

/**
 * Returns a text attribute encoded in the given token. If the token's
 * data is not <code>null</code> and a text attribute it is assumed that
 * it is the encoded text attribute. It returns the default text attribute
 * if there is no encoded text attribute found.
 *
 * @param token the token whose text attribute is to be determined
 * @return the token's text attribute
 */
private TextAttribute getTokenTextAttribute(IToken token) {
    TextAttribute ta = null;
    Object data = token.getData();
    if (data instanceof TextAttribute)
        ta = (TextAttribute) data;
    else {
        ta = (TextAttribute) getTextAttributes().get(IStyleConstantsJSPJava.JAVA_DEFAULT);
    }
    return ta;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute)

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