2 * Copyright (c) 2011 Greek Research and Technology Network
\r
4 package gr.grnet.pithos.web.client;
\r
6 import com.google.gwt.core.client.GWT;
\r
7 import com.google.gwt.dom.client.NativeEvent;
\r
8 import com.google.gwt.event.dom.client.ClickEvent;
\r
9 import com.google.gwt.event.dom.client.ClickHandler;
\r
10 import com.google.gwt.event.dom.client.KeyCodes;
\r
11 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
12 import com.google.gwt.user.client.ui.Button;
\r
13 import com.google.gwt.user.client.ui.DialogBox;
\r
14 import com.google.gwt.user.client.ui.HTML;
\r
15 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
16 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
17 import com.google.gwt.user.client.ui.VerticalPanel;
\r
20 * The 'quit' dialog box.
\r
22 public class QuitDialog extends DialogBox {
\r
25 * The widget's constructor.
\r
27 public QuitDialog() {
\r
28 Configuration conf = (Configuration) GWT.create(Configuration.class);
\r
29 String service = conf.serviceName();
\r
30 setText("Quit " + service);
\r
32 VerticalPanel outer = new VerticalPanel();
\r
33 HorizontalPanel buttons = new HorizontalPanel();
\r
35 HTML text = new HTML("Are you sure you want to quit " + service + "?");
\r
36 text.setStyleName("pithos-AboutText");
\r
39 // Create the 'Quit' button, along with a listener that hides the dialog
\r
40 // when the button is clicked and quits the application.
\r
41 Button quit = new Button("Quit", new ClickHandler() {
\r
43 public void onClick(ClickEvent event) {
\r
49 buttons.setCellHorizontalAlignment(quit, HasHorizontalAlignment.ALIGN_CENTER);
\r
50 // Create the 'Cancel' button, along with a listener that hides the
\r
51 // dialog when the button is clicked.
\r
52 Button cancel = new Button("Cancel", new ClickHandler() {
\r
54 public void onClick(ClickEvent event) {
\r
58 buttons.add(cancel);
\r
59 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
60 buttons.setSpacing(8);
\r
62 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
67 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
68 super.onPreviewNativeEvent(preview);
\r
70 NativeEvent evt = preview.getNativeEvent();
\r
71 if (evt.getType().equals("keydown"))
\r
72 // Use the popup's key preview hooks to close the dialog when either
\r
73 // enter or escape is pressed.
\r
74 switch (evt.getKeyCode()) {
\r
75 case KeyCodes.KEY_ENTER:
\r
79 case KeyCodes.KEY_ESCAPE:
\r