JIDE 3.5.15

com.jidesoft.editor
Class SyntaxDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.PlainDocument
          extended by com.jidesoft.editor.SyntaxDocument
All Implemented Interfaces:
LineBreak, Serializable, Document
Direct Known Subclasses:
LazyLoadDocument

public class SyntaxDocument
extends PlainDocument
implements LineBreak

A document implementation that can be tokenized by the syntax highlighting system.

Version:
$Id: SyntaxDocument.java,v 1.14 1999/12/13 03:40:30 sp Exp $
Author:
Slava Pestov
See Also:
Serialized Form

Nested Class Summary
protected  class SyntaxDocument.MyUndoableEditListener
           
 
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
 
Field Summary
protected  CompoundEdit _compoundEdit
           
protected  int _compoundEditCount
           
protected  UndoManager _undoManager
           
protected  TokenMarker tokenMarker
           
 
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 com.jidesoft.editor.LineBreak
CR, LF, LINE_BREAK_CODE_EDITOR, LINE_BREAK_MAC, LINE_BREAK_MIXED, LINE_BREAK_PC, LINE_BREAK_UNIX, LINE_BREAK_UNKNOWN, STRING_CR, STRING_CR_LF, STRING_LF
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
SyntaxDocument()
           
 
Method Summary
 void addUndoableEdit(UndoableEdit edit)
          Adds an undoable edit to this document's undo list.
 void beginCompoundEdit()
          Starts a compound edit that can be undone in one operation.
 char charAt(int offset)
           
static int convertLineBreaks(String text, StringBuffer buffer)
           
static int convertLineBreaks(String text, StringBuffer buffer, String newLineBreak)
           
 void endCompoundEdit()
          Ends a compound edit that can be undone in one operation.
 int findNext(String[] s, int fromIndex, int toIndex, boolean caseSensitive)
           
 int findNext(String[] s, int fromIndex, int toIndex, boolean caseSensitive, boolean wholeWords)
           
 int findPrevious(String[] s, int fromIndex, int toIndex, boolean caseSensitive)
           
 int findPrevious(String[] s, int fromIndex, int toIndex, boolean caseSensitive, boolean wholeWords)
           
protected  void fireInsertUpdate(DocumentEvent evt)
          We overwrite this method to update the token marker state immediately so that any event listeners get a consistent token marker.
protected  void fireRemoveUpdate(DocumentEvent evt)
          We overwrite this method to update the token marker state immediately so that any event listeners get a consistent token marker.
protected  void fireRemovingUpdate(DocumentEvent evt)
           
 int getLineCount()
           
 int getLineEndOffset(int line)
           
 int getLineLength(int line)
           
 int getLineNumber(int offset)
           
 int getLineStartOffset(int line)
           
 String getLineText(int offset)
           
 int getLookupBufferSize()
           
 TokenMarker getTokenMarker()
          Returns the token marker that is to be used to split lines of this document up into tokens.
 UndoManager getUndoManager()
           
protected  boolean isInCommentOrLiteral(int offset)
          Check if the character in the offset is inside a comment or literal.
 boolean isLineLoaded(int line)
           
 boolean isOffsetLoaded(int offset)
           
protected  boolean isWordChar(char ch)
          Check if the ch is a valid word char to determine if Searchable#fromStart() and Searchable#toEnd() is satisfied.
 void redo()
           
protected  void removeUpdate(AbstractDocument.DefaultDocumentEvent changed)
           
 void setLookupBufferSize(int lookupBufferSize)
           
 void setTokenMarker(TokenMarker tm)
          Sets the token marker that is to be used to split lines of this document up into tokens.
 void setUndoManager(UndoManager u)
           
 void tokenizeLines()
          Reparses the document, by passing all lines to the token marker.
 void tokenizeLines(int start, int len)
          Reparses the document, by passing the specified lines to the token marker.
 void undo()
           
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertString, insertUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_undoManager

protected UndoManager _undoManager

_compoundEdit

protected CompoundEdit _compoundEdit

_compoundEditCount

protected int _compoundEditCount

tokenMarker

protected TokenMarker tokenMarker
Constructor Detail

SyntaxDocument

public SyntaxDocument()
Method Detail

getLineText

public String getLineText(int offset)
                   throws BadLocationException
Throws:
BadLocationException

