GwtClientConsole.java :  » Web-Framework » swingweb » org » onemind » swingweb » client » gwt » Java Open Source

Java Open Source » Web Framework » swingweb 
swingweb » org » onemind » swingweb » client » gwt » GwtClientConsole.java
/*
 * Copyright (C) 2004 TiongHiang Lee
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not,  write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Email: thlee@onemindsoft.org
 */

package org.onemind.swingweb.client.gwt;

import org.onemind.swingweb.client.gwt.widget.MoveableWindow;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.*;
public class GwtClientConsole extends HorizontalPanel
{

    private static class Status
    {

        private Image _image;

        public Status(String imageUrl)
        {
            _image = new Image(imageUrl);
        }
    }

    private class ConsoleDialog extends MoveableWindow
    {

        private TextArea _textArea;

        public ConsoleDialog()
        {
            super();
            setTitle("GwtClient console");
            VerticalPanel panel = new VerticalPanel();
            panel.setHorizontalAlignment(panel.ALIGN_LEFT);
            panel.add(createControlPanel());
            _textArea = new TextArea();
            _textArea.setCharacterWidth(100);
            _textArea.setVisibleLines(10);
            DOM.setStyleAttribute(getElement(), "fontSize", "8");
            DOM.setStyleAttribute(getElement(), "backgroundColor", "#c4c4c4");
            panel.add(_textArea);
            setContent(panel);
            setWidth("850");
        }

        private Panel createControlPanel()
        {
            HorizontalPanel panel = new HorizontalPanel();
            panel.add(createButtonPanel());
            panel.add(createOptionPanel());
            return panel;
        }

        private Panel createButtonPanel()
        {
            VerticalPanel panel = new VerticalPanel();
            Button hide = new Button("Hide");
            hide.addClickListener(new ClickListener()
            {

                public void onClick(Widget sender)
                {
                    removeFromParent();
                }
            });
            Button clearText = new Button("Clear");
            clearText.addClickListener(new ClickListener()
            {

                public void onClick(Widget sender)
                {
                    _textArea.setText("");
                }
            });
            panel.add(hide);
            panel.add(clearText);
            return panel;
        }

        private Panel createOptionPanel()
        {
            VerticalPanel vp = new VerticalPanel();
            CheckBox cb1 = new CheckBox("Terse", _client.isLoggable(GwtClient.LOG_TERSE));
            cb1.addClickListener(new ClickListener()
            {

                public void onClick(Widget sender)
                {
                    _client.setLogLevel(GwtClient.LOG_TERSE, ((CheckBox) sender).isChecked());
                }
            });
            CheckBox cb2 = new CheckBox("Verbose", _client.isLoggable(GwtClient.LOG_VERBOSE));
            cb2.addClickListener(new ClickListener()
            {

                public void onClick(Widget sender)
                {
                    _client.setLogLevel(GwtClient.LOG_VERBOSE, ((CheckBox) sender).isChecked());
                }
            });
            CheckBox cb3 = new CheckBox("Debug", _client.isLoggable(GwtClient.LOG_DEBUG));
            cb3.addClickListener(new ClickListener()
            {

                public void onClick(Widget sender)
                {
                    _client.setLogLevel(GwtClient.LOG_DEBUG, ((CheckBox) sender).isChecked());
                }
            });
            CheckBox cb4 = new CheckBox("Clear on submit");
            cb3.addClickListener(new ClickListener()
            {

                public void onClick(Widget sender)
                {
                    //_client.setClearOnSubmit(((CheckBox)sender).isChecked());
                }
            });
            vp.add(cb1);
            vp.add(cb2);
            vp.add(cb3);
            return vp;
        }

        public void appendMessage(String msg)
        {
            _textArea.setText(_textArea.getText() + "\n" + msg);
            DOM.setStyleAttribute(_textArea.getElement(), "pixelTop", "1000");
        }
    }

    private Button _refresh;

    private Button _debugConsole;

    private GwtClient _client;

    private ConsoleDialog _dialog;

    private DeckPanel _status = new DeckPanel();

    public static final Status STATUS_REQUEST = new Status("images/red-light.gif"), STATUS_RENDER = new Status(
            "images/orange-light.gif"), STATUS_SYNC = new Status("images/green-light.gif");

    public GwtClientConsole(GwtClient client)
    {
        _client = client;
        _dialog = new ConsoleDialog();
        _refresh = new Button("Refresh");
        _refresh.addClickListener(new ClickListener()
        {

            public void onClick(Widget sender)
            {
                _client.refreshUI();
            }
        });
        _debugConsole = new Button("Show console");
        _debugConsole.addClickListener(new ClickListener()
        {

            public void onClick(Widget sender)
            {
                //_dialog.setPopupPosition(0, 0);
                //_dialog.show();
                RootPanel.get().add(_dialog);
            }
        });
        _status.add(STATUS_SYNC._image);
        _status.add(STATUS_REQUEST._image);
        _status.add(STATUS_RENDER._image);
        setStatus(STATUS_SYNC);
        add(_refresh);
        add(_debugConsole);
        add(_status);
    }

    public void setStatus(Status status)
    {
        _status.showWidget(_status.getWidgetIndex(status._image));
        //System.out.println("Show " + status._image.getUrl());
    }

    public void appendMessage(String msg)
    {
        _dialog.appendMessage(msg);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.