Interface Application
-
- All Known Implementing Classes:
- AbstractApplication, AppletApplication, MDIApplication, OSXApplication, SDIApplication
public interface ApplicationAn application handles the lifecycle ofViewobjects and provides windows to present them on screen.An application owns a
ApplicationModelwhich provides meta-data about the application, actions and factory methods for creating the views.Depending on the document interface style used by the application, an application can handle multiple views at the same time, or only one.
Typical document interface styles are the Single Document Interface (SDI), the Multiple Document Interface (MDI) and the Mac OS X Application Interface (OSX). Typically, for each of these styles an implementation of
Applicationexists.Some applications have to decorate all opened windows and dialogs with user interface elements and special behaviors. To make this work, it is essential that all code which opens JFrame's, JDialog's or JWindow's calls the addWindow/Palette and removeWindow/Palette methods on the application object.
Typical usage of this class:
public class MyMainClass { public static void main(String[] args) { Application app = new SDIApplication(); // or OSXApplication(), MDIApplication(). DefaultApplicationModel model = new DefaultApplicationModel(); model.setName("MyApplication"); model.setVersion("1.0"); model.setCopyright("Copyright 2006 (c) Werner Randelshofer. All Rights Reserved."); model.setViewClassName("org.jhotdraw.myapplication.MyView"); app.setModel(model); app.launch(args); }
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.Abstract Factory
MenuBuilderis used byApplicationfor creating menu items. TheMenuBuilderis provided byApplicationModel. Abstract Factory:MenuBuilder
Client:Application.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringACTIVE_VIEW_PROPERTYThe property name of the activeView property.static java.lang.StringRECENT_URIS_PROPERTYThe property name of the recentURIs property.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidadd(View p)Adds a view to this application.voidaddPalette(java.awt.Window palette)Adds a palette window to the application.voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)Adds a property change listener.voidaddRecentURI(java.net.URI uri)Appends a URI to the list of recent URIs.voidaddWindow(java.awt.Window window, View view)Adds a (non-palette) window to the application.voidclearRecentURIs()Clears the list of recent URIs.voidconfigure(java.lang.String[] args)Configures the application using the provided arguments array.javax.swing.JMenucreateEditMenu(View v)Creates an edit menu for the specified view or for the entire application.javax.swing.JMenucreateFileMenu(View v)Creates a file menu for the specified view or for the entire application.javax.swing.JMenucreateHelpMenu(View v)Creates a help menu for the specified view of for the entire application.ViewcreateView()Creates a new view for this application and initializes it, by callingView.init().javax.swing.JMenucreateViewMenu(View v)Creates a view menu for the specified view or for the entire application.javax.swing.JMenucreateWindowMenu(View v)Creates a window menu for the specified view or for the entire application.voiddestroy()Destroys the application and calls System.exit(0).voiddispose(View p)This is a convenience method for removing a view and disposing it.javax.swing.ActionMapgetActionMap(View v)Gets an action map for the specified view or for the entire application.ViewgetActiveView()Returns the active view.java.awt.ComponentgetComponent()Returns the application component.java.lang.StringgetCopyright()Returns the copyright of the application.URIChoosergetExportChooser(View v)Gets an export chooser for the specified view or for the entire application.URIChoosergetImportChooser(View v)Gets an import chooser for the specified view or for the entire application.ApplicationModelgetModel()Returns the application model.java.lang.StringgetName()Returns the name of the application.URIChoosergetOpenChooser(View v)Gets an open chooser for the specified view or for the entire application.java.util.List<java.net.URI>getRecentURIs()Returns the recently opened URIs.URIChoosergetSaveChooser(View v)Gets a save chooser for the specified view or for the entire application.java.lang.StringgetVersion()Returns the version of the application.voidhide(View p)Hides a view.voidinit()Initializes the application.booleanisEnabled()Returns the enabled state of the application.booleanisSharingToolsAmongViews()Returns true, if this application shares tools among multiple views.voidlaunch(java.lang.String[] args)Launches the application from the main method.voidremove(View p)Removes a view from this application and removes it from the users view.voidremovePalette(java.awt.Window palette)Removes a palette window from the application.voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)Removes a property change listener.voidremoveWindow(java.awt.Window window)Removes a (non-palette) window from the application.voidsetEnabled(boolean newValue)Sets the enabled state of the application.voidsetModel(ApplicationModel newValue)Sets the application model.voidshow(View p)Shows a view.voidstart(java.util.List<java.net.URI> uris)Starts the application.voidstop()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.
-
-
-
Field Detail
-
ACTIVE_VIEW_PROPERTY
static final java.lang.String ACTIVE_VIEW_PROPERTY
The property name of the activeView property.- See Also:
- Constant Field Values
-
RECENT_URIS_PROPERTY
static final java.lang.String RECENT_URIS_PROPERTY
The property name of the recentURIs property.- See Also:
- Constant Field Values
-
-
Method Detail
-
launch
void launch(java.lang.String[] args)
Launches the application from the main method. This method is typically invoked on the main Thread. This will invoke configure() on the current thread and then init() and start() on the AWT Event Dispatcher Thread.
-
configure
void configure(java.lang.String[] args)
Configures the application using the provided arguments array.
-
init
void init()
Initializes the application.configure()should have been invoked before the application is inited. Alternatively an application can be configured using setter methods.
-
start
void start(java.util.List<java.net.URI> uris)
Starts the application. This usually creates at least one view, and adds it to the application.init()must have been invoked before the application is started.- Parameters:
uris- Upon launch, the application may be requested to open views for a given list of URI's.
-
stop
void stop()
Stops the application without saving any unsaved views.init()must have been invoked before the application is stopped.
-
destroy
void destroy()
Destroys the application and calls System.exit(0).
-
createView
View createView()
Creates a new view for this application and initializes it, by callingView.init().
-
add
void add(View p)
Adds a view to this application. Fires a "documentCount" property change event. Invokes method setApplication(this) on the view object.
-
remove
void remove(View p)
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.
-
show
void show(View p)
Shows a view.
-
hide
void hide(View p)
Hides a view.
-
dispose
void dispose(View p)
This is a convenience method for removing a view and disposing it.
-
views
java.util.Collection<View> views()
Returns a read only collection view of the views of this application.
-
getActiveView
@Nullable View getActiveView()
Returns the active view. This is used for OSXApplication and MDIApplication which share actions among multiple View instances. Active view may be become null, if the application has no view.This is a bound property.
-
isEnabled
boolean isEnabled()
Returns the enabled state of the application.
-
setEnabled
void setEnabled(boolean newValue)
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.
-
addPropertyChangeListener
void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a property change listener.
-
removePropertyChangeListener
void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a property change listener.
-
getName
java.lang.String getName()
Returns the name of the application.
-
getVersion
java.lang.String getVersion()
Returns the version of the application.
-
getCopyright
java.lang.String getCopyright()
Returns the copyright of the application.
-
setModel
void setModel(ApplicationModel newValue)
Sets the application model.
-
getModel
ApplicationModel getModel()
Returns the application model.
-
isSharingToolsAmongViews
boolean isSharingToolsAmongViews()
Returns true, if this application shares tools among multiple views.
-
getComponent
@Nullable java.awt.Component getComponent()
Returns the application component. This may return null, if the application is not represented by a component of its own on the user interface.
-
addPalette
void addPalette(java.awt.Window palette)
Adds a palette window to the application.
-
removePalette
void removePalette(java.awt.Window palette)
Removes a palette window from the application.
-
addWindow
void addWindow(java.awt.Window window, @Nullable View view)Adds a (non-palette) window to the application.- Parameters:
window- The window.view- The View to which this window is associated, or null if the window is associated to the application.
-
removeWindow
void removeWindow(java.awt.Window window)
Removes a (non-palette) window from the application.
-
getRecentURIs
java.util.List<java.net.URI> getRecentURIs()
Returns the recently opened URIs. By convention, this is an immutable list.
-
addRecentURI
void addRecentURI(java.net.URI uri)
Appends a URI to the list of recent URIs. This fires a property change event for the property "recentURIs".
-
clearRecentURIs
void clearRecentURIs()
Clears the list of recent URIs. This fires a property change event for the property "recentURIs".
-
createFileMenu
@Nullable javax.swing.JMenu createFileMenu(@Nullable View v)
Creates a file menu for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A JMenu or null, if the menu is empty.
-
createEditMenu
@Nullable javax.swing.JMenu createEditMenu(@Nullable View v)
Creates an edit menu for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A JMenu or null, if the menu is empty.
-
createViewMenu
@Nullable javax.swing.JMenu createViewMenu(@Nullable View v)
Creates a view menu for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A JMenu or null, if the menu is empty.
-
createWindowMenu
@Nullable javax.swing.JMenu createWindowMenu(@Nullable View v)
Creates a window menu for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A JMenu or null, if the menu is empty.
-
createHelpMenu
@Nullable javax.swing.JMenu createHelpMenu(@Nullable View v)
Creates a help menu for the specified view of for the entire application.- Parameters:
v- A view or null.- Returns:
- A JMenu or null, if the menu is empty.
-
getOpenChooser
URIChooser getOpenChooser(@Nullable View v)
Gets an open chooser for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A chooser.
-
getSaveChooser
URIChooser getSaveChooser(@Nullable View v)
Gets a save chooser for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A chooser.
-
getExportChooser
URIChooser getExportChooser(@Nullable View v)
Gets an export chooser for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A chooser.
-
getImportChooser
URIChooser getImportChooser(@Nullable View v)
Gets an import chooser for the specified view or for the entire application.- Parameters:
v- A view or null.- Returns:
- A chooser.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG