@Override public void analyse(String text, IErrorReporter reporter) { ILexer lexer = new TableBasedLexer( build.getTables(), null, new ITokenFactory() { @Override public IToken newToken(int type, Span span, Object content) { return new DefaultToken( type, span.start(), span.length(), build.getMapping().getToken(type)); } }); lexer.setErrorReporter(reporter); lexer.skipComments(false); lexer.setInput(new StringReader(text)); tokens.clear(); int eof = build.getMapping().getTokenNumber("$EOF$"); try { while (true) { IToken t = lexer.nextToken(); if (t.type() == eof) break; tokens.add(t); } } catch (IOException e) { } }
@Override protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) throws BadLocationException { Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); Font saveFont = graphics.getFont(); Color saveColor = graphics.getColor(); SyntaxDocument doc = (SyntaxDocument) getDocument(); Segment segment = getLineBuffer(); try { Iterator<IToken> i = doc.getTokens(p0, p1); int start = p0; while (i.hasNext()) { IToken t = i.next(); if (start < t.start()) { doc.getText(start, t.start() - start, segment); x = defaultStyle.drawText(segment, x, y, graphics, this, start); } int l = t.length(); int s = t.start(); if (s < p0) { l -= (p0 - s); s = p0; } if (s + l > p1) { l = p1 - s; } doc.getText(s, l, segment); x = manager.getStyle(t.type()).drawText(segment, x, y, graphics, this, t.start()); start = t.start() + t.length(); } if (start < p1) { doc.getText(start, p1 - start, segment); x = defaultStyle.drawText(segment, x, y, graphics, this, start); } } catch (BadLocationException e) { } finally { graphics.setFont(saveFont); graphics.setColor(saveColor); } return x; }