Interface View
-
- All Superinterfaces:
- Disposable
- All Known Subinterfaces:
- PrintableView
- All Known Implementing Classes:
- AbstractView, DrawView, NetView, ODGView, PertView, SVGView, TeddyView
public interface View extends Disposable
A view paints a document on aJComponentwithin anApplication.The document is identified by an
URI(for example a text document which is identified by the URI"file://home/readme.txt"). If the sameURIis 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
Applicationon how to launch an application.The lifecycle of a view consists of the following steps:
- Creation
The application instantiates the view object by callingnewInstance()on the class of the view. - Initialisation
The application calls the following methods:setActionMap(); setApplication(); init(). Then it either callsclear()orread()on a worker thread. - Start
The application adds the component of the view to a container (for example a JFrame) and then callsstart(). - Activation
When a view becomes the active view of the application, application callsactivate(). - Deactivation
When a view is not anymore the active view of the application, application callsdeactivate(). At a later time, the view may become activated again. - Stop
The application callsstop()on the view and then removes the component from its container. At a later time, the view may be started again. - Dispose
When the view is no longer needed, application callsdispose()on the view, followed bysetApplication(null)and then removes all references to it, so that it can be garbage collected.
Design PatternsFramework
The interfaces and classes listed below together with theActionclasses in the org.jhotddraw.app.action package define the contracts of a framework for document oriented applications:
Contract:Application,ApplicationModel,View.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringAPPLICATION_PROPERTYThe name of the application property.static java.lang.StringENABLED_PROPERTYThe name of the enabled property.static java.lang.StringHAS_UNSAVED_CHANGES_PROPERTYThe name of the hasUnsavedChanges property.static java.lang.StringMULTIPLE_OPEN_ID_PROPERTYThe name of the multipleOpenId property.static java.lang.StringSHOWING_PROPERTYThe name of the showing property.static java.lang.StringTITLE_PROPERTYThe name of the title property.static java.lang.StringURI_PROPERTYThe name of the uri property.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidactivate()Activates the view.voidaddDisposable(Disposable disposable)Adds a disposable object, which will be disposed when the view is disposed.voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)Adds a property change listener.booleancanSaveTo(java.net.URI uri)Returns true, if this view can be saved to the specified URI.voidclear()Clears the view, for example by emptying the contents of the view, or by reading a template contents from a file.voiddeactivate()Deactivates the view.voiddispose()Gets rid of all the resources of the view.voidexecute(java.lang.Runnable worker)Executes the specified runnable on the worker thread of the view.javax.swing.ActionMapgetActionMap()Gets the action map of the view.ApplicationgetApplication()Gets the application to which this view belongs.javax.swing.JComponentgetComponent()Returns the visual component of the view.intgetMultipleOpenId()Returns the multiple open id.java.lang.StringgetTitle()Gets the title of the view.java.net.URIgetURI()Returns the uri which holds the document of the view.booleanhasUnsavedChanges()Returns true, if the view has unsaved changes.voidinit()Initializes the view.booleanisEmpty()Whether the view is empty.booleanisEnabled()Returns the enabled state of the view.booleanisShowing()This is used by Application to keep track if a view is showing.voidmarkChangesAsSaved()Marks all changes as saved.voidread(java.net.URI uri, URIChooser chooser)Reads the view from the specified URI.voidremoveDisposable(Disposable disposable)Removes a disposable object, which was previously added.voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)Removes a property change listener.voidsetActionMap(javax.swing.ActionMap m)Sets the action map for the view.voidsetApplication(Application newValue)Sets the application of the view.voidsetEnabled(boolean newValue)Sets the enabled state of the view.voidsetMultipleOpenId(int newValue)Sets the multiple open id.voidsetShowing(boolean newValue)This is used by Application to keep track if a view is showing.voidsetTitle(java.lang.String newValue)Sets the title of the view.voidsetURI(java.net.URI newValue)Sets the uri of the view.voidstart()Starts the view.voidstop()Stops the view.voidwrite(java.net.URI uri, URIChooser chooser)Writes the view to the specified URI.
-
-
-
Field Detail
-
URI_PROPERTY
static final java.lang.String URI_PROPERTY
The name of the uri property.- See Also:
- Constant Field Values
-
APPLICATION_PROPERTY
static final java.lang.String APPLICATION_PROPERTY
The name of the application property.- See Also:
- Constant Field Values
-
TITLE_PROPERTY
static final java.lang.String TITLE_PROPERTY
The name of the title property.- See Also:
- Constant Field Values
-
ENABLED_PROPERTY
static final java.lang.String ENABLED_PROPERTY
The name of the enabled property.- See Also:
- Constant Field Values
-
HAS_UNSAVED_CHANGES_PROPERTY
static final java.lang.String HAS_UNSAVED_CHANGES_PROPERTY
The name of the hasUnsavedChanges property.- See Also:
- Constant Field Values
-
MULTIPLE_OPEN_ID_PROPERTY
static final java.lang.String MULTIPLE_OPEN_ID_PROPERTY
The name of the multipleOpenId property.- See Also:
- Constant Field Values
-
SHOWING_PROPERTY
static final java.lang.String SHOWING_PROPERTY
The name of the showing property.- See Also:
- Constant Field Values
-
-
Method Detail
-
getApplication
@Nullable Application getApplication()
Gets the application to which this view belongs.
-
setApplication
void setApplication(@Nullable Application newValue)
Sets the application of the view. By convention, this is only invoked by Application.add() and Application.remove(). This is a bound property.
-
getComponent
javax.swing.JComponent getComponent()
Returns the visual component of the view.
-
isEnabled
boolean isEnabled()
Returns the enabled state of the view.
-
setEnabled
void setEnabled(boolean newValue)
Sets the enabled state of the view. The enabled state is used to prevent parallel invocation of actions on the view. If an action consists of a sequential part and a concurrent part, it must disable the view only for the sequential part. Actions that act on the view must check in their actionPerformed method whether the view is enabled. If the view is disabled, they must do nothing. If the view is enabled, they must disable the view, perform the action and then enable the view again. This is a bound property.
-
clear
void clear()
Clears the view, for example by emptying the contents of the view, or by reading a template contents from a file. By convention this method is never invoked on the AWT Event Dispatcher Thread.
-
isEmpty
boolean isEmpty()
Whether the view is empty. A view is considered empty if the application has implicit consent from the user to reuse or destroy the view at any time. For example, an application may open an empty view immediately after startup. If the user chooses to open a document, the document is opened in this view rather than in a new view.If this method returns true,
OpenFileActionand similar actions will open a file in this view, instead of opening a new view.- Returns:
- True if the view can be reused by open actions.
-
hasUnsavedChanges
boolean hasUnsavedChanges()
Returns true, if the view has unsaved changes. This is a bound property.
-
markChangesAsSaved
void markChangesAsSaved()
Marks all changes as saved. This changes the state of hasUnsavedChanges to false.
-
execute
void execute(java.lang.Runnable worker)
Executes the specified runnable on the worker thread of the view. Execution is performed sequentially in the same sequence as the runnables have been passed to this method.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.
-
init
void init()
Initializes the view. This is invoked right before the application shows the view. A view must not consume many resources before method init() is called. This is crucial for the responsivenes of an application.After a view has been initialized using init(), either method clear() must be called or method read, in order to fully initialize a View.
-
start
void start()
Starts the view. Invoked after a view has been made visible to the user. Multiple view can be visible at the same time.
-
activate
void activate()
Activates the view. This occurs, when the user activated the parent window of the view. Only one view can be active at any given time. This method is only invoked on a started view.
-
deactivate
void deactivate()
Deactivates the view. This occurs, when the user closes the view, or activated another view. This method is only invoked on a started view.
-
stop
void stop()
Stops the view. Invoked after a view window has been minimized or made invisible.
-
dispose
void dispose()
Gets rid of all the resources of the view. No other methods should be invoked on the view afterwards. A view must not consume many resources after method dispose() has been called. This is crucial for the responsivenes of an application.- Specified by:
disposein interfaceDisposable
-
getActionMap
javax.swing.ActionMap getActionMap()
Gets the action map of the view.
-
setActionMap
void setActionMap(javax.swing.ActionMap m)
Sets the action map for the view.
-
addPropertyChangeListener
void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a property change listener.
-
removePropertyChangeListener
void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a property change listener.
-
setMultipleOpenId
void setMultipleOpenId(int newValue)
Sets the multiple open id. The id is used to help distinguish multiply opened views. The id should be displayed in the title of the view.
-
getMultipleOpenId
int getMultipleOpenId()
Returns the multiple open id. If a view is open only once this should be 1.
-
isShowing
boolean isShowing()
This is used by Application to keep track if a view is showing.
-
setShowing
void setShowing(boolean newValue)
This is used by Application to keep track if a view is showing.
-
setTitle
void setTitle(java.lang.String newValue)
Sets the title of the view.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.
-
getTitle
java.lang.String getTitle()
Gets the title of the view.
-
addDisposable
void addDisposable(Disposable disposable)
Adds a disposable object, which will be disposed when the view is disposed.- Parameters:
disposable-
-
removeDisposable
void removeDisposable(Disposable disposable)
Removes a disposable object, which was previously added.- Parameters:
disposable-
-
getURI
java.net.URI getURI()
Returns the uri which holds the document of the view.
-
setURI
void setURI(java.net.URI newValue)
Sets the uri of the view. This is a bound property.
-
canSaveTo
boolean canSaveTo(java.net.URI uri)
Returns true, if this view can be saved to the specified URI. A reason why the view can't be saved to a URI, is that the view is unable to write to a file-URI with the given filename extension without losing data.The SaveAction uses this method to decide, whether to display a save dialog before saving the URI.
- Parameters:
uri- An URI. If this parameter is null, a NullPointerException is thrown.
-
write
void write(java.net.URI uri, @Nullable URIChooser chooser) throws java.io.IOExceptionWrites the view to the specified URI.By convention this method is never invoked on the AWT Event Dispatcher Thread.
- Parameters:
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.- Throws:
java.io.IOException
-
read
void read(java.net.URI uri, @Nullable URIChooser chooser) throws java.io.IOExceptionReads the view from the specified URI.By convention this method is never invoked on the AWT Event Dispatcher Thread.
- Parameters:
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.- Throws:
java.io.IOException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG