use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class TextPresentation method applyStyleRanges.
/**
* Applies the given ranges to this presentation. Each range must be a
* subrange of the presentation's default range. The ranges must be ordered
* by increasing offset and must not overlap (but may be adjacent).
*
* @param ranges the ranges to be added
* @param merge <code>true</code> if the style should be merged instead of replaced
* @since 3.0
*/
private void applyStyleRanges(StyleRange[] ranges, boolean merge) {
int j = 0;
ArrayList<StyleRange> oldRanges = fRanges;
ArrayList<StyleRange> newRanges = new ArrayList<>(2 * ranges.length + oldRanges.size());
for (StyleRange range : ranges) {
// for getFirstIndexAfterWindow(...)
fRanges = oldRanges;
for (int m = getFirstIndexAfterWindow(new Region(range.start, range.length)); j < m; j++) newRanges.add(oldRanges.get(j));
// for mergeStyleRange(...)
fRanges = newRanges;
applyStyleRange(range, merge);
}
for (int m = oldRanges.size(); j < m; j++) newRanges.add(oldRanges.get(j));
fRanges = newRanges;
}
use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class TextViewer method addPresentation.
/**
* Adds the given presentation to the viewer's style information.
*
* @param presentation the presentation to be added
*/
private void addPresentation(TextPresentation presentation) {
StyleRange range = presentation.getDefaultStyleRange();
if (range != null) {
range = modelStyleRange2WidgetStyleRange(range);
if (range != null)
fTextWidget.setStyleRange(range);
ArrayList<StyleRange> ranges = new ArrayList<>(presentation.getDenumerableRanges());
Iterator<StyleRange> e = presentation.getNonDefaultStyleRangeIterator();
while (e.hasNext()) {
range = e.next();
range = modelStyleRange2WidgetStyleRange(range);
if (range != null)
ranges.add(range);
}
if (!ranges.isEmpty())
fTextWidget.replaceStyleRanges(0, 0, ranges.toArray(new StyleRange[ranges.size()]));
} else {
IRegion region = modelRange2WidgetRange(presentation.getCoverage());
if (region == null)
return;
List<StyleRange> list = new ArrayList<>(presentation.getDenumerableRanges());
Iterator<StyleRange> e = presentation.getAllStyleRangeIterator();
while (e.hasNext()) {
range = e.next();
range = modelStyleRange2WidgetStyleRange(range);
if (range != null)
list.add(range);
}
if (!list.isEmpty()) {
StyleRange[] ranges = new StyleRange[list.size()];
list.toArray(ranges);
fTextWidget.replaceStyleRanges(region.getOffset(), region.getLength(), ranges);
}
}
}
use of org.eclipse.swt.custom.StyleRange in project linuxtools by eclipse.
the class ReportComparisonView method setStyledText.
/**
* Set properties for StlyedText widget.
* @param input String StyledText content.
*/
private void setStyledText(String input) {
result.setText(input);
result.setJustify(true);
result.setAlignment(SWT.LEFT);
result.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
List<StyleRange> styles = new ArrayList<>();
int ptr = 0;
// $NON-NLS-1$
String[] lines = input.split("\n");
for (String line : lines) {
if (Pattern.matches(DIFF_ENTRY, line)) {
Matcher m = Pattern.compile(DIFF_ENTRY).matcher(line);
if (m.matches() && m.group(1) != null && m.group(3) != null) {
try {
float baseline = Float.parseFloat(m.group(1).trim());
float delta = Float.parseFloat(m.group(3).trim());
if (baseline > 1 && Math.abs(delta) > 1) {
StyleRange curStyleRange;
if (delta < 0) {
curStyleRange = delta < -5 ? new StyleRange(ptr, line.length(), LIGHT_GREEN, null) : new StyleRange(ptr, line.length(), GREEN, null);
} else {
curStyleRange = delta < 5 ? new StyleRange(ptr, line.length(), ORANGE, null) : new StyleRange(ptr, line.length(), RED, null);
}
styles.add(curStyleRange);
}
} catch (NumberFormatException e) {
// set no StyleRange
}
}
}
// + 1 to skip over the '\n' at EOL that the tokenizer eats
ptr += line.length() + 1;
}
result.setStyleRanges(styles.toArray(new StyleRange[0]));
}
use of org.eclipse.swt.custom.StyleRange in project linuxtools by eclipse.
the class StatComparisonView method setStyledText.
/**
* Set String input in text display. Adapted from
* org.eclipse.linuxtools.internal.perf.ui.SourceDisassemblyView.
*
* @param input text to display
*/
private void setStyledText(String input) {
text.setText(input);
text.setAlignment(SWT.LEFT);
// set default TextConsole font (monospaced).
text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
List<StyleRange> styles = new ArrayList<>();
int ptr = 0;
// $NON-NLS-1$
String[] lines = input.split("\n");
for (String line : lines) {
if (Pattern.matches(OCCURRENCE, line)) {
Matcher m = Pattern.compile(OCCURRENCE).matcher(line);
if (m.matches() && m.group(1) != null) {
try {
float occurrence = StatComparisonData.toFloat(m.group(1).trim());
if (occurrence > 0) {
styles.add(new StyleRange(ptr, line.length(), RED, null));
} else if (occurrence < 0) {
styles.add(new StyleRange(ptr, line.length(), GREEN, null));
}
} catch (NumberFormatException e) {
// set no StyleRange
}
}
}
// + 1 to skip over the '\n' at EOL that the tokenizer eats
ptr += line.length() + 1;
}
text.setStyleRanges(styles.toArray(new StyleRange[0]));
}
use of org.eclipse.swt.custom.StyleRange in project knime-core by knime.
the class AnnotationEditPart method toSWTStyleRanges.
public static StyleRange[] toSWTStyleRanges(final AnnotationData t, final Font defaultFont) {
AnnotationData.StyleRange[] knimeStyleRanges = t.getStyleRanges();
ArrayList<StyleRange> swtStyleRange = new ArrayList<StyleRange>(knimeStyleRanges.length);
for (AnnotationData.StyleRange knimeSR : knimeStyleRanges) {
StyleRange swtStyle = new StyleRange();
Font f = FontStore.INSTANCE.getAnnotationFont(knimeSR, defaultFont);
swtStyle.font = f;
if (knimeSR.getFgColor() >= 0) {
int rgb = knimeSR.getFgColor();
RGB rgbObj = RGBintToRGBObj(rgb);
swtStyle.foreground = new Color(null, rgbObj);
}
swtStyle.start = knimeSR.getStart();
swtStyle.length = knimeSR.getLength();
swtStyleRange.add(swtStyle);
}
return swtStyleRange.toArray(new StyleRange[swtStyleRange.size()]);
}
Aggregations