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;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: /**
028: * The WidgetInfo class reveals a widget's available
029: * properties, presets and events
030: */
031:
032: public class WidgetInfo {
033: private boolean supportsAnchor = true;
034: private ArrayList properties = null;
035: private ArrayList presets = null;
036: private ArrayList events = null;
037: private Class clazz = null;
038: private String className = null;
039:
040: public class PropertyEntry {
041: public String propertyName;
042: public String propertyType;
043: public Object defaultValue;
044: public String className;
045:
046: public PropertyEntry() {
047: className = WidgetInfo.this .className;
048: }
049:
050: public String getDescription() {
051: return InternationalizationManager.getString("xmlgui."
052: + className + ".property." + propertyName);
053: }
054:
055: public String toString() {
056: return propertyName + " (" + getDescription() + ")";
057: }
058: };
059:
060: public class PresetEntry {
061: public String presetName;
062: public String className;
063:
064: public PresetEntry() {
065: className = WidgetInfo.this .className;
066: }
067:
068: public String getDescription() {
069: return InternationalizationManager.getString("xmlgui."
070: + className + ".preset." + presetName);
071: }
072:
073: public String toString() {
074: return presetName + " (" + getDescription() + ")";
075: }
076: };
077:
078: public class EventEntry {
079: public String eventName;
080: public String className;
081:
082: public EventEntry() {
083: className = WidgetInfo.this .className;
084: }
085:
086: public String getDescription() {
087: return InternationalizationManager.getString("xmlgui."
088: + className + ".event." + eventName);
089: }
090:
091: public String toString() {
092: return eventName + " (" + getDescription() + ")";
093: }
094: };
095:
096: public WidgetInfo(Class clazz) {
097: this .clazz = clazz;
098: properties = new ArrayList();
099: presets = new ArrayList();
100: events = new ArrayList();
101:
102: String fullName = clazz.getName();
103: className = fullName.substring(fullName.lastIndexOf('.') + 1);
104: }
105:
106: public WidgetInfo(Class clazz, WidgetInfo parentInfo) {
107: this (clazz);
108:
109: /* Inherit properties */
110: properties.addAll(parentInfo.getPropertyEntries());
111: /* Inherit events */
112: events.addAll(parentInfo.getEventEntries());
113: /* Presets are not inherited */
114: }
115:
116: public List getPropertyEntries() {
117: return properties;
118: }
119:
120: public List getPresetEntries() {
121: return presets;
122: }
123:
124: public PropertyEntry getPropertyEntry(String propertyName)
125: throws GUIException {
126: for (int i = 0; i < properties.size(); i++) {
127: PropertyEntry entry = (PropertyEntry) properties.get(i);
128: if (entry.propertyName.equals(propertyName))
129: return entry;
130: }
131: throw new GUIException("No property named [" + propertyName
132: + "] could be found for class [" + clazz.getName()
133: + "]");
134: }
135:
136: public EventEntry getEventEntry(String eventName)
137: throws GUIException {
138: for (int i = 0; i < events.size(); i++) {
139: EventEntry entry = (EventEntry) events.get(i);
140: if (entry.eventName.equals(eventName))
141: return entry;
142: }
143: throw new GUIException("No event named [" + eventName
144: + "] could be found for class [" + clazz.getName()
145: + "]");
146: }
147:
148: public List getEventEntries() {
149: return events;
150: }
151:
152: public void addPreset(String presetName) {
153: PresetEntry entry = new PresetEntry();
154: entry.presetName = presetName;
155: presets.add(entry);
156: }
157:
158: public void addEvent(String eventName) {
159: EventEntry entry = new EventEntry();
160: entry.eventName = eventName;
161: events.add(entry);
162: }
163:
164: public void addProperty(String propertyName, String propertyType) {
165: addProperty(propertyName, propertyType, null);
166: }
167:
168: public void removeProperty(String propertyName) {
169: for (int i = 0; i < properties.size(); i++) {
170: PropertyEntry entry = (PropertyEntry) properties.get(i);
171: if (entry.propertyName.equals(propertyName)) {
172: properties.remove(i);
173: return;
174: }
175: }
176: }
177:
178: public void addProperty(String propertyName, String propertyType,
179: Object defaultValue) {
180: PropertyEntry info = new PropertyEntry();
181: info.propertyName = propertyName;
182: info.propertyType = propertyType;
183: info.defaultValue = defaultValue;
184: properties.add(info);
185: }
186:
187: public String getDescription() {
188: return InternationalizationManager.getString("xmlgui."
189: + className);
190: }
191:
192: public Class getWidgetClass() {
193: return clazz;
194: }
195:
196: public boolean getSupportsAnchor() {
197: return supportsAnchor;
198: }
199:
200: public void setSupportsAnchor(boolean supportsAnchor) {
201: this.supportsAnchor = supportsAnchor;
202: }
203: }
|