站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

BaseDocument (Editor Library) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.lib/1 1.14.0 3

org.netbeans.editor
Class BaseDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by org.netbeans.editor.BaseDocument
All Implemented Interfaces:
Serializable, EventListener, Document, AtomicLockDocument, SettingsChangeListener
Direct Known Subclasses:
GuardedDocument

public class BaseDocument
extends AbstractDocument
implements SettingsChangeListener, AtomicLockDocument

Document implementation

See Also:
Serialized Form

Nested Class Summary
protected static class BaseDocument.LazyPropertyMap
           
static interface BaseDocument.PropertyEvaluator
          Property evaluator is useful for lazy evaluation of properties of the document when javax.swing.text.Document#getProperty(java.lang.String) is called.
 
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
static String BLOCKS_FINDER_PROP
          Highlight search finder property.
protected  Element defaultRootElem
          Default element - lazily inited
static String FILE_NAME_PROP
          File name property
static String ID_PROP
          Registry identification property
protected  boolean inited
           
static String KIT_CLASS_PROP
          Kit class property.
static String LINE_BATCH_SIZE
          Size of the line batch.
static String LINE_LIMIT_PROP
          Maximum line width encountered during the initial read operation.
protected  org.netbeans.editor.LineRootElement lineRootElement
          Root element of line elements representation
static String LS_CR
          Line separator is marked by CR (Macintosh)
static String LS_CRLF
          Line separator is marked by CR and LF (Windows)
static String LS_LF
          Line separator is marked by LF (Unix)
protected  boolean modified
           
static String READ_LINE_SEPARATOR_PROP
          Line separator property for reading files in
static String STRING_BWD_FINDER_PROP
          String backward finder property
static String STRING_FINDER_PROP
          String forward finder property
static ThreadLocal THREAD_LOCAL_LOCK_DEPTH
           
static String UNDO_MANAGER_PROP
          Undo manager property.
static String WRAP_SEARCH_MARK_PROP
          Wrap search mark property
static String WRITE_LINE_SEPARATOR_PROP
          Line separator property for writing content into files.
 
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
BaseDocument(Class kitClass, boolean addToRegistry)
          Create base document with a specified syntax.
 
Method Summary
 void addAtomicLockListener(AtomicLockListener l)
           
 void addDocumentListener(DocumentListener listener)
           
 boolean addLayer(DrawLayer layer, int visibility)
          Deprecated. Please use Highlighting SPI instead, for details see Editor Library 2.
 void atomicLock()
           
 void atomicUndo()
           
 void atomicUnlock()
           
 void breakAtomicLock()
          Break the atomic lock so that doc is no longer in atomic mode.
 void checkTrailingSpaces(int offset)
           
protected  BaseDocumentEvent createDocumentEvent(int pos, int length, DocumentEvent.EventType type)
           
protected  Dictionary createDocumentProperties(Dictionary origDocumentProperties)
           
 Position createPosition(int offset, Position.Bias bias)
          Create biased position in document
 void extWriteLock()
          Extended write locking of the document allowing reentrant write lock acquiring.
 void extWriteUnlock()
          Extended write unlocking.
 int find(Finder finder, int startPos, int limitPos)
          Find something in document using a finder.
 DrawLayer findLayer(String layerName)
          Deprecated. Please use Highlighting SPI instead, for details see Editor Library 2.
protected  void fireChangedUpdate(DocumentEvent e)
           
protected  void fireInsertUpdate(DocumentEvent e)
           
protected  void fireRemoveUpdate(DocumentEvent e)
           
protected  void fireUndoableEditUpdate(UndoableEditEvent e)
           
 Annotations getAnnotations()
          Returns object which represent list of annotations which are attached to this document.
protected  int getAtomicDepth()
           
 char[] getChars(int[] block)
           
 void getChars(int pos, char[] ret, int offset, int len)
           
 char[] getChars(int pos, int len)
           
 Element getDefaultRootElement()
          Return default root element
 Formatter getFormatter()
          Get the formatter for this document.
 Class getKitClass()
           
 Element getParagraphElement(int pos)
           
 Element[] getRootElements()
          Return array of root elements - usually only one
 int getShiftWidth()
          Get the width of one indentation level.
 SyntaxSupport getSyntaxSupport()
           
 int getTabSize()
          Get the number of spaces the TAB character ('\t') visually represents.
 CharSeq getText()
           
 String getText(int[] block)
           
 void insertString(int offset, String text, AttributeSet a)
          Inserts string into document
