001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.swingweb.client.gwt;
022:
023: import org.onemind.swingweb.client.gwt.widget.MoveableWindow;
024: import com.google.gwt.user.client.DOM;
025: import com.google.gwt.user.client.ui.*;
026:
027: public class GwtClientConsole extends HorizontalPanel {
028:
029: private static class Status {
030:
031: private Image _image;
032:
033: public Status(String imageUrl) {
034: _image = new Image(imageUrl);
035: }
036: }
037:
038: private class ConsoleDialog extends MoveableWindow {
039:
040: private TextArea _textArea;
041:
042: public ConsoleDialog() {
043: super ();
044: setTitle("GwtClient console");
045: VerticalPanel panel = new VerticalPanel();
046: panel.setHorizontalAlignment(panel.ALIGN_LEFT);
047: panel.add(createControlPanel());
048: _textArea = new TextArea();
049: _textArea.setCharacterWidth(100);
050: _textArea.setVisibleLines(10);
051: DOM.setStyleAttribute(getElement(), "fontSize", "8");
052: DOM.setStyleAttribute(getElement(), "backgroundColor",
053: "#c4c4c4");
054: panel.add(_textArea);
055: setContent(panel);
056: setWidth("850");
057: }
058:
059: private Panel createControlPanel() {
060: HorizontalPanel panel = new HorizontalPanel();
061: panel.add(createButtonPanel());
062: panel.add(createOptionPanel());
063: return panel;
064: }
065:
066: private Panel createButtonPanel() {
067: VerticalPanel panel = new VerticalPanel();
068: Button hide = new Button("Hide");
069: hide.addClickListener(new ClickListener() {
070:
071: public void onClick(Widget sender) {
072: removeFromParent();
073: }
074: });
075: Button clearText = new Button("Clear");
076: clearText.addClickListener(new ClickListener() {
077:
078: public void onClick(Widget sender) {
079: _textArea.setText("");
080: }
081: });
082: panel.add(hide);
083: panel.add(clearText);
084: return panel;
085: }
086:
087: private Panel createOptionPanel() {
088: VerticalPanel vp = new VerticalPanel();
089: CheckBox cb1 = new CheckBox("Terse", _client
090: .isLoggable(GwtClient.LOG_TERSE));
091: cb1.addClickListener(new ClickListener() {
092:
093: public void onClick(Widget sender) {
094: _client.setLogLevel(GwtClient.LOG_TERSE,
095: ((CheckBox) sender).isChecked());
096: }
097: });
098: CheckBox cb2 = new CheckBox("Verbose", _client
099: .isLoggable(GwtClient.LOG_VERBOSE));
100: cb2.addClickListener(new ClickListener() {
101:
102: public void onClick(Widget sender) {
103: _client.setLogLevel(GwtClient.LOG_VERBOSE,
104: ((CheckBox) sender).isChecked());
105: }
106: });
107: CheckBox cb3 = new CheckBox("Debug", _client
108: .isLoggable(GwtClient.LOG_DEBUG));
109: cb3.addClickListener(new ClickListener() {
110:
111: public void onClick(Widget sender) {
112: _client.setLogLevel(GwtClient.LOG_DEBUG,
113: ((CheckBox) sender).isChecked());
114: }
115: });
116: CheckBox cb4 = new CheckBox("Clear on submit");
117: cb3.addClickListener(new ClickListener() {
118:
119: public void onClick(Widget sender) {
120: //_client.setClearOnSubmit(((CheckBox)sender).isChecked());
121: }
122: });
123: vp.add(cb1);
124: vp.add(cb2);
125: vp.add(cb3);
126: return vp;
127: }
128:
129: public void appendMessage(String msg) {
130: _textArea.setText(_textArea.getText() + "\n" + msg);
131: DOM.setStyleAttribute(_textArea.getElement(), "pixelTop",
132: "1000");
133: }
134: }
135:
136: private Button _refresh;
137:
138: private Button _debugConsole;
139:
140: private GwtClient _client;
141:
142: private ConsoleDialog _dialog;
143:
144: private DeckPanel _status = new DeckPanel();
145:
146: public static final Status STATUS_REQUEST = new Status(
147: "images/red-light.gif"), STATUS_RENDER = new Status(
148: "images/orange-light.gif"), STATUS_SYNC = new Status(
149: "images/green-light.gif");
150:
151: public GwtClientConsole(GwtClient client) {
152: _client = client;
153: _dialog = new ConsoleDialog();
154: _refresh = new Button("Refresh");
155: _refresh.addClickListener(new ClickListener() {
156:
157: public void onClick(Widget sender) {
158: _client.refreshUI();
159: }
160: });
161: _debugConsole = new Button("Show console");
162: _debugConsole.addClickListener(new ClickListener() {
163:
164: public void onClick(Widget sender) {
165: //_dialog.setPopupPosition(0, 0);
166: //_dialog.show();
167: RootPanel.get().add(_dialog);
168: }
169: });
170: _status.add(STATUS_SYNC._image);
171: _status.add(STATUS_REQUEST._image);
172: _status.add(STATUS_RENDER._image);
173: setStatus(STATUS_SYNC);
174: add(_refresh);
175: add(_debugConsole);
176: add(_status);
177: }
178:
179: public void setStatus(Status status) {
180: _status.showWidget(_status.getWidgetIndex(status._image));
181: //System.out.println("Show " + status._image.getUrl());
182: }
183:
184: public void appendMessage(String msg) {
185: _dialog.appendMessage(msg);
186: }
187: }
|