01: /* FormFactory.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue May 15 14:58:13 2007, Created by henrichen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zkmob.factory;
20:
21: import javax.microedition.lcdui.AlertType;
22: import javax.microedition.lcdui.Gauge;
23:
24: import org.xml.sax.Attributes;
25: import org.zkoss.zkmob.UiManager;
26: import org.zkoss.zkmob.ZkComponent;
27: import org.zkoss.zkmob.ui.ZkAlert;
28:
29: /**
30: * A UiFactory that create an Alert Ui component.
31: *
32: * @author henrichen
33: */
34: public class AlertFactory extends AbstractUiFactory {
35: public AlertFactory(String name) {
36: super (name);
37: }
38:
39: public ZkComponent create(ZkComponent parent, String tag,
40: Attributes attrs, String hostURL, String pathURL) {
41: final String id = attrs.getValue("id"); //id
42: final String title = attrs.getValue("tt"); //title
43: final String text = attrs.getValue("tx"); //text
44: final String typeStr = attrs.getValue("tp"); //type
45: final String src = attrs.getValue("im");
46: final ZkAlert alert = new ZkAlert(((ZkComponent) parent)
47: .getZkDesktop(), id, title, src, text,
48: getAlertType(typeStr));
49:
50: final String timeoutStr = attrs.getValue("to"); //timeout
51: if (timeoutStr != null) {
52: int timeout = Integer.parseInt(timeoutStr);
53: alert.setTimeout(timeout);
54: }
55:
56: if ("t".equalsIgnoreCase(attrs.getValue("ic"))) { //indicator
57: alert
58: .setIndicator(new Gauge(null /*label*/,
59: false/*interactive*/, 10/*maxValue*/, 0/*initialValue*/));
60: }
61:
62: return alert;
63: }
64:
65: private AlertType getAlertType(String type) {
66: if ("al".equalsIgnoreCase(type))
67: return AlertType.ALARM;
68: if ("cf".equalsIgnoreCase(type))
69: return AlertType.CONFIRMATION;
70: if ("er".equalsIgnoreCase(type))
71: return AlertType.ERROR;
72: if ("if".equalsIgnoreCase(type))
73: return AlertType.INFO;
74: if ("wn".equalsIgnoreCase(type))
75: return AlertType.WARNING;
76:
77: return AlertType.INFO;
78: }
79: }
|