The Goal
Keep walking……
posts - 23,  comments - 1,  trackbacks - 0
  • Model-based adapters

与SWT widgets一起工作的JFace类可称为model-based adapters [或helper classes].这些adapter可以分为4类:
1.Viewers
将GUI组件中的信息与外观分离 [与SWT不同]
2.Actions and contributions
简化了事件的处理,将用户命令的反应与引发反应的事件分离
3.Image and font registries
注册机制,资源可以被按需分配和释放

4.Dialogs and wizards
信息框、错误框、进度框与向导框等

  • SET/JFace应用程序的三段式结构

package com.swtjface.Ch2;

import org.eclipse.jface.window.*;

import org.eclipse.swt.*;

import org.eclipse.swt.widgets.*;


public class HelloSWT_JFace extends ApplicationWindow {

public HelloSWT_JFace() {

super(null); //1.Window allocation

}

protected Control createContents(Composite parent) {

Text helloText = new Text(parent, SWT.CENTER);

helloText.setText("Hello SWT and JFace!");

parent.pack();

return parent; //2.Window presentation

/*处理窗口的设计,由于ApplicationWindow的可视部分不能被直接access,此方法连同一个Composite来控制GUI的显示,此container对象[Composite]是所有被加入应用程序的GUI组件的父件*/

}

public static void main(String[] args) {

HelloSWT_JFace awin = new HelloSWT_JFace();

awin.setBlockOnOpen(true);

awin.open();

Display.getCurrent().dispose();  //3.Window operation

/*负责GUI的实际运作。在分派好ApplicationWindow的资源之后,main方法使窗口显示,当setBlockOnOpen()方法以一个true参数被调用的时候,窗口关闭。然后ApplicationWindow的open()方法被调用,根据createContent()方法所返回的Composite来显示窗口。然后程序通过dispose()方法释放GUI的Display实例.因为此程序中的所有widget都是display的child,所以一旦释放Display,所有的widget都被释放*/

}

}

  • SWT与SWT/JFace的区别

SWT将GUI的外观和操作都放在它的Shell类里,而SWT/JFace却将两者分离开来了,其中外观由createContents()方法内的Compsite来控制,而操作部分大体上是通过ApplicationWindow类的实例来实现的。

  • ApplicationWindow

SWT/JFace同样需要一个单独的Display实例,但是只要ApplicationWindow通过一个null参数来构建,那么就会创建它自己的Shell。参阅下图

ApplicationWindow在Shell的基础上提供了更多的途径来设计窗口,其相关方法如下:
addMenuBar()
Configures the window with a top-level menu
addToolBar()
Adds a toolbar beneath the main menu
addStatusLine()
Creates a status area at the bottom of the window
setStatus(String)
Displays a message in the status area
getSeparator()
Returns the line separating the menu from the window
setDefaultImage(Image)
Displays an image when the application has no shell
setExceptionHandler(IExceptionHandler)
Configures the application to handle exceptions according to the specified interface

posted @ 2006-03-15 17:07 JOO 阅读(312) | 评论 (0)编辑 收藏
  • SWT应用程序的三段式结构:

package com.swtjface.Ch2;

import org.eclipse.swt.*;

import org.eclipse.swt.widgets.*;

public class HelloSWT {

public static void main (String [] args) {

Display display = new Display();

Shell shell = new Shell(display); //1.Allocation and initialization。
/*生成一个DisplayShell类的实例,GUI获取底层平台的资源并开辟了一个主窗口。*/

Text helloText = new Text(shell, SWT.CENTER);

helloText.setText("Hello SWT!");

helloText.pack();//2.Adding widgets to the shell

/* Shell 上加入一个文本小部件。The code in this section also sets the parameters for these widgets, containers, and events to make sure they look and act as required.其中pack()方法是tell the Shell and Text components to use only as much space as they need.*/

shell.pack();

shell.open();

while (!shell.isDisposed()){

if (!display.readAndDispatch()) display.sleep();

}

display.dispose(); //3.GUI operation

/*一旦Shell的open()方法被调用,应用程序的主窗口和其子部件都会被呈现。只要Shell保持在打开状态,Display实例就会通过它的readAndDispatch()方法来追踪在操作系统事件队列中的相关用户事件。当窗口关闭时,与Display对象(包括Shell以及其子部件等)相联系的资源就全部释放*/

}

}

  • Display 类

Display 类并不是可见的,但它负责监管着 GUI 的资源并管理着和操作系统的通信。它不光要关注着它自己的窗口是如何显示、移动和重画的,还同时要确保诸如鼠标点击、键盘敲击等事件送达widgets并去处理它们。

是任何 SWT JFace 应用程序的承载着,无论你是用 SWT/JFace 开发或是单用 SWT 开发,你必须在你的程序中包含这个类的一个实例。

Display 类的主要任务就是负责将你的代码重的 SWT JFace 命令翻译成底层的命令来调取操作系统。 这一过程包含了两部分: 1.Display 对象构建一个代表着操作系统平台的 OS 类的实例;这个类通过一系列被称之为native methods的特殊 Java 程序提供了接触计算机底层资源的途径。2. 这个 Display 对象使用这些方法来直接指令操作系统并向应用程序传达用户动作。

if any features in your operating system aren’t incorporated into SWT, you can use the Java Native Interface to add them yourself.All it requires is a native Java method in the SWT package and a C function in the native graphics library that calls the operating system.

  • Display 类的方法

1.Display()--Allocates platform resources and creates a Display object
must be used in any SWT-based GUI.它产生一个Display类的实例并将其和GUI相联系
2.getCurrent()--Returns the user-interface thread
must be used in any SWT-based GUI.它返回一个应用程序的主线程,用户界面线程,通常和dispose()一起使用来结束Display的操作。
3.readAndDispatch()--Display object interprets events and passes them to receiver
enable the application to receive notifications from the operating system whenever the user takes an action associated with the GUI.
accesses the operating system’s event queue and determines whether any of the user’s actions are related to the GUI.
Using this method, the HelloSWT class knows whether the user has decided to dispose of the Shell. If so, the method returns TRUE, and the application ends. Otherwise, the Display object invokes its sleep() method, and the application continues waiting.
4.sleep()--Display object waits for events
enable the application to receive notifications from the operating system whenever the user takes an action associated with the GUI.

  • Shell 类
  • The Shell class accesses the operating system through the OS class to an extent, but only to keep track of opening, activating, maximizing, minimizing, and closing the main window.

    The main function of the Shell class is to provide a common connection point for the containers, widgets, and events that need to be integrated into the GUI. Shell serves as the parent class to these components.

    attached to the Display的shell--top-level shells
    NOT directly attached to the Display instance的shell--secondary shell

    在你的GUI之内,你可以设定shell或其他小部件的风格参数值,若是多个值则可以用“|”相连.除了提到的属性,默认为“SHELL_TRIM”。

    SHELL_TRIM--有一个标题栏(SWT.TITLE)和用户可以最小化SWT.MIN)、最大化(SWT.MAX)、改变尺寸(SWT.RESIZE)和关闭(SWT.CLOSE)
    DIALOG_TRIM--有一个标题栏、一个活动区的边界(SWT.BORDER)和被关闭的能力

    你还可以确定
    shell的形态,以限定用户修改shell的modality,如A modal dialog box不能被移动或是改变尺寸,只可以使用给予的按钮关闭或是取消。


    NOT every platform can render these properties in GUI components.

    posted @ 2006-03-15 13:51 JOO 阅读(341) | 评论 (0)编辑 收藏
    仅列出标题
    共3页: 上一页 1 2 3 
    Hit the target!

    <2024年4月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    常用链接

    留言簿(2)

    随笔分类(23)

    随笔档案(22)

    文章档案(1)

    相册

    Neighbor

    搜索

    •  

    最新评论

    阅读排行榜

    评论排行榜