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.test;
023:
024: import java.util.Date;
025: import java.util.GregorianCalendar;
026: import java.util.Locale;
027:
028: import org.beryl.gui.Controller;
029: import org.beryl.gui.GUIEvent;
030: import org.beryl.gui.GUIException;
031: import org.beryl.gui.GUIUtils;
032: import org.beryl.gui.ImageIconFactory;
033: import org.beryl.gui.InternationalizationManager;
034: import org.beryl.gui.MessageDialog;
035: import org.beryl.gui.ScriptedController;
036: import org.beryl.gui.model.ListDataModel;
037: import org.beryl.gui.model.MapChangeEvent;
038: import org.beryl.gui.model.MapDataModel;
039: import org.beryl.gui.model.ModelChangeEvent;
040: import org.beryl.gui.model.ModelChangeListener;
041: import org.beryl.gui.model.TableChangeEvent;
042: import org.beryl.gui.model.TableDataModel;
043: import org.beryl.gui.model.TableRow;
044: import org.beryl.gui.swing.CommandEvent;
045: import org.beryl.gui.swing.ConsoleAttribute;
046: import org.beryl.gui.widgets.ComboBox;
047: import org.beryl.gui.widgets.Frame;
048: import org.beryl.gui.widgets.List;
049: import org.beryl.gui.widgets.Table;
050:
051: /**
052: * Beryl XML GUI test program
053: */
054: public class Test extends Controller {
055: private MapDataModel model = null;
056: private Table table = null;
057: private TableDataModel tableModel = null;
058: private Frame frame = null;
059: private ConsoleAttribute boldAttribute = null;
060:
061: public Test() throws GUIException {
062: /* Create a new data model and initialize it
063: * with default values for the main window */
064: model = new MapDataModel();
065: model.setValue("username", "wazlaf");
066: model.setValue("password", "blubb");
067: model.setValue("combo.index", new Integer(1));
068: model.setValue("list.index", new int[] { 1 });
069: model.setValue("icon.index", new Integer(1));
070: model.setValue("radio", "choice3");
071: model.setValue("ssl", new Boolean(true));
072: model.setValue("table.index", new int[] { 1 });
073:
074: /* Create some items for the combo box / list */
075: ListDataModel listModel = new ListDataModel();
076: for (int i = 1; i < 11; i++)
077: listModel.addValue("MVC item " + i);
078:
079: /* Create a table data model for the table widget and add
080: * some rows to it */
081: tableModel = new TableDataModel();
082: tableModel.addRow(new Person("Wenzel", "Jakob",
083: "wazlaf@tigris.org",
084: new GregorianCalendar(1983, 11, 04).getTime()));
085: tableModel.addRow(new Person("Hans", "Mustermann",
086: "asdf@asdf.com", new Date()));
087: tableModel.addRow(new Person("Test", "Person", "test@test.de",
088: new Date()));
089:
090: /* Add a debugging model change listener to the table data model */
091: tableModel.addModelChangeListener(new ModelChangeListener() {
092: public void modelChanged(ModelChangeEvent e) {
093: TableChangeEvent event = (TableChangeEvent) e;
094: log.debug("Table data model change : "
095: + event.getKey()
096: + "["
097: + event.getFirstIndex()
098: + "] -> '"
099: + ((TableDataModel) event.getModel()).getValue(
100: event.getFirstIndex(), event.getKey())
101: + "'");
102: }
103: });
104:
105: /* Add a debugging model change listener to the window data model */
106: model.addModelChangeListener(new ModelChangeListener() {
107: public void modelChanged(ModelChangeEvent e) {
108: MapChangeEvent event = (MapChangeEvent) e;
109: log.debug("Data model change : '" + event.getKey()
110: + "' => '" + event.getNewValue() + "'");
111: }
112: });
113:
114: /* Create the window */
115: frame = constructFrame("TestFrame", model);
116:
117: /* Associate the table data model with the table */
118: table = (Table) frame.getWidget("Table1");
119: table.setTableDataModel(tableModel);
120:
121: /* Associate the list data model with a combo box and a list */
122: ((ComboBox) frame.getWidget("Combo1"))
123: .setListDataModel(listModel);
124: ((List) frame.getWidget("List1")).setListDataModel(listModel);
125:
126: /* Initialize the console */
127: boldAttribute = new ConsoleAttribute();
128: boldAttribute.setBold(true);
129:
130: /* Show the frame */
131: frame.show();
132: }
133:
134: /**
135: * Called when events occur inside the GUI
136: */
137: public void eventOccured(GUIEvent e) {
138: String name = e.getName();
139: try {
140: log.debug("Caught event : " + e.toString());
141: if (name.equals("quit")) {
142: System.exit(0);
143: } else if (name.equals("wizard")) {
144: new WizardTest();
145: } else if (name.equals("outlook")) {
146: new OutlookBarTest();
147: } else if (name.equals("about")) {
148: new About(frame);
149: } else if (name.equals("dnd")) {
150: new DnDTest();
151: } else if (name.equals("groovy")) {
152: ScriptedController.launchScript(
153: "/org/beryl/gui/test/GroovyTest.groovy",
154: new Object[] { frame });
155: } else if (name.equals("message.info")) {
156: new MessageDialog(frame,
157: getString("test.message.info.title"),
158: getString("test.message.info.message"));
159: } else if (name.equals("message.warning")) {
160: new MessageDialog(frame, MessageDialog.WARNING_MESSAGE,
161: getString("test.message.warning.title"),
162: getString("test.message.warning.message"), null);
163: } else if (name.equals("message.error")) {
164: throw new GUIException("This is an example error");
165: } else if (name.equals("edit")) {
166: TableRow selection[] = (TableRow[]) model
167: .getValue("table.value");
168: for (int i = 0; i < selection.length; i++) {
169: new PersonEditor(selection[i]);
170: }
171: } else if (name.equals("consoleCommand")) {
172: CommandEvent event = (CommandEvent) e.getSwingEvent();
173: event.getSource().appendText(
174: getString("test.console.command"));
175: event.getSource().appendText(event.getCommand(),
176: boldAttribute);
177: event.getSource().appendText(
178: getString("test.console.notfound") + "\n");
179: } else if (name.equals("login")) {
180: log.debug("Login has been clicked. username ["
181: + model.getValue("username") + "], password ["
182: + model.getValue("password") + "], ssl ["
183: + model.getValue("ssl") + "], verbose ["
184: + model.getValue("verbose") + "]");
185: }
186: } catch (Exception ex) {
187: new MessageDialog(ex);
188: }
189: }
190:
191: public static void main(String args[]) {
192: try {
193: Locale locale = Locale.US;
194:
195: if (Locale.getDefault().getLanguage().equals("de"))
196: locale = new Locale("de", "DE");
197: GUIUtils.defaultInitialization(locale);
198: ImageIconFactory.addSearchPath("resources/test/icons");
199: InternationalizationManager
200: .addLanguageFile("resources/test/test");
201:
202: new Test();
203: } catch (Exception e) {
204: new MessageDialog(e);
205: }
206: }
207: }
|