|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--edu.princeton.swing.text.HighlightedDocument
HighlightedDocument is an abstract representation of a document which supports syntax highlighting. This document can then be displayed with a THighlightedTextArea.
| Nested Class Summary | |
class |
HighlightedDocument.Position
Position is a simple implementation of javax.swing.text.Position. |
class |
HighlightedDocument.PositionTriplet
PositionTriplet maintains three positions which permits efficient synchronous changes. |
class |
HighlightedDocument.UndoableEdit
UndoableEdit is a simple implementation of javax.swing.undo.UndoableEdit. |
| Field Summary | |
static boolean[] |
CHARACTER_ALLOWED
An array of all characters allowed in a HighlightedDocument. |
protected int |
charCount
|
protected char[] |
chars
|
protected byte[] |
charStyles
|
protected int |
lineCount
|
protected short[] |
lineOffsets
|
static char |
MAX_ALLOWED_CHARACTER
The allowed character with the greatest integer encoding. |
protected int |
maxLineLength
|
| Constructor Summary | |
HighlightedDocument()
Constructs a HighlightedDocument. |
|
| Method Summary | |
void |
addTextListener(TextListener listener)
Adds a listener to monitor changes in the text of the document. |
void |
addUndoableEditListener(UndoableEditListener listener)
Adds a listener to monitor undoable changes in the document. |
void |
allowRender(HighlightedDocumentRenderer renderer,
Object extraInfo)
Obtains a read lock and passes the protected data to an implementation of HighlightedDocumentRenderer. |
protected abstract void |
assignStyles()
Updates the charStyles array based on chars, charCount, lineOffsets, and lineCount. |
int |
coordinateToOffset(int column,
int line)
Takes a (column, line) pair and returns the nearest valid offset. |
int |
coordinateToOffset(Point p)
Takes a (column, line) pair and returns the nearest valid offset. |
HighlightedDocument.Position |
createPosition(int offset)
Creates a position at a given offset which will move with the text. |
HighlightedDocument.PositionTriplet |
createPositionTriplet()
Creates a position triplet. |
StringBuffer |
filterString(String string)
Filters out all "non-standard" ASCII characters from the string. |
void |
freePosition(HighlightedDocument.Position position)
Frees a position from future updates. |
void |
freePositionTriplet(HighlightedDocument.PositionTriplet positionTriplet)
Frees a position triplet from future updates. |
int |
getLength()
Returns the number of characters in the document. |
int |
getLineCount()
Returns the number of lines in the document. |
int |
getMaxLineLength()
Returns the length of the longest line. |
protected int[] |
getPositionOffsets()
Returns an integer array containing a backup image of the position HashSet. |
abstract int |
getStyleCount()
Returns the number of distinct styles used by this type of document. |
abstract int |
getTabSize()
Returns the number of spaces to replace all tabs with. |
String |
getText()
Returns the text of the document. |
String |
getText(int start,
int end)
Returns part of the text of the document. |
int[] |
getWordBounds(int offset)
Returns the bounds of the word containing the character at the given offset. |
void |
insertString(int offset,
String string,
boolean mergable)
Inserts a string at the specified index. |
Point |
offsetToCoordinate(int offset)
Takes an offset and returns the nearest valid (column, line) pair. |
protected void |
readLock()
Obtains a read-lock for this HighlightedDocument. |
protected void |
readUnlock()
Releases the read-lock for this HighlightedDocument. |
void |
remove(int offset,
int length,
boolean mergable)
Removes a segment of text specified by its offset and length. |
void |
removeTextListener(TextListener listener)
Removes a listener from this document. |
void |
removeUndoableEditListener(UndoableEditListener listener)
Removes a listener from this document. |
void |
replace(int offset,
int length,
String string,
boolean mergable)
Replaces the text in a given range with the specified string. |
protected void |
replace(int offset,
int length,
String string,
boolean mergable,
boolean generateUndoEvent,
int[] positionOffsets,
boolean disablePositionUpdate)
Replaces the text in a given range with the specified string. |
void |
setText(String string)
Sets the text to the given string. |
protected void |
writeLock()
Obtains a write-lock for this HighlightedDocument. |
protected void |
writeUnlock()
Releases the write-lock for this HighlightedDocument. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final char MAX_ALLOWED_CHARACTER
public static final boolean[] CHARACTER_ALLOWED
protected char[] chars
protected byte[] charStyles
protected int charCount
protected short[] lineOffsets
protected int lineCount
protected int maxLineLength
| Constructor Detail |
public HighlightedDocument()
| Method Detail |
public abstract int getStyleCount()
public abstract int getTabSize()
public void addTextListener(TextListener listener)
listener - The listener to add to this document. A null value will cause a
NullPointerException.public void removeTextListener(TextListener listener)
listener - The listener to remove from this document. A null value will cause a
NullPointerException.public void addUndoableEditListener(UndoableEditListener listener)
listener - The listener to add to this document. A null value will cause a
NullPointerException.public void removeUndoableEditListener(UndoableEditListener listener)
listener - The listener to remove from this document. A null value will cause a
NullPointerException.public HighlightedDocument.Position createPosition(int offset)
offset - The offset at which the position will start.
public void freePosition(HighlightedDocument.Position position)
position - The position object to be detached.public HighlightedDocument.PositionTriplet createPositionTriplet()
public void freePositionTriplet(HighlightedDocument.PositionTriplet positionTriplet)
positionTriplet - The positionTriplet object to be detached.protected int[] getPositionOffsets()
public void remove(int offset,
int length,
boolean mergable)
offset - The index of the start of the segment to remove.length - The length of the segment to remove.mergable - Wheter or not the UndoableEdit generated can be merged with appropriately
similar mergable UndoableEdits.
public void insertString(int offset,
String string,
boolean mergable)
offset - The index at which to insert the string.string - The string to insert.mergable - Wheter or not the UndoableEdit generated can be merged with appropriately
similar mergable UndoableEdits.
public void replace(int offset,
int length,
String string,
boolean mergable)
offset - The offset of the range about to be replaced.length - The length of the range about to be replaced.string - The string with which to replace the range.mergable - Wheter or not the UndoableEdit generated can be merged with appropriately
similar mergable UndoableEdits.public void setText(String string)
string - The string replace the old text with.
protected void replace(int offset,
int length,
String string,
boolean mergable,
boolean generateUndoEvent,
int[] positionOffsets,
boolean disablePositionUpdate)
offset - The offset of the range about to be replaced.length - The length of the range about to be replaced.string - The string with which to replace the range.mergable - Wheter or not the UndoableEdit generated can be merged with appropriately
similar mergable UndoableEdits.positionOffsets - An id-indexed array of position offsets to restore (this will be done
before the position adjustment step). Leave as null if positions should be moved around
normally.disablePositionUpdate - Wheter or not to disable position update.protected abstract void assignStyles()
public StringBuffer filterString(String string)
string - The string to be filtered. A null value will result in a NullPointerException.
public String getText()
public String getText(int start,
int end)
start - The offset at which to begin.end - The offset at which to end.
public int getLength()
public int getLineCount()
public int getMaxLineLength()
public int[] getWordBounds(int offset)
offset - The offset of one of the characters in the desired word.
public void allowRender(HighlightedDocumentRenderer renderer,
Object extraInfo)
renderer - The renderer that will recieve access to the protected data.extraInfo - An object to hold additional parameters from the caller of allowRender.HighlightedDocumentRenderer.doRender(char[], byte[], int, short[], int, Object)public int coordinateToOffset(Point p)
p - The point (where x is the column, and y is the line) to convert to an offset.
public int coordinateToOffset(int column,
int line)
column - The column of the coordinate to convert to an offset.line - The line of the coordinate to convert to an offset.
public Point offsetToCoordinate(int offset)
offset - The offset to convert to a coordinate.
protected final void writeLock()
writeUnlock(),
readLock(),
readUnlock()protected final void writeUnlock()
writeLock(),
readLock(),
readUnlock()protected final void readLock()
writeLock(),
writeUnlock(),
readUnlock()protected final void readUnlock()
writeLock(),
writeUnlock(),
readLock()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||