001: /* ListableList.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 22, 2007 9:34:16 AM, 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 java.util.Enumeration;
022: import java.util.Vector;
023:
024: import org.zkoss.zkmob.Listable;
025: import org.zkoss.zkmob.UiManager;
026: import org.zkoss.zkmob.ZkComponent;
027:
028: import javax.microedition.lcdui.Image;
029: import javax.microedition.lcdui.List;
030:
031: /**
032: * Implement Listable List.
033: *
034: * @author henrichen
035: */
036: public class ZkList extends List implements Listable, ZkComponent {
037: private String _id;
038: private ZkDesktop _zk;
039: private boolean _handlekid;
040: private Vector _listitems = new Vector(32);
041:
042: public ZkList(ZkDesktop zk, String id, String title, int listType) {
043: super (title, listType);
044: _id = id;
045: _zk = zk;
046: }
047:
048: //--Listable--//
049: public void appendChild(ZkComponent li) {
050: if (_handlekid) { //avoid dead loop
051: return;
052: }
053: try {
054: _handlekid = true;
055: if (li instanceof ZkListItem) {
056: final ZkListItem comp = (ZkListItem) li;
057: super .append(comp.getLabel(), null);
058: _listitems.addElement(li);
059: li.setParent(this );
060: UiManager.loadImageOnThread(comp, li.getZkDesktop()
061: .getHostURL(), li.getZkDesktop().getPathURL(),
062: comp.getImageSrc());
063: } else {
064: addCommand((ZkCommand) li);
065: li.setParent(this );
066: }
067: } finally {
068: _handlekid = false;
069: }
070: }
071:
072: public void insertChild(int index, ZkComponent li) {
073: try {
074: _handlekid = true;
075: if (li instanceof ZkListItem) {
076: final ZkListItem comp = (ZkListItem) li;
077: super .insert(index, comp.getLabel(), null);
078: _listitems.insertElementAt(li, index);
079: li.setParent(this );
080: UiManager.loadImageOnThread(comp, li.getZkDesktop()
081: .getHostURL(), li.getZkDesktop().getPathURL(),
082: comp.getImageSrc());
083: } else {
084: addCommand((ZkCommand) li);
085: li.setParent(this );
086: }
087: } finally {
088: _handlekid = false;
089: }
090: }
091:
092: public int indexOf(ZkComponent li) {
093: return _listitems.indexOf(li);
094: }
095:
096: public void delete(int index) {
097: super .delete(index);
098: _listitems.removeElementAt(index);
099: }
100:
101: public void super Delete(int index) {
102: super .delete(index);
103: }
104:
105: //--ZkComponent--//
106: public String getId() {
107: return _id;
108: }
109:
110: public void setParent(ZkComponent parent) {
111: //do nothing
112: }
113:
114: public ZkComponent getParent() {
115: return getZkDesktop();
116: }
117:
118: public ZkDesktop getZkDesktop() {
119: return _zk;
120: }
121:
122: public void setAttr(String attr, String val) {
123: //TODO:
124: }
125: }
|