public abstract class CloneableEditorSupport
extends org.openide.windows.CloneableOpenSupport
Document.
Can be assigned as a cookie to any editable data object.
This class is abstract, so any subclass has to provide implementation
for abstract method (usually for generating of messages) and also
provide environment CloneableEditorSupport.Env to give this support access to
input/output streams, mime type and other features of edited object.
This class implements methods of the interfaces
EditorCookie, OpenCookie,
EditCookie,
ViewCookie, LineCookie,
CloseCookie, and PrintCookie
but does not implement
those interfaces. It is up to the subclass to decide which interfaces
really implement and which not.
This class supports collecting multiple edits into a group which is treated
as a single edit by undo/redo. Send BEGIN_COMMIT_GROUP and
END_COMMIT_GROUP to UndoableEditListener. These must always be paired.
Send MARK_COMMIT_GROUP to commit accumulated edits and to continue
accumulating.
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
CloneableEditorSupport.Env |
Interface for providing data for the support and also
locking the source of data.
|
static interface |
CloneableEditorSupport.Pane |
Describes one existing editor.
|
| Modifier and Type | Field | Description |
|---|---|---|
static javax.swing.undo.UndoableEdit |
BEGIN_COMMIT_GROUP |
Start a group of edits which will be committed as a single edit
for purpose of undo/redo.
|
static java.lang.String |
EDITOR_MODE |
Common name for editor mode.
|
static javax.swing.undo.UndoableEdit |
END_COMMIT_GROUP |
End a group of edits.
|
static javax.swing.undo.UndoableEdit |
MARK_COMMIT_GROUP |
Any coalesced edits become a commit-group and a new commit-group
is started.
|
| Constructor | Description |
|---|---|
CloneableEditorSupport(CloneableEditorSupport.Env env) |
Creates new CloneableEditorSupport attached to given environment.
|
CloneableEditorSupport(CloneableEditorSupport.Env env,
org.openide.util.Lookup l) |
Creates new CloneableEditorSupport attached to given environment.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addChangeListener(javax.swing.event.ChangeListener l) |
Deprecated.
Deprecated since 3.40. Use
addPropertyChangeListener(java.beans.PropertyChangeListener) instead.
See also EditorCookie.Observable. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l) |
Add a PropertyChangeListener to the listener list.
|
protected void |
afterRedirect(org.openide.windows.CloneableOpenSupport redirectedTo) |
|
protected boolean |
asynchronousOpen() |
Controls behavior of method open.
|
protected boolean |
canClose() |
Should test whether all data is saved, and if not, prompt the user
to save.
|
protected boolean |
close(boolean ask) |
Closes all opened editors (if the user agrees) and
flushes content of the document to the file.
|
protected CloneableEditor |
createCloneableEditor() |
Allows subclasses to create their own version
of
CloneableEditor component. |
protected org.openide.windows.CloneableTopComponent |
createCloneableTopComponent() |
Prepares document, creates and initializes
new
CloneableEditor component. |
protected javax.swing.text.EditorKit |
createEditorKit() |
Creates editor kit for this source.
|
protected CloneableEditorSupport.Pane |
createPane() |
Creates and initializes
new
CloneableEditor component. |
PositionRef |
createPositionRef(int offset,
javax.swing.text.Position.Bias bias) |
Create a position reference for the given offset.
|
protected javax.swing.text.StyledDocument |
createStyledDocument(javax.swing.text.EditorKit kit) |
Method that can be overriden by children to create empty
styled document or attach additional document properties to it.
|
protected org.openide.awt.UndoRedo.Manager |
createUndoRedoManager() |
Create an undo/redo manager.
|
protected java.lang.String |
documentID() |
Constructs the ID used for persistence of opened editors.
|
protected void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue) |
Report a bound property update to any registered listeners.
|
javax.swing.text.StyledDocument |
getDocument() |
Get the document.
|
static javax.swing.text.EditorKit |
getEditorKit(java.lang.String mimePath) |
Gets an
EditorKit from Netbeans registry. |
java.io.InputStream |
getInputStream() |
Returns an InputStream which reads the current data from this editor, taking into
account the encoding of the file.
|
Line.Set |
getLineSet() |
Get the line set for all paragraphs in the document.
|
javax.swing.JEditorPane[] |
getOpenedPanes() |
Gets editor panes opened by this support.
|
protected org.openide.awt.UndoRedo.Manager |
getUndoRedo() |
Gets the undo redo manager.
|
protected void |
initializeCloneableEditor(CloneableEditor editor) |
Initialize the editor.
|
boolean |
isDocumentLoaded() |
Test whether the document is in memory, or whether loading is still in progress.
|
boolean |
isModified() |
Test whether the document is modified.
|
protected void |
loadFromStreamToKit(javax.swing.text.StyledDocument doc,
java.io.InputStream stream,
javax.swing.text.EditorKit kit) |
Actually read file data into an editor kit's document from an input stream.
|
protected java.lang.String |
messageHtmlName() |
Constructs message that should be used to name the editor component
in html fashion, with possible coloring, text styles etc.
|
protected java.lang.String |
messageLine(Line line) |
Computes display name for a line produced
by this
getLineSet(). |
protected abstract java.lang.String |
messageName() |
Constructs message that should be used to name the editor component.
|
protected abstract java.lang.String |
messageSave() |
Constructs message that should be displayed when the data object
is modified and is being closed.
|
protected abstract java.lang.String |
messageToolTip() |
Text to use as tooltip for component.
|
protected void |
notifyClosed() |
Method that is called when all components of the support are
closed.
|
protected boolean |
notifyModified() |
Called when the document is being modified.
|
protected void |
notifyUnmodified() |
Notification method called when the document become unmodified.
|
void |
open() |
Overrides superclass method, first processes document preparation.
|
protected CloneableEditorSupport.Pane |
openAt(PositionRef pos,
int column) |
Forcibly create one editor component.
|
javax.swing.text.StyledDocument |
openDocument() |
Get the document associated with this cookie.
|
org.openide.util.Task |
prepareDocument() |
Load the document into memory.
|
void |
print() |
A printing implementation suitable for
PrintCookie. |
protected org.openide.util.Task |
reloadDocument() |
Reload the document in response to external modification.
|
void |
removeChangeListener(javax.swing.event.ChangeListener l) |
Deprecated.
Deprecated since 3.40. Use
removePropertyChangeListener(java.beans.PropertyChangeListener) instead.
See also EditorCookie.Observable. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l) |
Remove a PropertyChangeListener from the listener list.
|
void |
saveDocument() |
Save the document in this thread.
|
protected void |
saveFromKitToStream(javax.swing.text.StyledDocument doc,
javax.swing.text.EditorKit kit,
java.io.OutputStream stream) |
Actually write file data to an output stream from an editor kit's document.
|
void |
setMIMEType(java.lang.String s) |
Set the MIME type for the document.
|
java.lang.String |
toString() |
|
protected void |
updateTitles() |
Updates titles of all editors.
|
protected java.awt.Component |
wrapEditorComponent(java.awt.Component editorComponent) |
Wraps the editor component in a custom component, allowing for creating
more complicated user interfaces which contain the editor UI in
an arbitrary place.
|
public static final java.lang.String EDITOR_MODE
public static final javax.swing.undo.UndoableEdit BEGIN_COMMIT_GROUP
public static final javax.swing.undo.UndoableEdit END_COMMIT_GROUP
public static final javax.swing.undo.UndoableEdit MARK_COMMIT_GROUP
public CloneableEditorSupport(CloneableEditorSupport.Env env)
env - environment that is source of all actions around the
data objectpublic CloneableEditorSupport(CloneableEditorSupport.Env env, org.openide.util.Lookup l)
env - environment that is source of all actions around the
data objectl - the context that will be passed to each Line produced
by this support's Line.Set. The line will return it from Line.getLookup
callprotected abstract java.lang.String messageSave()
protected abstract java.lang.String messageName()
protected java.lang.String messageHtmlName()
protected java.lang.String documentID()
protected abstract java.lang.String messageToolTip()
protected java.lang.String messageLine(Line line)
getLineSet(). The default
implementation reuses messageName and line number of the line.line - the line object to compute display name forprotected final org.openide.awt.UndoRedo.Manager getUndoRedo()
protected boolean asynchronousOpen()
CloneableEditorSupport.open()public void open()
open in class org.openide.windows.CloneableOpenSupportprepareDocument()public final void addPropertyChangeListener(java.beans.PropertyChangeListener l)
EditorCookie.Observable.l - the PropertyChangeListener to be addedpublic final void removePropertyChangeListener(java.beans.PropertyChangeListener l)
EditorCookie.Observable.l - the PropertyChangeListener to be removedprotected final void firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
propertyName - the programmatic name of the property that was changed.oldValue - rhe old value of the property.newValue - the new value of the property.public org.openide.util.Task prepareDocument()
public javax.swing.text.StyledDocument openDocument()
throws java.io.IOException
StyledDocument but it should
also understand the NetBeans NbDocument.GUARDED to
prevent certain lines from being edited by the user.
If the document is not loaded the method blocks until it is.
Method will throw UserQuestionException exception
if file size is too big. This exception could be caught and
its method UserQuestionException.confirmed()
can be used for confirmation. You need to call openDocument()}
one more time after confirmation.
java.io.IOException - if the document could not be loadedpublic javax.swing.text.StyledDocument getDocument()
prepareTask)
has been completed, in such a case the document must not be modified.null if it is not yet loadedpublic boolean isModified()
true if the document is in memory and is modified;
otherwise falsepublic void saveDocument()
throws java.io.IOException
java.io.IOException - on I/O errorpublic javax.swing.JEditorPane[] getOpenedPanes()
EditorCookie.getOpenedPanes()protected void afterRedirect(org.openide.windows.CloneableOpenSupport redirectedTo)
afterRedirect in class org.openide.windows.CloneableOpenSupportpublic Line.Set getLineSet()
public void print()
PrintCookie.protected org.openide.windows.CloneableTopComponent createCloneableTopComponent()
CloneableEditor component.
Typically do not override this method.
For creating your own CloneableEditor type component
override createCloneableEditor() method.createCloneableTopComponent in class org.openide.windows.CloneableOpenSupportCloneableEditor for this supportprotected CloneableEditorSupport.Pane createPane()
CloneableEditor component.
Typically do not override this method (unless you are dealing with
multiviews).
For creating your own CloneableEditor type component
override createCloneableEditor() method.CloneableEditorSupport.Pane for this supportprotected java.awt.Component wrapEditorComponent(java.awt.Component editorComponent)
The default implementation merely returns the passed
editorComponent parameter.
editorComponent - the component containing the editor
(usually not the JEditorPane, but some its ancestor).editorComponent or
editorComponent itself.protected boolean canClose()
canClose in class org.openide.windows.CloneableOpenSupporttrue if everything can be closedpublic boolean isDocumentLoaded()
true if document is loadedpublic void setMIMEType(java.lang.String s)
s - the new MIME type@Deprecated public void addChangeListener(javax.swing.event.ChangeListener l)
addPropertyChangeListener(java.beans.PropertyChangeListener) instead.
See also EditorCookie.Observable.l - new listener@Deprecated public void removeChangeListener(javax.swing.event.ChangeListener l)
removePropertyChangeListener(java.beans.PropertyChangeListener) instead.
See also EditorCookie.Observable.l - listener to removepublic final PositionRef createPositionRef(int offset, javax.swing.text.Position.Bias bias)
offset - the offset to create position atbias - the Position.Bias for new creating position.protected CloneableEditor createCloneableEditor()
CloneableEditor component.CloneableEditor for this supportprotected void initializeCloneableEditor(CloneableEditor editor)
editor - the editor that has been created and should be annotatedprotected org.openide.awt.UndoRedo.Manager createUndoRedoManager()
The default implementation uses improved UndoRedo.Manager,
with support for various extensions (including BEGIN_COMMIT_GROUP
and END_COMMIT_GROUP). It is not wise to override this
method without delegating to super.createUndoRedoManager.
public java.io.InputStream getInputStream()
throws java.io.IOException
saveFromKitToStream(javax.swing.text.StyledDocument, javax.swing.text.EditorKit, java.io.OutputStream).InputStream will contain the same data as if the file
was written out to the CloneableEditorSupport.Env (usually disk). So it will contain
guarded block markers etc. If the document is not loaded,
then the InputStream will be taken from the CloneableEditorSupport.Env.java.io.IOException - if saving the document to a virtual stream or other IO operation failsprotected void saveFromKitToStream(javax.swing.text.StyledDocument doc,
javax.swing.text.EditorKit kit,
java.io.OutputStream stream)
throws java.io.IOException,
javax.swing.text.BadLocationException
saveDocument().
The default implementation just calls EditorKit.write(...).
Subclasses could override this to provide support for persistent guard blocks, for example.
doc - the document to write fromkit - the associated editor kitstream - the open stream to write tojava.io.IOException - if there was a problem writing the filejavax.swing.text.BadLocationException - should not normally be thrownloadFromStreamToKit(javax.swing.text.StyledDocument, java.io.InputStream, javax.swing.text.EditorKit)protected void loadFromStreamToKit(javax.swing.text.StyledDocument doc,
java.io.InputStream stream,
javax.swing.text.EditorKit kit)
throws java.io.IOException,
javax.swing.text.BadLocationException
prepareDocument().
The default implementation just calls EditorKit.read(...).
Subclasses could override this to provide support for persistent guard blocks, for example.
doc - the document to read intostream - the open stream to read fromkit - the associated editor kitjava.io.IOException - if there was a problem reading the filejavax.swing.text.BadLocationException - should not normally be thrownsaveFromKitToStream(javax.swing.text.StyledDocument, javax.swing.text.EditorKit, java.io.OutputStream)protected org.openide.util.Task reloadDocument()
public static javax.swing.text.EditorKit getEditorKit(java.lang.String mimePath)
EditorKit from Netbeans registry. The method looks
in the MimeLookup for EditorKits registered for
the mime-path passed in and returns the first one it finds. If there is
no EditorKit registered for the mime-path it will fall back
to the 'text/plain' EditorKit and eventually to its own
default kit.
A mime-path is a concatenation of one or more mime-types allowing to address fragments of text with a different mime-type than the mime-type of a document that contains those fragments. As an example you can use a JSP page containing a java scriplet. The JSP page is a document of 'text/x-jsp' mime-type, while the mime-type of the java scriplet is 'text/x-java'. When accessing settings or services such as an 'EditorKit' for java scriplets embedded in a JSP page the scriplet's mime-path 'text/x-jsp/text/x-java' should be used.
If you are trying to get an 'EditorKit' for the whole document you can simply pass in the document's mime-type (e.g. 'text/x-java'). For the main document its mime-type and mime-path are the same.
mimePath - The mime-path to find an EditorKit for.EditorKit implementation registered for the given mime-path.MimeLookupprotected javax.swing.text.EditorKit createEditorKit()
protected javax.swing.text.StyledDocument createStyledDocument(javax.swing.text.EditorKit kit)
kit - the kit to useprotected void notifyUnmodified()
This implementation simply marks the associated environement unmodified and updates titles of all components.
protected boolean notifyModified()
protected void notifyClosed()
protected boolean close(boolean ask)
close in class org.openide.windows.CloneableOpenSupportask - ask whether to save the document or not?false if the operation is cancelledprotected void updateTitles()
protected final CloneableEditorSupport.Pane openAt(PositionRef pos, int column)
pos - where to place the caretcolumn - where to place the caretnull editorpublic java.lang.String toString()
toString in class java.lang.ObjectBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.