|
org.netbeans.modules.editor.util/1 1.17 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.netbeans.lib.editor.util.swing.DocumentUtilities
public final class DocumentUtilities
Various utility methods related to swing text documents.
Method Summary | |
---|---|
static void |
addDocumentListener(Document doc,
DocumentListener listener,
DocumentListenerPriority priority)
Add document listener to document with given priority or default to using regular Document.addDocumentListener(DocumentListener)
if the given document is not listener priority aware. |
static void |
addEventPropertyStorage(DocumentEvent evt)
Document provider should call this method to allow for document event properties being stored in document events. |
static boolean |
addPriorityDocumentListener(Document doc,
DocumentListener listener,
DocumentListenerPriority priority)
Suitable for document implementations - adds document listener to document with given priority and does not do anything if the given document is not listener priority aware. |
static int |
fixOffset(int offset,
DocumentEvent evt)
Fix the given offset according to the performed modification. |
static Object |
getEventProperty(DocumentEvent evt,
Object key)
Get a property of a given document event. |
static String |
getModificationText(DocumentEvent evt)
Get text of the given document modification. |
static Element |
getParagraphElement(Document doc,
int offset)
Get the paragraph element for the given document. |
static Element |
getParagraphRootElement(Document doc)
Get the root of the paragraph elements for the given document. |
static CharSequence |
getText(Document doc)
Get text of the given document as char sequence. |
static CharSequence |
getText(Document doc,
int offset,
int length)
Get a portion of text of the given document as char sequence. |
static DocumentListener |
initPriorityListening(Document doc)
This method should be used by swing document implementations that want to support document listeners prioritization. |
static boolean |
isReadLocked(Document doc)
Check whether the given document is read-locked by at least one thread or whether it was write-locked by the current thread. |
static boolean |
isTypingModification(Document doc)
This method should be used by document listeners to check whether the just performed document modification was caused by user's typing. |
static boolean |
isTypingModification(DocumentEvent evt)
Deprecated. |
static boolean |
isWriteLocked(Document doc)
Check whether the given document is write-locked by the current thread. |
static void |
putEventProperty(DocumentEvent evt,
Map.Entry mapEntry)
Set a property of a given document event by using the given map entry. |
static void |
putEventProperty(DocumentEvent evt,
Object key,
Object value)
Set a property of a given document event. |
static void |
removeDocumentListener(Document doc,
DocumentListener listener,
DocumentListenerPriority priority)
Remove document listener that was previously added to the document with given priority or use default Document.removeDocumentListener(DocumentListener)
if the given document is not listener priority aware. |
static boolean |
removePriorityDocumentListener(Document doc,
DocumentListener listener,
DocumentListenerPriority priority)
Suitable for document implementations - removes document listener from document with given priority and does not do anything if the given document is not listener priority aware. |
static void |
setTypingModification(Document doc,
boolean typingModification)
Mark that the ongoing document modification(s) will be caused by user's typing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void addDocumentListener(Document doc, DocumentListener listener, DocumentListenerPriority priority)
Document.addDocumentListener(DocumentListener)
if the given document is not listener priority aware.
doc
- document to which the listener should be added.listener
- document listener to add.priority
- priority with which the listener should be added.
If the document does not support document listeners ordering
then the listener is added in a regular way by using
Document.addDocumentListener(
javax.swing.event.DocumentListener)
method.public static boolean addPriorityDocumentListener(Document doc, DocumentListener listener, DocumentListenerPriority priority)
doc
- document to which the listener should be added.listener
- document listener to add.priority
- priority with which the listener should be added.
public static void removeDocumentListener(Document doc, DocumentListener listener, DocumentListenerPriority priority)
Document.removeDocumentListener(DocumentListener)
if the given document is not listener priority aware.
doc
- document from which the listener should be removed.listener
- document listener to remove.priority
- priority with which the listener should be removed.
It should correspond to the priority with which the listener
was added originally.public static boolean removePriorityDocumentListener(Document doc, DocumentListener listener, DocumentListenerPriority priority)
doc
- document from which the listener should be removed.listener
- document listener to remove.priority
- priority with which the listener should be removed.
public static DocumentListener initPriorityListening(Document doc)
class MyDocument extends AbstractDocument { MyDocument() { super.addDocumentListener(DocumentUtilities.initPriorityListening(this)); } public void addDocumentListener(DocumentListener listener) { if (!DocumentUtilities.addDocumentListener(this, listener, DocumentListenerPriority.DEFAULT)) super.addDocumentListener(listener); } public void removeDocumentListener(DocumentListener listener) { if (!DocumentUtilities.removeDocumentListener(this, listener, DocumentListenerPriority.DEFAULT)) super.removeDocumentListener(listener); } }
doc
- document to be initialized.
super.addDocumentListener()
in document's constructor.
IllegalStateException
- when the document already has
the property initialized.public static void setTypingModification(Document doc, boolean typingModification)
isTypingModification(Document)
.
This method should always be used in the following pattern:
DocumentUtilities.setTypingModification(doc, true); try { doc.insertString(offset, typedText, null); } finally { DocumentUtilities.setTypingModification(doc, false); }
isTypingModification(Document)
public static boolean isTypingModification(Document doc)
public static boolean isTypingModification(DocumentEvent evt)
isTypingModification(Document)
public static CharSequence getText(Document doc)
doc
- document for which the charsequence is being obtained.
public static CharSequence getText(Document doc, int offset, int length) throws BadLocationException
doc
- document for which the charsequence is being obtained.offset
- starting offset of the charsequence to obtain.length
- length of the charsequence to obtain
BadLocationException
- some portion of the given range
was not a valid part of the document. The location in the exception
is the first bad position encountered.
public static void addEventPropertyStorage(DocumentEvent evt)
evt
- document event to which the storage should be added.
It must be an undoable edit allowing to add an edit.public static Object getEventProperty(DocumentEvent evt, Object key)
evt
- non-null document event from which the property should be retrieved.key
- non-null key of the property.
public static void putEventProperty(DocumentEvent evt, Object key, Object value)
evt
- non-null document event to which the property should be stored.key
- non-null key of the property.value
- for the given property.public static void putEventProperty(DocumentEvent evt, Map.Entry mapEntry)
CompactMap.MapEntry
. Other map entry implementations
will be delegated to putEventProperty(DocumentEvent, Object, Object)
.
evt
- non-null document event to which the property should be stored.mapEntry
- non-null map entry which should be stored.
Generally after this method finishes the getEventProperty(DocumentEvent, Object)
will return mapEntry.getValue()
for mapEntry.getKey()
key.public static int fixOffset(int offset, DocumentEvent evt)
offset
- >=0 offset in a document.evt
- document event describing change in the document.
public static String getModificationText(DocumentEvent evt)
String.class
.
evt
- document event describing either document insertion or removal
(change event type events will produce null result).
public static boolean isReadLocked(Document doc)
AbstractDocument
based documents and it uses reflection.
doc
- non-null document instance.
public static boolean isWriteLocked(Document doc)
AbstractDocument
based documents and it uses reflection.
doc
- non-null document instance.
public static Element getParagraphElement(Document doc, int offset)
doc
- non-null document instance.offset
- offset in the document >=0
public static Element getParagraphRootElement(Document doc)
doc
- non-null document instance.
|
org.netbeans.modules.editor.util/1 1.17 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |