com.borland.primetime.editor
Class EditorDocument

java.lang.Object
  |
  +--javax.swing.text.AbstractDocument
        |
        +--javax.swing.text.PlainDocument
              |
              +--com.borland.primetime.editor.EditorDocument
All Implemented Interfaces:
javax.swing.text.Document, java.io.Serializable

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
          The default scanner that this document uses
protected  java.lang.ref.WeakReference docRef
          Create a weak reference to ourself
static LineMark[] EMPTY_MARKLIST
          The empty line mark array used for functions that have to return an array of line marks at times when there really are no line marks
static java.lang.String I18NProperty
          We need to create a copy of this variable which is defined final private in AbstractDocument
protected  EditorDocument.MarkList markList
          The list of linemarks that this document has
static java.lang.Object NOMARK
          The object that indicates that there is no mark on a line
protected  Scanner scanner
          The actual scanner that this document uses
protected  BasicStyleMap styleMap
          The style map used for syntax highlighting
protected  JBUndoManager undoManager
          The undo manager this document uses
 
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
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
EditorDocument()
          Create a new document
 
Method Summary
 void changeTabSize(java.lang.Object newTabSize)
          The tab size of the document has to be changed.
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 without checking if the linemarks are specific to a single editorPane.
 LineMark[] getLineMarks(int index, EditorPane editor)
          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()
          Get the reference to this document
 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 occurrences 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.
 void setLightweightLineMarks(int[] indexes, LineMark mark, EditorPane editor)
          Set a LineMark on an array of lines.
 int setLineMark(int index, LineMark mark)
          Set a LineMark on a particular line.
 int setLineMark(int index, LineMark mark, EditorPane editor)
          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, getListeners, 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
The default scanner that this document uses

docRef

protected java.lang.ref.WeakReference docRef
Create a weak reference to ourself

I18NProperty

public static final java.lang.String I18NProperty
We need to create a copy of this variable which is defined final private in AbstractDocument

styleMap

protected BasicStyleMap styleMap
The style map used for syntax highlighting

scanner

protected Scanner scanner
The actual scanner that this document uses

undoManager

protected JBUndoManager undoManager
The undo manager this document uses

EMPTY_MARKLIST

public static final LineMark[] EMPTY_MARKLIST
The empty line mark array used for functions that have to return an array of line marks at times when there really are no line marks

NOMARK

public static final java.lang.Object NOMARK
The object that indicates that there is no mark on a line

markList

protected EditorDocument.MarkList markList
The list of linemarks that this document has
Constructor Detail

EditorDocument

public EditorDocument()
Create a new document
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()
Get the reference to this document
Returns:
a weak reference to this document

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
Parameters:
e - The document event that triggered this insert update

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
Parameters:
e - The document event that triggered this remove update

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
Parameters:
e - The document event that triggered this change update

changeTabSize

public void changeTabSize(java.lang.Object newTabSize)
The tab size of the document has to be changed. Tell all listeners that something has changed.
Parameters:
newTabSize - Integer object describing the new tab size

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. The mark will be tied to the document, and all editors viewing this document will display the line mark.
Parameters:
indexes - An array of 0-based index entries at which the specified lightweight mark will be set.
mark - The lightweight LineMark to set.

setLightweightLineMarks

public void setLightweightLineMarks(int[] indexes,
                                    LineMark mark,
                                    EditorPane editor)
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. This function allows the mark to be only visible in a single editorPane
Parameters:
indexes - An array of 0-based index entries at which the specified lightweight mark will be set.
mark - The lightweight LineMark to set.
editor - If not null, the mark will only be visible in the specified editor pane.

removeLightweightLineMarks

public void removeLightweightLineMarks(LineMark mark)
Remove all occurrences 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. The LineMark will be tied to the document and all editors viewing that document will display the same line mark.
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.

setLineMark

public int setLineMark(int index,
                       LineMark mark,
                       EditorPane editor)
Set a LineMark on a particular line. This version allows the mark to be set for one particular editor instance.
Parameters:
index - The 0-based index at which the mark will be set.
mark - The LineMark to set.
editor - If not null, the mark will only be visible in the specified editor pane.
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 without checking if the linemarks are specific to a single editorPane.
Parameters:
index - The 0-based index for which to retrieve the marks.
Returns:
An array of LineMarks.

getLineMarks

public LineMark[] getLineMarks(int index,
                               EditorPane editor)
Get the list of LineMarks on a particular line. Check if the linemarks are specific to single editorPanes and if they are, make sure they belong to the incoming editorPane parameter. Do not call this function with an editorPane parameter that is null or invalid.
Parameters:
index - The 0-based index for which to retrieve the marks.
editor - If a lineMark is editor specific, make sure it belongs to this editor.
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