org.jhotdraw.app
Interface View

All Known Subinterfaces:
DirectoryView, ExportableView, PrintableView
All Known Implementing Classes:
AbstractView, DrawView, NetView, ODGView, PertView, SVGView, TeddyView

public interface View

A view on a document or a set of related documents within an Application.

After a view has been initialized using init(), either method clear() must be called or method read(), in order to fully initialize the View.

Version:
4.1 2008-03-23 Added method canSaveTo().
4.0 2008-03-20 Renamed from Project to View.
3.0 2007-12-25 Added start, stop, activate and deactivate methods. Added constants for property names.
2.0 2007-11-29 Method clear is now always invoked on a worker thread.
1.0 October 4, 2005 Created.
Author:
Werner Randelshofer

Field Summary
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 FILE_PROPERTY
          The name of the file 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.
 
Method Summary
 void activate()
          Activates the view.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds a property change listener.
 boolean canSaveTo(java.io.File file)
          Returns true, if this view can be saved to the specified file.
 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.Action getAction(java.lang.String id)
          Returns the action with the specified id.
 Application getApplication()
          Gets the application to which this view belongs.
 javax.swing.JComponent getComponent()
          Returns the visual component of the view.
 java.io.File getFile()
          Returns the file which holds the document of the view.
 int getMultipleOpenId()
          Returns the multiple open id.
 javax.swing.JFileChooser getOpenChooser()
          Gets the open file chooser for the view.
 javax.swing.JFileChooser getSaveChooser()
          Gets the save file chooser for the view.
 java.lang.String getTitle()
          Gets the title of the view.
 boolean hasUnsavedChanges()
          Returns true, if the view has unsaved changes.
 void init()
          Initializes the view.
 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 putAction(java.lang.String id, javax.swing.Action action)
          Puts an action with the specified id.
 void read(java.io.File f)
          Reads the view from the specified file.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes a property change listener.
 void setApplication(Application newValue)
          Sets the application of the view.
 void setEnabled(boolean newValue)
          Sets the enabled state of the view.
 void setFile(java.io.File newValue)
          Sets the file 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 start()
          Starts the view.
 void stop()
          Stops the view.
 void write(java.io.File f)
          Writes the view to the specified file.
 

Field Detail

APPLICATION_PROPERTY

static final java.lang.String APPLICATION_PROPERTY
The name of the application property.

See Also:
Constant Field Values

FILE_PROPERTY

static final java.lang.String FILE_PROPERTY
The name of the file 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

Application getApplication()
Gets the application to which this view belongs.


setApplication

void setApplication(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.


getFile

java.io.File getFile()
Returns the file which holds the document of the view.


setFile

void setFile(java.io.File newValue)
Sets the file of the view. This is a bound property.


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.


write

void write(java.io.File f)
           throws java.io.IOException
Writes the view to the specified file. By convention this method is never invoked on the AWT Event Dispatcher Thread.

Throws:
java.io.IOException

read

void read(java.io.File f)
          throws java.io.IOException
Reads the view from the specified file. By convention this method is never invoked on the AWT Event Dispatcher Thread.

Throws:
java.io.IOException

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.


getOpenChooser

javax.swing.JFileChooser getOpenChooser()
Gets the open file chooser for the view.


getSaveChooser

javax.swing.JFileChooser getSaveChooser()
Gets the save file chooser for the view.


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.


canSaveTo

boolean canSaveTo(java.io.File file)
Returns true, if this view can be saved to the specified file. A reason why the view can't be saved to a file, is that the view is unable to write to a file with the given filename extension without losing data.

The SaveAction uses this method to decide, whether to display a file dialog before saving the file.

Parameters:
file - A file. If this parameter is null, a NullPointerException is thrown.

execute

void execute(java.lang.Runnable worker)
Executes the specified runnable on the worker thread of the view. Execution is perfomred sequentially in the same sequence as the runnables have been passed to this method.


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.


getAction

javax.swing.Action getAction(java.lang.String id)
Returns the action with the specified id.


putAction

void putAction(java.lang.String id,
               javax.swing.Action action)
Puts an action with the specified id.


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