use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.
the class SemanticHighlightingManager method adaptToTextForegroundChange.
private void adaptToTextForegroundChange(HighlightingStyle highlighting, PropertyChangeEvent event) {
RGB rgb = null;
Object value = event.getNewValue();
if (value instanceof RGB)
rgb = (RGB) value;
else if (value instanceof String)
rgb = ColorHelper.toRGB((String) value);
if (rgb != null) {
Color color = EditorUtility.getColor(rgb);
TextAttribute oldAttr = highlighting.getTextAttribute();
highlighting.setTextAttribute(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
}
}
use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.
the class DTDSyntaxColoringPage 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 DTDSyntaxColoringPage 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 LineStyleProviderForDTDSubSet method getAttributeFor.
protected TextAttribute getAttributeFor(ITextRegion region) {
TextAttribute ta = null;
String prefString = getColorPreferences().getString(IStyleConstantsDTD.DTD_DEFAULT);
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();
ta = createTextAttribute(foreground, background, bold);
}
return ta;
}
use of org.eclipse.jface.text.TextAttribute in project webtools.sourceediting by eclipse.
the class CSSSyntaxColoringPage 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();
}
}
Aggregations