use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.
the class XMLSyntaxColoringPage 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 XMLSyntaxColoringPage 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 XMLSyntaxColoringPage 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());
}
use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.
the class SemanticHighlightingManager method adaptToTextStyleChange.
private void adaptToTextStyleChange(HighlightingStyle highlighting, PropertyChangeEvent event, int styleAttribute) {
boolean eventValue = false;
Object value = event.getNewValue();
if (value instanceof Boolean)
eventValue = ((Boolean) value).booleanValue();
else if (IPreferenceStore.TRUE.equals(value))
eventValue = true;
TextAttribute oldAttr = highlighting.getTextAttribute();
boolean activeValue = (oldAttr.getStyle() & styleAttribute) == styleAttribute;
if (activeValue != eventValue)
highlighting.setTextAttribute(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
}
use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.
the class SemanticHighlightingManager method createHighlightingStyle.
/**
* Creates a highlighting style based on the preferences defined in the semantic highlighting
* @param highlighting the semantic highlighting
* @return a highlighting style based on the preferences of the semantic highlighting
*/
private HighlightingStyle createHighlightingStyle(ISemanticHighlighting highlighting, String styleKey) {
IPreferenceStore store = highlighting.getPreferenceStore();
HighlightingStyle highlightingStyle = null;
if (store != null) {
TextAttribute attribute = null;
// A style string is used instead of separate attribute keys
if (styleKey != null) {
attribute = createTextAttribute(store.getString(styleKey));
} else {
int style = getBoolean(store, highlighting.getBoldPreferenceKey()) ? SWT.BOLD : SWT.NORMAL;
if (getBoolean(store, highlighting.getItalicPreferenceKey()))
style |= SWT.ITALIC;
if (getBoolean(store, highlighting.getStrikethroughPreferenceKey()))
style |= TextAttribute.STRIKETHROUGH;
if (getBoolean(store, highlighting.getUnderlinePreferenceKey()))
style |= TextAttribute.UNDERLINE;
String rgbString = getString(store, highlighting.getColorPreferenceKey());
Color color = null;
Color bgColor = null;
if (rgbString != null)
color = EditorUtility.getColor(ColorHelper.toRGB(rgbString));
if (highlighting instanceof ISemanticHighlightingExtension2) {
rgbString = getString(store, ((ISemanticHighlightingExtension2) highlighting).getBackgroundColorPreferenceKey());
if (rgbString != null) {
bgColor = EditorUtility.getColor(ColorHelper.toRGB(rgbString));
}
}
attribute = new TextAttribute(color, bgColor, style);
}
store.addPropertyChangeListener(fHighlightingChangeListener);
boolean isEnabled = getBoolean(store, highlighting.getEnabledPreferenceKey());
highlightingStyle = new HighlightingStyle(attribute, isEnabled);
}
return highlightingStyle;
}
Aggregations