edu.princeton.swing.text
public abstract class HighlightedDocument extends java.lang.Object
| Modifier and Type | Class and Description | 
|---|---|
| class  | HighlightedDocument.PositionPosition is a simple implementation of javax.swing.text.Position. | 
| class  | HighlightedDocument.PositionTripletPositionTriplet maintains three positions which permits efficient synchronous changes. | 
| class  | HighlightedDocument.UndoableEditUndoableEdit is a simple implementation of javax.swing.undo.UndoableEdit. | 
| Modifier and Type | Field and Description | 
|---|---|
| static boolean[] | CHARACTER_ALLOWEDAn array of all characters allowed in a HighlightedDocument. | 
| protected int | charCount | 
| protected char[] | chars | 
| protected byte[] | charStyles | 
| protected int | lineCount | 
| protected int[] | lineOffsets | 
| static char | MAX_ALLOWED_CHARACTERThe allowed character with the greatest integer encoding. | 
| protected int | maxLineLength | 
| Constructor and Description | 
|---|
| HighlightedDocument()Constructs a HighlightedDocument. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addTextListener(java.awt.event.TextListener listener)Adds a listener to monitor changes in the text of the document. | 
| void | addUndoableEditListener(javax.swing.event.UndoableEditListener listener)Adds a listener to monitor undoable changes in the document. | 
| void | allowRender(HighlightedDocumentRenderer renderer,
           java.lang.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(java.awt.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. | 
| java.lang.StringBuffer | filterString(java.lang.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. | 
| java.lang.String | getText()Returns the text of the document. | 
| java.lang.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,
            java.lang.String string,
            boolean mergable)Inserts a string at the specified index. | 
| java.awt.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(java.awt.event.TextListener listener)Removes a listener from this document. | 
| void | removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)Removes a listener from this document. | 
| void | replace(int offset,
       int length,
       java.lang.String string,
       boolean mergable)Replaces the text in a given range with the specified string. | 
| protected void | replace(int offset,
       int length,
       java.lang.String string,
       boolean mergable,
       boolean generateUndoEvent,
       int[] positionOffsets,
       boolean disablePositionUpdate)Replaces the text in a given range with the specified string. | 
| void | setText(java.lang.String string)Sets the text to the given string. | 
| protected void | utilReplace(int offset,
           int length,
           java.lang.StringBuffer buffer,
           int newLength,
           int[] positionOffsets,
           boolean disablePositionUpdate) | 
| protected void | writeLock()Obtains a write-lock for this HighlightedDocument. | 
| protected void | writeUnlock()Releases the write-lock for this HighlightedDocument. | 
public static final char MAX_ALLOWED_CHARACTER
public static final boolean[] CHARACTER_ALLOWED
protected char[] chars
protected byte[] charStyles
protected int charCount
protected int[] lineOffsets
protected int lineCount
protected int maxLineLength
public HighlightedDocument()
public abstract int getStyleCount()
public abstract int getTabSize()
public void addTextListener(java.awt.event.TextListener listener)
listener - The listener to add to this document.  A null value will cause a
 NullPointerException.public void removeTextListener(java.awt.event.TextListener listener)
listener - The listener to remove from this document.  A null value will cause a
 NullPointerException.public void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
listener - The listener to add to this document.  A null value will cause a
 NullPointerException.public void removeUndoableEditListener(javax.swing.event.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,
                java.lang.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,
           java.lang.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(java.lang.String string)
string - The string replace the old text with.protected void utilReplace(int offset,
               int length,
               java.lang.StringBuffer buffer,
               int newLength,
               int[] positionOffsets,
               boolean disablePositionUpdate)
protected void replace(int offset,
           int length,
           java.lang.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 java.lang.StringBuffer filterString(java.lang.String string)
string - The string to be filtered.  A null value will result in a NullPointerException.public java.lang.String getText()
public java.lang.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, java.lang.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, int[], int, Object)public int coordinateToOffset(java.awt.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 java.awt.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()