getLineNumber

public int getLineNumber(int offset)

undo

public void undo()

redo

public void redo()

getUndoManager

public UndoManager getUndoManager()

setUndoManager

public void setUndoManager(UndoManager u)

getTokenMarker

public TokenMarker getTokenMarker()
Returns the token marker that is to be used to split lines of this document up into tokens. May return null if this document is not to be colorized.

Returns:
the token marker.

setTokenMarker

public void setTokenMarker(TokenMarker tm)
Sets the token marker that is to be used to split lines of this document up into tokens. May throw an exception if this is not supported for this type of document.

Parameters:
tm - The new token marker

tokenizeLines

public void tokenizeLines()
Reparses the document, by passing all lines to the token marker. This should be called after the document is first loaded.


tokenizeLines

public void tokenizeLines(int start,
                          int len)
Reparses the document, by passing the specified lines to the token marker. This should be called after a large quantity of text is first inserted.

Parameters:
start - The first line to parse
len - The number of lines, after the first one to parse

isInCommentOrLiteral

protected boolean isInCommentOrLiteral(int offset)
                                throws BadLocationException
Check if the character in the offset is inside a comment or literal.

Parameters:
offset - the offset to check
Returns:
true if it is inside a comment or literal. Otherwise false.
Throws:
BadLocationException - if the location is not correct.

beginCompoundEdit

public void beginCompoundEdit()
Starts a compound edit that can be undone in one operation. Subclasses that implement undo should override this method; this class has no undo functionality so this method is empty.


endCompoundEdit

public void endCompoundEdit()
Ends a compound edit that can be undone in one operation. Subclasses that implement undo should override this method; this class has no undo functionality so this method is empty.


addUndoableEdit

public void addUndoableEdit(UndoableEdit edit)
Adds an undoable edit to this document's undo list. The edit should be ignored if something is currently being undone.

Parameters:
edit - The undoable edit

fireInsertUpdate

protected void fireInsertUpdate(DocumentEvent evt)
We overwrite this method to update the token marker state immediately so that any event listeners get a consistent token marker.

Overrides:
fireInsertUpdate in class AbstractDocument

fireRemoveUpdate

protected void fireRemoveUpdate(DocumentEvent evt)
We overwrite this method to update the token marker state immediately so that any event listeners get a consistent token marker.

Overrides:
fireRemoveUpdate in class AbstractDocument

convertLineBreaks

public static int convertLineBreaks(String text,
                                    StringBuffer buffer)

convertLineBreaks

public static int convertLineBreaks(String text,
                                    StringBuffer buffer,
                                    String newLineBreak)

charAt

public char charAt(int offset)
            throws BadLocationException
Throws:
BadLocationException

removeUpdate

protected void removeUpdate(AbstractDocument.DefaultDocumentEvent changed)
Overrides:
removeUpdate in class PlainDocument

fireRemovingUpdate

protected void fireRemovingUpdate(DocumentEvent evt)

getLookupBufferSize

public int getLookupBufferSize()

setLookupBufferSize

public void setLookupBufferSize(int lookupBufferSize)

findNext

public int findNext(String[] s,
                    int fromIndex,
                    int toIndex,
                    boolean caseSensitive)

findNext

public int findNext(String[] s,
                    int fromIndex,
                    int toIndex,
                    boolean caseSensitive,
                    boolean wholeWords)

isWordChar

protected boolean isWordChar(char ch)
Check if the ch is a valid word char to determine if Searchable#fromStart() and Searchable#toEnd() is satisfied.

Parameters:
ch - the character
Returns:
true if the ch is a valid character in a word. Otherwise false.
Since:
3.5.2

findPrevious

public int findPrevious(String[] s,
                        int fromIndex,
                        int toIndex,
                        boolean caseSensitive)

findPrevious

public int findPrevious(String[] s,
                        int fromIndex,
                        int toIndex,
                        boolean caseSensitive,
                        boolean wholeWords)

isOffsetLoaded

public boolean isOffsetLoaded(int offset)

isLineLoaded

public boolean isLineLoaded(int line)

getLineCount

public int getLineCount()

getLineStartOffset

public int getLineStartOffset(int line)

getLineEndOffset

public int getLineEndOffset(int line)

getLineLength

public int getLineLength(int line)

JIDE 3.5.15