javax.swing.text
Class Segment

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.swing.text.Segment
All Implemented Interfaces:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable , CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator

public class Segment
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable , CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator

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.


Field Summary
 char[] array sample code for javax.swing.text.Segment.array definition code for javax.swing.text.Segment.array
          This is the array containing the text of interest.
 int count sample code for javax.swing.text.Segment.count definition code for javax.swing.text.Segment.count
          This is the number of array elements that make up the text of interest.
 int offset sample code for javax.swing.text.Segment.offset definition code for javax.swing.text.Segment.offset
          This is the offset into the array that the desired text begins.
 
Fields inherited from interface java.text.CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
DONE sample code for java.text.CharacterIterator.DONE definition code for java.text.CharacterIterator.DONE
 
Constructor Summary
Segment sample code for javax.swing.text.Segment.Segment() definition code for javax.swing.text.Segment.Segment() ()
          Creates a new segment.
Segment sample code for javax.swing.text.Segment.Segment(char[], int, int) definition code for javax.swing.text.Segment.Segment(char[], int, int) (char[] array, int offset, int count)
          Creates a new segment referring to an existing array.
 
Method Summary
 Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for javax.swing.text.Segment.clone() definition code for javax.swing.text.Segment.clone() ()
          Creates a shallow copy.
 char current sample code for javax.swing.text.Segment.current() definition code for javax.swing.text.Segment.current() ()
          Gets the character at the current position (as returned by getIndex()).
 char first sample code for javax.swing.text.Segment.first() definition code for javax.swing.text.Segment.first() ()
          Sets the position to getBeginIndex() and returns the character at that position.
 int getBeginIndex sample code for javax.swing.text.Segment.getBeginIndex() definition code for javax.swing.text.Segment.getBeginIndex() ()
          Returns the start index of the text.
 int getEndIndex sample code for javax.swing.text.Segment.getEndIndex() definition code for javax.swing.text.Segment.getEndIndex() ()
          Returns the end index of the text.
 int getIndex sample code for javax.swing.text.Segment.getIndex() definition code for javax.swing.text.Segment.getIndex() ()
          Returns the current index.
 boolean isPartialReturn sample code for javax.swing.text.Segment.isPartialReturn() definition code for javax.swing.text.Segment.isPartialReturn() ()
          Flag to indicate that partial returns are valid.
 char last sample code for javax.swing.text.Segment.last() definition code for javax.swing.text.Segment.last() ()
          Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.
 char next sample code for javax.swing.text.Segment.next() definition code for javax.swing.text.Segment.next() ()
          Increments the iterator's index by one and returns the character at the new index.
 char previous sample code for javax.swing.text.Segment.previous() definition code for javax.swing.text.Segment.previous() ()
          Decrements the iterator's index by one and returns the character at the new index.
 char setIndex sample code for javax.swing.text.Segment.setIndex(int) definition code for javax.swing.text.Segment.setIndex(int) (int position)
          Sets the position to the specified position in the text and returns that character.
 void setPartialReturn sample code for javax.swing.text.Segment.setPartialReturn(boolean) definition code for javax.swing.text.Segment.setPartialReturn(boolean) (boolean p)
          Flag to indicate that partial returns are valid.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for javax.swing.text.Segment.toString() definition code for javax.swing.text.Segment.toString() ()
          Converts a segment into a String.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

array sample code for javax.swing.text.Segment.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.


offset sample code for javax.swing.text.Segment.offset

public int offset
This is the offset into the array that the desired text begins.


count sample code for javax.swing.text.Segment.count

public int count
This is the number of array elements that make up the text of interest.

Constructor Detail

Segment sample code for javax.swing.text.Segment() definition code for javax.swing.text.Segment()

public Segment()
Creates a new segment.


Segment sample code for javax.swing.text.Segment(char[], int, int) definition code for javax.swing.text.Segment(char[], int, int)

public Segment(char[] array,
               int offset,
               int count)
Creates a new segment referring to an existing array.

Parameters:
array - the array to refer to
offset - the offset into the array
count - the number of characters
Method Detail

setPartialReturn sample code for javax.swing.text.Segment.setPartialReturn(boolean) definition code for javax.swing.text.Segment.setPartialReturn(boolean)

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.

Parameters:
p - whether or not partial returns are valid.
Since:
1.4

