@Override public int documentToToken(int pos) { return pos + (textOffset-getOffset()); }
@Override public int tokenToDocument(int pos) { return pos + (getOffset()-textOffset); }
/** * Makes this token start at the specified offset into the document.<p> * * <b>Note:</b> You should not modify <code>Token</code> instances you * did not create yourself (e.g., came from an * <code>RSyntaxDocument</code>). If you do, rendering issues and/or * runtime exceptions will likely occur. You have been warned! * * @param pos The offset into the document this token should start at. * Note that this token must already contain this position; if * it doesn't, an exception is thrown. * @throws IllegalArgumentException If pos is not already contained by * this token. * @see #moveOffset(int) */ public void makeStartAt(int pos) { if (pos<getOffset() || pos>=(getOffset()+textCount)) { throw new IllegalArgumentException("pos " + pos + " is not in range " + getOffset() + "-" + (getOffset()+textCount-1)); } int shift = pos - getOffset(); setOffset(pos); textOffset += shift; textCount -= shift; }
/** * Moves the starting offset of this token.<p> * * <b>Note:</b> You should not modify <code>Token</code> instances you * did not create yourself (e.g., came from an * <code>RSyntaxDocument</code>). If you do, rendering issues and/or * runtime exceptions will likely occur. You have been warned! * * @param amt The amount to move the starting offset. This should be * between <code>0</code> and <code>textCount</code>, inclusive. * @throws IllegalArgumentException If <code>amt</code> is an invalid value. * @see #makeStartAt(int) */ public void moveOffset(int amt) { if (amt<0 || amt>textCount) { throw new IllegalArgumentException("amt " + amt + " is not in range 0-" + textCount); } setOffset(getOffset() + amt); textOffset += amt; textCount -= amt; }
@Override public int getOffsetBeforeX(RSyntaxTextArea textArea, TabExpander e, float startX, float endBeforeX) { FontMetrics fm = textArea.getFontMetricsForTokenType(getType()); int i = textOffset; int stop = i + textCount; float x = startX; while (i<stop) { if (text[i]=='\t') { x = e.nextTabStop(x, 0); } else { x += fm.charWidth(text[i]); } if (x>endBeforeX) { // If not even the first character fits into the space, go // ahead and say the first char does fit so we don't go into // an infinite loop. int intoToken = Math.max(i-textOffset, 1); return getOffset() + intoToken; } i++; } // If we got here, the whole token fit in (endBeforeX-startX) pixels. return getOffset() + textCount - 1; }
/** * Returns this token as a <code>String</code>, which is useful for * debugging. * * @return A string describing this token. */ @Override public String toString() { return "[Token: " + (getType()==Token.NULL ? "<null token>" : "text: '" + (text==null ? "<null>" : getLexeme() + "'; " + "offset: " + getOffset() + "; type: " + getType() + "; " + "isPaintable: " + isPaintable() + "; nextToken==null: " + (nextToken==null))) + "]"; }
@Override public int documentToToken(int pos) { return pos + (textOffset-getOffset()); }
@Override public int tokenToDocument(int pos) { return pos + (getOffset()-textOffset); }
/** * Makes this token start at the specified offset into the document.<p> * * <b>Note:</b> You should not modify <code>Token</code> instances you * did not create yourself (e.g., came from an * <code>RSyntaxDocument</code>). If you do, rendering issues and/or * runtime exceptions will likely occur. You have been warned! * * @param pos The offset into the document this token should start at. * Note that this token must already contain this position; if * it doesn't, an exception is thrown. * @throws IllegalArgumentException If pos is not already contained by * this token. * @see #moveOffset(int) */ public void makeStartAt(int pos) { if (pos<getOffset() || pos>=(getOffset()+textCount)) { throw new IllegalArgumentException("pos " + pos + " is not in range " + getOffset() + "-" + (getOffset()+textCount-1)); } int shift = pos - getOffset(); setOffset(pos); textOffset += shift; textCount -= shift; }
/** * Moves the starting offset of this token.<p> * * <b>Note:</b> You should not modify <code>Token</code> instances you * did not create yourself (e.g., came from an * <code>RSyntaxDocument</code>). If you do, rendering issues and/or * runtime exceptions will likely occur. You have been warned! * * @param amt The amount to move the starting offset. This should be * between <code>0</code> and <code>textCount</code>, inclusive. * @throws IllegalArgumentException If <code>amt</code> is an invalid value. * @see #makeStartAt(int) */ public void moveOffset(int amt) { if (amt<0 || amt>textCount) { throw new IllegalArgumentException("amt " + amt + " is not in range 0-" + textCount); } setOffset(getOffset() + amt); textOffset += amt; textCount -= amt; }
tempToken.textCount = selStart - tempToken.getOffset(); x = painter.paint(tempToken,g,x,y,host, this); tempToken.textCount = token.length(); tempToken.textCount = selEnd - tempToken.getOffset(); x = painter.paintSelected(tempToken, g, x,y, host, this, useSTC); tempToken.textCount = selStart - tempToken.getOffset(); x = painter.paint(tempToken,g,x,y,host, this); tempToken.textCount = token.length(); tempToken.textCount = selEnd - tempToken.getOffset(); x = painter.paintSelected(tempToken, g, x,y, host, this, useSTC);
@Override public int getOffsetBeforeX(RSyntaxTextArea textArea, TabExpander e, float startX, float endBeforeX) { FontMetrics fm = textArea.getFontMetricsForTokenType(getType()); int i = textOffset; int stop = i + textCount; float x = startX; while (i<stop) { if (text[i]=='\t') { x = e.nextTabStop(x, 0); } else { x += fm.charWidth(text[i]); } if (x>endBeforeX) { // If not even the first character fits into the space, go // ahead and say the first char does fit so we don't go into // an infinite loop. int intoToken = Math.max(i-textOffset, 1); return getOffset() + intoToken; } i++; } // If we got here, the whole token fit in (endBeforeX-startX) pixels. return getOffset() + textCount - 1; }
/** * Returns this token as a <code>String</code>, which is useful for * debugging. * * @return A string describing this token. */ @Override public String toString() { return "[Token: " + (getType()==Token.NULL ? "<null token>" : "text: '" + (text==null ? "<null>" : getLexeme() + "'; " + "offset: " + getOffset() + "; type: " + getType() + "; " + "isPaintable: " + isPaintable() + "; nextToken==null: " + (nextToken==null))) + "]"; }