APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text

public final Class StringContent

extends Object
implements Content, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.swing.text.AbstractDocument.Content
Annotations
@SuppressWarnings:serial
Imports
java.util.Vector, java.io.Serializable, javax.swing.undo.*, java.lang.ref.WeakReference

An implementation of the AbstractDocument.Content interface that is a brute force implementation that is useful for relatively small documents and/or debugging. It manages the character content as a simple character array. It is also quite inefficient.

It is generally recommended that the gap buffer or piece table implementations be used instead. This buffer does not scale up to large sizes.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Timothy Prinzing

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
StringContent.InsertUndo

UnoableEdit created for inserts.

pack-priv static class
StringContent.PosRec

holds the data for a mark...

pack-priv class
StringContent.RemoveUndo

UndoableEdit created for removes.

pack-priv class
pack-priv static class
StringContent.UndoPosRef

Used to hold a reference to a Position that is being reset as the result of removing from the content.

Field Summary

Modifier and TypeField and Description
private int
private char[]
private static final char[]
pack-priv transient Vector<StringContent.PosRec>

Constructor Summary

AccessConstructor and Description
public
StringContent()

Creates a new StringContent object.

public
StringContent(int
the initial size
initialLength
)

Creates a new StringContent object, with the initial size specified.

Method Summary

Modifier and TypeMethod and Description
public Position

Returns:

the position
createPosition
(int
the offset to create a position for >= 0
offset
)

Implements javax.swing.text.AbstractDocument.Content.createPosition.

Creates a position within the content that will track change as the content is mutated.

public void
getChars(int
the starting position >= 0
where
,
int
the number of characters to retrieve >= 0
len
,
Segment
the Segment object to return the characters in
chars
)

Implements javax.swing.text.AbstractDocument.Content.getChars.

Retrieves a portion of the content.

protected Vector<E>

Returns:

the set of instances
getPositionsInRange
(Vector<E>
the Vector to use, with a new one created on null
v
,
int
the starting offset >= 0
offset
,
int
the length >= 0
length
)

Returns a Vector containing instances of UndoPosRef for the Positions in the range offset to offset + length.

public String

Returns:

a string representing the content; may be empty
getString
(int
the starting position >= 0
where
,
int
the length to retrieve >= 0
len
)

Implements javax.swing.text.AbstractDocument.Content.getString.

Retrieves a portion of the content.

public UndoableEdit

Returns:

an UndoableEdit object for undoing
insertString
(int
the starting position >= 0 && < length()
where
,
String
the non-null string to insert
str
)

Implements javax.swing.text.AbstractDocument.Content.insertString.

Inserts a string into the content.

public int

Returns:

the length >= 1
length
()

Implements javax.swing.text.AbstractDocument.Content.length.

Returns the length of the content.

public UndoableEdit

Returns:

an UndoableEdit object for undoing
remove
(int
the starting position >= 0
where
,
int
the number of characters to remove >= 0
nitems
)

Implements javax.swing.text.AbstractDocument.Content.remove.

Removes part of the content.

pack-priv void
replace(int
offset into the array to start the replace
offset
,
int
number of characters to remove
length
,
char[]
replacement array
replArray
,
int
offset into the replacement array
replOffset
,
int
number of character to use from the replacement array.
replLength
)

Replaces some of the characters in the array

pack-priv void
resize(int ncount)

pack-priv synchronized void
updateMarksForInsert(int offset, int length)

pack-priv synchronized void
updateMarksForRemove(int offset, int length)

protected void
updateUndoPositions(Vector<E>
the positions of the instances
positions
)

Resets the location for all the UndoPosRef instances in positions.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count
databack to summary
private char[] data
emptyback to summary
private static final char[] empty
marksback to summary
pack-priv transient Vector<StringContent.PosRec> marks

Constructor Detail

StringContentback to summary
public StringContent()

Creates a new StringContent object. Initial size defaults to 10.

StringContentback to summary
public StringContent(int initialLength)

Creates a new StringContent object, with the initial size specified. If the length is < 1, a size of 1 is used.

Parameters
initialLength:int

the initial size

Method Detail

createPositionback to summary
public Position createPosition(int offset) throws BadLocationException

Implements javax.swing.text.AbstractDocument.Content.createPosition.

Creates a position within the content that will track change as the content is mutated.

Parameters
offset:int

the offset to create a position for >= 0

Returns:Position

the position

Exceptions
BadLocationException:
if the specified position is invalid
getCharsback to summary
public void getChars(int where, int len, Segment chars) throws BadLocationException

Implements javax.swing.text.AbstractDocument.Content.getChars.

Retrieves a portion of the content. where + len must be <= length()

Parameters
where:int

the starting position >= 0

len:int

the number of characters to retrieve >= 0

chars:Segment

the Segment object to return the characters in

Exceptions
BadLocationException:
if the specified position is invalid
See Also
AbstractDocument.Content#getChars
getPositionsInRangeback to summary
protected Vector<E> getPositionsInRange(Vector<E> v, int offset, int length)

