⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xformscreen.java.svn-base

📁 j2me mobile application for upload file to server.
💻 SVN-BASE
字号:
package org.celllife.clforms;

import java.util.Vector;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import org.celllife.clforms.api.XFElement;
import org.celllife.clforms.api.XForm;
import org.celllife.clforms.task.IOTask;

import de.enough.polish.util.Locale;

public class XFormScreen extends MVCComponent {

	private static Displayable screen = null;
	private static int currentElement;
	private static Command exitCommand;
	private static Command selectCommand;
	private static Command saveCommand;

	private static XForm xf;

	// The calling mdlet. Set from outsdie
	public static FormFiller m;
	public static String url;

	public XFormScreen() {

	}

	public XFormScreen(XForm x) {
		XFormScreen.xf = x;

	}

	public Displayable getScreen() {
		return screen;
	}

	public void getNextElementScreen() {
		if (currentElement < xf.getElements().size() - 1) {
			currentElement++;
			XFElement e = (XFElement) xf.getElements()
					.elementAt(currentElement);
			(new ElementScreen(e,currentElement,xf.getElements().size())).showScreen();
		} else
			// we are at the last element and must return to the main menu
			showScreen();
	}

	public void finalData() {
		
		IOTask t = new IOTask(Locale.get("model.url"), display, false);
		t.setXform(xf);
		t.go();

	}

	public void commandAction(Command c, Displayable s) {
		try {
			if (c == exitCommand) {
				m.destroyApp(false);
				m.notifyDestroyed();
			} else if (c == selectCommand) {
				XFElement e = (XFElement) xf.getElements().elementAt(
						((List) screen).getSelectedIndex());
				currentElement = ((List) screen).getSelectedIndex();
				(new ElementScreen(e,currentElement,xf.getElements().size())).showScreen();
			} else if (c == saveCommand) {
				finalData();
			}
		} catch (Exception e) {
			e.printStackTrace();
			Alert a = new Alert(Locale.get("error.menu") + " 1"); //$NON-NLS-1$
			a.setString(e.getMessage());
			a.setTimeout(Alert.FOREVER);
			display.setCurrent(a);
		}
	}

	protected void initModel() throws Exception {
		// nothing to do here
	}

	protected void createView() throws Exception {
		// static member, only init once
		exitCommand = new Command(Locale.get("menu.exit"), Command.BACK, 1); //$NON-NLS-1$
		selectCommand = new Command(Locale.get("menu.select"), Command.OK, 2); //$NON-NLS-1$
		saveCommand = new Command(Locale.get("menu.save"), Command.BACK, 1); //$NON-NLS-1$

		if (xf != null) {
			screen = new List(xf.getName(), List.IMPLICIT);
			Vector v = xf.getElements();
			String item;
			if (v.size() <= 0) {
				Alert a= new Alert("Empty form.");
				a.setString("Form contains no elements.");
				a.setType(AlertType.WARNING);
				a.setTimeout(Alert.FOREVER);
				screen = a;
			}
			for (int i = 0; i < v.size(); i++) {
				XFElement e = (XFElement) v.elementAt(i);
				if (e.getId() == null) {
					item = e.getLabel();
				} else {
					item = e.getId();
				}
				((List) screen).append(item, null);
			}
			
			((List) screen).addCommand(exitCommand);
			((List) screen).setSelectCommand(selectCommand);
			((List) screen).addCommand(saveCommand);
		} else {
			Alert a = new Alert("Form load error");
			a.setString("Form not loaded");
			a.setType(AlertType.WARNING);
			a.setTimeout(Alert.FOREVER);
			screen = a;
		}

	}

	protected void updateView() throws Exception {
		if (xf != null) {
			screen = new List(xf.getName(), List.IMPLICIT);
			Vector v = xf.getElements();
			String item;
			if (v.size() <= 0) {
				Alert a= new Alert("Empty form.");
				a.setString("Form contains no elements.");
				a.setType(AlertType.WARNING);
				a.setTimeout(Alert.FOREVER);
				screen = a;
			}
			for (int i = 0; i < v.size(); i++) {
				XFElement e = (XFElement) v.elementAt(i);
				if (e.getId() == null) {
					item = e.getLabel();
					if (e.getValue() != null)
						item = item + "   =  " + e.getStringValue();
				} else {
					item = e.getId();
					if (e.getValue() != null)
						item = item + "   =  " + e.getStringValue();
				}
				((List) screen).append(item, null);
			}

			((List) screen).addCommand(exitCommand);
			((List) screen).setSelectCommand(selectCommand);
			((List) screen).addCommand(saveCommand);
		} else {
			Alert a = new Alert("Form load error");
			a.setString("Form not loaded");
			a.setType(AlertType.WARNING);
			a.setTimeout(Alert.FOREVER);
			screen = a;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -