001: /* ImageableImageItem.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 21, 2007 5:27:07 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.Image;
023: import javax.microedition.lcdui.ImageItem;
024:
025: import org.zkoss.zkmob.Imageable;
026: import org.zkoss.zkmob.Itemable;
027: import org.zkoss.zkmob.UiManager;
028: import org.zkoss.zkmob.ZkComponent;
029:
030: /**
031: * Wrapping ImageItem with Imageable so its image can be loaded
032: * via {@link org.zkoss.zkmob.ImageRequest}.
033: *
034: * @author henrichen
035: *
036: */
037: public class ZkImageItem extends ImageItem implements Imageable,
038: ZkComponent, Itemable {
039: private String _id;
040: private String _image;
041: private ZkDesktop _zk;
042: private ZkForm _form;
043:
044: public ZkImageItem(ZkDesktop zk, String id, String label,
045: String image, int layout, String altText, int appearanceMode) {
046: super (label, null, layout, altText, appearanceMode);
047: _id = id;
048: _zk = zk;
049: _image = image;
050: }
051:
052: //--Imageable--//
053: public void loadImage(Image image) {
054: setImage(image);
055: }
056:
057: public String getImageSrc() {
058: return _image;
059: }
060:
061: //--ZkComponent--//
062: public String getId() {
063: return _id;
064: }
065:
066: public ZkDesktop getZkDesktop() {
067: return _zk;
068: }
069:
070: public ZkComponent getParent() {
071: return (ZkComponent) getForm();
072: }
073:
074: public void setParent(ZkComponent parent) {
075: if (_form != parent) { //yes, !=, not !equals
076: if (_form != null) {
077: _form.removeItem(this );
078: }
079: _form = (ZkForm) parent;
080: ZkDesktop newzk = null;
081: if (_form != null) {
082: _form.appendChild(this );
083: newzk = _form.getZkDesktop();
084: }
085: if (_zk != newzk) {
086: _zk = newzk;
087: }
088: }
089: }
090:
091: public void setAttr(String attr, String val) {
092: UiManager.setItemAttr(this , attr, val);
093:
094: if ("im".equals(attr)) {
095: if (val != null) {
096: UiManager.loadImageOnThread(this , _zk.getHostURL(), _zk
097: .getPathURL(), val);
098: } else {
099: setImage(null); //clean to empty
100: }
101: _image = val;
102: } else if ("tx".equals(attr)) {
103: setAltText(val);
104: }
105: }
106:
107: //--Itemable--//
108: public Form getForm() {
109: return _form;
110: }
111: }
|