Returns a Vector containing instances of UndoPosRef for the Positions in the range offset to offset + length. If v is not null the matching Positions are placed in there. The vector with the resulting Positions are returned.

This is meant for internal usage, and is generally not of interest to subclasses.

Parameters
v:Vector<E>

the Vector to use, with a new one created on null

offset:int

the starting offset >= 0

length:int

the length >= 0

Returns:Vector<E>

the set of instances

Annotations
@SuppressWarnings:rawtypes, unchecked
getStringback to summary
public String getString(int where, int len) throws BadLocationException

Implements javax.swing.text.AbstractDocument.Content.getString.

Retrieves a portion of the content. where + len must be <= length().

Parameters
where:int

the starting position >= 0

len:int

the length to retrieve >= 0

Returns:String

a string representing the content; may be empty

Exceptions
BadLocationException:
if the specified position is invalid
See Also
AbstractDocument.Content#getString
insertStringback to summary
public UndoableEdit insertString(int where, String str) throws BadLocationException

Implements javax.swing.text.AbstractDocument.Content.insertString.

Inserts a string into the content.

Parameters
where:int

the starting position >= 0 && < length()

str:String

the non-null string to insert

Returns:UndoableEdit

an UndoableEdit object for undoing

Exceptions
BadLocationException:
if the specified position is invalid
See Also
AbstractDocument.Content#insertString
lengthback to summary
public int length()

Implements javax.swing.text.AbstractDocument.Content.length.

Returns the length of the content.

Returns:int

the length >= 1

See Also
AbstractDocument.Content#length
removeback to summary
public UndoableEdit remove(int where, int nitems) throws BadLocationException

Implements javax.swing.text.AbstractDocument.Content.remove.

Removes part of the content. where + nitems must be < length().

Parameters
where:int

the starting position >= 0

nitems:int

the number of characters to remove >= 0

Returns:UndoableEdit

an UndoableEdit object for undoing

Exceptions
BadLocationException:
if the specified position is invalid
See Also
AbstractDocument.Content#remove
replaceback to summary
pack-priv void replace(int offset, int length, char[] replArray, int replOffset, int replLength)

Replaces some of the characters in the array

Parameters
offset:int

offset into the array to start the replace

length:int

number of characters to remove

replArray:char[]

replacement array

replOffset:int

offset into the replacement array

replLength:int

number of character to use from the replacement array.

resizeback to summary
pack-priv void resize(int ncount)
updateMarksForInsertback to summary
pack-priv synchronized void updateMarksForInsert(int offset, int length)
updateMarksForRemoveback to summary
pack-priv synchronized void updateMarksForRemove(int offset, int length)
updateUndoPositionsback to summary
protected void updateUndoPositions(Vector<E> positions)

Resets the location for all the UndoPosRef instances in positions.

This is meant for internal usage, and is generally not of interest to subclasses.

Parameters
positions:Vector<E>

the positions of the instances

Annotations
@SuppressWarnings:rawtypes
javax.swing.text back to summary

pack-priv Class StringContent.InsertUndo

extends AbstractUndoableEdit
Class Inheritance

UnoableEdit created for inserts.

Field Summary

Modifier and TypeField and Description
protected int
protected int
protected Vector<E>
protected String
Inherited from javax.swing.undo.AbstractUndoableEdit:
RedoNameUndoName

Constructor Summary

AccessConstructor and Description
protected
InsertUndo(int offset, int length)

Method Summary

Modifier and TypeMethod and Description
public void
redo()

Overrides javax.swing.undo.AbstractUndoableEdit.redo.

Implements javax.swing.undo.UndoableEdit.redo.

Throws CannotRedoException if canRedo returns false.

public void
undo()

Overrides javax.swing.undo.AbstractUndoableEdit.undo.

Implements javax.swing.undo.UndoableEdit.undo.

Throws CannotUndoException if canUndo returns false.

Inherited from javax.swing.undo.AbstractUndoableEdit:
addEditcanRedocanUndodiegetPresentationNamegetRedoPresentationNamegetUndoPresentationNameisSignificantreplaceEdittoString

Field Detail

lengthback to summary
protected int length
offsetback to summary
protected int offset
posRefsback to summary
protected Vector<E> posRefs
Annotations
@SuppressWarnings:rawtypes
stringback to summary
protected String string

Constructor Detail

InsertUndoback to summary
protected InsertUndo(int offset, int length)

Method Detail

redoback to summary
public void redo() throws CannotRedoException

Overrides javax.swing.undo.AbstractUndoableEdit.redo.

Implements javax.swing.undo.UndoableEdit.redo.

Doc from javax.swing.undo.AbstractUndoableEdit.redo.

Throws CannotRedoException if canRedo returns false. Sets hasBeenDone to true. Subclasses should override to redo the operation represented by this edit. Override should begin with a call to super.

Exceptions
CannotRedoException:
if canRedo returns false
undoback to summary
public void undo() throws CannotUndoException

Overrides javax.swing.undo.AbstractUndoableEdit.undo.

Implements javax.swing.undo.UndoableEdit.undo.

Doc from javax.swing.undo.AbstractUndoableEdit.undo.

