编辑Wazaabi UI
声明UI的三种方式
1、图形化建模工具
使用图形化建模编辑器,可以让美工参与GUI的设计开发工作。
通过定义好UI模型,指定一个渲染引擎来渲染模型,创建成目标用户界面技术
2、直接编码
Wazaabi 提供了API允许开发人员直接创建UI界面,下面是一个Java例子,
// create a composite and set its layout
Composite composite = WidgetsFactory.eINSTANCE.createComposite();
GridLayout gridLayout = LayoutsFactory.eINSTANCE.createGridLayout();
composite.setLayout(gridLayout);
//Set the number of columns
gridLayout.setNumColumns(2);
// create two labels with text
Label nameLabel = WidgetsFactory.eINSTANCE.createLabel();
Text nameText = WidgetsFactory.eINSTANCE.createText();
Label addressLabel = WidgetsFactory.eINSTANCE.createLabel();
Text addressText = WidgetsFactory.eINSTANCE.createText();
//Set the labels
nameLabel.setText("Name:");
addressLabel.setText("Address:");
//Save & cancel button
PushButton save = WidgetsFactory.eINSTANCE.createPushButton();
save.setText("Save");
PushButton cancel = WidgetsFactory.eINSTANCE.createPushButton();
cancel.setText("cancel");
//Add to the composite
composite.getChildren().add(nameLabel);
composite.getChildren().add(nameText);
composite.getChildren().add(addressLabel);
composite.getChildren().add(addressText);
composite.getChildren().add(save);
composite.getChildren().add(cancel);
完整例子看这里
/******************************************************************************* * Copyright (c) 2009 Skhiri Sabri * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http:// www.eclipse.org/legal/epl-v10.html * * Contributors: * Olivier Moses- initial API and implementation *******************************************************************************/ package org.wazaabi.engine.swt.snippets.standalone; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.wazaabi.engine.swt.SWTStandaloneHelper; import org.wazaabi.engine.swt.viewers.SWTControlViewer; import org.wazaabi.model.swt.layouts.GridLayout; import org.wazaabi.model.swt.layouts.LayoutsFactory; import org.wazaabi.model.swt.widgets.Composite; import org.wazaabi.model.swt.widgets.Label; import org.wazaabi.model.swt.widgets.PushButton; import org.wazaabi.model.swt.widgets.Text; import org.wazaabi.model.swt.widgets.WidgetsFactory; /** * Example of implementation of simple form. * @author sskhiri * */ public class FormSnippet { /** * @param args */ public static void main(String[] args) { // init SWT Engine in standalone mode SWTStandaloneHelper.init(); // create the shell Display display = new Display(); Shell mainShell = new Shell(display, SWT.SHELL_TRIM); mainShell.setText("Wazaabi UI form"); mainShell.setLayout(new FillLayout()); mainShell.setSize(300, 100); // create the viewer SWTControlViewer viewer = new SWTControlViewer(mainShell); // create a composite and set its layout Composite composite = WidgetsFactory.eINSTANCE.createComposite(); GridLayout gridLayout = LayoutsFactory.eINSTANCE.createGridLayout(); composite.setLayout(gridLayout); //Set the number of columns gridLayout.setNumColumns(2); // create two labels with text Label nameLabel = WidgetsFactory.eINSTANCE.createLabel(); Text nameText = WidgetsFactory.eINSTANCE.createText(); Label addressLabel = WidgetsFactory.eINSTANCE.createLabel(); Text addressText = WidgetsFactory.eINSTANCE.createText(); //Set the labels nameLabel.setText("Name:"); addressLabel.setText("Address:"); //Save & cancel button PushButton save = WidgetsFactory.eINSTANCE.createPushButton(); save.setText("Save"); PushButton cancel = WidgetsFactory.eINSTANCE.createPushButton(); cancel.setText("cancel"); //Add to the composite composite.getChildren().add(nameLabel); composite.getChildren().add(nameText); composite.getChildren().add(addressLabel); composite.getChildren().add(addressText); composite.getChildren().add(save); composite.getChildren().add(cancel); // Set the content viewer.setContents(composite); //Open the shell mainShell.open(); while (!mainShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
3、声明方式
Wazaabi框架提供了声明编辑器,可以很直观的设计GUI程序