001: /* ImageableListItem.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 22, 2007 8:54:13 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 javax.microedition.lcdui.Command;
022: import javax.microedition.lcdui.Image;
023:
024: import org.zkoss.zkmob.Imageable;
025: import org.zkoss.zkmob.Listable;
026: import org.zkoss.zkmob.UiManager;
027: import org.zkoss.zkmob.ZkComponent;
028:
029: /**
030: * A data carrier used for constructing list item of a Listable.
031: *
032: * @author henrichen
033: */
034: public class ZkListItem implements ZkComponent, Imageable {
035: private Listable _parent;
036: private String _id;
037: private String _label;
038: private String _image;
039:
040: public ZkListItem(String id, String label, String image) {
041: _id = id;
042: _label = label;
043: _image = image;
044: }
045:
046: public void setParent(ZkComponent parent) {
047: if (_parent != parent) {
048: _parent = (Listable) parent;
049: ((Listable) _parent).appendChild(this );
050: }
051: }
052:
053: public ZkComponent getParent() {
054: return (ZkComponent) _parent;
055: }
056:
057: public String getLabel() {
058: return _label;
059: }
060:
061: //--Imageable--//
062: public void loadImage(Image image) {
063: final int index = _parent.indexOf(this );
064: _parent.set(index, _parent.getString(index), image);
065: }
066:
067: public String getImageSrc() {
068: return _image;
069: }
070:
071: //--ZkComponent--//
072: public String getId() {
073: return _id;
074: }
075:
076: public ZkDesktop getZkDesktop() {
077: return _parent == null ? null : ((ZkComponent) _parent)
078: .getZkDesktop();
079: }
080:
081: public void setAttr(String attr, String val) {
082: if ("lb".equals(attr)) {
083: _label = val;
084: int index = _parent.indexOf(this );
085: final Image img = _parent.getImage(index);
086: _parent.set(index, val, img);
087: } else if ("im".equals(attr)) {
088: _image = val;
089: UiManager.loadImageOnThread(this , getZkDesktop()
090: .getHostURL(), getZkDesktop().getPathURL(),
091: getImageSrc());
092: }
093: }
094:
095: public void addCommand(Command cmd) {
096: //do nothing
097: }
098:
099: public void removeCommand(Command cmd) {
100: //do nothing
101: }
102: }
|