01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.client.awt;
22:
23: import java.awt.BorderLayout;
24: import java.awt.FlowLayout;
25: import java.awt.event.ActionEvent;
26: import java.awt.event.ActionListener;
27: import java.io.IOException;
28: import javax.swing.*;
29:
30: public class Console extends JFrame {
31:
32: private JButton _clear, _redraw, _quit;
33:
34: private JTextArea _console;
35:
36: private SwingWebClient _client;
37:
38: public Console(String title, SwingWebClient client) {
39: _client = client;
40: _client.setLogger(getLogger());
41: setTitle(title);
42: JPanel panel = new JPanel();
43: panel.setLayout(new FlowLayout());
44: _clear = new JButton("Clear");
45: _clear.addActionListener(new ActionListener() {
46:
47: public void actionPerformed(ActionEvent e) {
48: _console.setText("");
49: }
50: });
51: _redraw = new JButton("Redraw UI");
52: _redraw.addActionListener(new ActionListener() {
53:
54: public void actionPerformed(ActionEvent e) {
55: try {
56: _client.refreshUI();
57: } catch (IOException e1) {
58: e1.printStackTrace();
59: }
60: }
61: });
62: _quit = new JButton("Quit");
63: _quit.addActionListener(new ActionListener() {
64:
65: public void actionPerformed(ActionEvent e) {
66: System.exit(0);
67: }
68: });
69: panel.add(_clear);
70: panel.add(_redraw);
71: panel.add(_quit);
72: getContentPane().setLayout(new BorderLayout());
73: getContentPane().add(BorderLayout.NORTH, panel);
74: _console = new JTextArea();
75: _console.setRows(10);
76: JScrollPane sp = new JScrollPane();
77: sp.getViewport().add(_console);
78: getContentPane().add(BorderLayout.CENTER, sp);
79: }
80:
81: public Logger getLogger() {
82: return new Logger() {
83:
84: public void log(int requestId, String log) {
85: _console.append(requestId + ": " + log);
86: }
87: };
88: }
89: }
|