|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | 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.
Nested Class Summary | |
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. |
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. |
|
CloneableEditorSupport(CloneableEditorSupport.Env env,
Lookup l)
Creates new CloneableEditorSupport attached to given environment. |
Method Summary | |
void |
addChangeListener(ChangeListener l)
Deprecated. Deprecated since 3.40. Use addPropertyChangeListener(java.beans.PropertyChangeListener) instead.
See also EditorCookie.Observable . |
void |
addPropertyChangeListener(PropertyChangeListener l)
Add a PropertyChangeListener to the listener list. |
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 CloneableTopComponent |
createCloneableTopComponent()
Prepares document, creates and initializes new CloneableEditor component. |
protected EditorKit |
createEditorKit()
Creates editor kit for this source. |
protected CloneableEditorSupport.Pane |
createPane()
|
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. |
protected String |
documentID()
Constructs the ID used for persistence of opened editors. |
protected void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Report a bound property update to any registered listeners. |
StyledDocument |
getDocument()
Get the document. |
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. |
JEditorPane[] |
getOpenedPanes()
Gets editor panes opened by this support. |
protected 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(StyledDocument doc,
InputStream stream,
EditorKit kit)
Actually read file data into an editor kit's document from an input stream. |
protected String |
messageHtmlName()
Constructs message that should be used to name the editor component in html fashion, with possible coloring, text styles etc. |
protected String |
messageLine(Line line)
Computes display name for a line produced by this getLineSet() . |
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. |
void |
open()
Overrides superclass method, first processes document preparation. |
protected CloneableEditorSupport.Pane |
openAt(PositionRef pos,
int column)
Forcibly create one editor component. |
StyledDocument |
openDocument()
Get the document associated with this cookie. |
Task |
prepareDocument()
Load the document into memory. |
void |
print()
A printing implementation suitable for PrintCookie . |
protected Task |
reloadDocument()
Reload the document in response to external modification. |
void |
removeChangeListener(ChangeListener l)
Deprecated. Deprecated since 3.40. Use removePropertyChangeListener(java.beans.PropertyChangeListener) instead.
See also EditorCookie.Observable . |
void |
removePropertyChangeListener(PropertyChangeListener l)
Remove a PropertyChangeListener from the listener list. |
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. |
protected Component |
wrapEditorComponent(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. |
Methods inherited from class org.openide.windows.CloneableOpenSupport |
close, edit, messageOpened, messageOpening, 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 objectpublic CloneableEditorSupport(CloneableEditorSupport.Env env, 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
callMethod Detail |
protected abstract String messageSave()
protected abstract String messageName()
protected String messageHtmlName()
protected String documentID()
protected abstract String messageToolTip()
protected String messageLine(Line line)
getLineSet()
. The default
implementation reuses messageName and line number of the line.
line
- the line object to compute display name for
protected final UndoRedo.Manager getUndoRedo()
public void open()
prepareDocument()
public final void addPropertyChangeListener(PropertyChangeListener l)
EditorCookie.Observable
.
l
- the PropertyChangeListener to be addedpublic final void removePropertyChangeListener(PropertyChangeListener l)
EditorCookie.Observable
.
l
- the PropertyChangeListener to be removedprotected final void firePropertyChange(String propertyName, Object oldValue, 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 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()
EditorCookie.getOpenedPanes()
public Line.Set getLineSet()
public void print()
PrintCookie
.
protected CloneableTopComponent createCloneableTopComponent()
CloneableEditor
component.
Typically do not override this method.
For creating your own CloneableEditor
type component
override createCloneableEditor()
method.
CloneableEditor
for this supportprotected CloneableEditorSupport.Pane createPane()
protected Component wrapEditorComponent(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()
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)
addPropertyChangeListener(java.beans.PropertyChangeListener)
instead.
See also EditorCookie.Observable
.
l
- new listenerpublic void removeChangeListener(ChangeListener l)
removePropertyChangeListener(java.beans.PropertyChangeListener)
instead.
See also EditorCookie.Observable
.
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
component.
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 uses improved UndoRedo.Manager
.
public InputStream getInputStream() throws 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
.
IOException
- if saving the document to a virtual stream or other IO operation failsprotected 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 to
IOException
- if there was a problem writing the file
BadLocationException
- 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 kit
IOException
- if there was a problem reading the file
BadLocationException
- 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 use
protected 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)
ask
- 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 caret
null
editor
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |