01: /* TextFieldFactory.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: May 15, 2007 3:28:33 PM, 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.Form;
22: import javax.microedition.lcdui.TextField;
23:
24: import org.xml.sax.Attributes;
25: import org.zkoss.zkmob.ZkComponent;
26: import org.zkoss.zkmob.UiManager;
27: import org.zkoss.zkmob.ui.ZkDesktop;
28: import org.zkoss.zkmob.ui.ZkTextField;
29:
30: /**
31: * @author henrichen
32: *
33: */
34: public class TextFieldFactory extends AbstractUiFactory {
35: public TextFieldFactory(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"); //label
42: final String label = attrs.getValue("lb"); //label
43: String text = attrs.getValue("tx"); //text
44: if (text == null)
45: text = "";
46: final String constraintsStr = attrs.getValue("cs"); //constraints
47: final String maxSizeStr = attrs.getValue("xs"); //maxSize
48: final int maxSize = Integer.parseInt(maxSizeStr);
49: if (text.length() > maxSize)
50: text = text.substring(0, maxSize);
51: final int constraints = Integer.parseInt(constraintsStr);
52: final String onChange = attrs.getValue("on");
53: final String onChanging = attrs.getValue("og");
54: final ZkDesktop zk = ((ZkComponent) parent).getZkDesktop();
55:
56: final ZkTextField component = new ZkTextField(zk, id, label,
57: text, maxSize, constraints, onChange == null ? null
58: : new Boolean("t".equals(onChange)),
59: onChanging == null ? null : new Boolean("t"
60: .equals(onChanging)));
61:
62: UiManager.applyItemProperties(parent, component, attrs);
63:
64: return component;
65: }
66:
67: }
|