use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.
the class SpringConfigurationStyledText method updateStyledRanges.
private void updateStyledRanges(ExtendedModifyEvent event) {
StyledText st = (StyledText) event.widget;
int start = event.start;
int length = event.length;
String replacedText = event.replacedText;
String textRange = st.getTextRange(start, length);
/*
* if no real change
* then return
*/
if ("".equals(textRange.trim()) && "".equals(replacedText.trim())) {
return;
}
List<StyleRange> styles = new ArrayList<StyleRange>();
scanner.setRange(st.getText());
int token = scanner.nextToken();
while (token != EOF) {
int startOffset = scanner.getStartOffset();
int tokenLength = scanner.getLength();
String tokenText = st.getTextRange(startOffset, tokenLength).trim();
for (String s : fgKeywords) {
if (s.equals(tokenText)) {
token = KEY;
break;
}
}
Color color = getColor(token);
StyleRange style = new StyleRange(startOffset, tokenLength, color, null);
if (token == KEY) {
style.fontStyle = SWT.BOLD;
}
styles.add(style);
token = scanner.nextToken();
}
st.setStyleRanges(styles.toArray(new StyleRange[0]));
}
Aggregations