public interface View extends Disposable
JComponent
within an
Application
.
The document is identified by an URI
(for example a text document
which is identified by the URI "file://home/readme.txt"
).
If the same URI
is opened in multiple views, the application sets
a 'multiple open ID' on the view, so that the user can distinguish between
the views.
The life of view objects is managed by an application. See the class
comment of Application
on how to launch an application.
The lifecycle of a view consists of the following steps:
newInstance()
on the class of the view.
setActionMap();
setApplication(); init()
.
Then it either calls clear()
or read()
on a worker thread.
start()
.
activate()
.
deactivate()
. At a later time, the view may become activated again.
stop()
on the view and then removes the
component from its container. At a later time, the view may be started
again.
dispose()
on
the view, followed by setApplication(null)
and then removes all
references to it, so that it can be garbage collected.
Framework
The interfaces and classes listed below together with the Action
classes in the org.jhotddraw.app.action package define the contracts of a
framework for document oriented applications:
Contract: Application
, ApplicationModel
, View
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_PROPERTY
The name of the application property.
|
static java.lang.String |
ENABLED_PROPERTY
The name of the enabled property.
|
static java.lang.String |
HAS_UNSAVED_CHANGES_PROPERTY
The name of the hasUnsavedChanges property.
|
static java.lang.String |
MULTIPLE_OPEN_ID_PROPERTY
The name of the multipleOpenId property.
|
static java.lang.String |
SHOWING_PROPERTY
The name of the showing property.
|
static java.lang.String |
TITLE_PROPERTY
The name of the title property.
|
static java.lang.String |
URI_PROPERTY
The name of the uri property.
|
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activates the view.
|
void |
addDisposable(Disposable disposable)
Adds a disposable object, which will be disposed when the view
is disposed.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a property change listener.
|
boolean |
canSaveTo(java.net.URI uri)
Returns true, if this view can be saved to the specified URI.
|
void |
clear()
Clears the view, for example by emptying the contents of
the view, or by reading a template contents from a file.
|
void |
deactivate()
Deactivates the view.
|
void |
dispose()
Gets rid of all the resources of the view.
|
void |
execute(java.lang.Runnable worker)
Executes the specified runnable on the worker thread of the view.
|
javax.swing.ActionMap |
getActionMap()
Gets the action map of the view.
|
Application |
getApplication()
Gets the application to which this view belongs.
|
javax.swing.JComponent |
getComponent()
Returns the visual component of the view.
|
int |
getMultipleOpenId()
Returns the multiple open id.
|
java.lang.String |
getTitle()
Gets the title of the view.
|
java.net.URI |
getURI()
Returns the uri which holds the document of the view.
|
boolean |
hasUnsavedChanges()
Returns true, if the view has unsaved changes.
|
void |
init()
Initializes the view.
|
boolean |
isEmpty()
Whether the view is empty.
|
boolean |
isEnabled()
Returns the enabled state of the view.
|
boolean |
isShowing()
This is used by Application to keep track if a view is showing.
|
void |
markChangesAsSaved()
Marks all changes as saved.
|
void |
read(java.net.URI uri,
URIChooser chooser)
Reads the view from the specified URI.
|
void |
removeDisposable(Disposable disposable)
Removes a disposable object, which was previously added.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a property change listener.
|
void |
setActionMap(javax.swing.ActionMap m)
Sets the action map for the view.
|
void |
setApplication(Application newValue)
Sets the application of the view.
|
void |
setEnabled(boolean newValue)
Sets the enabled state of the view.
|
void |
setMultipleOpenId(int newValue)
Sets the multiple open id.
|
void |
setShowing(boolean newValue)
This is used by Application to keep track if a view is showing.
|
void |
setTitle(java.lang.String newValue)
Sets the title of the view.
|
void |
setURI(java.net.URI newValue)
Sets the uri of the view.
|
void |
start()
Starts the view.
|
void |
stop()
Stops the view.
|
void |
write(java.net.URI uri,
URIChooser chooser)
Writes the view to the specified URI.
|
static final java.lang.String URI_PROPERTY
static final java.lang.String APPLICATION_PROPERTY
static final java.lang.String TITLE_PROPERTY
static final java.lang.String ENABLED_PROPERTY
static final java.lang.String HAS_UNSAVED_CHANGES_PROPERTY
static final java.lang.String MULTIPLE_OPEN_ID_PROPERTY
static final java.lang.String SHOWING_PROPERTY
Application getApplication()
void setApplication(Application newValue)
javax.swing.JComponent getComponent()
boolean isEnabled()
void setEnabled(boolean newValue)
void clear()
boolean isEmpty()
If this method returns true, OpenFileAction
and similar actions will open a file in this view, instead of
opening a new view.
boolean hasUnsavedChanges()
void markChangesAsSaved()
void execute(java.lang.Runnable worker)
Use this method for long running tasks which affect the contents of the view as a whole. For example for loading and saving a document.
void init()
After a view has been initialized using init(), either method clear() must be called or method read, in order to fully initialize a View.
void start()
void activate()
void deactivate()
void stop()
void dispose()
dispose
in interface Disposable
javax.swing.ActionMap getActionMap()
void setActionMap(javax.swing.ActionMap m)
void addPropertyChangeListener(java.beans.PropertyChangeListener l)
void removePropertyChangeListener(java.beans.PropertyChangeListener l)
void setMultipleOpenId(int newValue)
int getMultipleOpenId()
boolean isShowing()
void setShowing(boolean newValue)
void setTitle(java.lang.String newValue)
The title is generated by the application, based on the current URI of the view. The application ensures that the title uniquely identifies each open view.
The application displays the title in the title bar of the view window and in all windows which are associated to the view.
This is a bound property.
java.lang.String getTitle()
void addDisposable(Disposable disposable)
disposable
- void removeDisposable(Disposable disposable)
disposable
- java.net.URI getURI()
void setURI(java.net.URI newValue)
boolean canSaveTo(java.net.URI uri)
The SaveAction uses this method to decide, whether to display a save dialog before saving the URI.
uri
- An URI. If this parameter is null, a NullPointerException
is thrown.void write(java.net.URI uri, URIChooser chooser) throws java.io.IOException
By convention this method is never invoked on the AWT Event Dispatcher Thread.
uri
- The location where to write the view.chooser
- The chooser which was used for selecting the URI. This
parameter is null if no chooser was used.java.io.IOException
void read(java.net.URI uri, URIChooser chooser) throws java.io.IOException
By convention this method is never invoked on the AWT Event Dispatcher Thread.
uri
- The location where to write the view.chooser
- The chooser which was used for selecting the URI. This
parameter is null if no chooser was used.java.io.IOException