站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc 4.1.0

CloneableEditorSupport (NetBeans APIs) - NetBeans API Javadoc 4.1.0


org.openide.text
Class CloneableEditorSupport

java.lang.Object
  extended byorg.openide.windows.CloneableOpenSupport
      extended byorg.openide.text.CloneableEditorSupport

public abstract class CloneableEditorSupport
extends CloneableOpenSupport

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 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.
 
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

EDITOR_MODE

public static final String EDITOR_MODE
Common name for editor mode.

See Also:
Constant Field Values
Constructor Detail

CloneableEditorSupport

public CloneableEditorSupport(CloneableEditorSupport.Env env)
Creates new CloneableEditorSupport attached to given environment.

Parameters:
env - environment that is source of all actions around the data object

CloneableEditorSupport

public CloneableEditorSupport(CloneableEditorSupport.Env env,
                              Lookup l)
Creates new CloneableEditorSupport attached to given environment.

Parameters:
env - environment that is source of all actions around the data object
l - the context that will be passed to each Line produced by this support's Line.Set. The line will return it from Line.getLookup call
Method Detail

messageSave

protected abstract String messageSave()
Constructs message that should be displayed when the data object is modified and is being closed.

Returns:
text to show to the user

messageName

protected abstract String messageName()
Constructs message that should be used to name the editor component.

Returns:
name of the editor

documentID

protected String documentID()
Constructs the ID used for persistence of opened editors. Should be overridden to return sane ID of the underlying document, like the name of the disk file.

Returns:
ID of the document
Since:
4.24

messageToolTip

protected abstract String messageToolTip()
Text to use as tooltip for component.

Returns:
text to show to the user

messageLine

protected String messageLine(Line line)
Computes display name for a line produced by this getLineSet(). The default implementation reuses messageName and line number of the line.

Parameters:
line - the line object to compute display name for
Returns:
display name for the line like "MyFile.java:243"
Since:
4.3

getUndoRedo

protected final UndoRedo.Manager getUndoRedo()
Gets the undo redo manager.

Returns:
the manager

open

public void open()
Overrides superclass method, first processes document preparation.

Overrides:
open in class CloneableOpenSupport
See Also:
prepareDocument()

addPropertyChangeListener

public final void addPropertyChangeListener(PropertyChangeListener l)
Add a PropertyChangeListener to the listener list. See EditorCookie.Observable.

Parameters:
l - the PropertyChangeListener to be added
Since:
3.40

removePropertyChangeListener

public final void removePropertyChangeListener(PropertyChangeListener l)
Remove a PropertyChangeListener from the listener list. See EditorCookie.Observable.

Parameters:
l - the PropertyChangeListener to be removed
Since:
3.40

firePropertyChange

protected final void firePropertyChange(String propertyName,
                                        Object oldValue,
                                        Object newValue)
Report a bound property update to any registered listeners.

Parameters:
propertyName - the programmatic name of the property that was changed.
oldValue - rhe old value of the property.
newValue - the new value of the property.
Since:
3.40

prepareDocument

public Task prepareDocument()
Load the document into memory. This is done in different thread. A task for the thread is returned so anyone may test whether the loading has been finished or is still in process.

Returns:
task for control over loading

openDocument

public StyledDocument openDocument()
                            throws IOException
Get the document associated with this cookie. It is an instance of Swing's 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.

Returns:
the styled document for this cookie that understands the guarded attribute
Throws:
IOException - if the document could not be loaded

getDocument

public StyledDocument getDocument()
Get the document. This method may be called before the document initialization (prepareTask) has been completed, in such a case the document must not be modified.

Returns:
document or null if it is not yet loaded

isModified

public boolean isModified()
Test whether the document is modified.

Returns:
true if the document is in memory and is modified; otherwise false

saveDocument

public void saveDocument()
                  throws IOException
Save the document in this thread. Create 'orig' document for the case that the save would fail.

Throws:
IOException - on I/O error

getOpenedPanes

public JEditorPane[] getOpenedPanes()
Gets editor panes opened by this support.

Returns:
a non-empty array of panes, or null
See Also:
EditorCookie.getOpenedPanes()

getLineSet

public Line.Set getLineSet()
Get the line set for all paragraphs in the document.

Returns:
positions of all paragraphs on last save

print

public void print()
A printing implementation suitable for PrintCookie.


createCloneableTopComponent

protected CloneableTopComponent createCloneableTopComponent()
Prepares document, creates and initializes new CloneableEditor component. Typically do not override this method. For creating your own CloneableEditor type component override createCloneableEditor() method.

Specified by:
createCloneableTopComponent in class CloneableOpenSupport
Returns:
the CloneableEditor for this support

createPane

protected CloneableEditorSupport.Pane createPane()

canClose

protected boolean canClose()
Should test whether all data is saved, and if not, prompt the user to save.

Overrides:
canClose in class CloneableOpenSupport
Returns:
true if everything can be closed

isDocumentLoaded

public boolean isDocumentLoaded()
Test whether the document is in memory, or whether loading is still in progress.

Returns:
true if document is loaded

setMIMEType

public void setMIMEType(String s)
Set the MIME type for the document.

Parameters:
s - the new MIME type

addChangeListener

