??xml version="1.0" encoding="utf-8" standalone="yes"?>
本篇译自?/span>
Eclipse.Building.Commercial.Quality.Plug.ins.2nd.Edition
》第四章W二节,希望对入门者有所帮助?/span>
lg的生命周?/span>
设计
SWT
的一个目标就是小而灵巧。ؓ(f)?jin)达到这个目标,一个基本的设计{略Q就是尽可能的ɾlg的状态存储在q_lg中而不是存储在
SWT
lg?/span>
(
q句话,我不理解Q也译的不明白Q附原文Q?/span>
To achieve this, a basic design decision was made that as much widget state as possible would be stored in the platform widget rather than in the SWT widget.)
。这?/span>
Swing
形成显著的对比,
Swing
?/span>
Swing
lg中维护了(jin)所有的lg状态?/span>
(
可能是这P(x)
SWT
把各个组件的状态交l系l^台来理Q?/span>
Swing
自己理各个
Swing
lg的状态,q样
Swing
复杂,耗费的资源,内存的需求也多,不知道是不是
J
)
。通过不把pȝq_U别的组件信息复制过来自q护,
SWT
非常的y而且对内存的需求也相应?/span>
辑ֈq个目的所付出的代价就?/span>
SWT
的组件不能够自己独立存在。当一?/span>
SWT
lg被创建时Q同时立卛_pȝq_下也创徏?jin)该lg的对应体。接下来Q几乎所有对该组件的信息状态请求都?x)由q_来处理?/span>
大部分的pȝq_在创Z个组件时Q需要该lg明确的父lg的上下文Q所?/span>
SWT
需要一个父lg来最为它的构造声明。许多^台在创徏lg时还需要该lg的特定风格参数的讑֮。例如:(x)按钮有复选框Q单选框Q简单按钮和文本域有单行和多行之分?/span>
?/span>
SWT
cMQ风gD는整数cd来定义且不会(x)更改。风格参数被l织在一P其它各种构造器传递着q些参数来创Z个组件的初始风格。注意到Q所有的q_q不支持所有的风格Q所以在很多情况下,被请求的风格被认为是一U提C,它或怼(x)或许不会(x)对一个特D的q_产生影响?/span>
?/span>
SWT
lg不在需要时Q一些^台要求作出明的释放。对于组件本w和一些资?/span>
(
例如Q图形,字体Q颜?/span>
)
而言Q他们已l具备了(jin)pȝ的这个要求。基本的规则是:(x)如果你创Z(jin)一个组Ӟp使用
dispose()
Ҏ(gu)来撤销q个lg。如果你使用?jin)一些系l资源,例如pȝ颜色Q你׃需要释放他们?/span>
q运的,当一个组件被释放的,它的所有子lg?x)自动地被释?/b>。这意味着Q如果你释放?jin)一?/span>
shell
Q那么所?/span>
shell
包含的组仉?x)被自动释放?/span>
]]>
HelloWorld (tng)一?/span>SWT 首先建立一?span lang="EN-US">java工程。在开始?span lang="EN-US">SWT之前Q需要将SWT库文件添加到工程的类路径中。步骤如下:(x)
1. (tng) (tng) (tng) 下蝲SWT。在Eclipse SDK的下载页面中Q提供了(jin)独立版本?span lang="EN-US">SWT下蝲。找到标?span class="docemphstrong">SWT Binary and Source的栏目。下载适合你操作系l的版本Q不用解压,直接保存到硬盘(sh)?/span>
2. (tng) (tng) (tng) ?span lang="EN-US">Eclipse菜单栏,选择File-?span lang="EN-US">Import...打开导入向导
3. (tng) (tng) (tng) 选择Existing Projects into WorkspaceQ点?b>Next按钮
4. (tng) (tng) (tng) 选择 Select archive fileq?Browse...按钮来找C刚才下蝲?span lang="EN-US">SWT文g?
(tng)5. (tng) (tng) (tng) 点击Finish按钮Q完?span lang="EN-US">SWT导入?
(tng)6. (tng) (tng) (tng) 右键点击你徏立的工程Q选择Properties 来打开Properties对话框?/span>
(tng)7. (tng) (tng) (tng) 选择 Java Build Path -> Projects tabq点?span class="docemphstrong">Add按钮.
(tng)8. (tng) (tng) (tng) 选择 org.eclipse.swt工程Q?点击 OKQ完成添?span lang="EN-US">SWT库到你的工程?span lang="EN-US">(见图1).
(tng)
(tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) 1
SWT 代码
现在在你建立?span lang="EN-US">java工程中,新徏一?span lang="EN-US">java文gQ取名ؓ(f)
HelloWorld。在HelloWorld.java文g中把main()Ҏ(gu)覆盖Z下代?span lang="EN-US">: (tng) (tng)
在覆盖了(jin)上述代码?span lang="EN-US">, 选择菜单栏中?
Source
-> Organize Imports命o(h) (或者按Ctrl+Shift+O) 来把需要引用的SWT包导入到HelloWorld.java文g?
?span lang="EN-US">
2行:(x)每个ZSWT的应用程序都有一?span lang="EN-US">Displaycȝ实例。用来将低层q_?span lang="EN-US">SWTq行链接。除?jin)管?span lang="EN-US">SWT的事件@环,q能讉KSWT需要的q_资源。在16行,display实例会(x)提交l垃圾收集器?span lang="EN-US">
3行:(x)每一个窗口都有一?span lang="EN-US">ShellH口框架Q来与用戯行交互?span lang="EN-US">Shell像所有的windowspȝ一h处理动作行ؓ(f)Qƈ作ؓ(f)H口控g的放|场所?span lang="EN-US">
4行:(x) setText()Ҏ(gu)讄H口的标?span lang="EN-US">.
5行:(x) setBounds() Ҏ(gu)讄H口的大和攄的位|?span lang="EN-US">. 在这个例子中, 讄H口?span lang="EN-US">200个像素宽Q?span lang="EN-US">50个像素高Qƈ攑֜dq的左上?span lang="EN-US">100x100像素的位|上?span lang="EN-US">
W?span lang="EN-US">6行:(x) setLayout()Ҏ(gu) 讄H口框架的布局. FillLayoutQ充满式布局理器,使得lg大小?x)尽量的充满整个容?span lang="EN-US">.SWT的布局理器会(x)在以后详l介l?
7行:(x)?span lang="EN-US">shell上新Z个简单的labellgq居中显C?span lang="EN-US">label的文本内宏V?span lang="EN-US">
8行:(x) setText() Ҏ(gu) 讄label的文本内宏V?span lang="EN-US">
9行:(x)创徏一个红色的颜色cȝ实例。你也可以用以下语句获得系l红色的实例Q?span lang="EN-US">
10行:(x) setForeground() Ҏ(gu) (tng)讄label的前景色
11行:(x)到目前ؓ(f)止,H口框架q是不可见的。通过open()Ҏ(gu)使得H口可见?span lang="EN-US">
12行:(x) while语句循环(g)窗口有没有关闭?span lang="EN-US">
W?span lang="EN-US">13行:(x)display 控制事g的@?span lang="EN-US">. readAndDispatch() Ҏ(gu)从^台的事g队列中读取事Ӟq分配他们到合适的处理E序(接收?span lang="EN-US">)。只要队列中一直有事g可以处理Q这个方法一直返?span lang="EN-US">trueQ当事g队列为空Ӟ则返?span lang="EN-US">false(因此允许用户界面UIU程Zsleep状态直C仉列不为空)?
15,16行:(x)当@环检到H口被关闭时Q需要将colorQ?span lang="EN-US">display和一些相兌的^台资源释放。注意到pȝ颜色实例(colors)会(x)被提交释放?span lang="EN-US">
(tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)
java应用E序Q会(x)使用Run As -?/b>
Java Application
UnsatisfiedLinkError
SWT
Run As > SWT Application
SWT
2
2
run
(tng)
(tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) 2
run
3
(tng)
(tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) 3
(以后l箋(hu))
A workbench window is a top level window in a workbench. Visually, a workbench window has a menubar, a toolbar, a status bar, and a main area for displaying a single page consisting of a collection of views and editors.
Each workbench window has a collection of 0 or more pages; the active page is the one that is being presented to the end user; at most one page is active in a window at a time.
This interface is not intended to be implemented by clients.
一个工作台H口是一个工作台的顶层窗?从视觉上?一个工作台H口拥有一个菜单栏,工具?状态栏和一个主区域,用来昄包括昄和编辑的一个页?
每个工作台窗口有0个或者更多的面.zd的页面是一U显C给当前使用者的面.大多数情况下,在一个时d有一个页面处于活动状?
q个接口不打由用户来实?
(to more)
Rich Client Tutorial Part 1
The Rich Client Platform (RCP) is an exciting new way to build Java applications that can compete with native applications on any platform. This tutorial is designed to get you started building RCP applications quickly. It has been updated for Eclipse 3.1.2
Try this experiment: Show Eclipse to some friends or co-workers who haven't seen it before and ask them to guess what language it is written in. Chances are, they'll guess VB, C++, or C#, because those languages are used most often for high quality client side applications. Then watch the look on their faces when you tell them it was created in Java, especially if they are Java programmers.
Because of its unique open source license, you can use the technologies that went into Eclipse to create your own commercial quality programs. Before version 3.0, this was possible but difficult, especially when you wanted to heavily customize the menus, layouts, and other user interface elements. That was because the "IDE-ness" of Eclipse was hard-wired into it. Version 3.0 introduced the Rich Client Platform (RCP), which is basically a refactoring of the fundamental parts of Eclipse's UI, allowing it to be used for non-IDE applications. Version 3.1 updated RCP with new capabilities, and, most importantly, new tooling support to make it easier to create than before.
If you want to cut to the chase and look at the code for this part you can find it in the accompanying zip file . Otherwise, let's take a look at how to construct an RCP application.
Eclipse Eclipse VB C++ C# java java
Eclipse 开放源代码许可的,你可以用 Eclipse 3.0 Eclipse IDE 3.0 Eclipse RCP Eclipse UI Eclipse UI Eclipse IDE 3.1 Eclipse RCP RCP
Rich Client Tutorial Part 1
accompanying zip file
RCP
RCP applications are based on the familiar Eclipse plug-in architecture, (if it's not familiar to you, see the references section). Therefore, you'll need to create a plug-in to be your main program. Eclipse's Plug-in Development Environment (PDE) provides a number of wizards and editors that take some of the drudgery out of the process. PDE is included with the Eclipse SDK download so that is the package you should be using. Here are the steps you should follow to get started.
RCP
Eclipse
Eclipse
PDE
PDE
Eclipse SDK
PDE
First, bring up Eclipse and select File > New > Project, then expand Plug-in Development and double-click Plug-in Project to bring up the Plug-in Project wizard. On the subsequent pages, enter a Project name such as org.eclipse.ui.tutorials.rcp.part1, indicate you want a Java project, select the version of Eclipse you're targeting (at least 3.1), and enable the option to Create an OSGi bundle manifest. Then click Next >.
Eclipse
Q选择File > New > Project?/strong>接下来选中
Plug-in DevelopmentQ?/strong>双击来打开插g工程向导。在弹出的页面中Q键入工E名Q例如:(x)
org.eclipse.ui.tutorials.rcp.part1Q,指明你要一?/span>
java工程Q选择你想创徏适用?/span>
Eclise的版本,q中使用
OSGI包。接下来点击
Next>
?/span>
noteQ?/b>Beginning in Eclipse 3.1 you will get best results by using the OSGi bundle manifest. In contrast to previous versions, this is now the default.
In the next page of the Wizard you can change the Plug-in ID and other parameters. Of particular importance is the question, "Would you like to create a rich client application?". Select Yes. The generated plug-in class is optional but for this example just leave all the other options at their default values. Click Next > to continue.
通过使用
Eclipse 3.1
OSGI
OSGi
ID
号和其他参数。尤其要x(chng)一个问题:(x)“你惌创徏一个富客户端的应用E序吗?”,选择“是”。生成的插gcL可选的Q但对于q个例子Q一切其他的可选项都设为默认倹{单?strong>Next >C一?strong>?/strong>
Getting started
noteQ?/b> If you get a dialog asking if Eclipse can switch to the Plug-in Development Perspective click Remember my decision and select Yes (this is optional).
Eclipse Starting with Eclipse 3.1, several templates have been provided to make creating an RCP application a breeze. We'll use the simplest one available and see how it works. Make sure the option to Create a plug-in using one of the templates is enabled, then select the Hello RCP template. This is RCP's equivalent of "Hello, world". Click Finish to accept all the defaults and generate the project (see Figure 1). Eclipse will open the Plug-in Manifest Editor. The Plug-in Manifest editor puts a friendly face on the various configuration files that control your RCP application.
Eclipse 3.1 RCP Hello RCP RCP Hello, world Eclipse
Figure 1. The Hello World RCP project was created by a PDE wizard.
]]>
վ֩ģ壺
˫|
Ӫɽ|
|
|
|
|
ʯ|
|
|
|
ͼ|
|
|
˰|
|
|
|
|
|
ɽ|
|
|
Ԫ|
|
ɽ|
|
ߺ|
|
ϰˮ|
|
|
Ұ|
|
ˮ|
ͼ|
|
|
ɽ|
Դ|
|
Ӣɽ|