1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.google.gwt.sample.mail.client;
17 
18 import com.google.gwt.core.client.GWT;
19 import com.google.gwt.dom.client.NativeEvent;
20 import com.google.gwt.event.dom.client.ClickEvent;
21 import com.google.gwt.event.dom.client.KeyCodes;
22 import com.google.gwt.uibinder.client.UiBinder;
23 import com.google.gwt.uibinder.client.UiField;
24 import com.google.gwt.uibinder.client.UiHandler;
25 import com.google.gwt.user.client.Event.NativePreviewEvent;
26 import com.google.gwt.user.client.ui.Button;
27 import com.google.gwt.user.client.ui.DialogBox;
28 import com.google.gwt.user.client.ui.Widget;
29 
30 /**
31  * A simple example of an 'about' dialog box.
32  */
33 public class AboutDialog extends DialogBox {
34 
35   interface Binder extends UiBinder<Widget, AboutDialog> { }
36   private static final Binder binder = GWT.create(Binder.class);
37 
38   @UiField Button closeButton;
39 
AboutDialog()40   public AboutDialog() {
41     // Use this opportunity to set the dialog's caption.
42     setText("About the Mail Sample");
43     setWidget(binder.createAndBindUi(this));
44 
45     setAnimationEnabled(true);
46     setGlassEnabled(true);
47   }
48 
49   @Override
onPreviewNativeEvent(NativePreviewEvent preview)50   protected void onPreviewNativeEvent(NativePreviewEvent preview) {
51     super.onPreviewNativeEvent(preview);
52 
53     NativeEvent evt = preview.getNativeEvent();
54     if (evt.getType().equals("keydown")) {
55       // Use the popup's key preview hooks to close the dialog when either
56       // enter or escape is pressed.
57       switch (evt.getKeyCode()) {
58         case KeyCodes.KEY_ENTER:
59         case KeyCodes.KEY_ESCAPE:
60           hide();
61           break;
62       }
63     }
64   }
65 
66   @UiHandler("closeButton")
onSignOutClicked(ClickEvent event)67   void onSignOutClicked(ClickEvent event) {
68     hide();
69   }
70 }
71