protected  void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
           
 void invalidateSyntaxMarks()
          Invalidate the state-infos in all the syntax-marks in the whole document.
 boolean isAtomicLock()
          Is the document currently atomically locked? It's not synced as this method must be called only from writer thread.
 boolean isIdentifierPart(char ch)
           
 boolean isModified()
          Was the document modified by either insert/remove but not the initial read)?
 boolean isWhitespace(char ch)
           
protected  void postRemoveUpdate(AbstractDocument.DefaultDocumentEvent chng)
           
protected  void preInsertCheck(int offset, String text, AttributeSet a)
          This method is called automatically before the document insertion occurs and can be used to revoke the insertion before it occurs by throwing the BadLocationException.
protected  void preInsertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
           
protected  void preRemoveCheck(int offset, int len)
          This method is called automatically before the document removal occurs and can be used to revoke the removal before it occurs by throwing the BadLocationException.
 void print(PrintContainer container)
           
 void print(PrintContainer container, boolean usePrintColoringMap, boolean lineNumberEnabled, int startOffset, int endOffset)
          Print into given container.
 void print(PrintContainer container, boolean usePrintColoringMap, Boolean lineNumberEnabled, int startOffset, int endOffset)
          Print into given container.
 int processText(TextBatchProcessor tbp, int startPos, int endPos)
          Perform any generic text processing.
 void read(Reader reader, int pos)
          Insert contents of reader at specified position into document.
 void remove(int offset, int len)
          Removes portion of a document
 void removeAtomicLockListener(AtomicLockListener l)
           
 void removeDocumentListener(DocumentListener listener)
           
protected  void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
           
 void render(Runnable r)
          Runs the runnable under read lock.
 void repaintBlock(int startOffset, int endOffset)
          Fire the change event to repaint the given block of text.
 void resetUndoMerge()
          This method prohibits merging of the next document modification with the previous one even if it would be normally possible.
 void runAtomic(Runnable r)
          Runs the runnable under write lock.
 void runAtomicAsUser(Runnable r)
          Runs the runnable under write lock.
 void setPostModificationDocumentListener(DocumentListener listener)
          Set or clear a special document listener that gets notified after the modification and that is allowed to do further mutations to the document.
 void settingsChange(SettingsChangeEvent evt)
          Called when settings were changed.
 String toString()
           
 String toStringDetail()
          Detailed debug info about the document
 void write(Writer writer, int pos, int len)
          Write part of the document into specified writer.
 
Methods inherited from class javax.swing.text.AbstractDocument
addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getStartPosition, getText, getText, getUndoableEditListeners, putProperty, readLock, readUnlock, removeUndoableEditListener, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.text.Document
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getStartPosition, getText, getText, putProperty, removeUndoableEditListener
 

Field Detail

ID_PROP

public static final String ID_PROP
Registry identification property

See Also:
Constant Field Values

READ_LINE_SEPARATOR_PROP

public static final String READ_LINE_SEPARATOR_PROP
Line separator property for reading files in

See Also:
Constant Field Values

WRITE_LINE_SEPARATOR_PROP

public static final String WRITE_LINE_SEPARATOR_PROP
Line separator property for writing content into files. If not set the writing defaults to the READ_LINE_SEPARATOR_PROP.

See Also:
Constant Field Values

FILE_NAME_PROP

public static final String FILE_NAME_PROP
File name property

See Also:
Constant Field Values

WRAP_SEARCH_MARK_PROP

public static final String WRAP_SEARCH_MARK_PROP
Wrap search mark property

See Also:
Constant Field Values

UNDO_MANAGER_PROP

public static final String UNDO_MANAGER_PROP
Undo manager property. This can be used to implement undo in a simple way. Default undo and redo actions try to get this property and perform undo and redo through it.

See Also:
Constant Field Values

KIT_CLASS_PROP

public static final String KIT_CLASS_PROP
Kit class property. This can become useful for getting the settings that logicaly belonging to the document.

See Also:
Constant Field Values

STRING_FINDER_PROP

public static final String STRING_FINDER_PROP
String forward finder property

See Also:
Constant Field Values

STRING_BWD_FINDER_PROP

public static final String STRING_BWD_FINDER_PROP
String backward finder property

See Also:
Constant Field Values

BLOCKS_FINDER_PROP

public static final String BLOCKS_FINDER_PROP
Highlight search finder property.

See Also:
Constant Field Values

LINE_LIMIT_PROP