isPartialReturn sample code for javax.swing.text.Segment.isPartialReturn() definition code for javax.swing.text.Segment.isPartialReturn()

public boolean isPartialReturn()
Flag to indicate that partial returns are valid.

Returns:
whether or not partial returns are valid.
Since:
1.4

toString sample code for javax.swing.text.Segment.toString() definition code for javax.swing.text.Segment.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Converts a segment into a String.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the string

first sample code for javax.swing.text.Segment.first() definition code for javax.swing.text.Segment.first()

public char first()
Sets the position to getBeginIndex() and returns the character at that position.

Specified by:
first sample code for java.text.CharacterIterator.first() definition code for java.text.CharacterIterator.first() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the first character in the text, or DONE if the text is empty
See Also:
getBeginIndex() sample code for javax.swing.text.Segment.getBeginIndex() definition code for javax.swing.text.Segment.getBeginIndex()

last sample code for javax.swing.text.Segment.last() definition code for javax.swing.text.Segment.last()

public char last()
Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.

Specified by:
last sample code for java.text.CharacterIterator.last() definition code for java.text.CharacterIterator.last() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the last character in the text, or DONE if the text is empty
See Also:
getEndIndex() sample code for javax.swing.text.Segment.getEndIndex() definition code for javax.swing.text.Segment.getEndIndex()

current sample code for javax.swing.text.Segment.current() definition code for javax.swing.text.Segment.current()

public char current()
Gets the character at the current position (as returned by getIndex()).

Specified by:
current sample code for java.text.CharacterIterator.current() definition code for java.text.CharacterIterator.current() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the character at the current position or DONE if the current position is off the end of the text.
See Also:
getIndex() sample code for javax.swing.text.Segment.getIndex() definition code for javax.swing.text.Segment.getIndex()

next sample code for javax.swing.text.Segment.next() definition code for javax.swing.text.Segment.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.

Specified by:
next sample code for java.text.CharacterIterator.next() definition code for java.text.CharacterIterator.next() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the character at the new position or DONE if the new position is off the end of the text range.

previous sample code for javax.swing.text.Segment.previous() definition code for javax.swing.text.Segment.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.

Specified by:
previous sample code for java.text.CharacterIterator.previous() definition code for java.text.CharacterIterator.previous() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the character at the new position or DONE if the current position is equal to getBeginIndex().

setIndex sample code for javax.swing.text.Segment.setIndex(int) definition code for javax.swing.text.Segment.setIndex(int)

public char setIndex(int position)
Sets the position to the specified position in the text and returns that character.

Specified by:
setIndex sample code for java.text.CharacterIterator.setIndex(int) definition code for java.text.CharacterIterator.setIndex(int) in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Parameters:
position - the position within the text. Valid values range from getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown if an invalid value is supplied.
Returns:
the character at the specified position or DONE if the specified position is equal to getEndIndex()

getBeginIndex sample code for javax.swing.text.Segment.getBeginIndex() definition code for javax.swing.text.Segment.getBeginIndex()

public int getBeginIndex()
Returns the start index of the text.

Specified by:
getBeginIndex sample code for java.text.CharacterIterator.getBeginIndex() definition code for java.text.CharacterIterator.getBeginIndex() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the index at which the text begins.

getEndIndex sample code for javax.swing.text.Segment.getEndIndex() definition code for javax.swing.text.Segment.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.

Specified by:
getEndIndex sample code for java.text.CharacterIterator.getEndIndex() definition code for java.text.CharacterIterator.getEndIndex() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the index after the last character in the text

getIndex sample code for javax.swing.text.Segment.getIndex() definition code for javax.swing.text.Segment.getIndex()

public int getIndex()
Returns the current index.

Specified by:
getIndex sample code for java.text.CharacterIterator.getIndex() definition code for java.text.CharacterIterator.getIndex() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Returns:
the current index.

clone sample code for javax.swing.text.Segment.clone() definition code for javax.swing.text.Segment.clone()

public Object sample code for java.lang.Object definition code for java.lang.Object  clone()
Creates a shallow copy.

Specified by:
clone sample code for java.text.CharacterIterator.clone() definition code for java.text.CharacterIterator.clone() in interface CharacterIterator sample code for java.text.CharacterIterator definition code for java.text.CharacterIterator
Overrides:
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the copy
See Also:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable