01: /*
02: * Beryl - A web platform based on XML, XSLT and Java
03: * This file is part of the Beryl XML GUI
04: *
05: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11:
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
20: */
21:
22: package org.beryl.gui.widgets;
23:
24: import java.awt.Component;
25:
26: import org.beryl.gui.GUIEvent;
27: import org.beryl.gui.GUIEventListener;
28: import org.beryl.gui.GUIException;
29: import org.beryl.gui.Widget;
30: import org.beryl.gui.WidgetInfo;
31: import org.beryl.gui.swing.CommandEvent;
32: import org.beryl.gui.swing.CommandListener;
33: import org.beryl.gui.swing.ConsoleAttribute;
34: import org.beryl.gui.swing.JCommandConsole;
35:
36: public class Console extends Widget {
37: protected static WidgetInfo consoleInfo = null;
38: private JCommandConsole console = null;
39:
40: static {
41: consoleInfo = new WidgetInfo(Console.class, widgetInfo);
42: consoleInfo.addEvent("command");
43: };
44:
45: public Console(Widget parent, String name) throws GUIException {
46: super (parent, name);
47: console = new JCommandConsole();
48: }
49:
50: public void setProperty(String name, Object value)
51: throws GUIException {
52: super .setProperty(name, value);
53: }
54:
55: public void addListener(String event, final String name,
56: final GUIEventListener listener) throws GUIException {
57: if ("command".equals(event)) {
58: console.addCommandListener(new CommandListener() {
59: public void onCommand(CommandEvent e) {
60: listener.eventOccured(new GUIEvent(Console.this ,
61: name, e));
62: }
63: });
64: } else {
65: super .addListener(event, name, listener);
66: }
67: }
68:
69: public void clear() {
70: console.clear();
71: }
72:
73: public void appendText(String text) {
74: console.appendText(text);
75: }
76:
77: public void appendText(String text, ConsoleAttribute attribute) {
78: console.appendText(text, attribute);
79: }
80:
81: public Component getWidget() {
82: return console;
83: }
84:
85: public WidgetInfo getWidgetInfo() {
86: return consoleInfo;
87: }
88: }
|