|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.openide.windows.CloneableOpenSupport | +--org.openide.text.CloneableEditorSupport
Support for associating an editor and a Swing 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.
Inner Class Summary | |
static interface |
CloneableEditorSupport.Env
Interface for providing data for the support and also locking the source of data. |
Inner classes inherited from class org.openide.windows.CloneableOpenSupport |
CloneableOpenSupport.Env |
Field Summary | |
static String |
EDITOR_MODE
Common name for editor mode. |
Fields inherited from class org.openide.windows.CloneableOpenSupport |
allEditors, env |
Constructor Summary | |
CloneableEditorSupport(CloneableEditorSupport.Env env)
Creates new CloneableEditorSupport attached to given environment. |
Method Summary | |
void |
addChangeListener(ChangeListener l)
Adds a listener for status changes. |
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 editor. |
protected CloneableTopComponent |
createCloneableTopComponent()
A method to create a new component. |
protected EditorKit |
createEditorKit()
Creates editor kit for this source. |
PositionRef |
createPositionRef(int offset,
Position.Bias bias)
Create a position reference for the given offset. |
protected StyledDocument |
createStyledDocument(EditorKit kit)
Method that can be overriden by children to create empty styled document or attach additional document properties to it. |
protected UndoRedo.Manager |
createUndoRedoManager()
Create an undo/redo manager. |
StyledDocument |
getDocument()
Get the document. |
Line.Set |
getLineSet()
Get the line set for all paragraphs in the document. |
JEditorPane[] |
getOpenedPanes()
|
protected UndoRedo.Manager |
getUndoRedo()
Getter for 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(StyledDocument doc,
InputStream stream,
EditorKit kit)
Actually read file data into an editor kit's document from an input stream. |
protected abstract String |
messageName()
Constructs message that should be used to name the editor component. |
protected abstract String |
messageSave()
Constructs message that should be displayed when the data object is modified and is being closed. |
protected abstract 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. |
StyledDocument |
openDocument()
Get the document associated with this cookie. |
Task |
prepareDocument()
Load the document into memory. |
void |
print()
The implementation of @see org.openide.cookies.PrintCookie#print() method. |
protected Task |
reloadDocument()
Reload the document in response to external modification. |
void |
removeChangeListener(ChangeListener l)
Removes a listener for status changes. |
void |
saveDocument()
Save the document in this thread. |
protected void |
saveFromKitToStream(StyledDocument doc,
EditorKit kit,
OutputStream stream)
Actually write file data to an output stream from an editor kit's document. |
void |
setMIMEType(String s)
Set the MIME type for the document. |
protected void |
updateTitles()
Updates titles of all editors. |
Methods inherited from class org.openide.windows.CloneableOpenSupport |
close, edit, messageOpened, messageOpening, open, openCloneableTopComponent, view |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String EDITOR_MODE
Constructor Detail |
public CloneableEditorSupport(CloneableEditorSupport.Env env)
env
- environment that is source of all actions around the
data objectMethod Detail |
protected abstract String messageSave()
protected abstract String messageName()
protected abstract String messageToolTip()
protected final UndoRedo.Manager getUndoRedo()
public Task prepareDocument()
public StyledDocument openDocument() throws 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.
IOException
- if the document could not be loadedpublic 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 false
public void saveDocument() throws IOException
IOException
- on I/O errorpublic JEditorPane[] getOpenedPanes()
public Line.Set getLineSet()
public void print()
protected CloneableTopComponent createCloneableTopComponent()
CloneableOpenSupport
createCloneableTopComponent
in class CloneableOpenSupport
org.openide.windows.CloneableOpenSupport
protected boolean canClose()
canClose
in class CloneableOpenSupport
true
if everything can be closedpublic boolean isDocumentLoaded()
true
if document is loadedpublic void setMIMEType(String s)
s
- the new MIME typepublic void addChangeListener(ChangeListener l)
l
- new listenerpublic void removeChangeListener(ChangeListener l)
l
- listener to removepublic final PositionRef createPositionRef(int offset, Position.Bias bias)
offset
- the offset to create position atbias
- the Position.Bias for new creating position.protected CloneableEditor createCloneableEditor()
CloneableEditor
for this supportprotected void initializeCloneableEditor(CloneableEditor editor)
editor
- the editor that has been created and should be annotatedprotected UndoRedo.Manager createUndoRedoManager()
The default implementation simply uses UndoRedo.Manager
.
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, 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 toIOException
- if there was a problem writing the fileBadLocationException
- should not normally be thrownloadFromStreamToKit(javax.swing.text.StyledDocument, java.io.InputStream, javax.swing.text.EditorKit)
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, 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 kitIOException
- if there was a problem reading the fileBadLocationException
- should not normally be thrownsaveFromKitToStream(javax.swing.text.StyledDocument, javax.swing.text.EditorKit, java.io.OutputStream)
protected Task reloadDocument()
protected EditorKit createEditorKit()
protected StyledDocument createStyledDocument(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 CloneableOpenSupport
ask
- ask whether to save the document or not?false
if the operation is cancelledprotected void updateTitles()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |