站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题XSWT for Eclipse form layout

XSWT for Eclipse form layout

摘要: XSWT for Eclipse form layout

XSWT is an XML-based GUI-description language for SWT. The XSWT engine uses Java reflection to actually construct a user interface, so it is automatically compatible with current and future SWT controls. An eclipse editor for XSWT files is included.

现在开发的产品中用户界面也是用XML定义的,但是界面定义很不灵活。XSWT网站上介绍说XSWT是和SWT元素一一对应的,应该有很大的灵活性。

xswt的下载地址是:http://xswt.sourceforge.net/cgi-bin/xswt/download
也可以使用Eclipse的Update Manager从http://xswt.sourceforge.net/updates 在线更新。

下载了一个试用了一下,总体感觉还好。但是好像项目还没有开发完,文档没有。而且官方网站上说支持Groovy脚本语言的功能好像还没有提供。期待中。。。。

以下是一个我写的示例代码,演示了在XSWT中如何处理事件。
/*******************************************************************************
* $Header$
* $Revision$
* $Date$
*
*==============================================================================
*
* Copyright (c) 2001-2004 XYZ Technologies, Ltd.
* All rights reserved.
*
* Created on 2004-11-27
*******************************************************************************/

import java.io.InputStream;
import java.util.Map;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.swtworkbench.community.xswt.XSWT;


/**
* TODO此处填写 class 信息
*
* @author Yanfei (mailto:yanfei@hotmail.com)
*/
/*
* 修改历史
* $Log$
*/
public class XSWTDialogTest {

/**
*
*/
public XSWTDialogTest() {
super();
}

public static void main(String[] args) throws Exception{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());

InputStream in = XSWTDialogTest.class.getResource("JavaEditorPreferencePage.xswt").openStream();
Map controls = XSWT.create(shell, in);

Button button1 = (Button) controls.get("button1");
button1.addSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent e) {
MessageDialog.openInformation(shell, "Message", "button1 selected");
}

public void widgetDefaultSelected(SelectionEvent e) {

}
});

shell.setSize(600, 600);
shell.open();
while(!shell.isDisposed())
if(!display.readAndDispatch())
display.sleep();
display.dispose();
}

}

以下是定义界面的XSWT文件:
<?xml version="1.0" encoding="UTF-8"?>
























































































































































以下付上XSWT邮件列表中关于event handling的对话:
<table border=0> <tr> <td noWrap bgColor=#dddddd>From: ted stockwell
Event Handling?
2004-11-16 05:07 </td></tr> <tr> <td>

 Hi all,

 I just now downloaded XSWT and took a quick look around. 

 One thing that is not obvious to me is how to handle events.

 For instance, how do I handle a button selection?

 TIA,

 ted stockwell

</td></tr></table>



↑返回目录
前一篇: 使用eclipse(v3.01)与mingw(v3.1.0)搭建Windows下C/C++开发环境
后一篇: Eclipse资源改变通知机制