本文整理汇总了Java中javax.swing.text.Segment类的典型用法代码示例。如果您正苦于以下问题:Java Segment类的具体用法?Java Segment怎么用?Java Segment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Segment类属于javax.swing.text包,在下文中一共展示了Segment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initSyntax
import javax.swing.text.Segment; //导入依赖的package包/类
/** Initialize the syntax so it's ready to scan the given area.
* @param syntax lexical analyzer to prepare
* @param startPos starting position of the scanning
* @param endPos ending position of the scanning
* @param forceLastBuffer force the syntax to think that the scanned area is the last
* in the document. This is useful for forcing the syntax to process all the characters
* in the given area.
* @param forceNotLastBuffer force the syntax to think that the scanned area is NOT
* the last buffer in the document. This is useful when the syntax will continue
* scanning on another buffer.
*/
public void initSyntax(Syntax syntax, int startPos, int endPos,
boolean forceLastBuffer, boolean forceNotLastBuffer)
throws BadLocationException {
doc.readLock();
try {
Segment text = new Segment();
int docLen = doc.getLength();
doc.prepareSyntax(text, syntax, startPos, 0, forceLastBuffer, forceNotLastBuffer);
int preScan = syntax.getPreScan();
char[] buffer = doc.getChars(startPos - preScan, endPos - startPos + preScan);
boolean lastBuffer = forceNotLastBuffer ? false
: (forceLastBuffer || (endPos == docLen));
syntax.relocate(buffer, preScan, endPos - startPos, lastBuffer, endPos);
} finally {
doc.readUnlock();
}
}
示例2: getChars
import javax.swing.text.Segment; //导入依赖的package包/类
public void getChars(int offset, int length, Segment chars)
throws BadLocationException {
checkBounds(offset, length, length());
if ((offset + length) <= gapStart) { // completely below gap
chars.array = charArray;
chars.offset = offset;
} else if (offset >= gapStart) { // completely above gap
chars.array = charArray;
chars.offset = offset + gapLength;
} else { // spans the gap, must copy
chars.array = copySpanChars(offset, length);
chars.offset = 0;
}
chars.count = length;
}
示例3: getText
import javax.swing.text.Segment; //导入依赖的package包/类
@Override
public void getText(int offset, int length, Segment txt) throws BadLocationException {
if (lastOffset == offset && lastLength == length) {
txt.array = segArray;
txt.offset = segOffset;
txt.count = segCount;
txt.setPartialReturn(segPartialReturn);
return;
}
super.getText(offset, length, txt);
if (length > CACHE_BOUNDARY || lastLength <= CACHE_BOUNDARY) {
segArray = txt.array;
segOffset = txt.offset;
segCount = txt.count;
segPartialReturn = txt.isPartialReturn();
lastOffset = offset;
lastLength = length;
}
}
示例4: DocumentWordTokenizer
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Creates a new DocumentWordTokenizer to work on a document
*
* @param document The document to spell check
*/
public DocumentWordTokenizer(Document document) {
this.document = document;
//Create a text segment over the entire document
text = new Segment();
sentenceIterator = BreakIterator.getSentenceInstance();
try {
document.getText(0, document.getLength(), text);
sentenceIterator.setText(text);
currentWordPos = getNextWordStart(text, 0);
//If the current word pos is -1 then the string was all white space
if (currentWordPos != -1) {
currentWordEnd = getNextWordEnd(text, currentWordPos);
nextWordPos = getNextWordStart(text, currentWordEnd);
}
else {
moreTokens = false;
}
}
catch (BadLocationException ex) {
moreTokens = false;
}
}
示例5: regionMatches
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Checks if a subregion of a <code>Segment</code> is equal to a string.
*
* @param ignoreCase
* True if case should be ignored, false otherwise
* @param text
* The segment
* @param offset
* The offset into the segment
* @param match
* The string to match
*/
public static boolean regionMatches(boolean ignoreCase, Segment text, int offset, String match) {
int length = offset + match.length();
char[] textArray = text.array;
if (length > text.offset + text.count) {
return false;
}
for (int i = offset, j = 0; i < length; i++, j++) {
char c1 = textArray[i];
char c2 = match.charAt(j);
if (ignoreCase) {
c1 = Character.toUpperCase(c1);
c2 = Character.toUpperCase(c2);
}
if (c1 != c2) {
return false;
}
}
return true;
}
示例6: markTokensImpl
import javax.swing.text.Segment; //导入依赖的package包/类
@Override
public byte markTokensImpl(byte token, Segment line, int lineIndex) {
if (line.count == 0) {
return Token.NULL;
}
switch (line.array[line.offset]) {
case '+':
case '>':
addToken(line.count, Token.KEYWORD1);
break;
case '-':
case '<':
addToken(line.count, Token.KEYWORD2);
break;
case '@':
case '*':
addToken(line.count, Token.KEYWORD3);
break;
default:
addToken(line.count, Token.NULL);
break;
}
return Token.NULL;
}
示例7: returnPressed
import javax.swing.text.Segment; //导入依赖的package包/类
synchronized void returnPressed() {
Document doc = getDocument();
int len = doc.getLength();
Segment segment = new Segment();
try {
doc.getText(outputMark, len - outputMark, segment);
} catch(javax.swing.text.BadLocationException ignored) {
ignored.printStackTrace();
}
if(segment.count > 0) {
history.add(segment.toString());
}
historyIndex = history.size();
inPipe.write(segment.array, segment.offset, segment.count);
append("\n");
outputMark = doc.getLength();
inPipe.write("\n");
inPipe.flush();
console1.flush();
}
示例8: DocumentWordTokenizer
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Creates a new DocumentWordTokenizer to work on a document
* @param document The document to spell check
*/
public DocumentWordTokenizer(Document document) {
this.document = document;
//Create a text segment over the entire document
text = new Segment();
sentenceIterator = BreakIterator.getSentenceInstance();
try {
document.getText(0, document.getLength(), text);
sentenceIterator.setText(text);
// robert: use text.getBeginIndex(), not 0, for segment's first offset
currentWordPos = getNextWordStart(text, text.getBeginIndex());
//If the current word pos is -1 then the string was all white space
if (currentWordPos != -1) {
currentWordEnd = getNextWordEnd(text, currentWordPos);
nextWordPos = getNextWordStart(text, currentWordEnd);
} else {
moreTokens = false;
}
} catch (BadLocationException ex) {
moreTokens = false;
}
}
示例9: posStartFullWordFrom
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* 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);
}
示例10: testNPE
import javax.swing.text.Segment; //导入依赖的package包/类
private static void testNPE() {
Graphics g = null;
try {
String test = "\ttest\ttest2";
BufferedImage buffImage = new BufferedImage(
100, 100, BufferedImage.TYPE_INT_RGB);
g = buffImage.createGraphics();
Segment segment = new Segment(test.toCharArray(), 0, test.length());
Utilities.drawTabbedText(segment, 0, 0, g, null, 0);
} finally {
if (g != null) {
g.dispose();
}
}
}
示例11: getTokenList
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
*
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
resetTokenList();
this.offsetShift = -text.offset + startOffset;
// Start off in the proper state.
int state = YYINITIAL;
start = text.offset;
s = text;
try {
yyreset(zzReader);
yybegin(state);
return yylex();
} catch (IOException ioe) {
ioe.printStackTrace();
return new TokenImpl();
}
}
示例12: getTokenList
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
*
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
resetTokenList();
this.offsetShift = -text.offset + startOffset;
// Start off in the proper state.
int state = TokenTypes.NULL;
s = text;
try {
yyreset(zzReader);
yybegin(state);
return yylex();
} catch (IOException ioe) {
ioe.printStackTrace();
return new TokenImpl();
}
}
示例13: getTokenList
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
*
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
resetTokenList();
this.offsetShift = -text.offset + startOffset;
// Start off in the proper state.
int state = Token.NULL;
switch (initialTokenType) {
default:
state = Token.NULL;
}
s = text;
try {
yyreset(zzReader);
yybegin(state);
return yylex();
} catch (IOException ioe) {
ioe.printStackTrace();
return new TokenImpl();
}
}
示例14: readObject
import javax.swing.text.Segment; //导入依赖的package包/类
/**
* Deserializes a document.
*
* @param in The stream to read from.
* @throws ClassNotFoundException
* @throws IOException
*/
private void readObject(ObjectInputStream in)
throws ClassNotFoundException, IOException {
in.defaultReadObject();
// Install default TokenMakerFactory. To support custom TokenMakers,
// both JVM's should install default TokenMakerFactories that support
// the language they want to use beforehand.
setTokenMakerFactory(null);
// Handle other transient stuff
this.s = new Segment();
int lineCount = getDefaultRootElement().getElementCount();
lastTokensOnLines = new DynamicIntArray(lineCount);
setSyntaxStyle(syntaxStyle); // Actually install (transient) TokenMaker
}
示例15: nextConverted
import javax.swing.text.Segment; //导入依赖的package包/类
public Segment nextConverted() throws IOException {
readWholeBuffer = false;
if (reader == null) { // no more chars to read
return null;
}
int readOffset = 0;
int readSize = readBuffer(reader, convertedText.array, readOffset, true);
if (readSize == 0) { // no more chars in reader
reader.close();
reader = null;
return null;
}
readWholeBuffer = (readSize == convertedText.array.length);
if (lastCharCR && readSize > 0 && convertedText.array[readOffset] == '\n') {
/* the preceding '\r' was already converted to '\n'
* in the previous buffer so here just skip initial '\n'
*/
readOffset++;
readSize--;
}
convertedText.offset = readOffset;
convertedText.count = readSize;
lastCharCR = convertSegmentToLineFeed(convertedText);
return convertedText;
}