JHotDraw 7.0.9

org.jhotdraw.application
Interface DocumentView

All Known Subinterfaces:
ExportableDocumentView
All Known Implementing Classes:
AbstractDocumentView, TeddyView

public interface DocumentView

Provides a view to a document inside of a document oriented Application.

A DocumentView usually goes through the following method calls after its creation: init), {@code setEnabled(false)}, ({@code clear} or {@code read}), {@code setEnabled(true)}, {@code start}

Version:
2.0 2007-07-07 Renamed from Project to DocumentView. Overhauled overall design.
1.0 2007-03-22 Created.
Author:
Werner Randelshofer

Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds a property change listener.
 void clear()
          Clears the contents of the document view.
 void destroy()
          Called by the WindowManager to inform this view that it is being reclaimed and that it should destroy of any resources that it has allocated.
 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.
 javax.swing.JComponent getComponent()
          Returns the visual component of the view.
 java.io.File getFile()
          Returns the file which is associated to this document view.
 java.lang.String getName()
          Returns the name of the view.
 javax.swing.JFileChooser getOpenChooser()
          Gets the open file chooser for the document view.
 javax.swing.JFileChooser getSaveChooser()
          Gets the save file chooser for the document view.
 void init()
          Called by the WindowManager to inform this view that it has been loaded into the system.
 boolean isEnabled()
          Determines whether this view is enabled.
 boolean isModified()
          Returns true, if the document view has unsaved changes.
 void putAction(java.lang.String id, javax.swing.Action action)
          Puts an action with the specified id.
 void read(java.io.File f)
          Reads contents for the document view from the specified file.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes a property change listener.
 void setEnabled(boolean newValue)
          Sets the enabled state of the view.
 void setFile(java.io.File newValue)
          Associates the document view with a file.
 void setModified(boolean newValue)
          Sets the modified state of the document view.
 void setName(java.lang.String newValue)
          Sets the name of the view.
 void start()
          Called by the WindowManager to inform this view that it should start its execution.
 void stop()
          Called by the WindowManager to inform this view that it should stop its execution.
 void write(java.io.File f)
          Writes the contents of the view to the specified file.
 

Method Detail

getComponent

javax.swing.JComponent getComponent()
Returns the visual component of the view.

Returns:
The visual component of the view.

setName

void setName(java.lang.String newValue)
Sets the name of the view. The name is used by the user to uniquely identify a view.

Parameters:
newValue - the new name of the view

getName

java.lang.String getName()
Returns the name of the view.

Returns:
the name of the view

init

void init()
Called by the WindowManager to inform this view that it has been loaded into the system. It is always called before the first time that the start method is called.


destroy

void destroy()
Called by the WindowManager to inform this view that it is being reclaimed and that it should destroy of any resources that it has allocated. The stop method will always be called before destroy.


start

void start()
Called by the WindowManager to inform this view that it should start its execution. It is called after the init method and each time the window wich contains the view is made visible or restored from minimized state.


stop

void stop()
Called by the WindowManager to inform this view that it should stop its execution. It is called when the window which contains the view has been hidded or minimized, and also just before the view is to be destroyed.


isEnabled

boolean isEnabled()
Determines whether this view is enabled. An enabled view can respond to user input and can perform actions on behalf of the user. Views are enabled initially by default. A view may be enabled or disabled by calling its setEnabled method.

Actions that act on the view must check in their actionPerformed method whether the view is enabled. If the document view is disabled, they must do nothing. Ideally, Actions which perform on a view, couple their enabled state with the enabled state of the view.

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 document view. If an action consists of a sequential part and a concurrent part, it must disable the document view only for the sequential part. This is a bound property.


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.


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.


getFile

java.io.File getFile()
Returns the file which is associated to this document view. Returns null, if the document view has been created in memory and never been saved yet.

Parameters:
the - file associated with this document view, or null.

setFile

void setFile(java.io.File newValue)
Associates the document view with a file.

Changing the value of this property does not trigger file loading or saving.

Parameters:
file - the file associated with this document view. Null values are allowed.

clear

void clear()
           throws java.io.IOException
Clears the contents of the document view.

The cleared contents does not need to be entirely empty. A view may read a template from the file system or another slow media, to get its cleared state.

By convention this method is never invoked on the AWT Event Dispatcher Thread. The view needs to be disabled before this method is invoked, and needs to be enabled afterwards.

Throws:
java.io.IOException

write

void write(java.io.File f)
           throws java.io.IOException
Writes the contents of the view to the specified file.

By convention this method is never invoked on the AWT Event Dispatcher Thread. The view needs to be disabled before this method is invoked, and needs to be enabled afterwards.

Parameters:
f - The file.
Throws:
java.io.IOException

read

void read(java.io.File f)
          throws java.io.IOException
Reads contents for the document view from the specified file.

By convention this method is never invoked on the AWT Event Dispatcher Thread. The view needs to be disabled before this method is invoked, and needs to be enabled afterwards.

Parameters:
f - The file.
Throws:
java.io.IOException

getOpenChooser

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

The document view can accessorize the file chooser. The document view should keep the file chooser instance over multiple invocations of this method, so that it remembers its state.


getSaveChooser

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

The document view can accessorize the file chooser. The document view should keep the file chooser instance over multiple invocations of this method, so that it remembers its state.


isModified

boolean isModified()
Returns true, if the document view has unsaved changes. This is a bound property.


setModified

void setModified(boolean newValue)
Sets the modified state of the document view. This is a bound property.

A view should change its modified state by itself, when its contents is modified.


Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.