Throws CannotUndoException if canUndo returns false. Sets hasBeenDone to false. Subclasses should override to undo the operation represented by this edit. Override should begin with a call to super.

Exceptions
CannotUndoException:
if canUndo returns false
javax.swing.text back to summary

pack-priv final Class StringContent.PosRec

extends WeakReference<StringContent.StickyPosition>
Class Inheritance

holds the data for a mark... separately from the real mark so that the real mark can be collected if there are no more references to it.... the update table holds only a reference to this grungy thing.

Field Summary

Modifier and TypeField and Description
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
PosRec(int offset, StringContent.StickyPosition position)

Field Detail

offsetback to summary
pack-priv int offset

Constructor Detail

PosRecback to summary
pack-priv PosRec(int offset, StringContent.StickyPosition position)
javax.swing.text back to summary

pack-priv Class StringContent.RemoveUndo

extends AbstractUndoableEdit
Class Inheritance

UndoableEdit created for removes.

Field Summary

Modifier and TypeField and Description
protected int
protected int
protected Vector<StringContent.UndoPosRef>
protected String
Inherited from javax.swing.undo.AbstractUndoableEdit:
RedoNameUndoName

Constructor Summary

AccessConstructor and Description
protected
RemoveUndo(int offset, String string)

Method Summary

Modifier and TypeMethod and Description
public void
redo()

Overrides javax.swing.undo.AbstractUndoableEdit.redo.

Implements javax.swing.undo.UndoableEdit.redo.

Throws CannotRedoException if canRedo returns false.

public void
undo()

Overrides javax.swing.undo.AbstractUndoableEdit.undo.

Implements javax.swing.undo.UndoableEdit.undo.

Throws CannotUndoException if canUndo returns false.

Inherited from javax.swing.undo.AbstractUndoableEdit:
addEditcanRedocanUndodiegetPresentationNamegetRedoPresentationNamegetUndoPresentationNameisSignificantreplaceEdittoString

Field Detail

lengthback to summary
protected int length
offsetback to summary
protected int offset
posRefsback to summary
protected Vector<StringContent.UndoPosRef> posRefs
stringback to summary
protected String string

Constructor Detail

RemoveUndoback to summary
protected RemoveUndo(int offset, String string)
Annotations
@SuppressWarnings:unchecked

Method Detail

redoback to summary
public void redo() throws CannotRedoException

Overrides javax.swing.undo.AbstractUndoableEdit.redo.

Implements javax.swing.undo.UndoableEdit.redo.

Doc from javax.swing.undo.AbstractUndoableEdit.redo.

Throws CannotRedoException if canRedo returns false. Sets hasBeenDone to true. Subclasses should override to redo the operation represented by this edit. Override should begin with a call to super.

Annotations
@SuppressWarnings:unchecked
Exceptions
CannotRedoException:
if canRedo returns false
undoback to summary
public void undo() throws CannotUndoException

Overrides javax.swing.undo.AbstractUndoableEdit.undo.

Implements javax.swing.undo.UndoableEdit.undo.

Doc from javax.swing.undo.AbstractUndoableEdit.undo.

Throws CannotUndoException if canUndo returns false. Sets hasBeenDone to false. Subclasses should override to undo the operation represented by this edit. Override should begin with a call to super.

Exceptions
CannotUndoException:
if canUndo returns false
javax.swing.text back to summary

pack-priv final Class StringContent.StickyPosition

extends Object
implements Position
Class Inheritance
All Implemented Interfaces
javax.swing.text.Position

Field Summary

Modifier and TypeField and Description
pack-priv StringContent.PosRec

Constructor Summary

AccessConstructor and Description
pack-priv
StickyPosition(int offset)

Method Summary

Modifier and TypeMethod and Description
public int
getOffset()

Implements javax.swing.text.Position.getOffset.

Fetches the current offset within the document.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

recback to summary
pack-priv StringContent.PosRec rec

Constructor Detail

StickyPositionback to summary
pack-priv StickyPosition(int offset)

Method Detail

getOffsetback to summary
public int getOffset()

Implements javax.swing.text.Position.getOffset.

Doc from javax.swing.text.Position.getOffset.

Fetches the current offset within the document.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

javax.swing.text back to summary

pack-priv final Class StringContent.UndoPosRef

extends Object
Class Inheritance

Used to hold a reference to a Position that is being reset as the result of removing from the content.

Field Summary

Modifier and TypeField and Description
protected StringContent.PosRec
rec

Position to reset offset.

protected int
undoLocation

Location to reset to when resetLocation is invoked.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
resetLocation()

Resets the location of the Position to the offset when the receiver was instantiated.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

recback to summary
protected StringContent.PosRec rec

Position to reset offset.

undoLocationback to summary
protected int undoLocation

Location to reset to when resetLocation is invoked.

Constructor Detail

UndoPosRefback to summary
pack-priv UndoPosRef(StringContent.PosRec rec)

Method Detail

resetLocationback to summary
protected void resetLocation()

Resets the location of the Position to the offset when the receiver was instantiated.