JHotDraw 7rev733

org.jhotdraw.app
Class AbstractApplication

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.app.AbstractApplication
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Application
Direct Known Subclasses:
AppletApplication, MDIApplication, OSXApplication, SDIApplication

public abstract class AbstractApplication
extends AbstractBean
implements Application

This abstract class can be extended to implement an Application.

AbstractApplication supports the command line parameter -open filename to open views for specific URI's upon launch of the application.


Features

Open last URI on launch
When the application is started, the last opened URI is opened in a view.
The following methods participate in this feature:
Data suppliers addRecentURI(java.net.URI), getRecentURIs().
Behavior: start(java.util.List).
See org.jhotdraw.app for a list of participating classes.

Allow multiple views for URI
Allows opening the same URI in multiple views. When the feature is disabled, opening multiple views is prevented, and saving to a file for which a view is currently open is prevented.
The following methods participate in this feature:
Data suppliers getViews(). See org.jhotdraw.app for a list of participating classes.

Version:
$Id: AbstractApplication.java 756 2011-09-07 07:35:21Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
protected  ResourceBundleUtil labels
           
protected  ApplicationModel model
           
static java.lang.String VIEW_COUNT_PROPERTY
           
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Fields inherited from interface org.jhotdraw.app.Application
ACTIVE_VIEW_PROPERTY, RECENT_URIS_PROPERTY
 
Constructor Summary
AbstractApplication()
          Creates a new instance.
 
Method Summary
 void add(View v)
          Adds a view to this application.
protected  void addAction(javax.swing.JMenu m, javax.swing.Action a)
          Adds the specified action as a menu item to the supplied menu.
protected  void addAction(javax.swing.JMenu m, View view, java.lang.String actionID)
          Adds the specified action as a menu item to the supplied menu.
protected  void addMenuItem(javax.swing.JMenu m, javax.swing.JMenuItem mi)
          Adds the specified action as a menu item to the supplied menu.
 void addPalette(java.awt.Window palette)
          Adds a palette window to the application.
 void addRecentURI(java.net.URI uri)
          Adds an URI to the start of the list of recent URIs.
 void addWindow(java.awt.Window window, View p)
          Adds a (non-palette) window to the application.
protected  View basicCreateView()
           
 void clearRecentURIs()
          Clears the list of recent URIs.
 void configure(java.lang.String[] args)
          Configures the application using the provided arguments array.
 java.awt.Container createContainer()
           
protected  javax.swing.JMenu createOpenRecentFileMenu(View view)
           
 View createView()
          Creates a new view for this application and initializes it, by calling View.init().
protected abstract  javax.swing.ActionMap createViewActionMap(View p)
           
 void destroy()
          Stops the application and then calls System.exit(0).
 void dispose(View view)
          This is a convenience method for removing a view and disposing it.
protected  javax.swing.Action getAction(View view, java.lang.String actionID)
           
 javax.swing.ActionMap getActionMap(View v)
          Gets the action map.
 View getActiveView()
          Gets the active view.
 java.lang.String getCopyright()
          Returns the copyright of the application.
 URIChooser getExportChooser(View v)
          Gets an export chooser for the specified view or for the application.
 URIChooser getImportChooser(View v)
          Gets an import chooser for the specified view or for the application.
 ApplicationModel getModel()
          Returns the application model.
 java.lang.String getName()
          Returns the name of the application.
 URIChooser getOpenChooser(View v)
          Gets an open chooser for the specified view or for the application.
protected  java.util.List<java.net.URI> getOpenURIsFromMainArgs(java.lang.String[] args)
          Parses the arguments to the main method and returns a list of URI's for which views need to be opened upon launch of the application.
 java.util.List<java.net.URI> getRecentURIs()
          Returns the recently opened URIs.
 URIChooser getSaveChooser(View v)
          Gets a save chooser for the specified view or for the application.
 java.lang.String getVersion()
          Returns the version of the application.
 java.util.List<View> getViews()
          Returns an unmodifiable list of all views of the application.
 void init()
          Initializes the application after it has been configured.
protected  void initLabels()
           
 boolean isEnabled()
          Returns the enabled state of the application.
 void launch(java.lang.String[] args)
          Launches the application.
protected  void maybeAddSeparator(javax.swing.JMenu m)
          Adds a separator to the supplied menu.
 void remove(View v)
          Removes a view from this application and removes it from the users view.
 void removePalette(java.awt.Window palette)
          Removes a palette window from the application.
protected  void removeTrailingSeparators(javax.swing.JMenu m)
           
 void removeWindow(java.awt.Window window)
          Removes a (non-palette) window from the application.
 void setActionMap(javax.swing.ActionMap m)
          Sets the application-wide action map.
 void setActiveView(View newValue)
          Sets the active view.
 void setEnabled(boolean newValue)
          Sets the enabled state of the application.
 void setModel(ApplicationModel newValue)
          Sets the application model.
 void start(java.util.List<java.net.URI> uris)
          Starts the application.
 void stop()
          Stops the application without saving any unsaved views.
 java.util.Collection<View> views()
          Returns a read only collection view of the views of this application.
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.app.Application
addPropertyChangeListener, createEditMenu, createFileMenu, createHelpMenu, createViewMenu, createWindowMenu, getComponent, hide, isSharingToolsAmongViews, removePropertyChangeListener, show
 

