本文整理汇总了Java中javax.swing.text.Segment.setIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Segment.setIndex方法的具体用法?Java Segment.setIndex怎么用?Java Segment.setIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Segment
的用法示例。
在下文中一共展示了Segment.setIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextWordStart
import javax.swing.text.Segment; //导入方法依赖的package包/类
/** This helper method will return the start character of the next
* word in the buffer from the start position
*/
private static int getNextWordStart(Segment text, int startPos) {
if (startPos <= text.getEndIndex())
for (char ch = text.setIndex(startPos); ch != Segment.DONE; ch = text.next()) {
if (Character.isLetterOrDigit(ch)) {
return text.getIndex();
}
}
return -1;
}
示例2: getNextWordEnd
import javax.swing.text.Segment; //导入方法依赖的package包/类
/** This helper method will return the end of the next word in the buffer.
*
*/
private static int getNextWordEnd(Segment text, int startPos) {
for (char ch = text.setIndex(startPos); ch != Segment.DONE; ch = text.next()) {
if (!Character.isLetterOrDigit(ch)) {
if (ch == '-' || ch == '\'') { // handle ' and - inside words
char ch2 = text.next();
text.previous();
if (ch2 != Segment.DONE && Character.isLetterOrDigit(ch2))
continue;
}
return text.getIndex();
}
}
return text.getEndIndex();
}
示例3: removeEndingWhitespace
import javax.swing.text.Segment; //导入方法依赖的package包/类
/**
* Removes any spaces or tabs from the end of the segment.
*
* @param segment The segment from which to remove tailing whitespace.
* @return <code>segment</code> with trailing whitespace removed.
*/
private static Segment removeEndingWhitespace(Segment segment) {
int toTrim = 0;
char currentChar = segment.setIndex(segment.getEndIndex()-1);
while ((currentChar==' ' || currentChar=='\t') && currentChar!=Segment.DONE) {
toTrim++;
currentChar = segment.previous();
}
String stringVal = segment.toString();
String newStringVal = stringVal.substring(0,stringVal.length()-toTrim);
return new Segment(newStringVal.toCharArray(), 0, newStringVal.length());
}
示例4: getNextWordStart
import javax.swing.text.Segment; //导入方法依赖的package包/类
/**
* This helper method will return the start character of the next
* word in the buffer from the start position
*
* @param text Description of the Parameter
* @param startPos Description of the Parameter
* @return The nextWordStart value
*/
private static int getNextWordStart(Segment text, int startPos) {
if (startPos <= text.getEndIndex())
for (char ch = text.setIndex(startPos); ch != Segment.DONE; ch = text.next()) {
// changed by Saruta
if (Character.isLetterOrDigit(ch) || ch == '-' || ch == '\'' || ch == '~') {
return text.getIndex();
}
}
return -1;
}
示例5: getNextWordEnd
import javax.swing.text.Segment; //导入方法依赖的package包/类
/**
* This helper method will return the end of the next word in the buffer.
*
* @param text Description of the Parameter
* @param startPos Description of the Parameter
* @return The nextWordEnd value
*/
private static int getNextWordEnd(Segment text, int startPos) {
for (char ch = text.setIndex(startPos); ch != Segment.DONE; ch = text.next()) {
if (!Character.isLetterOrDigit(ch)) {
// changed by Saruta
if (ch == '-' || ch == '\'' || ch == '~') {
// handle ' and - inside words
continue;
}
return text.getIndex();
}
}
return text.getEndIndex();
}