public void addChangeListener(ChangeListener l)
Deprecated. Deprecated since 3.40. Use addPropertyChangeListener(java.beans.PropertyChangeListener) instead. See also EditorCookie.Observable.

Adds a listener for status changes. An event is fired when the document is moved or removed from memory.

Parameters:
l - new listener

removeChangeListener

public void removeChangeListener(ChangeListener l)
Deprecated. Deprecated since 3.40. Use removePropertyChangeListener(java.beans.PropertyChangeListener) instead. See also EditorCookie.Observable.

Removes a listener for status changes.

Parameters:
l - listener to remove

createPositionRef

public final PositionRef createPositionRef(int offset,
                                           Position.Bias bias)
Create a position reference for the given offset. The position moves as the document is modified and reacts to closing and opening of the document.

Parameters:
offset - the offset to create position at
bias - the Position.Bias for new creating position.
Returns:
position reference for that offset

createCloneableEditor

protected CloneableEditor createCloneableEditor()
Allows subclasses to create their own version of CloneableEditor component.

Returns:
the CloneableEditor for this support

initializeCloneableEditor

protected void initializeCloneableEditor(CloneableEditor editor)
Initialize the editor. This method is called after the editor component is deserialized and also when the component is created. It allows the subclasses to annotate the component with icon, selected nodes, etc.

Parameters:
editor - the editor that has been created and should be annotated

createUndoRedoManager

protected UndoRedo.Manager createUndoRedoManager()
Create an undo/redo manager. This manager is then attached to the document, and listens to all changes made in it.

The default implementation uses improved UndoRedo.Manager.

Returns:
the undo/redo manager

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns an InputStream which reads the current data from this editor, taking into account the encoding of the file. The returned InputStream will be useful for example when passing the file to an external compiler or other tool, which expects an input stream and which deals with encoding internally.
See also saveFromKitToStream(javax.swing.text.StyledDocument, javax.swing.text.EditorKit, java.io.OutputStream).

Returns:
input stream for the file. If the file is open in the editor (and possibly modified), then the returned 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.
Throws:
IOException - if saving the document to a virtual stream or other IO operation fails
Since:
4.7

saveFromKitToStream

protected void saveFromKitToStream(StyledDocument doc,
                                   EditorKit kit,
                                   OutputStream stream)
                            throws IOException,
                                   BadLocationException
Actually write file data to an output stream from an editor kit's document. Called during a file save by saveDocument().

The default implementation just calls EditorKit.write(...). Subclasses could override this to provide support for persistent guard blocks, for example.

Parameters:
doc - the document to write from
kit - the associated editor kit
stream - the open stream to write to
Throws:
IOException - if there was a problem writing the file
BadLocationException - should not normally be thrown
See Also:
loadFromStreamToKit(javax.swing.text.StyledDocument, java.io.InputStream, javax.swing.text.EditorKit)

loadFromStreamToKit

protected void loadFromStreamToKit(StyledDocument doc,
                                   InputStream stream,
                                   EditorKit kit)
                            throws IOException,
                                   BadLocationException
Actually read file data into an editor kit's document from an input stream. Called during a file load by prepareDocument().

The default implementation just calls EditorKit.read(...). Subclasses could override this to provide support for persistent guard blocks, for example.

Parameters:
doc - the document to read into
stream - the open stream to read from
kit - the associated editor kit
Throws:
IOException - if there was a problem reading the file
BadLocationException - should not normally be thrown
See Also:
saveFromKitToStream(javax.swing.text.StyledDocument, javax.swing.text.EditorKit, java.io.OutputStream)

reloadDocument

protected Task reloadDocument()
Reload the document in response to external modification.

Returns:
task that reloads the document. It can be also obtained by calling prepareDocument().

createEditorKit

protected EditorKit createEditorKit()
Creates editor kit for this source.

Returns:
editor kit

createStyledDocument

protected StyledDocument createStyledDocument(EditorKit kit)
Method that can be overriden by children to create empty styled document or attach additional document properties to it.

Parameters:
kit - the kit to use
Returns:
styled document to use

notifyUnmodified

protected void notifyUnmodified()
Notification method called when the document become unmodified. Called after save or after reload of document.

This implementation simply marks the associated environement unmodified and updates titles of all components.


notifyModified

protected boolean notifyModified()
Called when the document is being modified. The responsibility of this method is to inform the environment that its document is modified. Current implementation Just calls env.setModified (true) to notify it about modification.

Returns:
true if the environment accepted being marked as modified or false if it refused it and the document should still be unmodified

notifyClosed

protected void notifyClosed()
Method that is called when all components of the support are closed. The default implementation closes the document.


close

protected boolean close(boolean ask)
Closes all opened editors (if the user agrees) and flushes content of the document to the file.

Overrides:
close in class CloneableOpenSupport
Parameters:
ask - ask whether to save the document or not?
Returns:
false if the operation is cancelled

updateTitles

protected void updateTitles()
Updates titles of all editors.


openAt

protected final CloneableEditorSupport.Pane openAt(PositionRef pos,
                                                   int column)
Forcibly create one editor component. Then set the caret to the given position.

Parameters:
pos - where to place the caret
Returns:
always non-null editor
Since:
5.2


Built on May 4 2005.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.