Field Detail

labels

protected ResourceBundleUtil labels

model

protected ApplicationModel model

VIEW_COUNT_PROPERTY

public static final java.lang.String VIEW_COUNT_PROPERTY
See Also:
Constant Field Values
Constructor Detail

AbstractApplication

public AbstractApplication()
Creates a new instance.

Method Detail

init

public void init()
Initializes the application after it has been configured.

Specified by:
init in interface Application

start

public void start(java.util.List<java.net.URI> uris)
Starts the application.

This method creates a view for each supplied URI, and adds it to the application. If no URI has been supplied, this method may open an empty view.

By convention this method is only called after Application.init() has been called.

This method implements behavior for the following feature: Open URI on launch. See org.jhotdraw.app.

Specified by:
start in interface Application
Parameters:
uris - Upon launch, the application may be requested to open views for a given list of URI's.

createView

public final View createView()
Description copied from interface: Application
Creates a new view for this application and initializes it, by calling View.init(). The view has not been added to the application yet. To make the view usable with this application, call Application.add(View). To make it visible, first call add(View), then Application.show(View).

Specified by:
createView in interface Application

setModel

public void setModel(ApplicationModel newValue)
Description copied from interface: Application
Sets the application model.

Specified by:
setModel in interface Application

getModel

public ApplicationModel getModel()
Description copied from interface: Application
Returns the application model.

Specified by:
getModel in interface Application

basicCreateView

protected View basicCreateView()

setActiveView

public void setActiveView(@Nullable
                          View newValue)
Sets the active view. Calls deactivate on the previously active view, and then calls activate on the given view.

Parameters:
newValue - Active view, can be null.

getActiveView

@Nullable
public View getActiveView()
Gets the active view.

Specified by:
getActiveView in interface Application
Returns:
The active view can be null.

getName

public java.lang.String getName()
Description copied from interface: Application
Returns the name of the application.

Specified by:
getName in interface Application

getVersion

public java.lang.String getVersion()
Description copied from interface: Application
Returns the version of the application.

Specified by:
getVersion in interface Application

getCopyright

public java.lang.String getCopyright()
Description copied from interface: Application
Returns the copyright of the application.

Specified by:
getCopyright in interface Application

stop

public void stop()
Description copied from interface: Application
Stops the application without saving any unsaved views.

By convention this method is only called after Application.init() has been called.

This method must be called from AWT Event Dispatcher Thread.

Specified by:
stop in interface Application

destroy

public void destroy()
Description copied from interface: Application
Stops the application and then calls System.exit(0).

By convention this method is only called after Application.init() has been called.

This method must be called from AWT Event Dispatcher Thread.

Specified by:
destroy in interface Application

remove

public void remove(View v)
Description copied from interface: Application
Removes a view from this application and removes it from the users view. Fires a "documentCount" property change event. Invokes method setApplication(null) on the view object.

Specified by:
remove in interface Application

add

public void add(View v)
Description copied from interface: Application
Adds a view to this application. Fires a "documentCount" property change event. Invokes method setApplication(this) on the view object.

Specified by:
add in interface Application

getViews

public java.util.List<View> getViews()
Description copied from interface: Application
Returns an unmodifiable list of all views of the application.

The list of views is used by the Allow multiple views per URI feature. See org.jhotdraw.app.

Specified by:
getViews in interface Application

createViewActionMap

protected abstract javax.swing.ActionMap createViewActionMap(View p)

dispose

public void dispose(View view)
Description copied from interface: Application
This is a convenience method for removing a view and disposing it.

Specified by:
dispose in interface Application

views

public java.util.Collection<View> views()
Description copied from interface: Application
Returns a read only collection view of the views of this application.

Specified by:
views in interface Application

isEnabled

public boolean isEnabled()
Description copied from interface: Application
Returns the enabled state of the application.

Specified by:
isEnabled in interface Application

setEnabled

public void setEnabled(boolean newValue)
Description copied from interface: Application
Sets the enabled state of the application. The enabled state is used to prevent parallel invocation of actions on the application. If an action consists of a sequential part and a concurrent part, it must disable the application only for the sequential part. Actions that act on the application must check in their actionPerformed method whether the application is enabled. If the application is disabled, they must do nothing. If the application is enabled, they must disable the application, perform the action and then enable the application again. This is a bound property.

Specified by:
setEnabled in interface Application

createContainer

public java.awt.Container createContainer()

launch

public void launch(java.lang.String[] args)
Launches the application.

Specified by:
launch in interface Application
Parameters:
args - This implementation supports the command-line parameter "-open" which can be followed by one or more filenames or URI's.

getOpenURIsFromMainArgs

protected java.util.List<java.net.URI> getOpenURIsFromMainArgs(java.lang.String[] args)
Parses the arguments to the main method and returns a list of URI's for which views need to be opened upon launch of the application.

This implementation supports the command-line parameter "-open" which can be followed by one or more filenames or URI's.

