javax.swing.text
Class Segment
- CharacterIterator, Cloneable
A segment of a character array representing a fragment
of text. It should be treated as immutable even though
the array is directly accessible. This gives fast access
to fragments of text without the overhead of copying
around characters. This is effectively an unprotected
String.
The Segment implements the java.text.CharacterIterator
interface to support use with the i18n support without
copying text into a string.
char[] | array- This is the array containing the text of
interest.
|
int | count- This is the number of array elements that
make up the text of interest.
|
int | offset- This is the offset into the array that
the desired text begins.
|
Segment()- Creates a new segment.
|
Segment(char[] array, int offset, int count)- Creates a new segment referring to an existing array.
|
Object | clone()- Creates a shallow copy.
|
char | current()- Gets the character at the current position (as returned by getIndex()).
|
char | first()- Sets the position to getBeginIndex() and returns the character at that
position.
|
int | getBeginIndex()- Returns the start index of the text.
|
int | getEndIndex()- Returns the end index of the text.
|
int | getIndex()- Returns the current index.
|
boolean | isPartialReturn()- Flag to indicate that partial returns are valid.
|
char | last()- Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
and returns the character at that position.
|
char | next()- Increments the iterator's index by one and returns the character
at the new index.
|
char | previous()- Decrements the iterator's index by one and returns the character
at the new index.
|
char | setIndex(int position)- Sets the position to the specified position in the text and returns that
character.
|
void | setPartialReturn(boolean p)- Flag to indicate that partial returns are valid.
|
String | toString()- Converts a segment into a String.
|
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait |
array
public char[] array
This is the array containing the text of
interest. This array should never be modified;
it is available only for efficiency.
View More Examples of array
1: import ;
2: import ;
3:
4: ...
5:
6: public SegmentCharSequence(Segment seg)
7: {
8: ...
9:
10: public SegmentCharSequence(Segment seg, boolean reverse)
11: {
12: ...
13: index = length - index - 1;
14: return seg.array[seg.offset + offset + index];
View Full Code Here
1:
2: import ;
3:
4: ...
5:
6: public byte lookup(Segment segment, int offset, int length)
7: {
8: ...
9: {
10: char firstChar=Character.toUpperCase(segment.array[offset]);
11: ...
12: char lastChar=Character.toUpperCase(segment.array[offset+length-1]);
View Full Code Here
1:
2: import ;
3:
4: ...
5:
6: public byte markTokensImpl(byte token, Segment line, int lineIndex)
7: {
8: ...
9: {
10: switch(line.array[i])
11: {
12: ...
13: case '*':
14: if(token == JEditToken.COMMENT1 && length - i >= 1 && line.array[i+1] == '/')
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: int numLines = 1;
6: Segment s = new Segment(text.toCharArray(), 0, 0);
7: ...
8: s.count = s.array.length;
9: TabExpander te = new MyTabExpander(fm);
10: ...
11: int breaks = getBreakLocation(s, fm, 0, width, te, 0);
12: while((breaks+s.offset) < s.array.length) {
View Full Code Here
count
public int count
This is the number of array elements that
make up the text of interest.
View More Examples of count
1:
2: import ;
3:
4: ...
5:
6: public void paintPlainLine(Writer out, int lineNumber, Segment line, SyntaxToken tokens)
7: {
8: ...
9: int pos = this.position.getPos();
10: String expandedText = this.expander.expand(pos, line.array, line.offset, line.count);
11: this.position.incPos(expandedText.length());
12: ...
13: public void paintSyntaxLine(
14: Writer out, int lineNumber, Segment line, SyntaxToken tokens
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: int numLines = 1;
6: Segment s = new Segment(text.toCharArray(), 0, 0);
7: ...
8: s.count = s.array.length;
9: TabExpander te = new MyTabExpander(fm);
10: ...
11: s.offset += breaks;
12: s.count = s.array.length - s.offset;
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5:
6: private Segment segment;
7:
8: ...
9: int segmentOffset=segment.offset;
10: segment.count=tokenLength;
11: Style style=styleSchema.getStyle(styleId);
12: ...
13: {
14: segment.count=selectionStart-start-offset;
View Full Code Here
offset
public int offset
This is the offset into the array that
the desired text begins.
View More Examples of offset
1:
2: public void handleToken(Segment seg, byte id, int offset, int length,
3: TokenMarker.LineContext context)
4: ...
5: if(Character.isWhitespace(seg.array[
6: seg.offset + chunk.offset]))
7: {
8: ...
9: Chunk nextLine = new Chunk(endOfWhitespace,
10: end.offset + end.length,
11: getParserRuleSet(context));
12: ...
13:
14: protected void initChunk(Chunk chunk, Segment seg)
View Full Code Here
1:
2: import ;
3:
4: ...
5:
6: public void paintPlainLine(Writer out, int lineNumber, Segment line, SyntaxToken tokens)
7: {
8: ...
9: int pos = this.position.getPos();
10: String expandedText = this.expander.expand(pos, line.array, line.offset, line.count);
11: this.position.incPos(expandedText.length());
12: ...
13: public void paintSyntaxLine(
14: Writer out, int lineNumber, Segment line, SyntaxToken tokens
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: int numLines = 1;
6: Segment s = new Segment(text.toCharArray(), 0, 0);
7: s.count = s.array.length;
8: ...
9: int breaks = getBreakLocation(s, fm, 0, width, te, 0);
10: while((breaks+s.offset) < s.array.length) {
11: ...
12: s.offset += breaks;
View Full Code Here
Segment
public Segment()
Creates a new segment.
View More Examples of Segment()
1: if(end > start)
2: { Segment segment = new Segment();
3: requester.getDocument().getText( start, end - start, segment );
4: return segment.toString().trim();
5: }
View Full Code Here
1: int doclen = doc.getLength();
2: Segment segment = new Segment();
3: try {
4: doc.getText(mark, doclen - mark, segment);
5: } catch (BadLocationException ble) {
View Full Code Here
Segment
public Segment(char[] array,
int offset,
int count) Creates a new segment referring to an existing array.
array - the array to refer tooffset - the offset into the arraycount - the number of characters
View More Examples of Segment(char[] array,int offset,int count)
1: char[] chars = document.get().toCharArray();
2: text = new Segment(chars, 0, chars.length);
3: }
4:
5: protected int getNextWordStart(Segment text, int startPos) {
View Full Code Here
current
public char current()
Gets the character at the current position (as returned by getIndex()).
- current in interface CharacterIterator
- the character at the current position or DONE if the current
position is off the end of the text.
first
public char first()
Sets the position to getBeginIndex() and returns the character at that
position.
- first in interface CharacterIterator
- the first character in the text, or DONE if the text is empty
getEndIndex
public int getEndIndex()
Returns the end index of the text. This index is the index of the first
character following the end of the text.
- getEndIndex in interface CharacterIterator
- the index after the last character in the text
View More Examples of getEndIndex()
1:
2: import ;
3:
4: ...
5: protected int endDistance = 0;
6: protected Segment text;
7: protected BreakIterator sentenceIterator;
8: ...
9: char[] chars = document.get().toCharArray();
10: text = new Segment(chars, 0, chars.length);
11: }
12: ...
13: (selectionLength <= 0)
14: ? text.getEndIndex()
View Full Code Here
View More Examples of getIndex()
1:
2: import ;
3:
4: ...
5: protected int endDistance = 0;
6: protected Segment text;
7: protected BreakIterator sentenceIterator;
8: ...
9: char[] chars = document.get().toCharArray();
10: text = new Segment(chars, 0, chars.length);
11: }
12: ...
13: if (Character.isLetterOrDigit(ch) && isToBeChecked()) {
14: return text.getIndex() - ignored;
View Full Code Here
isPartialReturn
public boolean isPartialReturn()
Flag to indicate that partial returns are valid.
- whether or not partial returns are valid.
last
public char last()
Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
and returns the character at that position.
- last in interface CharacterIterator
- the last character in the text, or DONE if the text is empty
next
public char next()
Increments the iterator's index by one and returns the character
at the new index. If the resulting index is greater or equal
to getEndIndex(), the current index is reset to getEndIndex() and
a value of DONE is returned.
- next in interface CharacterIterator
- the character at the new position or DONE if the new
position is off the end of the text range.
previous
public char previous()
Decrements the iterator's index by one and returns the character
at the new index. If the current index is getBeginIndex(), the index
remains at getBeginIndex() and a value of DONE is returned.
- previous in interface CharacterIterator
- the character at the new position or DONE if the current
position is equal to getBeginIndex().
View More Examples of previous()
1:
2: import ;
3:
4: ...
5: protected int endDistance = 0;
6: protected Segment text;
7: protected BreakIterator sentenceIterator;
8: ...
9: char[] chars = document.get().toCharArray();
10: text = new Segment(chars, 0, chars.length);
11: }
12: ...
13: if (ch2 == Segment.DONE || !Character.isLetterOrDigit(ch2)) {
14: text.previous();
View Full Code Here
setIndex
public char setIndex(int position)
Sets the position to the specified position in the text and returns that
character.
- setIndex in interface CharacterIterator
position - the position within the text. Valid values range from
getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown
if an invalid value is supplied.
- the character at the specified position or DONE if the specified position is equal to getEndIndex()
setPartialReturn
public void setPartialReturn(boolean p)
Flag to indicate that partial returns are valid. If the flag is true,
an implementation of the interface method Document.getText(position,length,Segment)
should return as much text as possible without making a copy. The default
state of the flag is false which will cause Document.getText(position,length,Segment)
to provide the same return behavior it always had, which may or may not
make a copy of the text depending upon the request.
p - whether or not partial returns are valid.
View More Examples of setPartialReturn(boolean p)
1: import ;
2: import ;
3:
4: ...
5: int docLength = adoc.getLength();
6: Segment segment = new Segment();
7: ...
8: segment.setPartialReturn(true);
9: int start = locateWordStart(adoc, offset, docLength, segment);
View Full Code Here
1: javax.swing.text.Document doc = output.getDocument();
2: Segment seg = new Segment(new char[4096],0,4096);
3: ...
4: seg.setPartialReturn(true);
5:
6: int offset = 0;
7: while (offset < doc.getLength())
View Full Code Here
View More Examples of toString()
1: import ;
2: import ;
3: import ;
4: ...
5: System.out.println
6: ( "\t" + attributeName.toString()
7: ...
8: + "\t-->\t" + attributeValue.toString()
9: + " (" + attributeValue.getClass().getName() +")"
10: ...
11: if(end > start)
12: { Segment segment = new Segment();
View Full Code Here
1:
2: import ;
3:
4: ...
5: protected int endDistance = 0;
6: protected Segment text;
7: protected BreakIterator sentenceIterator;
8: ...
9: char[] chars = document.get().toCharArray();
10: text = new Segment(chars, 0, chars.length);
11: }
12: ...
13: public String getContext() {
14: return text.toString();
View Full Code Here
1: import ;
2: import ;
3:
4: ...
5: {
6: final String str = this.buffer.toString();
7: this.buffer.setLength(0);
8: ...
9: final int len = doc.getLength();
10: final Segment segment = new Segment();
11:
12: ...
13: {
14: this.history.add(segment.toString());
View Full Code Here
1: }
2: msg = buf.toString();
3: }
4: ...
5: int len = doc.getLength();
6: Segment segment = new Segment();
7: try {
8: ...
9: }
10: String text = segment.toString();
11: if (debugGui.dim.stringIsCompilableUnit(text)) {
View Full Code Here
1: }
2: msg = buf.toString();
3: }
4: ...
5: int len = doc.getLength();
6: Segment segment = new Segment();
7: try {
8: ...
9: }
10: String text = segment.toString();
11: if (db.stringIsCompilableUnit(text)) {
12: ...
13: }
14: url = sb.toString();
View Full Code Here