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);
}
}
}
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;
}
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();
}
}
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);
}
}
}
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;
}
Aggregations