diva.gui
Interface StoragePolicy
- All Known Implementing Classes:
- AbstractStoragePolicy, BasicStoragePolicy, DefaultStoragePolicy
public interface StoragePolicy
StoragePolicy captures the notion of how an application
deals with persistent storage. For example, suppose a user selects
the Close entry on a menu. The application typically needs to
check whether the document has been edited, and if so, it needs
to decide what to do about it. Two choices are:
- Prompt the user asking whether to save the document first.
- Save it anyway.
- Save it but checkpoint the current state of the document so
it can be undone later.
- Sing "Daisy"
Each of these is an example of a storage policy. Because different
applications may need different policies, yet some applications
will use the same policies as other application, the concept of
a storage policy has been reified into this interface and a
set of implementing classes.
- Version:
- $Id: StoragePolicy.java 38798 2005-07-08 20:00:01Z cxh $
- Author:
- John Reekie
close
boolean close(Document d)
- Close the document. Depending on the policy, this method will
probably check whether the document has been edited and annoy
the user with dialog boxes. If the document is null, do
nothing. Return true if the document closed, otherwise false.
open
Document open(Application app)
- Open a new document. This method will generally prompt the
user for a location to open. If a new Document is created,
return it, otherwise return null. (Note that if an existing
document is re-opened, null is still returned.)
open
Document open(java.io.File file,
Application app)
- Open a file and create a new document. Depending on the
policy, this method may choose to check whether the file has
already been opened, and use the existing data, open a
read-only view, etc. If it does open the file, it will use the
passed DocumentFactory to do so. If a new Document is created,
return it, otherwise return null. (Note that if an existing
document is re-opened, null is still returned.)
open
Document open(java.net.URL url,
Application app)
- Open a URL and create a new document. Depending on the policy,
this method may choose to check whether the URL has already
been opened, and use the existing data, etc. If it does open
the file, it will use the passed DocumentFactory to do so. If
a new Document is created, return it, otherwise return
null. (Note that if an existing document is re-opened, null is
still returned.)
save
boolean save(Document d)
- Save the document. Most policies will just save the file if it
is possible to do so, but different policies may take different
action of the file is write-protected (for example). Do
nothing if the document is null. Return true if the file saved,
otherwise false.
saveAs
boolean saveAs(Document d)
- Save the document to a user-specified location. Depending on
the policy, this may prompt the user for the file or URL
location, and may or may not change the file or URL of the
document to the new location. Do nothing if the document is
null. Return true if the file saved, otherwise false.