public class BaseDocument extends AbstractDocument implements AtomicLockDocument, org.netbeans.api.editor.document.LineDocument, org.netbeans.api.editor.document.CustomUndoDocument
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseDocument.LazyPropertyMap |
static interface |
BaseDocument.PropertyEvaluator
Property evaluator is useful for lazy evaluation
of properties of the document when
Document.getProperty(Object)
is called. |
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
Modifier and Type | Field and Description |
---|---|
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 |
FORMATTER
Name of the formatter setting.
|
static String |
ID_PROP
Registry identification property
|
protected boolean |
inited |
static String |
KIT_CLASS_PROP
Kit class property.
|
static String |
LINE_BATCH_SIZE
Deprecated.
property no longer populated; deprecated without replacement.
|
static String |
LINE_LIMIT_PROP
Deprecated.
property no longer populated; deprecated without replacement.
|
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)
|
static String |
MIME_TYPE_PROP
Mime type of the document.
|
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 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.
|
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
StreamDescriptionProperty, TitleProperty
Constructor and Description |
---|
BaseDocument(boolean addToRegistry,
String mimeType)
Creates a new document.
|
BaseDocument(Class kitClass,
boolean addToRegistry)
Deprecated.
Use of editor kit's implementation classes is deprecated
in favor of mime types.
|
Modifier and Type | Method and Description |
---|---|
void |
addAtomicLockListener(org.netbeans.api.editor.document.AtomicLockListener l) |
void |
addAtomicLockListener(AtomicLockListener l)
Deprecated.
use LineDocumentUtils.as(doc, AtomicLockDocument.class).addAtomicLockListener(l);
|
void |
addDocumentListener(DocumentListener listener) |
void |
addPostModificationDocumentListener(DocumentListener listener)
Add a special document listener that gets notified
after the modification and that is allowed to do further
mutations to the document.
|
void |
addUndoableEdit(UndoableEdit edit)
Add a custom undoable edit during atomic lock of the document.
|
void |
addUndoableEditListener(UndoableEditListener listener) |
void |
addUpdateDocumentListener(DocumentListener listener)
Add a special document listener that gets notified after physical
insertion/removal has been done but when the document event
(which is a
CompoundEdit ) is still
opened for extra undoable edits that can be added by the clients (listeners). |
void |
atomicLock()
Deprecated.
Please use
BaseDocument.runAtomic(java.lang.Runnable) instead. |
void |
atomicUndo() |
void |
atomicUnlock()
Deprecated.
Please use
BaseDocument.runAtomic(java.lang.Runnable) instead. |
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.
|
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
|
Class |
getKitClass()
Deprecated.
Don't use implementation class of editor kits. Use mime type,
MimePath and MimeLookup . |
Element |
getParagraphElement(int pos) |
Element[] |
getRootElements()
Return array of root elements - usually only one
|
int |
getShiftWidth()
Deprecated.
Please use Editor Indentation API instead, for details see
Editor Indentation.
|
SyntaxSupport |
getSyntaxSupport()
Deprecated.
Please use Lexer instead, for details see
Lexer.
|
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 attrs)
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 |
isModifiable()
When called within runnable of
BaseDocument.runAtomic(java.lang.Runnable)
this method returns true if the document can be mutated or false
if any attempt of inserting/removing text would throw GuardedException . |
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 length)
Removes portion of a document
|
void |
removeAtomicLockListener(org.netbeans.api.editor.document.AtomicLockListener l) |
void |
removeAtomicLockListener(AtomicLockListener l)
Deprecated.
use LineDocumentUtils.as(doc, AtomicLockDocument.class).removeAtomicLockListener(l);
|
void |
removeDocumentListener(DocumentListener listener) |
void |
removePostModificationDocumentListener(DocumentListener listener) |
protected void |
removeUpdate(AbstractDocument.DefaultDocumentEvent chng) |
void |
removeUpdateDocumentListener(DocumentListener listener) |
void |
render(Runnable r)
Runs the runnable under read lock.
|
void |
repaintBlock(int startOffset,
int endOffset)
Deprecated.
Please use
JTextComponent.getUI().damageRange() instead. |
void |
replace(int offset,
int length,
String text,
AttributeSet attrs) |
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)
Deprecated.
Use addPostModificationDocumentListener(DocumentListener)
|
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.
|
createBranchElement, createLeafElement, createPosition, dump, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getStartPosition, getText, getText, getUndoableEditListeners, putProperty, readLock, readUnlock, removeUndoableEditListener, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createPosition, getEndPosition, getLength, getProperty, getStartPosition, getText, getText, putProperty, removeUndoableEditListener
public static final String MIME_TYPE_PROP
public static final String ID_PROP
public static final String READ_LINE_SEPARATOR_PROP
public static final String WRITE_LINE_SEPARATOR_PROP
public static final String FILE_NAME_PROP
public static final String WRAP_SEARCH_MARK_PROP
public static final String UNDO_MANAGER_PROP
public static final String KIT_CLASS_PROP
public static final String STRING_FINDER_PROP
public static final String STRING_BWD_FINDER_PROP
public static final String BLOCKS_FINDER_PROP
@Deprecated public static final String LINE_LIMIT_PROP
@Deprecated public static final String LINE_BATCH_SIZE
public static final String LS_CR
public static final String LS_LF
public static final String LS_CRLF
public static final String FORMATTER
protected boolean inited
protected boolean modified
protected Element defaultRootElem
@Deprecated public BaseDocument(Class kitClass, boolean addToRegistry)
kitClass
- class used to initialize this document with proper settings
category based on the editor kit for which this document is createdaddToRegistry
- If true
the document will be listed in the
EditorRegistry
. In most situations true
is the
correct. However, if you are absolutely sure that document should not be
listed in the registry, then set this parameter to false
.public BaseDocument(boolean addToRegistry, String mimeType)
addToRegistry
- If true
the document will be listed in the
EditorRegistry
. In most situations true
is the
correct. However, if you are absolutely sure that document should not be
listed in the registry, then set this parameter to false
.mimeType
- The mime type for the document.public CharSeq getText()
@Deprecated public SyntaxSupport getSyntaxSupport()
public int processText(TextBatchProcessor tbp, int startPos, int endPos) throws BadLocationException
tbp
- text batch processor to be used to process the text batchesstartPos
- 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.BadLocationException
public boolean isIdentifierPart(char ch)
public boolean isWhitespace(char ch)
public boolean isModifiable()
BaseDocument.runAtomic(java.lang.Runnable)
this method returns true if the document can be mutated or false
if any attempt of inserting/removing text would throw GuardedException
.BaseDocument.insertString(int, java.lang.String, javax.swing.text.AttributeSet)
or BaseDocument.remove(int, int)
.public void insertString(int offset, String text, AttributeSet attrs) throws BadLocationException
insertString
in interface Document
insertString
in class AbstractDocument
BadLocationException
public void checkTrailingSpaces(int offset)
public void remove(int offset, int length) throws BadLocationException
remove
in interface Document
remove
in class AbstractDocument
BadLocationException
public void replace(int offset, int length, String text, AttributeSet attrs) throws BadLocationException
replace
in class AbstractDocument
BadLocationException
protected void preInsertCheck(int offset, String text, AttributeSet a) throws BadLocationException
offset
- position where the insertion will be donetext
- string to be inserteda
- attributes of the inserted textBadLocationException
protected void preRemoveCheck(int offset, int len) throws BadLocationException
offset
- position where the insertion will be donelen
- length of the removalBadLocationException
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
insertUpdate
in class AbstractDocument
protected void preInsertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
removeUpdate
in class AbstractDocument
protected void postRemoveUpdate(AbstractDocument.DefaultDocumentEvent chng)
postRemoveUpdate
in class AbstractDocument
public String getText(int[] block) throws BadLocationException
BadLocationException
public char[] getChars(int pos, int len) throws BadLocationException
pos
- position of the first character to get.len
- number of characters to obtain.BadLocationException
public char[] getChars(int[] block) throws BadLocationException
block
- two-element array with starting and ending offsetBadLocationException
public void getChars(int pos, char[] ret, int offset, int len) throws BadLocationException
pos
- position of the first character to get.ret
- destination arrayoffset
- offset in the destination array.len
- number of characters to obtain.BadLocationException
public int find(Finder finder, int startPos, int limitPos) throws BadLocationException
finder
- finder to be used for the searchstartPos
- position in the document where the search will startlimitPos
- position where the search will be end with reporting
that nothing was found.BadLocationException
@Deprecated public void repaintBlock(int startOffset, int endOffset)
JTextComponent.getUI().damageRange()
instead.public void print(PrintContainer container)
public void print(PrintContainer container, boolean usePrintColoringMap, boolean lineNumberEnabled, int startOffset, int endOffset)
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 printendOffset
- end offset of text to printpublic void print(PrintContainer container, boolean usePrintColoringMap, Boolean lineNumberEnabled, int startOffset, int endOffset)
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 parameterstartOffset
- start offset of text to printendOffset
- end offset of text to printpublic Position createPosition(int offset, Position.Bias bias) throws BadLocationException
createPosition
in interface org.netbeans.api.editor.document.LineDocument
BadLocationException
public Element[] getRootElements()
getRootElements
in interface Document
getRootElements
in class AbstractDocument
public Element getDefaultRootElement()
getDefaultRootElement
in interface Document
getDefaultRootElement
in class AbstractDocument
public void render(Runnable r)
render
in interface Document
render
in class AbstractDocument
public void runAtomic(Runnable r)
public void runAtomicAsUser(Runnable r)
public void read(Reader reader, int pos) throws IOException, BadLocationException
reader
- reader from which data will be readpos
- on which position that data will be insertedIOException
BadLocationException
public void write(Writer writer, int pos, int len) throws IOException, BadLocationException
writer
- writer into which data will be written.pos
- from which position get the datalen
- how many characters writeIOException
BadLocationException
public void invalidateSyntaxMarks()
public int getTabSize()
SettingsNames.TAB_SIZE
setting.@Deprecated public int getShiftWidth()
formatter.getSpacesPerTab()
.BaseDocument.getTabSize()
@Deprecated public final Class getKitClass()
MimePath
and MimeLookup
.public void resetUndoMerge()
protected void fireChangedUpdate(DocumentEvent e)
fireChangedUpdate
in class AbstractDocument
protected void fireInsertUpdate(DocumentEvent e)
fireInsertUpdate
in class AbstractDocument
protected void fireRemoveUpdate(DocumentEvent e)
fireRemoveUpdate
in class AbstractDocument
protected void fireUndoableEditUpdate(UndoableEditEvent e)
fireUndoableEditUpdate
in class AbstractDocument
public final void extWriteLock()
public final void extWriteUnlock()
BaseDocument.extWriteLock()
@Deprecated public final void atomicLock()
BaseDocument.runAtomic(java.lang.Runnable)
instead.atomicLock
in interface AtomicLockDocument
@Deprecated public final void atomicUnlock()
BaseDocument.runAtomic(java.lang.Runnable)
instead.atomicUnlock
in interface AtomicLockDocument
public final boolean isAtomicLock()
public final void breakAtomicLock()
public void atomicUndo()
atomicUndo
in interface AtomicLockDocument
public void addAtomicLockListener(org.netbeans.api.editor.document.AtomicLockListener l)
public void removeAtomicLockListener(org.netbeans.api.editor.document.AtomicLockListener l)
@Deprecated public void addAtomicLockListener(AtomicLockListener l)
addAtomicLockListener
in interface AtomicLockDocument
l
- @Deprecated public void removeAtomicLockListener(AtomicLockListener l)
removeAtomicLockListener
in interface AtomicLockDocument
l
- protected final int getAtomicDepth()
public void addDocumentListener(DocumentListener listener)
addDocumentListener
in interface Document
addDocumentListener
in class AbstractDocument
public void removeDocumentListener(DocumentListener listener)
removeDocumentListener
in interface Document
removeDocumentListener
in class AbstractDocument
protected BaseDocumentEvent createDocumentEvent(int pos, int length, DocumentEvent.EventType type)
@Deprecated public void setPostModificationDocumentListener(DocumentListener listener)
public void addPostModificationDocumentListener(DocumentListener listener)
public void removePostModificationDocumentListener(DocumentListener listener)
public void addUpdateDocumentListener(DocumentListener listener)
CompoundEdit
) is still
opened for extra undoable edits that can be added by the clients (listeners).listener
- non-null listener to be added.public void removeUpdateDocumentListener(DocumentListener listener)
public void addUndoableEditListener(UndoableEditListener listener)
addUndoableEditListener
in interface Document
addUndoableEditListener
in class AbstractDocument
public void addUndoableEdit(UndoableEdit edit)
addUndoableEdit
in interface org.netbeans.api.editor.document.CustomUndoDocument
edit
- non-null undoable edit.IllegalStateException
- if the document is not under atomic lock.public boolean isModified()
public Element getParagraphElement(int pos)
getParagraphElement
in interface org.netbeans.api.editor.document.LineDocument
getParagraphElement
in class AbstractDocument
public Annotations getAnnotations()
protected Dictionary createDocumentProperties(Dictionary origDocumentProperties)
public String toStringDetail()