001: /* ZkTextField.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 29, 2007 3:43:22 PM, Created by henrichen
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zkmob.ui;
020:
021: import javax.microedition.lcdui.Form;
022: import javax.microedition.lcdui.TextField;
023:
024: import org.zkoss.zkmob.Inputable;
025: import org.zkoss.zkmob.Itemable;
026: import org.zkoss.zkmob.UiManager;
027: import org.zkoss.zkmob.ZkComponent;
028:
029: /**
030: * @author henrichen
031: *
032: */
033: public class ZkTextField extends TextField implements ZkComponent,
034: Inputable, Itemable {
035: private String _id;
036: private ZkDesktop _zk;
037: private Boolean _onChange; //null mean no such event required, t means asap, f means !asap
038: private Boolean _onChanging; //null mean no such event required, t means asap, f means !asap
039: private ZkForm _form;
040:
041: public ZkTextField(ZkDesktop zk, String id, String label,
042: String text, int maxSize, int constraints,
043: Boolean onChange, Boolean onChanging) {
044: super (label, text, maxSize, constraints);
045: _id = id;
046: _zk = zk;
047: _onChange = onChange;
048: _onChanging = onChanging;
049: }
050:
051: //--Inputable--//
052: public Boolean getOnChange() {
053: return _onChange;
054: }
055:
056: public Boolean getOnChanging() {
057: return _onChanging;
058: }
059:
060: //--ZkComponent--//
061: public String getId() {
062: return _id;
063: }
064:
065: public ZkComponent getParent() {
066: return (ZkComponent) getForm();
067: }
068:
069: public void setParent(ZkComponent parent) {
070: if (_form != parent) { //yes, !=, not !equals
071: if (_form != null) {
072: _form.removeItem(this );
073: }
074: _form = (ZkForm) parent;
075: ZkDesktop newzk = null;
076: if (_form != null) {
077: _form.appendChild(this );
078: newzk = _form.getZkDesktop();
079: }
080: if (_zk != newzk) {
081: _zk = newzk;
082: }
083: }
084: }
085:
086: public ZkDesktop getZkDesktop() {
087: return _zk;
088: }
089:
090: public void setAttr(String attr, String val) {
091: UiManager.setItemAttr(this , attr, val);
092: if ("tx".equals(attr)) {
093: setString(val);
094: } else if ("xs".equals(attr)) {
095: setMaxSize(val == null ? 32 : Integer.parseInt(val));
096: } else if ("cs".equals(attr)) {
097: setConstraints(Integer.parseInt(val));
098: } else if ("md".equals(attr)) { //initialInputMode
099: setInitialInputMode(val);
100: }
101: }
102:
103: //--Itemable--//
104: public Form getForm() {
105: return _form;
106: }
107: }
|