use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.
the class AnsiConsoleStyleListener method lineGetStyle.
@Override
public void lineGetStyle(LineStyleEvent event) {
if (event == null || event.lineText == null || event.lineText.length() == 0)
return;
StyleRange defStyle;
if (event.styles != null && event.styles.length > 0) {
defStyle = (StyleRange) event.styles[0].clone();
if (defStyle.background == null)
defStyle.background = AnsiConsoleUtils.getDebugConsoleBgColor();
} else {
defStyle = new StyleRange(1, lastRangeEnd, new Color(null, AnsiConsoleColorPalette.getColor(0)), new Color(null, AnsiConsoleColorPalette.getColor(15)), SWT.NORMAL);
}
lastRangeEnd = 0;
List<StyleRange> ranges = new ArrayList<StyleRange>();
String currentText = event.lineText;
Matcher matcher = pattern.matcher(currentText);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
String theEscape = currentText.substring(matcher.start() + 2, matcher.end() - 1);
char code = currentText.charAt(matcher.end() - 1);
if (code == ESCAPE_SGR) {
// Select Graphic Rendition (SGR) escape sequence
List<Integer> nCommands = new ArrayList<Integer>();
for (String cmd : theEscape.split(";")) {
int nCmd = AnsiConsoleUtils.tryParseInteger(cmd);
if (nCmd != -1)
nCommands.add(nCmd);
}
if (nCommands.isEmpty())
nCommands.add(0);
interpretCommand(nCommands);
}
if (lastRangeEnd != start)
addRange(ranges, event.lineOffset + lastRangeEnd, start - lastRangeEnd, defStyle.foreground, false);
lastAttributes = currentAttributes.clone();
addRange(ranges, event.lineOffset + start, end - start, defStyle.foreground, true);
}
if (lastRangeEnd != currentText.length())
addRange(ranges, event.lineOffset + lastRangeEnd, currentText.length() - lastRangeEnd, defStyle.foreground, false);
lastAttributes = currentAttributes.clone();
if (!ranges.isEmpty())
event.styles = ranges.toArray(new StyleRange[ranges.size()]);
}
use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.
the class AnsiConsoleStyleListener method addRange.
private void addRange(List<StyleRange> ranges, int start, int length, Color foreground, boolean isCode) {
StyleRange range = new StyleRange(start, length, foreground, null);
AnsiConsoleAttributes.updateRangeStyle(range, lastAttributes);
if (isCode) {
range.metrics = new GlyphMetrics(0, 0, 0);
}
ranges.add(range);
lastRangeEnd = lastRangeEnd + range.length;
}
use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.
the class SearchCellLabelProvider method update.
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
final String text = getText(element);
cell.setText(text);
cell.setImage(getImage(element));
cell.setFont(getFont(element));
if (filterString != null && !filterString.isEmpty()) {
int filterIndex = text.indexOf(filterString);
StyleRange styleRange = new StyleRange(filterIndex, filterString.length(), null, hightLight);
cell.setStyleRanges(new StyleRange[] { styleRange });
} else {
cell.setStyleRanges(null);
}
}
use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.
the class ProductInfoDialog method getCurrentRange.
/**
* Find the range of the current selection.
*
* @param text the StyledText
* @return the StyleRange
*/
protected StyleRange getCurrentRange(StyledText text) {
StyleRange[] ranges = text.getStyleRanges();
int currentSelectionEnd = text.getSelection().y;
int currentSelectionStart = text.getSelection().x;
for (int i = 0; i < ranges.length; i++) {
if ((currentSelectionStart >= ranges[i].start) && (currentSelectionEnd <= (ranges[i].start + ranges[i].length))) {
return ranges[i];
}
}
return null;
}
use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.
the class ProductInfoDialog method setLinkRanges.
/**
* Sets the styled text's link (blue) ranges
*
* @param styledText the styledText
* @param linkRanges the range array
*/
protected void setLinkRanges(StyledText styledText, int[][] linkRanges) {
Color fg = JFaceColors.getHyperlinkText(styledText.getShell().getDisplay());
for (int i = 0; i < linkRanges.length; i++) {
StyleRange r = new StyleRange(linkRanges[i][0], linkRanges[i][1], fg, null);
styledText.setStyleRange(r);
}
}
Aggregations