This method is invoked from the Application.launch method.

Parameters:
args - Arguments to the main method.
Returns:
A list of URI's parsed from the arguments. Returns an empty list if no URI's shall be opened.

initLabels

protected void initLabels()

configure

public void configure(java.lang.String[] args)
Configures the application using the provided arguments array.

Specified by:
configure in interface Application

removePalette

public void removePalette(java.awt.Window palette)
Description copied from interface: Application
Removes a palette window from the application.

Specified by:
removePalette in interface Application

addPalette

public void addPalette(java.awt.Window palette)
Description copied from interface: Application
Adds a palette window to the application.

Specified by:
addPalette in interface Application

removeWindow

public void removeWindow(java.awt.Window window)
Description copied from interface: Application
Removes a (non-palette) window from the application.

Specified by:
removeWindow in interface Application

addWindow

public void addWindow(java.awt.Window window,
                      @Nullable
                      View p)
Description copied from interface: Application
Adds a (non-palette) window to the application.

Specified by:
addWindow in interface Application
Parameters:
window - The window.
p - The View to which this window is associated, or null if the window is associated to the application.

getAction

protected javax.swing.Action getAction(@Nullable
                                       View view,
                                       java.lang.String actionID)

addAction

protected void addAction(javax.swing.JMenu m,
                         @Nullable
                         View view,
                         java.lang.String actionID)
Adds the specified action as a menu item to the supplied menu.


addAction

protected void addAction(javax.swing.JMenu m,
                         javax.swing.Action a)
Adds the specified action as a menu item to the supplied menu.


addMenuItem

protected void addMenuItem(javax.swing.JMenu m,
                           javax.swing.JMenuItem mi)
Adds the specified action as a menu item to the supplied menu.


maybeAddSeparator

protected void maybeAddSeparator(javax.swing.JMenu m)
Adds a separator to the supplied menu. The separator will only be added, if the previous item is not a separator.


removeTrailingSeparators

protected void removeTrailingSeparators(javax.swing.JMenu m)

getRecentURIs

public java.util.List<java.net.URI> getRecentURIs()
Description copied from interface: Application
Returns the recently opened URIs. By convention, this is an unmodifiable list. The first item in the list is the most recently opened URI.

The most recent URI is used by the Open last URI on launch feature. See org.jhotdraw.app.

Specified by:
getRecentURIs in interface Application

clearRecentURIs

public void clearRecentURIs()
Description copied from interface: Application
Clears the list of recent URIs. This fires a property change event for the property "recentURIs".

The recent URIs are persisted (for example using the Java Preferences API) so that they are available on the next launch of the application.

The most recent URI is used by the Open last URI on launch feature. See org.jhotdraw.app.

Specified by:
clearRecentURIs in interface Application

addRecentURI

public void addRecentURI(java.net.URI uri)
Description copied from interface: Application
Adds an URI to the start of the list of recent URIs.

This fires a property change event for the property "recentURIs".

The recent URIs are persisted (for example using the Java Preferences API) so that they are available on the next launch of the application.

The most recent URI is used by the Open last URI on launch feature. See org.jhotdraw.app.

Specified by:
addRecentURI in interface Application

createOpenRecentFileMenu

protected javax.swing.JMenu createOpenRecentFileMenu(@Nullable
                                                     View view)

getOpenChooser

public URIChooser getOpenChooser(View v)
Gets an open chooser for the specified view or for the application.

If the chooser has an accessory panel, it can access the view using the client property "view" on the component of the chooser. It can access the application using the client property "application" on the chooser.

Specified by:
getOpenChooser in interface Application
Parameters:
v - The view. Specify null to get a chooser for the application.
Returns:
A chooser.

getSaveChooser

public URIChooser getSaveChooser(View v)
Gets a save chooser for the specified view or for the application.

If the chooser has an accessory panel, it can access the view using the client property "view" on the component of the chooser. It can access the application using the client property "application" on the chooser.

Specified by:
getSaveChooser in interface Application
Parameters:
v - The view. Specify null to get a chooser for the application.
Returns:
A chooser.

getImportChooser

public URIChooser getImportChooser(View v)
Gets an import chooser for the specified view or for the application.

If the chooser has an accessory panel, it can access the view using the client property "view" on the component of the chooser. It can access the application using the client property "application" on the chooser.

Specified by:
getImportChooser in interface Application
Parameters:
v - The view. Specify null to get a chooser for the application.
Returns:
A chooser.

getExportChooser

public URIChooser getExportChooser(View v)
Gets an export chooser for the specified view or for the application.

If the chooser has an accessory panel, it can access the view using the client property "view" on the component of the chooser. It can access the application using the client property "application" on the chooser.

Specified by:
getExportChooser in interface Application
Parameters:
v - The view. Specify null to get a chooser for the application.
Returns:
A chooser.

setActionMap

public void setActionMap(javax.swing.ActionMap m)
Sets the application-wide action map.


getActionMap

public javax.swing.ActionMap getActionMap(@Nullable
                                          View v)
Gets the action map.

Specified by:
getActionMap in interface Application
Parameters:
v - A view or null

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.