当前位置: 首页 > 工具软件 > JHotDraw > 使用案例 >

jhotdraw docs: org.jhotdraw.app.application

慕容安易
2023-12-01

<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->

org.jhotdraw.app
接口 Application


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


 

 

版本:
$Id: Application.java 668 2010-07-28 21:22:39Z rawcoder $
作者:
Werner Randelshofer

<!-- =========== 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 =========== --><!-- -->

字段详细信息

<!-- -->

ACTIVE_VIEW_PROPERTY

static final java.lang.String ACTIVE_VIEW_PROPERTY

activeView 属性.

The property name of the activeView property.

 

另请参见:
常量字段值

<!-- -->

RECENT_URIS_PROPERTY

static final java.lang.String RECENT_URIS_PROPERTY

recentURIs 属性.

The property name of the recentURIs property.

 

另请参见:
常量字段值
<!-- ============ METHOD DETAIL ========== -->

<!-- -->

方法详细信息

<!-- -->

launch

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.

 


<!-- -->

configure

void configure(java.lang.String[] args)

配置字符串数组args来配置应用程序.

Configures the application using the provided arguments array.

 


<!-- -->

init

void init()

初始化应用程序. 在初始化程序之前, 必须先调用configure(). 配置应用程序可以调用对应的setter方法来完成.

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()

开始应用程序. 该方法创建一个新的视图, 并将该视图添加至应用程序中. 在开始应用程序之前, 必须先调用init()方法.

Starts the application. This usually creates a new view, and adds it to the application. init() must have been invoked before the application is started.

 


<!-- -->

stop

void stop()
在没有做任何保存操作的情况下停止应用程序.
在停止一个应用程序时, 必须保证该程序曾经调用过 init()方法.
Stops the application without saving any unsaved views. init() must have been invoked before the application is stopped.

 


<!-- -->

destroy

void destroy()
终止应用程序,并调用System.exit(0).

Destroys the application and calls System.exit(0).

 


<!-- -->

createView

org.jhotdraw.app.View createView()
常见一个应用程序的视图, 并通过调用 View.init() 对该视图进行初始化.

Creates a new view for this application and initializes it, by calling View.init().

 


<!-- -->

add

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.

 


<!-- -->

remove

void remove(org.jhotdraw.app.View p)
从应用程序和用户视图中删除一个视图(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.

 


<!-- -->

show

void show(org.jhotdraw.app.View p)
显示一个视图.

Shows a view.

 


<!-- -->

hide

void hide(org.jhotdraw.app.View p)
隐藏一个视图.

Hides a view.

 


<!-- -->

dispose

void dispose(org.jhotdraw.app.View p)
删除并隐藏一个视图.

This is a convenience method for removing a view and disposing it.

 


<!-- -->

views

java.util.Collection<org.jhotdraw.app.View> views()
以 collection 返回应用程序所有视图对象. 该collection 是只读的.

Returns a read only collection view of the views of this application.

 


<!-- -->

getActiveView

org.jhotdraw.app.View getActiveView()
返回活动的视图. 该方法用于OSX和MDI等在多个视图中共享动作(action)的应用程序. 如果应用程序当前没有视图, 则返回空(null)

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)
将 PropertyChangeListener 添加到侦听器列表

Adds a property change listener.

 


<!-- -->

removePropertyChangeListener

void removePropertyChangeListener(java.beans.PropertyChangeListener l)
将 PropertyChangeListener 从侦听器列表删除

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(org.jhotdraw.app.ApplicationModel newValue)
设置应用程序模型.

Sets the application model.

 


<!-- -->

getModel

org.jhotdraw.app.ApplicationModel getModel()
返回应用程序模型.

Returns the application model.

 


<!-- -->

isSharingToolsAmongViews

boolean isSharingToolsAmongViews()
若该应用程序在多个视图间共享工具则返回true.

Returns true, if this application shares tools among multiple views.

 


<!-- -->

getComponent

@Nullable
java.awt.Component getComponent()
返回应用程序组件. 如果应用程序UI并非以组件的形式显示, 则返回null.

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

<!-- -->

removeWindow

void removeWindow(java.awt.Window window)
从应用程序中删除一个窗口(非浮动窗口).

Removes a (non-palette) window from the application.

 


<!-- -->

getRecentURIs

java.util.List<java.net.URI> getRecentURIs()
返回最近打开的项目的URI列表, 该链表的内容是不可改变的.

Returns the recently opened URIs. By convention, this is an immutable list.

 


<!-- -->

addRecentURI

void addRecentURI(java.net.URI uri)
添加一个URI至最近打开列表. 该方法将引起一个名为"recentURIs"的属性变更事件.

Appends a URI to the list of recent URIs. This fires a property change event for the property "recentURIs".

 


<!-- -->

clearRecentURIs

void clearRecentURIs()
清除最近打开的列表. 该方法将引起一个名为"recentURIs"的属性变更事件.

Clears the list of recent URIs. This fires a property change event for the property "recentURIs".

 


<!-- -->

createFileMenu

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

返回:
菜单(JMenu)或者 null.

A JMenu or null, if the menu is empty.


<!-- -->

createEditMenu

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

返回:
菜单(JMenu)或者 null.

A JMenu or null, if the menu is empty.


<!-- -->

createViewMenu

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

返回:
菜单(JMenu)或者 null.

A JMenu or null, if the menu is empty.


<!-- -->

createWindowMenu

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

返回:
菜单(JMenu)或者 null.

A JMenu or null, if the menu is empty.


<!-- -->

createHelpMenu

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

返回:
菜单(JMenu)或者 null.

A JMenu or null, if the menu is empty.


<!-- -->

getOpenChooser

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.


<!-- -->

getSaveChooser

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.


<!-- -->

getExportChooser

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.


<!-- -->

getImportChooser

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.


<!-- -->

getActionMap

javax.swing.ActionMap getActionMap(@Nullable
                                   org.jhotdraw.app.View v)
获取特定视图或者整个应用程序的动作表(ActionMap)

Gets an action map for the specified view or for the entire application.

 

参数:
v - 一个视图或者null.

A view or null

<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->

<!-- -->

 类似资料:

相关阅读

相关文章

相关问答