public static final String LINE_LIMIT_PROP
Maximum line width encountered during the initial read operation. This is filled by Analyzer and used by UI to set the correct initial width of the component. Values: java.lang.Integer

See Also:
Constant Field Values

LINE_BATCH_SIZE

public static final String LINE_BATCH_SIZE
Size of the line batch. Line batch can be used at various places especially when processing lines by syntax scanner.

See Also:
Constant Field Values

LS_CR

public static final String LS_CR
Line separator is marked by CR (Macintosh)

See Also:
Constant Field Values

LS_LF

public static final String LS_LF
Line separator is marked by LF (Unix)

See Also:
Constant Field Values

LS_CRLF

public static final String LS_CRLF
Line separator is marked by CR and LF (Windows)

See Also:
Constant Field Values

THREAD_LOCAL_LOCK_DEPTH

public static final ThreadLocal THREAD_LOCAL_LOCK_DEPTH

inited

protected boolean inited

modified

protected boolean modified

defaultRootElem

protected Element defaultRootElem
Default element - lazily inited


lineRootElement

protected org.netbeans.editor.LineRootElement lineRootElement
Root element of line elements representation

Constructor Detail

BaseDocument

public BaseDocument(Class kitClass,
                    boolean addToRegistry)
Create base document with a specified syntax.

Parameters:
kitClass - class used to initialize this document with proper settings category based on the editor kit for which this document is created
syntax - syntax scanner to use with this document
Method Detail

getText

public CharSeq getText()

settingsChange

public void settingsChange(SettingsChangeEvent evt)
Called when settings were changed. The method is called also in constructor, so the code must count with the evt being null.

Specified by:
settingsChange in interface SettingsChangeListener

getFormatter

public Formatter getFormatter()
Get the formatter for this document.


getSyntaxSupport

public SyntaxSupport getSyntaxSupport()

processText

public int processText(TextBatchProcessor tbp,
                       int startPos,
                       int endPos)
                throws BadLocationException
Perform any generic text processing. The advantage of this method is that it allows the text to processed in line batches. The initial size of the batch is given by the SettingsNames.LINE_BATCH_SIZE. The TextBatchProcessor.processTextBatch() method is called for every text batch. If the method returns true, it means the processing should continue with the next batch of text which will have double line count compared to the previous one. This guarantees there will be not too many batches so the processing should be more efficient.

Parameters:
tbp - text batch processor to be used to process the text batches
startPos - starting position of the processing.
endPos - ending position of the processing. This can be -1 to signal the end of document. If the endPos is lower than startPos then the batches are created in the backward direction.
Returns:
the returned value from the last tpb.processTextBatch() call. The -1 will be returned for (startPos == endPos).
Throws:
BadLocationException

isIdentifierPart

public boolean isIdentifierPart(char ch)

isWhitespace

public boolean isWhitespace(char ch)

insertString

public void insertString(int offset,
                         String text,
                         AttributeSet a)
                  throws BadLocationException
Inserts string into document

Specified by:
insertString in interface Document
Overrides:
insertString in class AbstractDocument
Throws:
BadLocationException

checkTrailingSpaces

public void checkTrailingSpaces(int offset)

remove

public void remove(int offset,
                   int len)
            throws BadLocationException
Removes portion of a document

Specified by:
remove in interface Document
Overrides:
remove in class AbstractDocument
Throws:
BadLocationException

preInsertCheck

protected void preInsertCheck(int offset,
                              String text,
                              AttributeSet a)
                       throws BadLocationException
This method is called automatically before the document insertion occurs and can be used to revoke the insertion before it occurs by throwing the BadLocationException.

Parameters:
offset - position where the insertion will be done
text - string to be inserted
a - attributes of the inserted text
Throws:
BadLocationException

preRemoveCheck

protected void preRemoveCheck(int offset,
                              int len)
                       throws BadLocationException
This method is called automatically before the document removal occurs and can be used to revoke the removal before it occurs by throwing the BadLocationException.

Parameters:
offset - position where the insertion will be done
len - length of the removal
Throws:
BadLocationException

insertUpdate

protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
                            AttributeSet attr)
Overrides:
insertUpdate in class AbstractDocument

preInsertUpdate

protected void preInsertUpdate(AbstractDocument.DefaultDocumentEvent chng,
                               AttributeSet attr)

removeUpdate

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

postRemoveUpdate

protected void postRemoveUpdate(AbstractDocument.DefaultDocumentEvent chng)
Overrides:
postRemoveUpdate in class AbstractDocument

