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 org.apache.log4j.Logger;
025: import org.beryl.gui.model.MapDataModel;
026: import org.beryl.gui.widgets.Dialog;
027: import org.beryl.gui.widgets.Frame;
028:
029: /**
030: * Abstract controller class. All created GUI should have their logic
031: * in subclasses of this class
032: */
033: public abstract class Controller implements GUIEventListener {
034: private static WidgetFactory wf = WidgetFactory.getInstance();
035: protected Logger log = null;
036:
037: /**
038: * Create the controller
039: */
040: public Controller() {
041: log = Logger.getLogger(getClass());
042: }
043:
044: /**
045: * Return an internationalized string
046: */
047: protected String getString(String identifier) {
048: return InternationalizationManager.getString(identifier);
049: }
050:
051: /**
052: * Manually show a given help id
053: *
054: * @param id The help id
055: */
056: protected void showHelp(String id) {
057: Widget.getHelpBroker()
058: .showID(id, "javax.help.MainWindow", null);
059: }
060:
061: /**
062: * Convenience function: constructs a widget with a data model
063: * @param name The widget name inside the XML description
064: * @param dataModel The data model which the widget should use
065: */
066: protected Widget constructWidget(String name, MapDataModel dataModel)
067: throws GUIException {
068: return wf.constructWidget(getClass(), name, this , dataModel);
069: }
070:
071: /**
072: * Convenience function: constructs a widget
073: * @param name The widget name inside the XML description
074: */
075: protected Widget constructWidget(String name) throws GUIException {
076: return constructWidget(name, null);
077: }
078:
079: /**
080: * Convenience function: constructs a frame
081: * @param name The frame name inside the XML description
082: */
083: protected Frame constructFrame(String name) throws GUIException {
084: return (Frame) constructWidget(name);
085: }
086:
087: /**
088: * Convenience function: constructs a frame with a data model
089: * @param name The frame name inside the XML description
090: * @param dataModel The data model which the frame should use
091: */
092: protected Frame constructFrame(String name, MapDataModel dataModel)
093: throws GUIException {
094: return (Frame) constructWidget(name, dataModel);
095: }
096:
097: /**
098: * Convenience function: constructs a dialog
099: * @param name The dialog name inside the XML description
100: */
101: protected Dialog constructDialog(String name) throws GUIException {
102: return (Dialog) constructWidget(name);
103: }
104:
105: /**
106: * Convenience function: constructs a dialog with a data model
107: * @param name The dialog name inside the XML description
108: * @param dataModel The data model which the dialog should use
109: */
110: protected Dialog constructDialog(String name, MapDataModel dataModel)
111: throws GUIException {
112: return (Dialog) constructWidget(name, dataModel);
113: }
114:
115: /**
116: * Implement event handling in subclasses
117: */
118: public abstract void eventOccured(GUIEvent event);
119: }
|