001: /* ZkForm.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 29, 2007 3:20:30 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.Item;
023:
024: import org.zkoss.zkmob.Imageable;
025: import org.zkoss.zkmob.Itemable;
026: import org.zkoss.zkmob.UiManager;
027: import org.zkoss.zkmob.ZkComponent;
028:
029: /**
030: * ZK Form.
031: * @author henrichen
032: *
033: */
034: public class ZkForm extends Form implements ZkComponent {
035: private String _id;
036: private ZkDesktop _zk;
037: private boolean _handlekid;
038:
039: public ZkForm(ZkDesktop zk, String id, String title) {
040: super (title);
041: _id = id;
042: _zk = zk;
043: }
044:
045: public void removeItem(Item comp) {
046: final int sz = size();
047: for (int j = 0; j < sz; ++j) {
048: final Item item = get(j);
049: if (comp == item) { //found
050: delete(j);
051: break;
052: }
053: }
054: }
055:
056: public int indexOf(Item comp) {
057: final int sz = size();
058: for (int j = 0; j < sz; ++j) {
059: final Item item = get(j);
060: if (comp == item) { //found
061: return j;
062: }
063: }
064: return -1;
065: }
066:
067: public void appendChild(ZkComponent kid) {
068: if (_handlekid) { //avoid dead loop
069: return;
070: }
071: try {
072: _handlekid = true;
073: if (kid instanceof Item) {
074: super .append((Item) kid);
075: } else { //ZkCommand
076: addCommand((ZkCommand) kid);
077: }
078: kid.setParent(this );
079: if (kid instanceof Imageable) {
080: final String hostURL = kid.getZkDesktop().getHostURL();
081: final String pathURL = kid.getZkDesktop().getPathURL();
082: final Imageable comp = (Imageable) kid;
083: UiManager.loadImageOnThread(comp, hostURL, pathURL,
084: comp.getImageSrc());
085: }
086: } finally {
087: _handlekid = false;
088: }
089: }
090:
091: public void insertChild(int itemNum, ZkComponent kid) {
092: try {
093: _handlekid = true;
094: if (kid instanceof Item) {
095: super .insert(itemNum, (Item) kid);
096: } else { //ZkCommand
097: addCommand((ZkCommand) kid);
098: }
099: kid.setParent(this );
100: if (kid instanceof Imageable) {
101: final String hostURL = kid.getZkDesktop().getHostURL();
102: final String pathURL = kid.getZkDesktop().getPathURL();
103: final Imageable comp = (Imageable) kid;
104: UiManager.loadImageOnThread(comp, hostURL, pathURL,
105: comp.getImageSrc());
106: }
107: } finally {
108: _handlekid = false;
109: }
110: }
111:
112: //--ZkComponent--//
113: public String getId() {
114: return _id;
115: }
116:
117: public ZkDesktop getZkDesktop() {
118: return _zk;
119: }
120:
121: public void setParent(ZkComponent parent) {
122: _zk = (ZkDesktop) parent;
123: }
124:
125: public ZkComponent getParent() {
126: return getZkDesktop();
127: }
128:
129: public void setAttr(String attr, String val) {
130: if ("visibility".equals(attr)) {
131: if ("true".equals(val)) {
132: _zk.setCurrent(this);
133: }
134: }
135: }
136: }
|