org.cloudcoder.app.client.view.OkDialogBox.java Source code

Java tutorial

Introduction

Here is the source code for org.cloudcoder.app.client.view.OkDialogBox.java

Source

// CloudCoder - a web-based pedagogical programming environment
// Copyright (C) 2011-2012, Jaime Spacco <jspacco@knox.edu>
// Copyright (C) 2011-2012, David H. Hovemeyer <david.hovemeyer@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

package org.cloudcoder.app.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;

/**
 * A very simple dialog where the only choice is "OK",
 * which dismisses the dialog.
 * 
 * @author David Hovemeyer
 */
public class OkDialogBox extends DialogBox {
    public OkDialogBox(String title, String message) {
        setTitle(title);
        setGlassEnabled(true);

        FlowPanel panel = new FlowPanel();
        panel.add(new HTML(new SafeHtmlBuilder().appendEscaped(message).toSafeHtml()));
        Button ok = new Button("OK");
        ok.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                hide();
            }
        });
        panel.add(ok);

        add(panel);
    }
}