com.borland.primetime.editor
Class EditorDocument

java.lang.Object
  |
  +--javax.swing.text.AbstractDocument
        |
        +--javax.swing.text.PlainDocument
              |
              +--com.borland.primetime.editor.EditorDocument

public class EditorDocument
extends javax.swing.text.PlainDocument

This is the editor document that the JBuilder editor is going to use. It's modeled on the standard PlainDocument, but modified to fit our particular needs better. In particular, it's aware of a Scanner element and uses AbstractDocument.StyledLeafElement objects to store style information for syntax highlighting. It also has an associated undo manager to handle undo at the document level.

See Also:
Serialized Form

Inner Class Summary
protected  class EditorDocument.MarkChain
          This class maintains the list of LineMarks on a particular line of this document.
protected  class EditorDocument.MarkList
          This class maintains the list of LineMarks for this document.
static class EditorDocument.RunInfo
          This inner class stores blocks of run information.
 class EditorDocument.StyledLeafElement
           
 
Inner classes inherited from class javax.swing.text.AbstractDocument
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement
 
Field Summary
static Scanner DEFAULT_SCANNER
           
protected  java.lang.ref.WeakReference docRef
           
static LineMark[] EMPTY_MARKLIST
           
static java.lang.String I18NProperty
           
protected  EditorDocument.MarkList markList
           
static java.lang.Object NOMARK
           
protected  Scanner scanner
           
protected  BasicStyleMap styleMap
           
protected  JBUndoManager undoManager
           
 
Fields inherited from class javax.swing.text.PlainDocument
lineLimitAttribute, tabSizeAttribute
 
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
Constructor Summary
EditorDocument()
           
 
Method Summary
protected  javax.swing.text.Element createLeafElement(javax.swing.text.Element parent, javax.swing.text.AttributeSet a, int p0, int p1)
          Creates a document leaf element.
protected  void fireChangedUpdate(javax.swing.event.DocumentEvent e)
          Notify interested listeners that a change was made to the document.
protected  void fireInsertUpdate(javax.swing.event.DocumentEvent e)
          Notify interested listeners that an insertion was made into the document.
protected  void fireRemoveUpdate(javax.swing.event.DocumentEvent e)
          Notify interested listeners that a removal was made from the document.
 void fireRowsChanged(int start, int end)
          Called by the scanner to tell the editor that the syntax highlighting for the given rows have changed.
 LineMark[] getLineMarks(int index)
          Get the list of LineMarks on a particular line.
 int getMarkIndex(LineMark mark)
          Get the 0-based index on which a particular mark exists.
 java.lang.ref.WeakReference getReference()
           
 Scanner getScanner()
          Get the scanner currently in use for this document.
 BasicStyleMap getStyleMap()
          Get the StyleMap to use when Rendering this Document.
 JBUndoManager getUndoManager()
          Get the JBUndoManager for this document.
 void removeLightweightLineMarks(LineMark mark)
          Remove all occurances of a particular linemark from this document.
 int removeLineMark(LineMark mark)
          Remove a LineMark.
 void reparse(javax.swing.event.DocumentEvent e)
          Tell the scanner to reparse the document.
 void setLightweightLineMarks(int[] indexes, LineMark mark)
          Set a LineMark on an array of lines.
 int setLineMark(int index, LineMark mark)
          Set a LineMark on a particular line.
 void setScanner(Scanner scanner)
          Set the scanner to use for this document.
 void setStyleMap(BasicStyleMap styleMap)
          Set the StyleMap to use for this document.
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createPosition, dump, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentProperties, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, insertString, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SCANNER

public static final Scanner DEFAULT_SCANNER

docRef

protected java.lang.ref.WeakReference docRef

I18NProperty

public static final java.lang.String I18NProperty

styleMap

protected BasicStyleMap styleMap

scanner

protected Scanner scanner

undoManager

protected JBUndoManager undoManager

EMPTY_MARKLIST

public static final LineMark[] EMPTY_MARKLIST

NOMARK

public static final java.lang.Object NOMARK

markList

protected EditorDocument.MarkList markList
Constructor Detail

EditorDocument

public EditorDocument()
Method Detail

fireRowsChanged

public void fireRowsChanged(int start,
                            int end)
