本文整理汇总了Java中javax.swing.text.TabExpander.nextTabStop方法的典型用法代码示例。如果您正苦于以下问题:Java TabExpander.nextTabStop方法的具体用法?Java TabExpander.nextTabStop怎么用?Java TabExpander.nextTabStop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.TabExpander
的用法示例。
在下文中一共展示了TabExpander.nextTabStop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTabbedSpan
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
@Override
public float getTabbedSpan(float x, TabExpander e) {
int offset = getStartOffset();
int endOffset = offset + getLength();
float tabX = e.nextTabStop(x, offset++);
firstTabWidth = tabX - x;
while (offset < endOffset) {
tabX = e.nextTabStop(tabX, offset++);
}
width = tabX - x;
return width;
}
示例2: getOffsetBeforeX
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
@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;
}
示例3: getWidthUpTo
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
@Override
public float getWidthUpTo(int numChars, RSyntaxTextArea textArea,
TabExpander e, float x0) {
float width = x0;
FontMetrics fm = textArea.getFontMetricsForTokenType(getType());
if (fm != null) {
int w;
int currentStart = textOffset;
int endBefore = textOffset + numChars;
for (int i = currentStart; i < endBefore; i++) {
if (text[i] == '\t') {
// Since TokenMaker implementations usually group all
// adjacent whitespace into a single token, there
// aren't usually any characters to compute a width
// for here, so we check before calling.
w = i - currentStart;
if (w > 0) {
width += fm.charsWidth(text, currentStart, w);
}
currentStart = i + 1;
width = e.nextTabStop(width, 0);
}
}
// Most (non-whitespace) tokens will have characters at this
// point to get the widths for, so we don't check for w>0 (mini-
// optimization).
w = endBefore - currentStart;
width += fm.charsWidth(text, currentStart, w);
}
return width - x0;
}
示例4: getOffsetBeforeX
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
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;
}
示例5: getWidthUpTo
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
public float getWidthUpTo(int numChars, RSyntaxTextArea textArea,
TabExpander e, float x0) {
float width = x0;
FontMetrics fm = textArea.getFontMetricsForTokenType(getType());
if (fm != null) {
int w;
int currentStart = textOffset;
int endBefore = textOffset + numChars;
for (int i = currentStart; i < endBefore; i++) {
if (text[i] == '\t') {
// Since TokenMaker implementations usually group all
// adjacent whitespace into a single token, there
// aren't usually any characters to compute a width
// for here, so we check before calling.
w = i - currentStart;
if (w > 0)
width += fm.charsWidth(text, currentStart, w);
currentStart = i + 1;
width = e.nextTabStop(width, 0);
}
}
// Most (non-whitespace) tokens will have characters at this
// point to get the widths for, so we don't check for w>0 (mini-
// optimization).
w = endBefore - currentStart;
width += fm.charsWidth(text, currentStart, w);
}
return width - x0;
}
示例6: getWidthUpTo
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* Returns the width of a specified number of characters in this token. For example, for the token "while",
* specifying a value of <code>3</code> here returns the width of the "whi" portion of the token.
* <p>
*
* @param numChars
* The number of characters for which to get the width.
* @param textArea
* The text area in which this token is being painted.
* @param e
* How to expand tabs. This value cannot be <code>null</code>.
* @param x0
* The pixel-location at which this token begins. This is needed because of tabs.
* @return The width of the specified number of characters in this token.
* @see #getWidth
*/
public float getWidthUpTo(int numChars, RSyntaxTextArea textArea,
TabExpander e, float x0) {
float width = x0;
FontMetrics fm = textArea.getFontMetricsForTokenType(type);
if (fm != null) {
int w;
int currentStart = textOffset;
int endBefore = textOffset + numChars;
for (int i = currentStart; i < endBefore; i++) {
if (text[i] == '\t') {
// Since TokenMaker implementations usually group all
// adjacent whitespace into a single token, there
// aren't usually any characters to compute a width
// for here, so we check before calling.
w = i - currentStart;
if (w > 0)
width += fm.charsWidth(text, currentStart, w);
currentStart = i + 1;
width = e.nextTabStop(width, 0);
}
}
// Most (non-whitespace) tokens will have characters at this
// point to get the widths for, so we don't check for w>0 (mini-
// optimization).
w = endBefore - currentStart;
width += fm.charsWidth(text, currentStart, w);
}
return width - x0;
}
示例7: getOffsetBeforeX
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* Returns the position in the document that represents the last character in the token that will fit into
* <code>endBeforeX-startX</code> pixels. For example, if you're using a monospaced 8-pixel-per-character font, have
* the token "while" and <code>startX</code> is <code>0</code> and <code>endBeforeX</code> is <code>30</code>, this
* method will return the document position of the "i" in "while", because the "i" ends at pixel <code>24</code>,
* while the "l" ends at <code>32</code>. If not even the first character fits in <code>endBeforeX-startX</code>,
* the first character's position is still returned so calling methods don't go into infinite loops.
*
* @param textArea
* The text area in which this token is being painted.
* @param e
* How to expand tabs.
* @param startX
* The x-coordinate at which the token will be painted. This is needed because of tabs.
* @param endBeforeX
* The x-coordinate for which you want to find the last character of <code>t</code> which comes before
* it.
* @return The last document position that will fit in the specified amount of pixels.
*/
/*
* @see #getTokenListOffsetBeforeX FIXME: This method does not compute correctly! It needs to be abstract and
* implemented by subclasses.
*/
public int getOffsetBeforeX(RSyntaxTextArea textArea, TabExpander e,
float startX, float endBeforeX) {
FontMetrics fm = textArea.getFontMetricsForTokenType(type);
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 offset + intoToken;
}
i++;
}
// If we got here, the whole token fit in (endBeforeX-startX) pixels.
return offset + textCount - 1;
}
示例8: getTabbedTextOffset
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* If round equals false it needs that symbol is placed completely. If
* round equals true it needs that more than half of the symbol is placed.
*/
public static final int getTabbedTextOffset(final Segment s,
final FontMetrics fm,
final int start,
final int end,
final TabExpander t,
final int pos,
final boolean round) {
String str = ""; //$NON-NLS-1$
int segmentOffset = pos - s.getBeginIndex();
boolean isTab = false;
boolean isNullTabExpander = (t == null);
int currentEnd = start < 0 ? 0 : start;
int x1 = start < 0 ? start : 0;
int currentIndex = 0;
int prevEnd = currentEnd;
int tabEnd = currentEnd;
for (char c = s.first(); c != CharacterIterator.DONE; c = s.next()) {
isTab = (c == '\t');
if (isTab && !isNullTabExpander) {
tabEnd = (int)t.nextTabStop(currentEnd, s.getIndex()
+ segmentOffset);
str = ""; //$NON-NLS-1$
} else {
str += (isTab) ? ' ' : c;
isTab = false;
}
int tmpEnd = tabEnd + x1;
currentEnd = isTab ? tmpEnd: tmpEnd + fm.stringWidth(str);
int delta = (round) ? (currentEnd - prevEnd) / 2 : 0;
if (currentEnd > end + delta) {
break;
}
currentIndex++;
prevEnd = currentEnd;
}
return currentIndex;
}
示例9: getTabbedTextEnd
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
private static int getTabbedTextEnd(final Segment s, final FontMetrics fm,
final int x, final TabExpander t,
final int pos, final boolean needDraw,
final Graphics g, final int y) {
int x1 = x < 0 ? x : 0;
int res = x < 0 ? 0 : x;
String buffer = s.toString();
int tabIndex = buffer.indexOf("\t"); //$NON-NLS-1$
int currentIndex = pos - s.getBeginIndex() + s.offset;
if (t == null) {
String buf = buffer.replaceAll("\t", " "); //$NON-NLS-1$ //$NON-NLS-2$
drawString(buf, needDraw, g, x, y);
return fm.stringWidth(buf) + x;
}
String substr = null;
int lastTabIndex = -1;
while (tabIndex >= 0) {
substr = buffer.substring(lastTabIndex + 1, tabIndex);
drawString(substr, needDraw, g, res + x1, y);
res = (int)t.nextTabStop(res + fm.stringWidth(substr),
tabIndex + currentIndex);
lastTabIndex = tabIndex;
tabIndex = buffer.indexOf("\t", tabIndex + 1); //$NON-NLS-1$
}
int tmp = res + x1;
substr = buffer.substring(lastTabIndex + 1, buffer.length());
drawString(substr, needDraw, g, tmp, y);
return (tabIndex >= 0) ? tmp : tmp + fm.stringWidth(substr);
}
示例10: getOffsetBeforeX
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* Returns the position in the document that represents the last character
* in the token that will fit into <code>endBeforeX-startX</code> pixels.
* For example, if you're using a monospaced 8-pixel-per-character font,
* have the token "while" and <code>startX</code> is <code>0</code> and
* <code>endBeforeX</code> is <code>30</code>, this method will return the
* document position of the "i" in "while", because the "i" ends at pixel
* <code>24</code>, while the "l" ends at <code>32</code>. If not even the
* first character fits in <code>endBeforeX-startX</code>, the first
* character's position is still returned so calling methods don't go into
* infinite loops.
*
* @param textArea The text area in which this token is being painted.
* @param e How to expand tabs.
* @param startX The x-coordinate at which the token will be painted. This
* is needed because of tabs.
* @param endBeforeX The x-coordinate for which you want to find the last
* character of <code>t</code> which comes before it.
* @return The last document position that will fit in the specified amount
* of pixels.
*/
/*
* @see #getTokenListOffsetBeforeX
* FIXME: This method does not compute correctly! It needs to be abstract
* and implemented by subclasses.
*/
public int getOffsetBeforeX(RSyntaxTextArea textArea, TabExpander e,
float startX, float endBeforeX) {
FontMetrics fm = textArea.getFontMetricsForTokenType(type);
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 offset + intoToken;
}
i++;
}
// If we got here, the whole token fit in (endBeforeX-startX) pixels.
return offset + textCount - 1;
}
示例11: getWidthUpTo
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* Returns the width of a specified number of characters in this token.
* For example, for the token "while", specifying a value of <code>3</code>
* here returns the width of the "whi" portion of the token.
*
* @param numChars The number of characters for which to get the width.
* @param textArea The text area in which the token is being painted.
* @param e How to expand tabs. This value cannot be <code>null</code>.
* @param x0 The pixel-location at which this token begins. This is needed
* because of tabs.
* @return The width of the specified number of characters in this token.
* @see #getWidth
*/
public float getWidthUpTo(int numChars, RSyntaxTextArea textArea,
TabExpander e, float x0) {
float width = x0;
FontMetrics fm = textArea.getFontMetricsForTokenType(type);
if (fm != null) {
int w;
int currentStart = textOffset;
int endBefore = textOffset + numChars;
for (int i = currentStart; i < endBefore; i++) {
if (text[i] == '\t') {
// Since TokenMaker implementations usually group all
// adjacent whitespace into a single token, there
// aren't usually any characters to compute a width
// for here, so we check before calling.
w = i - currentStart;
if (w > 0)
width += fm.charsWidth(text, currentStart, w);
currentStart = i + 1;
width = e.nextTabStop(width, 0);
}
}
// Most (non-whitespace) tokens will have characters at this
// point to get the widths for, so we don't check for w>0 (mini-
// optimization).
w = endBefore - currentStart;
width += fm.charsWidth(text, currentStart, w);
}
return width - x0;
}
示例12: getListOffset
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
@Override
public int getListOffset(RSyntaxTextArea textArea, TabExpander e,
float x0, float x) {
// If the coordinate in question is before this line's start, quit.
if (x0 >= x) {
return getOffset();
}
float currX = x0; // x-coordinate of current char.
float nextX = x0; // x-coordinate of next char.
float stableX = x0; // Cached ending x-coord. of last tab or token.
TokenImpl token = this;
int last = getOffset();
FontMetrics fm = null;
while (token != null && token.isPaintable()) {
fm = textArea.getFontMetricsForTokenType(token.getType());
char[] text = token.text;
int start = token.textOffset;
int end = start + token.textCount;
for (int i = start; i < end; i++) {
currX = nextX;
if (text[i] == '\t') {
nextX = e.nextTabStop(nextX, 0);
stableX = nextX; // Cache ending x-coord. of tab.
start = i + 1; // Do charsWidth() from next char.
}
else {
nextX = stableX + fm.charsWidth(text, start, i - start + 1);
}
if (x >= currX && x < nextX) {
if ((x - currX) < (nextX - x)) {
return last + i - token.textOffset;
}
return last + i + 1 - token.textOffset;
}
}
stableX = nextX; // Cache ending x-coordinate of token.
last += token.textCount;
token = (TokenImpl)token.getNextToken();
}
// If we didn't find anything, return the end position of the text.
return last;
}
示例13: paintImpl
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* Does the dirty-work of actually painting the token.
*/
protected float paintImpl(Token token, Graphics2D g, float x, float y,
RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
int origX = (int)x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
int end = textOffs + token.length();
float nextX = x;
int flushLen = 0;
int flushIndex = textOffs;
Color fg = useSTC ? host.getSelectedTextColor() :
host.getForegroundForToken(token);
Color bg = selected ? null : host.getBackgroundForToken(token);
g.setFont(host.getFontForTokenType(token.getType()));
FontMetrics fm = host.getFontMetricsForTokenType(token.getType());
for (int i=textOffs; i<end; i++) {
switch (text[i]) {
case '\t':
nextX = e.nextTabStop(
x + fm.charsWidth(text, flushIndex,flushLen), 0);
if (bg!=null) {
paintBackground(x,y, nextX-x,fm.getHeight(),
g, fm.getAscent(), host, bg);
}
if (flushLen > 0) {
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int)x,(int)y);
flushLen = 0;
}
flushIndex = i + 1;
x = nextX;
break;
default:
flushLen += 1;
break;
}
}
nextX = x+fm.charsWidth(text, flushIndex,flushLen);
java.awt.Rectangle r = host.getMatchRectangle();
if (flushLen>0 && nextX>=clipStart) {
if (bg!=null) {
paintBackground(x,y, nextX-x,fm.getHeight(),
g, fm.getAscent(), host, bg);
if (token.length()==1 && r!=null && r.x==x) {
((RSyntaxTextAreaUI)host.getUI()).paintMatchedBracketImpl(
g, host, r);
}
}
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int)x,(int)y);
}
if (host.getUnderlineForToken(token)) {
g.setColor(fg);
int y2 = (int)(y+1);
g.drawLine(origX,y2, (int)nextX,y2);
}
// Don't check if it's whitespace - some TokenMakers may return types
// other than Token.WHITESPACE for spaces (such as Token.IDENTIFIER).
// This also allows us to paint tab lines for MLC's.
if (host.getPaintTabLines() && origX==host.getMargin().left) {// && isWhitespace()) {
paintTabLines(token, origX, (int)y, (int)nextX, g, e, host);
}
return nextX;
}
示例14: getListOffset
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
public int getListOffset(RSyntaxTextArea textArea, TabExpander e,
float x0, float x) {
// If the coordinate in question is before this line's start, quit.
if (x0 >= x)
return getOffset();
float currX = x0; // x-coordinate of current char.
float nextX = x0; // x-coordinate of next char.
float stableX = x0; // Cached ending x-coord. of last tab or token.
TokenImpl token = this;
int last = getOffset();
FontMetrics fm = null;
while (token != null && token.isPaintable()) {
fm = textArea.getFontMetricsForTokenType(token.getType());
char[] text = token.text;
int start = token.textOffset;
int end = start + token.textCount;
for (int i = start; i < end; i++) {
currX = nextX;
if (text[i] == '\t') {
nextX = e.nextTabStop(nextX, 0);
stableX = nextX; // Cache ending x-coord. of tab.
start = i + 1; // Do charsWidth() from next char.
}
else {
nextX = stableX + fm.charsWidth(text, start, i - start + 1);
}
if (x >= currX && x < nextX) {
if ((x - currX) < (nextX - x)) {
return last + i - token.textOffset;
}
return last + i + 1 - token.textOffset;
}
}
stableX = nextX; // Cache ending x-coordinate of token.
last += token.textCount;
token = (TokenImpl)token.getNextToken();
}
// If we didn't find anything, return the end position of the text.
return last;
}
示例15: paintImpl
import javax.swing.text.TabExpander; //导入方法依赖的package包/类
/**
* Does the dirty-work of actually painting the token.
*/
protected float paintImpl(Token token, Graphics2D g, float x, float y,
RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
int origX = (int)x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
int end = textOffs + token.length();
float nextX = x;
int flushLen = 0;
int flushIndex = textOffs;
Color fg = useSTC ? host.getSelectedTextColor() :
host.getForegroundForToken(token);
Color bg = selected ? null : host.getBackgroundForToken(token);
g.setFont(host.getFontForTokenType(token.getType()));
FontMetrics fm = host.getFontMetricsForTokenType(token.getType());
for (int i=textOffs; i<end; i++) {
switch (text[i]) {
case '\t':
nextX = e.nextTabStop(
x+fm.charsWidth(text, flushIndex,flushLen), 0);
if (bg!=null) {
paintBackground(x,y, nextX-x,fm.getHeight(),
g, fm.getAscent(), host, bg);
}
if (flushLen > 0) {
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int)x,(int)y);
flushLen = 0;
}
flushIndex = i + 1;
x = nextX;
break;
default:
flushLen += 1;
break;
}
}
nextX = x+fm.charsWidth(text, flushIndex,flushLen);
java.awt.Rectangle r = host.getMatchRectangle();
if (flushLen>0 && nextX>=clipStart) {
if (bg!=null) {
paintBackground(x,y, nextX-x,fm.getHeight(),
g, fm.getAscent(), host, bg);
}
if (token.length()==1 && r!=null && r.x==x) {
((RSyntaxTextAreaUI)host.getUI()).paintMatchedBracketImpl(g, host, r);
}
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int)x,(int)y);
}
if (host.getUnderlineForToken(token)) {
g.setColor(fg);
int y2 = (int)(y+1);
g.drawLine(origX,y2, (int)nextX,y2);
}
// Don't check if it's whitespace - some TokenMakers may return types
// other than Token.WHITESPACE for spaces (such as Token.IDENTIFIER).
// This also allows us to paint tab lines for MLC's.
if (host.getPaintTabLines() && origX==host.getMargin().left) {// && isWhitespace()) {
paintTabLines(token, origX, (int)y, (int)nextX, g, e, host);
}
return nextX;
}