getText

public String getText(int[] block)
               throws BadLocationException
Throws:
BadLocationException

getChars

public char[] getChars(int pos,
                       int len)
                throws BadLocationException
Parameters:
pos - position of the first character to get.
len - number of characters to obtain.
Returns:
array with the requested characters.
Throws:
BadLocationException

getChars

public char[] getChars(int[] block)
                throws BadLocationException
Parameters:
block - two-element array with starting and ending offset
Returns:
array with the requested characters.
Throws:
BadLocationException

getChars

public void getChars(int pos,
                     char[] ret,
                     int offset,
                     int len)
              throws BadLocationException
Parameters:
pos - position of the first character to get.
ret - destination array
offset - offset in the destination array.
len - number of characters to obtain.
Throws:
BadLocationException

find

public int find(Finder finder,
                int startPos,
                int limitPos)
         throws BadLocationException
Find something in document using a finder.

Parameters:
finder - finder to be used for the search
startPos - position in the document where the search will start
limitPos - position where the search will be end with reporting that nothing was found.
Throws:
BadLocationException

repaintBlock

public void repaintBlock(int startOffset,
                         int endOffset)
Fire the change event to repaint the given block of text.


print

public void print(PrintContainer container)

print

public void print(PrintContainer container,
                  boolean usePrintColoringMap,
                  boolean lineNumberEnabled,
                  int startOffset,
                  int endOffset)
Print into given container.

Parameters:
container - printing container into which the printing will be done.
usePrintColoringMap - use printing coloring settings instead of the regular ones.
lineNumberEnabled - if set to false the line numbers will not be printed. If set to true the visibility of line numbers depends on the settings for the line number visibility.
startOffset - start offset of text to print
endOffset - end offset of text to print

print

public void print(PrintContainer container,
                  boolean usePrintColoringMap,
                  Boolean lineNumberEnabled,
                  int startOffset,
                  int endOffset)
Print into given container.

Parameters:
container - printing container into which the printing will be done.
usePrintColoringMap - use printing coloring settings instead of the regular ones.
lineNumberEnabled - if null, the visibility of line numbers is the same as it is given by settings for the line number visibility, otherwise the visibility equals the boolean value of the parameter
startOffset - start offset of text to print
endOffset - end offset of text to print

createPosition

public Position createPosition(int offset,
                               Position.Bias bias)
                        throws BadLocationException
Create biased position in document

Throws:
BadLocationException

getRootElements

public Element[] getRootElements()
Return array of root elements - usually only one

Specified by:
getRootElements in interface Document
Overrides:
getRootElements in class AbstractDocument

getDefaultRootElement

public Element getDefaultRootElement()
Return default root element

Specified by:
getDefaultRootElement in interface Document
Specified by:
getDefaultRootElement in class AbstractDocument

render

public void render(Runnable r)
Runs the runnable under read lock.

Specified by:
render in interface Document
Overrides:
render in class AbstractDocument

runAtomic

public void runAtomic(Runnable r)
Runs the runnable under write lock. This is a stronger version of the runAtomicAsUser() method, because if there any locked sections in the documents this methods breaks the modification locks and modifies the document. If there are any excpeptions thrown during the processing of the runnable, all the document modifications are rolled back automatically.


runAtomicAsUser

public void runAtomicAsUser(Runnable r)
Runs the runnable under write lock. If there are any excpeptions thrown during the processing of the runnable, all the document modifications are rolled back automatically.


read

public void read(Reader reader,
                 int pos)
          throws IOException,
                 BadLocationException
Insert contents of reader at specified position into document.

Parameters:
reader - reader from which data will be read
pos - on which position that data will be inserted
Throws:
IOException
BadLocationException

write

public void write(Writer writer,
                  int pos,
                  int len)
           throws IOException,
                  BadLocationException
Write part of the document into specified writer.

Parameters:
writer - writer into which data will be written.
pos - from which position get the data
len - how many characters write
Throws:
IOException
BadLocationException

invalidateSyntaxMarks

public void invalidateSyntaxMarks()
Invalidate the state-infos in all the syntax-marks in the whole document. The Syntax can call this method if it changes its internal state in the way that affects the future returned tokens. The syntax-state-info in all the marks is reset and it will be lazily restored when necessary.


getTabSize

public int getTabSize()
Get the number of spaces the TAB character ('\t') visually represents. This is related to SettingsNames.TAB_SIZE setting.