Called by the scanner to tell the editor that the syntax highlighting for the given rows have changed.
Parameters:
start - the first line that changed
end - the last line that changed

getReference

public java.lang.ref.WeakReference getReference()

getScanner

public Scanner getScanner()
Get the scanner currently in use for this document.
Returns:
the current scanner for this document.

setScanner

public void setScanner(Scanner scanner)
Set the scanner to use for this document.
Parameters:
scanner - the scanner to use for this document.

getUndoManager

public JBUndoManager getUndoManager()
Get the JBUndoManager for this document.
Returns:
the undo manager.

setStyleMap

public void setStyleMap(BasicStyleMap styleMap)
Set the StyleMap to use for this document.
Parameters:
styleMap - the StyleMap to use.

getStyleMap

public BasicStyleMap getStyleMap()
Get the StyleMap to use when Rendering this Document.
Returns:
the StyleMap to use for this document.

reparse

public void reparse(javax.swing.event.DocumentEvent e)
Tell the scanner to reparse the document.
Parameters:
e - the DocumentEvent to pass to the scanner's parse method.

fireInsertUpdate

protected void fireInsertUpdate(javax.swing.event.DocumentEvent e)
Notify interested listeners that an insertion was made into the document. We take this opportunity to reparse the changed text to update the syntax information for syntax highlighting before the event is actually fired.
Overrides:
fireInsertUpdate in class javax.swing.text.AbstractDocument

fireRemoveUpdate

protected void fireRemoveUpdate(javax.swing.event.DocumentEvent e)
Notify interested listeners that a removal was made from the document. We take this opportunity to reparse the changed text to update the syntax information for syntax highlighting before the event is actually fired.
Overrides:
fireRemoveUpdate in class javax.swing.text.AbstractDocument

fireChangedUpdate

protected void fireChangedUpdate(javax.swing.event.DocumentEvent e)
Notify interested listeners that a change was made to the document. We take this opportunity to reparse the changed text to update the syntax information for syntax highlighting before the event is actually fired.
Overrides:
fireChangedUpdate in class javax.swing.text.AbstractDocument

setLightweightLineMarks

public void setLightweightLineMarks(int[] indexes,
                                    LineMark mark)
Set a LineMark on an array of lines. The mark should be a lightweight mark, as the same mark will be placed in a number of locations.
Parameters:
indexes - An array of 0-based index entries at which the specified lightweight mark will be set.
mark - The lightweight LineMark to set.

removeLightweightLineMarks

public void removeLightweightLineMarks(LineMark mark)
Remove all occurances of a particular linemark from this document. The mark should be a lightweight mark, which can exist in more than one location. For a normal "heavyweight" mark, use removeLineMark instead.
Parameters:
mark - The lightweight LineMark to be removed.
See Also:
removeLineMark

setLineMark

public int setLineMark(int index,
                       LineMark mark)
Set a LineMark on a particular line.
Parameters:
index - The 0-based index at which the mark will be set.
mark - The LineMark to set.
Returns:
The 0-based index at which the mark was added.

removeLineMark

public int removeLineMark(LineMark mark)
Remove a LineMark.
Parameters:
mark - The LineMark to remove.
Returns:
The 0-based index from which the mark was removed.

getLineMarks

public LineMark[] getLineMarks(int index)
Get the list of LineMarks on a particular line.
Parameters:
index - The 0-based index for which to retrieve the marks.
Returns:
An array of LineMarks.

getMarkIndex

public int getMarkIndex(LineMark mark)
Get the 0-based index on which a particular mark exists.
Parameters:
mark - The LineMark to look up.
Returns:
The 0-based index on which the mark exists.

createLeafElement

protected javax.swing.text.Element createLeafElement(javax.swing.text.Element parent,
                                                     javax.swing.text.AttributeSet a,
                                                     int p0,
                                                     int p1)
Creates a document leaf element. Hook through which elements are created to represent the document structure. Because this implementation keeps structure and content seperate, elements grow automatically when content is extended so splits of existing elements follow. The document itself gets to decide how to generate elements to give flexibility in the type of elements used.
Overrides:
createLeafElement in class javax.swing.text.AbstractDocument
Parameters:
parent - the parent element
a - the attributes for the element
p0 - the beginning of the range >= 0
p1 - the end of the range >= p0
Returns:
the new element