List of usage examples for javax.swing.text Utilities drawTabbedText
public static final float drawTabbedText(Segment s, float x, float y, Graphics2D g, TabExpander e, int startOffset)
From source file:FormattedTextFieldExample.java
protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException { g.setColor(unselected);// ww w. j a va 2s. c om workBuff.array = contentBuff.array; workBuff.offset = p0; workBuff.count = p1 - p0; return Utilities.drawTabbedText(workBuff, x, y, g, this, p0); }
From source file:FormattedTextFieldExample.java
protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException { workBuff.array = contentBuff.array;// ww w . j a v a2 s.co m workBuff.offset = p0; workBuff.count = p1 - p0; g.setColor(selected); return Utilities.drawTabbedText(workBuff, x, y, g, this, p0); }
From source file:ro.nextreports.designer.ui.sqleditor.syntax.SyntaxView.java
@Override protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) { Font saveFont = graphics.getFont(); Color saveColor = graphics.getColor(); SyntaxDocument doc = (SyntaxDocument) getDocument(); Segment segment = getLineBuffer(); try {//from w w w . ja v a2s . c om // Colour the parts Iterator<Token> tokens = doc.getTokens(p0, p1); int start = p0; while (tokens.hasNext()) { Token t = tokens.next(); // if there is a gap between the next token start and where we // should be starting (spaces not returned in tokens), then draw // it in the default type if (start < t.start) { SyntaxStyles.getInstance().setGraphicsStyle(graphics, TokenType.DEFAULT); doc.getText(start, t.start - start, segment); x = Utilities.drawTabbedText(segment, x, y, graphics, this, start); } // t and s are the actual start and length of what we should // put on the screen. assume these are the whole token.... int l = t.length; int s = t.start; // ... unless the token starts before p0: if (s < p0) { // token is before what is requested. adgust the length and s l -= (p0 - s); s = p0; } // if token end (s + l is still the token end pos) is greater // than p1, then just put up to p1 if (s + l > p1) { l = p1 - s; } doc.getText(s, l, segment); x = SyntaxStyles.getInstance().drawText(segment, x, y, graphics, this, t); start = t.start + t.length; } // now for any remaining text not tokenized: if (start < p1) { SyntaxStyles.getInstance().setGraphicsStyle(graphics, TokenType.DEFAULT); doc.getText(start, p1 - start, segment); x = Utilities.drawTabbedText(segment, x, y, graphics, this, start); } } catch (BadLocationException e) { System.err.println("Requested: " + e.offsetRequested()); LOG.error(e.getMessage(), e); } finally { graphics.setFont(saveFont); graphics.setColor(saveColor); } return x; }