Package diva.gui.tutorial
Class TextDocument
- java.lang.Object
-
- diva.gui.AbstractDocument
-
- diva.gui.tutorial.TextDocument
-
- All Implemented Interfaces:
Document
public class TextDocument extends AbstractDocument
A example document that contains plain boring old text and saves it to ascii files. Here you can see some sample implementations of the open, save, saveAs, and close methods. You should also notice that this class adds methods for accessing the contained document's data in an application-useful format. (In this case, there are just simple getText and setText methods.) The setText properly realized that the document's data has been changed and sets the Dirty flag. This is used in the application tutorial by the StoragePolicy to prevent a user from closing the document without saving changes.This class also contains a DocumentFactory for documents of this type. The document factory is used by an application to create documents of this type.
- Version:
- $Id$
- Author:
- Steve Neuendorffer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TextDocument.Factory
TextDocument.Factory is a factory for Text Documents
-
Constructor Summary
Constructors Constructor Description TextDocument(Application application)
Create an text document for the given application containing an empty string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the document.java.lang.String
getText()
Return the text contained in this document.void
open()
Open the document from its current file or URL.void
save()
Save the document to its current file or URL.void
saveAs(java.io.File file)
Save the document to the given file.void
saveAs(java.net.URL url)
Save the document to the given URL.void
setText(java.lang.String text)
Set the text contained by this document.-
Methods inherited from class diva.gui.AbstractDocument
addPropertyChangeListener, getApplication, getEditSupport, getFile, getShortTitle, getTitle, getUndoManager, getURL, isDirty, isEditable, isWritable, removePropertyChangeListener, setDirty, setEditable, setFile, setURL, setWritable
-
-
-
-
Constructor Detail
-
TextDocument
public TextDocument(Application application)
Create an text document for the given application containing an empty string.
-
-
Method Detail
-
close
public void close()
Close the document. Do not attempt to save the document first or do any other user-interface things like that. This method can thrown an exception if there is a failure, but it should only do do if there is no way it can recover. Note that actions such as querying the user to save a modified document and so on are the responsibility of the application, not the Document implementation.- Specified by:
close
in interfaceDocument
- Overrides:
close
in classAbstractDocument
-
getText
public java.lang.String getText()
Return the text contained in this document.
-
open
public void open() throws java.lang.Exception
Open the document from its current file or URL. Throw an exception if the operation failed.- Specified by:
open
in interfaceDocument
- Specified by:
open
in classAbstractDocument
- Throws:
java.lang.Exception
- If the close operation fails.
-
save
public void save() throws java.lang.Exception
Save the document to its current file or URL. Throw an exception if the operation failed. Reasons for failure might include the fact that the file is not writable, or that the document has a URL but we haven't implemented HTTP-DAV support yet...- Specified by:
save
in interfaceDocument
- Specified by:
save
in classAbstractDocument
- Throws:
java.lang.Exception
- If the save operation fails.
-
saveAs
public void saveAs(java.io.File file) throws java.lang.Exception
Save the document to the given file. Throw an exception if the operation failed. Return true if successful, false if not. Do not change the file attribute to the new File object as that is the responsibility of the application, which it will do according to its storage policy.- Specified by:
saveAs
in interfaceDocument
- Specified by:
saveAs
in classAbstractDocument
- Throws:
java.lang.Exception
- If the save-as operation fails.- See Also:
save()
-
saveAs
public void saveAs(java.net.URL url) throws java.lang.Exception
Save the document to the given URL. Throw an exception if the operation failed. Do not change the URL attribute to the new URL object as that is the responsibility of the application, which it will do according to its storage policy.- Specified by:
saveAs
in interfaceDocument
- Specified by:
saveAs
in classAbstractDocument
- Throws:
java.lang.Exception
- If the save-as operation fails.- See Also:
save()
-
setText
public void setText(java.lang.String text)
Set the text contained by this document. If the given text is different from the previously contained text, then set the dirty flag.
-
-