001: /*
002: * Beryl - A web platform based on XML, XSLT and Java
003: * This file is part of the Beryl XML GUI
004: *
005: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011:
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
020: */
021:
022: package org.beryl.gui.widgets;
023:
024: import java.awt.Component;
025:
026: import javax.swing.ImageIcon;
027:
028: import org.beryl.gui.GUIException;
029: import org.beryl.gui.ImageIconFactory;
030: import org.beryl.gui.Widget;
031: import org.beryl.gui.WidgetInfo;
032: import org.beryl.gui.model.ListDataModel;
033: import org.beryl.gui.swing.IconElement;
034:
035: /**
036: * Dummy widget which can be used to fill the List, Combo
037: * and IconView widgets
038: */
039:
040: public class Item extends Widget implements IconElement {
041: protected static WidgetInfo itemInfo = null;
042: private String text = null;
043: private ImageIcon icon = null;
044: private ListDataModel owningDataModel = null;
045: private Object object = null;
046:
047: static {
048: itemInfo = new WidgetInfo(Item.class);
049: itemInfo.addProperty("text", "istring", "");
050: itemInfo.setSupportsAnchor(false);
051: try {
052: itemInfo.addProperty("icon", "icon", ImageIconFactory
053: .getIcon("broken"));
054: } catch (Exception e) {
055: throw new RuntimeException(e);
056: }
057: };
058:
059: public Item(Widget parent, String name) throws GUIException {
060: super (parent, name);
061: text = "";
062: }
063:
064: public void setProperty(String name, Object value)
065: throws GUIException {
066: if ("icon".equals(name)) {
067: setIcon((ImageIcon) value);
068: } else if ("text".equals(name)) {
069: setText((String) value);
070: } else {
071: throw new GUIException(
072: "Item only supports name and icon properties");
073: }
074: }
075:
076: public void setOwningDataModel(ListDataModel owningDataModel) {
077: this .owningDataModel = owningDataModel;
078: }
079:
080: public void setText(String text) {
081: this .text = text;
082: }
083:
084: public String getText() {
085: return text;
086: }
087:
088: public void setIcon(ImageIcon icon) {
089: this .icon = icon;
090: }
091:
092: public ImageIcon getIcon() {
093: return icon;
094: }
095:
096: public String toString() {
097: return text;
098: }
099:
100: public void setUserObject(Object object) {
101: this .object = object;
102: }
103:
104: public Object getUserObject() {
105: return object;
106: }
107:
108: public void revalidate() throws GUIException {
109: if (owningDataModel != null) {
110: int index = owningDataModel.indexOf(this );
111: if (index != -1) {
112: owningDataModel.setValue(this , index, this );
113: }
114: }
115: }
116:
117: public Component getWidget() {
118: return null;
119: }
120:
121: public WidgetInfo getWidgetInfo() {
122: return itemInfo;
123: }
124: }
|