Search in sources :

Example 96 with TextAttribute

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

the class LineStyleProviderForJSDT method addTextAttribute.

/**
 * Looks up the colorKey in the preference store and adds the style
 * information to list of TextAttributes
 *
 * @param colorKey
 */
protected void addTextAttribute(String colorKey) {
    IPreferenceStore javaStore = getJavaColorPreferences();
    if (javaStore != null && colorKey != null) {
        TextAttribute ta = null;
        if (colorKey == IStyleConstantsJSDT.JAVA_KEYWORD) {
            // keyword
            RGB foreground = PreferenceConverter.getColor(javaStore, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR);
            boolean bold = javaStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD);
            boolean italics = javaStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC);
            boolean strikethrough = javaStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_STRIKETHROUGH);
            boolean underline = javaStore.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 == IStyleConstantsJSDT.JAVA_STRING) {
            // string
            RGB foreground = PreferenceConverter.getColor(javaStore, PreferenceConstants.EDITOR_STRING_COLOR);
            boolean bold = javaStore.getBoolean(PreferenceConstants.EDITOR_STRING_BOLD);
            boolean italics = javaStore.getBoolean(PreferenceConstants.EDITOR_STRING_ITALIC);
            boolean strikethrough = javaStore.getBoolean(PreferenceConstants.EDITOR_STRING_STRIKETHROUGH);
            boolean underline = javaStore.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 == IStyleConstantsJSDT.JAVA_SINGLE_LINE_COMMENT) {
            // single line comment
            RGB foreground = PreferenceConverter.getColor(javaStore, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR);
            boolean bold = javaStore.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD);
            boolean italics = javaStore.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_ITALIC);
            boolean strikethrough = javaStore.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_STRIKETHROUGH);
            boolean underline = javaStore.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 == IStyleConstantsJSDT.JAVA_MULTI_LINE_COMMENT) {
            // multi line comment
            RGB foreground = PreferenceConverter.getColor(javaStore, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR);
            boolean bold = javaStore.getBoolean(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD);
            boolean italics = javaStore.getBoolean(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_ITALIC);
            boolean strikethrough = javaStore.getBoolean(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_STRIKETHROUGH);
            boolean underline = javaStore.getBoolean(PreferenceConstants.EDITOR_MULTI_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 == IStyleConstantsJSDT.JAVA_DEFAULT) {
            // default
            RGB foreground = PreferenceConverter.getColor(javaStore, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR);
            boolean bold = javaStore.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD);
            boolean italics = javaStore.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC);
            boolean strikethrough = javaStore.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_STRIKETHROUGH);
            boolean underline = javaStore.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);
        } else if (colorKey == IStyleConstantsXML.COMMENT_BORDER || colorKey == IStyleConstantsJs.JSP_CONTENT) {
            /**
             * @see AbstractLineStyleProvider#addTextAttribute
             */
            ta = (TextAttribute) getTextAttributes().get(colorKey);
            String prefString = getHTMLColorPreferences().getString(colorKey);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                RGB foreground = ColorHelper.toRGB(stylePrefs[0]);
                RGB background = ColorHelper.toRGB(stylePrefs[1]);
                boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue();
                boolean italic = Boolean.valueOf(stylePrefs[3]).booleanValue();
                boolean strikethrough = Boolean.valueOf(stylePrefs[4]).booleanValue();
                boolean underline = Boolean.valueOf(stylePrefs[5]).booleanValue();
                int style = SWT.NORMAL;
                if (bold) {
                    style = style | SWT.BOLD;
                }
                if (italic) {
                    style = style | SWT.ITALIC;
                }
                if (strikethrough) {
                    style = style | TextAttribute.STRIKETHROUGH;
                }
                if (underline) {
                    style = style | TextAttribute.UNDERLINE;
                }
                ta = createTextAttribute(foreground, background, 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 97 with TextAttribute

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

the class LineStyleProviderForJSDT 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(IStyleConstantsJSDT.JAVA_DEFAULT);
    }
    return ta;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute)

Example 98 with TextAttribute

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

the class JSPSyntaxColoringPage 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);
        boolean enableBackgroundOnly = IStyleConstantsJSP.JSP_CONTENT.equals(namedStyle);
        fBold.setEnabled(!enableBackgroundOnly);
        fItalic.setEnabled(!enableBackgroundOnly);
        fStrike.setEnabled(!enableBackgroundOnly);
        fUnderline.setEnabled(!enableBackgroundOnly);
        fForegroundLabel.setEnabled(!enableBackgroundOnly);
        fForegroundColorEditor.setEnabled(!enableBackgroundOnly);
        fBackgroundLabel.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 99 with TextAttribute

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

the class LineStyleProviderForJava method addRange.

/**
 * Adds style information to the given text presentation.
 *
 * @param presentation the text presentation to be extended
 * @param offset the offset of the range to be styled
 * @param length the length of the range to be styled
 * @param attr the attribute describing the style of the range to be styled
 */
private void addRange(Collection presentation, int offset, int length, TextAttribute attr) {
    // support for user defined backgroud for JSP scriptlet regions
    TextAttribute ta = (TextAttribute) getTextAttributes().get(IStyleConstantsJSP.JSP_CONTENT);
    Color bgColor = ta.getBackground();
    if (bgColor == null)
        bgColor = attr.getBackground();
    StyleRange result = new StyleRange(offset, length, attr.getForeground(), bgColor, attr.getStyle());
    if ((attr.getStyle() & TextAttribute.STRIKETHROUGH) != 0) {
        result.strikeout = true;
    }
    if ((attr.getStyle() & TextAttribute.UNDERLINE) != 0) {
        result.underline = true;
    }
    presentation.add(result);
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 100 with TextAttribute

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

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

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