本文整理汇总了Java中javax.swing.text.Segment.DONE属性的典型用法代码示例。如果您正苦于以下问题:Java Segment.DONE属性的具体用法?Java Segment.DONE怎么用?Java Segment.DONE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.swing.text.Segment
的用法示例。
在下文中一共展示了Segment.DONE属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: posStartFullWordFrom
/**
* Sets the current word position at the start of the word containing
* the char at position pos. This way a call to nextWord() will return
* this word.
*
* @param pos position in the word we want to set as current.
*/
public void posStartFullWordFrom(int pos){
currentWordPos=text.getBeginIndex();
if(pos>text.getEndIndex())
pos=text.getEndIndex();
for (char ch = text.setIndex(pos); ch != Segment.DONE; ch = text.previous()) {
if (!Character.isLetterOrDigit(ch)) {
if (ch == '-' || ch == '\'') { // handle ' and - inside words
char ch2 = text.previous();
text.next();
if (ch2 != Segment.DONE && Character.isLetterOrDigit(ch2))
continue;
}
currentWordPos=text.getIndex()+1;
break;
}
}
//System.out.println("CurPos:"+currentWordPos);
if(currentWordPos==0)
first=true;
moreTokens=true;
currentWordEnd = getNextWordEnd(text, currentWordPos);
nextWordPos = getNextWordStart(text, currentWordEnd + 1);
}
示例2: getNextWordStart
/** 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;
}
示例3: getNextWordEnd
/** 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();
}
示例4: removeEndingWhitespace
/**
* 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());
}
示例5: getNextWordStart
/**
* 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;
}
示例6: getNextWordEnd
/**
* 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();
}
示例7: posStartFullWordFrom
/**
* Sets the current word position at the start of the word containing
* the char at position pos. This way a call to nextWord() will return
* this word.
*
* @param pos position in the word we want to set as current.
*/
public void posStartFullWordFrom(int pos) {
currentWordPos = text.getBeginIndex();
if (pos > text.getEndIndex())
pos = text.getEndIndex();
for (char ch = text.setIndex(pos); ch != Segment.DONE; ch = text.previous()) {
if (!Character.isLetterOrDigit(ch)) {
// changed by Saruta (trial and error)
if (ch == '-' || ch == '\'' || ch == '~') {
continue;
}
if (ch == '-' || ch == '\'') {
// handle ' and - inside words
char ch2 = text.previous();
text.next();
if (ch2 != Segment.DONE && Character.isLetterOrDigit(ch2))
continue;
}
currentWordPos = text.getIndex() + 1;
break;
}
}
//System.out.println("CurPos:"+currentWordPos);
if (currentWordPos == 0)
first = true;
moreTokens = true;
currentWordEnd = getNextWordEnd(text, currentWordPos);
nextWordPos = getNextWordStart(text, currentWordEnd + 1);
}
示例8: getWordStart
@Override
protected int getWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs==start) {
return start;
}
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--;
}
doc.getText(start, end-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs-start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
char nextCh = offs==end ? 0 : seg.array[seg.getIndex() + 1];
// The "word" is a group of letters and/or digits
int languageIndex = 0; // TODO
if (doc.isIdentifierChar(languageIndex, ch)) {
if (offs!=end && !doc.isIdentifierChar(languageIndex, nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// The "word" is whitespace
else if (Character.isWhitespace(ch)) {
if (offs!=end && !Character.isWhitespace(nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" a single "something else" char (operator,
// etc.).
offs -= firstIndex - seg.getIndex() + 1;//seg.getEndIndex() - seg.getIndex();
if (ch!=Segment.DONE && nextCh!='\n') {
offs++;
}
return offs;
}
示例9: getPreviousWordStart
@Override
protected int getPreviousWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs==start) {
return start-1; // Just delete the newline
}
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--;
}
doc.getText(start, end-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs-start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
// Always strip off whitespace first
if (Character.isWhitespace(ch)) {
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// The "word" is a group of letters and/or digits
int languageIndex = 0; // TODO
if (doc.isIdentifierChar(languageIndex, ch)) {
do {
ch = seg.previous();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// The "word" is a series of symbols.
else {
while (!Character.isWhitespace(ch) &&
!doc.isIdentifierChar(languageIndex, ch) &&
ch!=Segment.DONE) {
ch = seg.previous();
}
}
if (ch==Segment.DONE) {
return start; // Removed last "token" of the line
}
offs -= firstIndex - seg.getIndex();
return offs;
}
示例10: getNextWord
/**
* Overridden to do better with skipping "words" in code.
*/
@Override
protected int getNextWord(RTextArea textArea, int offs)
throws BadLocationException {
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
if (offs==doc.getLength()) {
return offs;
}
Element root = doc.getDefaultRootElement();
int line = root.getElementIndex(offs);
int end = root.getElement(line).getEndOffset() - 1;
if (offs==end) {// If we're already at the end of the line...
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
if (rsta.isCodeFoldingEnabled()) { // Start of next visible line
FoldManager fm = rsta.getFoldManager();
int lineCount = root.getElementCount();
while (++line<lineCount && fm.isLineHidden(line));
if (line<lineCount) { // Found a lower visible line
offs = root.getElement(line).getStartOffset();
}
// No lower visible line - we're already at last visible offset
return offs;
}
else {
return offs+1; // Start of next line.
}
}
doc.getText(offs, end-offs, seg);
// Determine the "type" of char at offs - letter/digit,
// whitespace or other
char ch = seg.first();
// Skip the group of letters and/or digits
int languageIndex = 0;
if (doc.isIdentifierChar(languageIndex, ch)) {
do {
ch = seg.next();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// Skip groups of "anything else" (operators, etc.).
else if (!Character.isWhitespace(ch)) {
do {
ch = seg.next();
} while (ch!=Segment.DONE &&
!(doc.isIdentifierChar(languageIndex, ch) ||
Character.isWhitespace(ch)));
}
// Skip any trailing whitespace
while (Character.isWhitespace(ch)) {
ch = seg.next();
}
offs += seg.getIndex() - seg.getBeginIndex();
return offs;
}
示例11: getPreviousWord
/**
* Overridden to do better with skipping "words" in code.
*/
@Override
protected int getPreviousWord(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
Element root = doc.getDefaultRootElement();
int line = root.getElementIndex(offs);
int start = root.getElement(line).getStartOffset();
if (offs==start) {// If we're already at the start of the line...
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
if (rsta.isCodeFoldingEnabled()) { // End of next visible line
FoldManager fm = rsta.getFoldManager();
while (--line>=0 && fm.isLineHidden(line));
if (line>=0) { // Found an earlier visible line
offs = root.getElement(line).getEndOffset() - 1;
}
// No earlier visible line - we must be at offs==0...
return offs;
}
else {
return start-1; // End of previous line.
}
}
doc.getText(start, offs-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other
char ch = seg.last();
// Skip any "leading" whitespace
while (Character.isWhitespace(ch)) {
ch = seg.previous();
}
// Skip the group of letters and/or digits
int languageIndex = 0;
if (doc.isIdentifierChar(languageIndex, ch)) {
do {
ch = seg.previous();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// Skip groups of "anything else" (operators, etc.).
else if (!Character.isWhitespace(ch)) {
do {
ch = seg.previous();
} while (ch!=Segment.DONE &&
!(doc.isIdentifierChar(languageIndex, ch) ||
Character.isWhitespace(ch)));
}
offs -= seg.getEndIndex() - seg.getIndex();
if (ch!=Segment.DONE) {
offs++;
}
return offs;
}