Search in sources :

Example 6 with TextPresentation

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);
        }
    }
}
Also used : HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) StyleRange(org.eclipse.swt.custom.StyleRange) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) TextPresentation(org.eclipse.jface.text.TextPresentation)

Example 7 with TextPresentation

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);
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) TextPresentation(org.eclipse.jface.text.TextPresentation)

Aggregations

TextPresentation (org.eclipse.jface.text.TextPresentation)7 StyleRange (org.eclipse.swt.custom.StyleRange)5 StringReader (java.io.StringReader)3 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 HTML2TextReader (org.eclipse.jface.internal.text.html.HTML2TextReader)2 IOException (java.io.IOException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1