开发SmartSWT应用
开发SmartSWT应用基本上和开发普通的SWT应用相同。您可以使用Eclipse的SWT可视化插件来帮助创建一个SWT应用程序,比较好的有Designer及Eclipse的VisualEditor等。
用于部署到SmartSWT服务器的SWT应用在开发时有些小的限制,幸好这些通常都只是举手之劳:
1. Display的获取必须统一使用Display display = Display.getDefault()方法,不能使用new Deisplay()创建,SmartSWT目前尚不支持多Display的应用,对大多数应用来说这不是问题;
2. 创建的Shell最好必须调用shell.setSize()对其尺寸进行初始化,否则在SmartSWT将默认呈最小化状态;
3. 尽量不要使用非公开的API,因为有少量非公开API,可能SmartSWT并没有实现它;
4. 尽量不要使用其它JNI技术和ActiveX控件,不要使用SWING和AWT等非基于SWT的控件;
5. 避免初始化时一次创建几十上百个控件,这样会造成启动时间较长,应在需要显示时创建控件。
部署SmartSWT应用
SmartSWT的部署一样很简单,只需将调试通过的SWT程序的类文件,按包名目录结构原封不动拷贝至SmartSWTServer的swtapps目录,然后在SmartSWTServer.xml文件中按以下格式注册一下,最后重启SmartSWTServer,你就可以通过客户端浏览器启动SmartSWT桌面,在Start->Programs菜单里启动它:
1 <!-- Configuration of each SWT Application
2 name: the name of the SWT Application
3 mainClass: the main class to start the SWT Application
4 startup: will it start just after the smartswt desktop started(haven't supported)
5 description: the description of the SWT Application
6 -->
7 <Application name="ControlExample"
8 mainClass="org.eclipse.swt.examples.controlexample.ControlExample">
9 <startup>false</startup>
10 <description>ControlExample Application</description>
11 </Application>
12
2 name: the name of the SWT Application
3 mainClass: the main class to start the SWT Application
4 startup: will it start just after the smartswt desktop started(haven't supported)
5 description: the description of the SWT Application
6 -->
7 <Application name="ControlExample"
8 mainClass="org.eclipse.swt.examples.controlexample.ControlExample">
9 <startup>false</startup>
10 <description>ControlExample Application</description>
11 </Application>
12