@NotNull public interface Application
Application 用于控制View类的生命周期并提供一个窗口来显示View
类.
一个application拥有一个ApplicationModel
, ApplicationModel封装了关于应用程序 的信息(名称,版本,版权)以及创建View的模板方法.
application实现了基于文档界面的风格(document interface style), 一个application可以同时处理一个或者多个文档.
典型的文档界面有单文档界面(SDI, Single Document Interface), 多文档界面(MDI, Multiple Document Interface) 和Mac系统界面(OSX, Mac OS X Application Interface). 针对这些文档风格, JHotDraw已经提供了每种文档的默认实现. Application
exists.
一些应用程序需要对所有打开的窗口和对话窗进行特别的设置, 这就需要在打开JFrame, JDialog或JWindow时调用application的addWindow/Palette 或removeWindow/Palette 方法.(仅7.4之后的版本)
该类典型的使用方法:
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); }
设计模式
框架(Framework)
以下的接口和org.jhotdraw.app.action 包里所有类定义了面向文档应用程序的契约: ApplicationModel(org.jhotdraw.app), View(org.jhotdraw.app). Contract: Application
, ApplicationModel
, View
.
An application handles the lifecycle of View
objects and provides windows to present them on screen.
An application owns a ApplicationModel
which 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 Application
exists.
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 Patterns
Framework
The interfaces and classes listed below together with the Action
classes in the org.jhotddraw.app.action package define the contracts of a framework for document oriented applications:
Contract: Application
, ApplicationModel
, View
.
<!-- =========== FIELD SUMMARY =========== --><!-- -->
字段摘要 | |
---|---|
static java.lang.String | ACTIVE_VIEW_PROPERTY activeView 属性. |
static java.lang.String | RECENT_URIS_PROPERTY recentURIs 属性. |
<!-- ========== METHOD SUMMARY =========== -->
方法摘要 | |
---|---|
void | add(org.jhotdraw.app.View p) 为应用程序添加一个视图. |
void | addPalette(java.awt.Window palette) 将一个浮动窗口添加至应用程序. |
void | addPropertyChangeListener(java.beans.PropertyChangeListener l) 将 PropertyChangeListener 添加到侦听器列表 Adds a property change listener. |
void | addRecentURI(java.net.URI uri) 添加一个URI至最近打开列表. |
void | addWindow(java.awt.Window window, org.jhotdraw.app.View view) 添加一个窗口(非浮动窗口)至应用程序. |
void | clearRecentURIs() 清除最近打开的列表. |
void | configure(java.lang.String[] args) 配置字符串数组args来配置应用程序. |
javax.swing.JMenu | createEditMenu(org.jhotdraw.app.View v) 为应用程序或者指定的视图添加"编辑"菜单. |
javax.swing.JMenu | createFileMenu(org.jhotdraw.app.View v) 为应用程序或者指定的视图添加"文件"菜单. |
javax.swing.JMenu | createHelpMenu(org.jhotdraw.app.View v) 为应用程序或者指定的视图添加"帮助"菜单. |
org.jhotdraw.app.View | createView() 常见一个应用程序的视图, 并通过调用 View.init() 对该视图进行初始化. |
javax.swing.JMenu | createViewMenu(org.jhotdraw.app.View v) 为应用程序或者指定的视图添加"视图"菜单. |
javax.swing.JMenu | createWindowMenu(org.jhotdraw.app.View v) 为应用程序或者指定的视图添加"窗口"菜单. |
void | destroy() 终止应用程序,并调用System.exit(0). |
void | dispose(org.jhotdraw.app.View p) 删除并隐藏一个视图. |
javax.swing.ActionMap | getActionMap(org.jhotdraw.app.View v) 获取特定视图或者整个应用程序的动作表(ActionMap) Gets an action map for the specified view or for the entire application. |
org.jhotdraw.app.View | getActiveView() 返回活动的视图. |
java.awt.Component | getComponent() 返回应用程序组件. |
java.lang.String | getCopyright() 返回应用程序的版权信息. |
org.jhotdraw.gui.URIChooser | getExportChooser(org.jhotdraw.app.View v) 获取特定视图或者应用程序的"导出选择器". |
org.jhotdraw.gui.URIChooser | getImportChooser(org.jhotdraw.app.View v) 获取特定视图或者应用程序的"导入选择器". |
org.jhotdraw.app.ApplicationModel | getModel() 返回应用程序模型. |
java.lang.String | getName() 返回应用程序的名称. |
org.jhotdraw.gui.URIChooser | getOpenChooser(org.jhotdraw.app.View v) 获取特定视图或者应用程序的"打开选择器". |
java.util.List<java.net.URI> | getRecentURIs() 返回最近打开的项目的URI列表, 该链表的内容是不可改变的. |
org.jhotdraw.gui.URIChooser | getSaveChooser(org.jhotdraw.app.View v) 获取特定视图或者应用程序的"保存选择器". |
java.lang.String | getVersion() 返回应用程序的版本号. |
void | hide(org.jhotdraw.app.View p) 隐藏一个视图. |
void | init() 初始化应用程序. |
boolean | isEnabled() 确定应用程序是否启用. |
boolean | isSharingToolsAmongViews() 若该应用程序在多个视图间共享工具则返回true. |
void | launch(java.lang.String[] args) 启动应用程序, 通常在main方法中调用该方法. |
void | remove(org.jhotdraw.app.View p) 从应用程序和用户视图中删除一个视图(p). |
void | removePalette(java.awt.Window palette) 从应用程序中删除一个浮动窗口. |
void | removePropertyChangeListener(java.beans.PropertyChangeListener l) 将 PropertyChangeListener 从侦听器列表删除 Removes a property change listener. |
void | removeWindow(java.awt.Window window) 从应用程序中删除一个窗口(非浮动窗口). |
void | setEnabled(boolean newValue) 根据参数启用或者禁用应用程序. |
void | setModel(org.jhotdraw.app.ApplicationModel newValue) 设置应用程序模型. |
void | show(org.jhotdraw.app.View p) 显示一个视图. |
void | start() 开始应用程序. |
void | stop() 在没有做任何保存操作的情况下停止应用程序. |
java.util.Collection<org.jhotdraw.app.View> | views() 以 collection 返回应用程序所有视图对象. |
<!-- ============ FIELD DETAIL =========== --><!-- -->
字段详细信息 |
---|
static final java.lang.String ACTIVE_VIEW_PROPERTY
activeView 属性.
The property name of the activeView property.
static final java.lang.String RECENT_URIS_PROPERTY
recentURIs 属性.
The property name of the recentURIs property.
方法详细信息 |
---|
void launch(java.lang.String[] args)
启动应用程序, 通常在main方法中调用该方法.
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.
void configure(java.lang.String[] args)
配置字符串数组args来配置应用程序.
Configures the application using the provided arguments array.
void init()
初始化应用程序. 在初始化程序之前, 必须先调用configure()
. 配置应用程序可以调用对应的setter方法来完成.
configure()
should have been invoked before the application is inited. Alternatively an application can be configured using setter methods.
void start()
开始应用程序. 该方法创建一个新的视图, 并将该视图添加至应用程序中. 在开始应用程序之前, 必须先调用init()
方法.
init()
must have been invoked before the application is started.
void stop()
init()
方法.
init()
must have been invoked before the application is stopped.
void destroy()
Destroys the application and calls System.exit(0).
org.jhotdraw.app.View createView()
View.init()
对该视图进行初始化.
Creates a new view for this application and initializes it, by calling View.init()
.
void add(org.jhotdraw.app.View p)
该方法将引起一个 "documentCount" 属性改变事件.
调用视图对象(p)的setApplication(this) 方法.
Adds a view to this application. Fires a "documentCount" property change event. Invokes method setApplication(this) on the view object.
void remove(org.jhotdraw.app.View p)
该方法将引起一个 "documentCount" 属性改变事件.
调用视图对象(p)的setApplication(null) 方法.
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.
void show(org.jhotdraw.app.View p)
Shows a view.
void hide(org.jhotdraw.app.View p)
Hides a view.
void dispose(org.jhotdraw.app.View p)
This is a convenience method for removing a view and disposing it.
java.util.Collection<org.jhotdraw.app.View> views()
Returns a read only collection view of the views of this application.
org.jhotdraw.app.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.
boolean isEnabled()
Returns the enabled state of the application.
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.
void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a property change listener.
void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a property change listener.
java.lang.String getName()
Returns the name of the application.
java.lang.String getVersion()
Returns the version of the application.
java.lang.String getCopyright()
Returns the copyright of the application.
void setModel(org.jhotdraw.app.ApplicationModel newValue)
Sets the application model.
org.jhotdraw.app.ApplicationModel getModel()
Returns the application model.
boolean isSharingToolsAmongViews()
Returns true, if this application shares tools among multiple views.
@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.
void addPalette(java.awt.Window palette)
Adds a palette window to the application.
void removePalette(java.awt.Window palette)
Removes a palette window from the application.
void addWindow(java.awt.Window window, @Nullable org.jhotdraw.app.View view)
Adds a (non-palette) window to the application.
window
- 要添加到窗口. The window.
view
- 要添加窗口所属视图. 若view为null, 则该窗口将添加至应用程序层. The View to which this window is associated, or null if the window is associated to the application.
void removeWindow(java.awt.Window window)
Removes a (non-palette) window from the application.
java.util.List<java.net.URI> getRecentURIs()
Returns the recently opened URIs. By convention, this is an immutable list.
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".
void clearRecentURIs()
Clears the list of recent URIs. This fires a property change event for the property "recentURIs".
@Nullable javax.swing.JMenu createFileMenu(@Nullable org.jhotdraw.app.View v)
Creates a file menu for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A JMenu or null, if the menu is empty.
@Nullable javax.swing.JMenu createEditMenu(@Nullable org.jhotdraw.app.View v)
Creates an edit menu for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A JMenu or null, if the menu is empty.
@Nullable javax.swing.JMenu createViewMenu(@Nullable org.jhotdraw.app.View v)
Creates a view menu for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A JMenu or null, if the menu is empty.
@Nullable javax.swing.JMenu createWindowMenu(@Nullable org.jhotdraw.app.View v)
Creates a window menu for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A JMenu or null, if the menu is empty.
@Nullable javax.swing.JMenu createHelpMenu(@Nullable org.jhotdraw.app.View v)
Creates a help menu for the specified view of for the entire application.
v
- 一个视图或者null.
A view or null.
A JMenu or null, if the menu is empty.
org.jhotdraw.gui.URIChooser getOpenChooser(@Nullable org.jhotdraw.app.View v)
Gets an open chooser for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A chooser.
org.jhotdraw.gui.URIChooser getSaveChooser(@Nullable org.jhotdraw.app.View v)
Gets a save chooser for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A chooser.
org.jhotdraw.gui.URIChooser getExportChooser(@Nullable org.jhotdraw.app.View v)
Gets an export chooser for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A chooser.
org.jhotdraw.gui.URIChooser getImportChooser(@Nullable org.jhotdraw.app.View v)
Gets an import chooser for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null.
A chooser.
javax.swing.ActionMap getActionMap(@Nullable org.jhotdraw.app.View v)
Gets an action map for the specified view or for the entire application.
v
- 一个视图或者null.
A view or null
<!-- -->
|