getShiftWidth

public int getShiftWidth()
Get the width of one indentation level. The algorithm first checks whether there's a value for the INDENT_SHIFT_WIDTH setting. If so it uses it, otherwise it uses formatter.getSpacesPerTab().

See Also:
getTabSize(), Formatter.getSpacesPerTab()

getKitClass

public final Class getKitClass()

resetUndoMerge

public void resetUndoMerge()
This method prohibits merging of the next document modification with the previous one even if it would be normally possible.


fireChangedUpdate

protected void fireChangedUpdate(DocumentEvent e)
Overrides:
fireChangedUpdate in class AbstractDocument

fireInsertUpdate

protected void fireInsertUpdate(DocumentEvent e)
Overrides:
fireInsertUpdate in class AbstractDocument

fireRemoveUpdate

protected void fireRemoveUpdate(DocumentEvent e)
Overrides:
fireRemoveUpdate in class AbstractDocument

fireUndoableEditUpdate

protected void fireUndoableEditUpdate(UndoableEditEvent e)
Overrides:
fireUndoableEditUpdate in class AbstractDocument

extWriteLock

public final void extWriteLock()
Extended write locking of the document allowing reentrant write lock acquiring.


extWriteUnlock

public final void extWriteUnlock()
Extended write unlocking.

See Also:
extWriteLock()

atomicLock

public final void atomicLock()
Specified by:
atomicLock in interface AtomicLockDocument

atomicUnlock

public final void atomicUnlock()
Specified by:
atomicUnlock in interface AtomicLockDocument

isAtomicLock

public final boolean isAtomicLock()
Is the document currently atomically locked? It's not synced as this method must be called only from writer thread.


breakAtomicLock

public final void breakAtomicLock()
Break the atomic lock so that doc is no longer in atomic mode. All the performed changes are rolled back automatically. Even after calling this method, the atomicUnlock() must still be called. This method is not synced as it must be called only from writer thread.


atomicUndo

public void atomicUndo()
Specified by:
atomicUndo in interface AtomicLockDocument

addAtomicLockListener

public void addAtomicLockListener(AtomicLockListener l)
Specified by:
addAtomicLockListener in interface AtomicLockDocument

removeAtomicLockListener

public void removeAtomicLockListener(AtomicLockListener l)
Specified by:
removeAtomicLockListener in interface AtomicLockDocument

getAtomicDepth

protected final int getAtomicDepth()

addDocumentListener

public void addDocumentListener(DocumentListener listener)
Specified by:
addDocumentListener in interface Document
Overrides:
addDocumentListener in class AbstractDocument

removeDocumentListener

public void removeDocumentListener(DocumentListener listener)
Specified by:
removeDocumentListener in interface Document
Overrides:
removeDocumentListener in class AbstractDocument

createDocumentEvent

protected BaseDocumentEvent createDocumentEvent(int pos,
                                                int length,
                                                DocumentEvent.EventType type)

setPostModificationDocumentListener

public void setPostModificationDocumentListener(DocumentListener listener)
Set or clear a special document listener that gets notified after the modification and that is allowed to do further mutations to the document.
Additional mutations will be made in a single atomic transaction with an original mutation.
This functionality may be used for example by code templates to synchronize other regions of the document with the one currently being modified.
If there is an active post modification document listener then each document modification is encapsulated in an atomic lock transaction automatically to allow further changes inside a transaction.


isModified

public boolean isModified()
Was the document modified by either insert/remove but not the initial read)?


findLayer

public DrawLayer findLayer(String layerName)
Deprecated. Please use Highlighting SPI instead, for details see Editor Library 2.

Get the layer with the specified name. Using of DrawLayers has been deprecated.


addLayer

public boolean addLayer(DrawLayer layer,
                        int visibility)
Deprecated. Please use Highlighting SPI instead, for details see Editor Library 2.

Using of DrawLayers has been deprecated.


getParagraphElement

public Element getParagraphElement(int pos)
Specified by:
getParagraphElement in class AbstractDocument

getAnnotations

public Annotations getAnnotations()
Returns object which represent list of annotations which are attached to this document.

Returns:
object which represent attached annotations

createDocumentProperties

protected Dictionary createDocumentProperties(Dictionary origDocumentProperties)

toString

public String toString()
Overrides:
toString in class Object

toStringDetail

public String toStringDetail()
Detailed debug info about the document


org.netbeans.modules.editor.lib/1 1.14.0 3

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.