Search in sources :

Example 1 with ITokenScanner

use of org.eclipse.jface.text.rules.ITokenScanner in project translationstudio8 by heartsome.

the class TagStyleConfigurator method configure.

public static void configure(TextLayout textLayout) {
    String text = textLayout.getText();
    Document doc = new Document(text);
    ITokenScanner scanner = getRecipeScanner(doc);
    scanner.setRange(doc, 0, doc.getLength());
    IToken token;
    while ((token = scanner.nextToken()) != Token.EOF) {
        int offset = scanner.getTokenOffset();
        int length = scanner.getTokenLength();
        Object data = token.getData();
        if (data != null && data instanceof TextStyle) {
            TextStyle textStyle = (TextStyle) data;
            textLayout.setStyle(textStyle, offset, offset + length - 1);
        }
    }
    scanner = null;
    doc = null;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TextStyle(org.eclipse.swt.graphics.TextStyle) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ITokenScanner(org.eclipse.jface.text.rules.ITokenScanner)

Example 2 with ITokenScanner

use of org.eclipse.jface.text.rules.ITokenScanner in project translationstudio8 by heartsome.

the class TagStyleConfigurator method configure.

public static void configure(TextLayout textLayout) {
    String text = textLayout.getText();
    Document doc = new Document(text);
    ITokenScanner scanner = getRecipeScanner(doc);
    scanner.setRange(doc, 0, doc.getLength());
    IToken token;
    while ((token = scanner.nextToken()) != Token.EOF) {
        int offset = scanner.getTokenOffset();
        int length = scanner.getTokenLength();
        Object data = token.getData();
        if (data != null && data instanceof TextStyle) {
            TextStyle textStyle = (TextStyle) data;
            textLayout.setStyle(textStyle, offset, offset + length - 1);
        }
    }
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TextStyle(org.eclipse.swt.graphics.TextStyle) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ITokenScanner(org.eclipse.jface.text.rules.ITokenScanner)

Aggregations

Document (org.eclipse.jface.text.Document)2 IDocument (org.eclipse.jface.text.IDocument)2 IToken (org.eclipse.jface.text.rules.IToken)2 ITokenScanner (org.eclipse.jface.text.rules.ITokenScanner)2 TextStyle (org.eclipse.swt.graphics.TextStyle)2