public final class NbDocument extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
NbDocument.Annotatable
Enhanced version of document which is capable of
attaching/detaching of annotations.
|
static interface |
NbDocument.CustomEditor
Enabled documents to add special UI components to their Editor pane.
|
static interface |
NbDocument.CustomToolbar
Enabled documents to add special UI toolbar components to their Editor pane.
|
static interface |
NbDocument.PositionBiasable
Enhanced version of document that provides better support for
holding and working with biased positions.
|
static interface |
NbDocument.Printable
Document which may support styled text printing.
|
static interface |
NbDocument.WriteLockable
Specialized version of document that knows how to lock the document
for complex modifications.
|
Modifier and Type | Field and Description |
---|---|
static String |
BREAKPOINT_STYLE_NAME
Deprecated.
since 6.29. Use
Annotation instead. |
static String |
CURRENT_STYLE_NAME
Deprecated.
since 6.29. Use
Annotation instead. |
static String |
ERROR_STYLE_NAME
Deprecated.
since 6.29. Use
Annotation instead. |
static Object |
GUARDED
Attribute that signals that a given character is guarded (cannot
be modified).
|
static String |
NORMAL_STYLE_NAME
Deprecated.
since 6.29. Use
Annotation instead. |
Modifier and Type | Method and Description |
---|---|
static void |
addAnnotation(StyledDocument doc,
Position startPos,
int length,
Annotation annotation)
Add annotation to the document.
|
static Position |
createPosition(Document doc,
int offset,
Position.Bias bias)
Creates position with a bias.
|
static int |
findLineColumn(StyledDocument doc,
int offset)
Finds column number given an offset.
|
static int |
findLineNumber(StyledDocument doc,
int offset)
For given document and an offset, find the line number.
|
static int |
findLineOffset(StyledDocument doc,
int lineNumber)
Finds offset of the beginning of a line.
|
static Element |
findLineRootElement(StyledDocument doc)
Find the root element of all lines.
|
static Object |
findPageable(StyledDocument doc)
Find a way to print a given document.
|
static JEditorPane |
findRecentEditorPane(EditorCookie ec)
Gets recently selected editor pane opened by editor cookie
Can be called from AWT event thread only.
|
static StyledDocument |
getDocument(Lookup.Provider provider)
Get the document associated with a file.
|
static <T extends UndoableEdit> |
getEditToBeRedoneOfType(EditorCookie ec,
Class<T> type)
Get an edit of given type that would be redone if a redo operation would be invoked
at this time for an editor cookie.
|
static <T extends UndoableEdit> |
getEditToBeUndoneOfType(EditorCookie ec,
Class<T> type)
Get an edit of given type that would be undone if an undo operation would be invoked
at this time for an editor cookie.
|
static void |
insertGuarded(StyledDocument doc,
int offset,
String txt)
Inserts a text into given offset and marks it guarded.
|
static void |
markBreakpoint(StyledDocument doc,
int offset)
Deprecated.
since 1.20. Use addAnnotation() instead
|
static void |
markCurrent(StyledDocument doc,
int offset)
Deprecated.
since 1.20. Use addAnnotation() instead
|
static void |
markError(StyledDocument doc,
int offset)
Deprecated.
since 1.20. Use addAnnotation() instead
|
static void |
markGuarded(StyledDocument doc,
int offset,
int len)
Mark part of a document as guarded (immutable to the user).
|
static void |
markNormal(StyledDocument doc,
int offset)
Deprecated.
since 1.20. Use addAnnotation() instead
|
static boolean |
openDocument(Lookup.Provider provider,
int line,
int column,
Line.ShowOpenType openType,
Line.ShowVisibilityType visibilityType)
Open the document associated with a file in the Editor window in a
position specified by the line and column while controlling open and visibility behavior.
|
static boolean |
openDocument(Lookup.Provider provider,
int offset,
Line.ShowOpenType openType,
Line.ShowVisibilityType visibilityType)
Open the document associated with a file in the Editor window in a
position specified by the offset while controlling open and visibility behavior.
|
static void |
removeAnnotation(StyledDocument doc,
Annotation annotation)
Removal of added annotation.
|
static void |
runAtomic(StyledDocument doc,
Runnable run)
Locks the document to have exclusive access to it.
|
static void |
runAtomicAsUser(StyledDocument doc,
Runnable run)
Executes given runnable in "user mode" does not allowing any modifications
to parts of text marked as guarded.
|
static void |
unmarkGuarded(StyledDocument doc,
int offset,
int len)
Remove guarded mark on a block of a document.
|
public static final Object GUARDED
AttributeSet.CharacterAttribute
to signal that
this attribute applies to characters, not paragraphs.@Deprecated public static final String BREAKPOINT_STYLE_NAME
Annotation
instead.@Deprecated public static final String ERROR_STYLE_NAME
Annotation
instead.@Deprecated public static final String CURRENT_STYLE_NAME
Annotation
instead.@Deprecated public static final String NORMAL_STYLE_NAME
Annotation
instead.public static Element findLineRootElement(StyledDocument doc)
doc
- styled document (expecting NetBeans document)NullPointerException
- If the doc
parameter
is null
.public static int findLineNumber(StyledDocument doc, int offset)
doc
- the documentoffset
- offset in the documentNullPointerException
- If the doc
parameter
is null
.public static int findLineColumn(StyledDocument doc, int offset)
doc
- the documentoffset
- offset in the documentNullPointerException
- If the doc
parameter
is null
.public static int findLineOffset(StyledDocument doc, int lineNumber)
doc
- the documentlineNumber
- number of the line to find the start of (zero-based)NullPointerException
- If the doc
parameter
is null
.IndexOutOfBoundsException
- when incorrect
lineNumber
value is insertedpublic static Position createPosition(Document doc, int offset, Position.Bias bias) throws BadLocationException
Backward
then if an insert occures at the position, the text is inserted
after the position. If the bias is Forward
, then the text is
inserted before the position.
The method checks if the document implements NbDocument.PositionBiasable
,
and if so, createPosition
is called.
Otherwise an attempt is made to provide a Position
with the correct behavior.
doc
- document to create position inoffset
- the current offset for the positionbias
- the bias to use for the positionNullPointerException
- If the doc
parameter
is null
.BadLocationException
- if the offset is invalidpublic static void markGuarded(StyledDocument doc, int offset, int len)
doc
- styled documentoffset
- offset to start atlen
- length of text to mark as guardedNullPointerException
- If the doc
parameter
is null
.public static void unmarkGuarded(StyledDocument doc, int offset, int len)
doc
- styled documentoffset
- offset to start atlen
- length of text to mark as unguardedNullPointerException
- If the doc
parameter
is null
.public static void insertGuarded(StyledDocument doc, int offset, String txt) throws BadLocationException
doc
- document to insert tooffset
- offset of insertiontxt
- string text to insertNullPointerException
- If the doc
parameter
is null
.BadLocationException
@Deprecated public static void markBreakpoint(StyledDocument doc, int offset)
NbDocument.BREAKPOINT_STYLE_NAME
, it is used.
Otherwise, a new style is defined.doc
- the documentoffset
- identifies the line to set breakpoint toNullPointerException
- If the doc
parameter
is null
.@Deprecated public static void markError(StyledDocument doc, int offset)
NbDocument.ERROR_STYLE_NAME
, it is used.
Otherwise, a new style is defined.doc
- the documentoffset
- identifies the line to markNullPointerException
- If the doc
parameter
is null
.@Deprecated public static void markCurrent(StyledDocument doc, int offset)
NbDocument.CURRENT_STYLE_NAME
, it is used.
Otherwise, a new style is defined.doc
- the documentoffset
- identifies the line to markNullPointerException
- If the doc
parameter
is null
.@Deprecated public static void markNormal(StyledDocument doc, int offset)
NbDocument.NORMAL_STYLE_NAME
.
This method should be used to undo the effect of NbDocument.markBreakpoint(javax.swing.text.StyledDocument, int)
, NbDocument.markError(javax.swing.text.StyledDocument, int)
and NbDocument.markCurrent(javax.swing.text.StyledDocument, int)
.doc
- the documentoffset
- identified the line to unmarkNullPointerException
- If the doc
parameter
is null
.public static JEditorPane findRecentEditorPane(EditorCookie ec)
ec
- EditorCookie used to find out recently selected editor panepublic static void runAtomic(StyledDocument doc, Runnable run)
NbDocument.WriteLockable
can specify exactly how to do this.doc
- document to lockrun
- the action to runNullPointerException
- If the doc
parameter
is null
.public static void runAtomicAsUser(StyledDocument doc, Runnable run) throws BadLocationException
doc
- document to modifyrun
- runnable to run in user mode that will have exclusive access to modify the documentNullPointerException
- If the doc
parameter
is null
.BadLocationException
- if a modification of guarded text occured
and that is why no changes to the document has been done.public static Object findPageable(StyledDocument doc)
Printable
is used as a wrapper. In this last case it is useful
to implement NbDocument.Printable
to describe how to print in terms of
attributed characters, rather than specifying the complete page layout from scratch.public static void addAnnotation(StyledDocument doc, Position startPos, int length, Annotation annotation)
doc
- the document which will be annotatedstartPos
- position which represent begining
of the annotated textlength
- length of the annotated text. If -1 is specified
the whole line will be annotatedannotation
- annotation which is attached to this textpublic static void removeAnnotation(StyledDocument doc, Annotation annotation)
doc
- the annotated documentannotation
- annotation which is going to be removedpublic static <T extends UndoableEdit> T getEditToBeUndoneOfType(EditorCookie ec, Class<T> type)
T
- type of undoable edit to be retrieved.ec
- editor cookie providing an undo/redo manager.type
- class of undoable edit to be retrieved.public static <T extends UndoableEdit> T getEditToBeRedoneOfType(EditorCookie ec, Class<T> type)
T
- type of undoable edit to be retrieved.ec
- editor cookie providing an undo/redo manager.type
- class of undoable edit to be retrieved.public static StyledDocument getDocument(Lookup.Provider provider)
Method will throw UserQuestionException
exception if file size is too big. This exception is caught and its
method UserQuestionException.confirmed()
is used
for confirmation.
provider
- for example a org.openide.loaders.DataObject
public static boolean openDocument(Lookup.Provider provider, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType)
provider
- for example a org.openide.loaders.DataObject
offset
- the position the document should be opened (starting at 0)openType
- control open behavior, Line.ShowOpenType.OPEN
would typically be usedvisibilityType
- control visibility behavior, Line.ShowVisibilityType.FOCUS
would typically be usedUserQuestionException handling
public static boolean openDocument(Lookup.Provider provider, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType)
provider
- for example a org.openide.loaders.DataObject
line
- the line the document should be opened (starting at 0)column
- the column which should be selected (starting at 0), value
-1 does not change previously selected columnopenType
- control open behavior, Line.ShowOpenType.OPEN
would typically be usedvisibilityType
- control visibility behavior, Line.ShowVisibilityType.FOCUS
would typically be usedUserQuestionException handling