use of org.eclipse.jface.text.TextPresentation in project eclipse.platform.text by eclipse.
the class HTML2TextReaderTest method verify.
private void verify(String input, String expectedOutput, StyleRange[] styleRanges) throws IOException {
Reader reader = new StringReader(input);
TextPresentation textPresentation = new TextPresentation();
String result;
try (HTML2TextReader htmlReader = new HTML2TextReader(reader, textPresentation)) {
result = htmlReader.getString();
}
if (DEBUG)
System.out.println("<" + result + "/>");
assertEquals(expectedOutput, result);
Iterator<StyleRange> styleRangeIterator = textPresentation.getAllStyleRangeIterator();
List<StyleRange> ranges = new ArrayList<>();
while (styleRangeIterator.hasNext()) {
ranges.add(styleRangeIterator.next());
}
Collections.sort(ranges, (r1, r2) -> r1.start - r2.start);
assertEquals(Arrays.asList(styleRanges), ranges);
for (int i = 0; i < ranges.size() - 1; i++) {
StyleRange range1 = ranges.get(i);
StyleRange range2 = ranges.get(i + 1);
if (range1.start + range1.length > range2.start) {
assertTrue("StyleRanges overlap", false);
}
}
}
use of org.eclipse.jface.text.TextPresentation in project linuxtools by eclipse.
the class ManTextViewer method setDocument.
/**
* Sets the document to display.
*
* @param document
* The document to display.
*/
public void setDocument(ManDocument document) {
super.setDocument(document);
TextPresentation style = new TextPresentation();
for (int underlineSymbol : document.getUnderlinedSymbols()) {
StyleRange styleRange = new StyleRange(underlineSymbol, 1, null, null, SWT.NORMAL);
styleRange.underline = true;
style.addStyleRange(styleRange);
}
for (int boldSymbol : document.getBoldSymbols()) {
style.mergeStyleRange(new StyleRange(boldSymbol, 1, null, null, SWT.BOLD));
}
getTextWidget().setBackground(getControl().getDisplay().getSystemColor(SWT.COLOR_GRAY));
changeTextPresentation(style, true);
}
Aggregations