summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2008-12-12 21:11:02 -0800
committerShawn O. Pearce <sop@google.com>2008-12-12 21:30:49 -0800
commit84f5b84cab9275f71c537ce7a3d173d642e13a80 (patch)
tree7ff81472f6644800492b6652feaca780999bc12e /webapp
parent7782f742c4c0070d6edbafe0066a5efaa5029969 (diff)
Automatically resize and center dialogs when the window changes
We resize and reposition dialogs automatically when the parent window resizes, so the iframe's scrollbars will enable if the parent window is not big enough to show the entire iframe at once, rather than making the user scroll the parent window. Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'webapp')
-rw-r--r--webapp/src/com/google/gerrit/client/ErrorDialog.java6
-rw-r--r--webapp/src/com/google/gerrit/client/SignInDialog.java23
-rw-r--r--webapp/src/com/google/gerrit/client/ui/AutoCenterDialogBox.java61
3 files changed, 82 insertions, 8 deletions
diff --git a/webapp/src/com/google/gerrit/client/ErrorDialog.java b/webapp/src/com/google/gerrit/client/ErrorDialog.java
index fddbbc832d..e99b959613 100644
--- a/webapp/src/com/google/gerrit/client/ErrorDialog.java
+++ b/webapp/src/com/google/gerrit/client/ErrorDialog.java
@@ -15,16 +15,16 @@
package com.google.gerrit.client;
import com.google.gerrit.client.rpc.RpcUtil;
+import com.google.gerrit.client.ui.AutoCenterDialogBox;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
-import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwtjsonrpc.client.RemoteJsonException;
/** A dialog box showing an error message, when bad things happen. */
-public class ErrorDialog extends DialogBox {
+public class ErrorDialog extends AutoCenterDialogBox {
private final FlowPanel body;
protected ErrorDialog() {
@@ -73,7 +73,7 @@ public class ErrorDialog extends DialogBox {
body.add(label(cn, "gerrit-ErrorDialog-ErrorType"));
body.add(label(what.getMessage(), "gerrit-ErrorDialog-ErrorMessage"));
}
-
+
private static Label label(final String what, final String style) {
final Label r = new Label(what);
r.setStyleName(style);
diff --git a/webapp/src/com/google/gerrit/client/SignInDialog.java b/webapp/src/com/google/gerrit/client/SignInDialog.java
index c9729c3778..0031d8f70c 100644
--- a/webapp/src/com/google/gerrit/client/SignInDialog.java
+++ b/webapp/src/com/google/gerrit/client/SignInDialog.java
@@ -17,11 +17,12 @@ package com.google.gerrit.client;
import com.google.gerrit.client.account.SignInResult;
import com.google.gerrit.client.account.SignInResult.Status;
import com.google.gerrit.client.rpc.GerritCallback;
+import com.google.gerrit.client.ui.AutoCenterDialogBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
+import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwtjsonrpc.client.CallbackHandle;
@@ -44,12 +45,12 @@ import com.google.gwtjsonrpc.client.CallbackHandle;
* in) or <code>null</code> (the sign in was aborted/canceled before it
* completed).
*/
-public class SignInDialog extends DialogBox {
+public class SignInDialog extends AutoCenterDialogBox {
private static SignInDialog current;
private final CallbackHandle<SignInResult> signInCallback;
private final AsyncCallback<?> appCallback;
- private Frame loginFrame;
+ private final Frame loginFrame;
/**
* Create a new dialog to handle user sign in.
@@ -70,13 +71,25 @@ public class SignInDialog extends DialogBox {
appCallback = callback;
loginFrame = new Frame();
- loginFrame.setWidth("630px");
- loginFrame.setHeight("440px");
+ onResize(Window.getClientWidth(), Window.getClientHeight());
add(loginFrame);
setText(Gerrit.C.signInDialogTitle());
}
@Override
+ protected void onResize(final int width, final int height) {
+ resizeFrame(width, height);
+ super.onResize(width, height);
+ }
+
+ private void resizeFrame(final int width, final int height) {
+ final int w = Math.min(630, width - 15);
+ final int h = Math.min(440, height - 60);
+ loginFrame.setWidth(w + "px");
+ loginFrame.setHeight(h + "px");
+ }
+
+ @Override
public void show() {
if (current != null) {
current.hide();
diff --git a/webapp/src/com/google/gerrit/client/ui/AutoCenterDialogBox.java b/webapp/src/com/google/gerrit/client/ui/AutoCenterDialogBox.java
new file mode 100644
index 0000000000..43569d5085
--- /dev/null
+++ b/webapp/src/com/google/gerrit/client/ui/AutoCenterDialogBox.java
@@ -0,0 +1,61 @@
+// Copyright 2008 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.client.ui;
+
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.WindowResizeListener;
+import com.google.gwt.user.client.ui.DialogBox;
+
+/** A DialogBox that automatically re-centers itself if the window changes */
+public class AutoCenterDialogBox extends DialogBox {
+ private WindowResizeListener recenter;
+
+ public AutoCenterDialogBox() {
+ }
+
+ public AutoCenterDialogBox(final boolean autoHide) {
+ super(autoHide);
+ }
+
+ public AutoCenterDialogBox(final boolean autoHide, final boolean modal) {
+ super(autoHide, modal);
+ }
+
+ @Override
+ public void show() {
+ if (recenter == null) {
+ recenter = new WindowResizeListener() {
+ public void onWindowResized(final int width, final int height) {
+ onResize(width, height);
+ }
+ };
+ Window.addWindowResizeListener(recenter);
+ }
+ super.show();
+ }
+
+ @Override
+ protected void onUnload() {
+ if (recenter != null) {
+ Window.removeWindowResizeListener(recenter);
+ recenter = null;
+ }
+ super.onUnload();
+ }
+
+ protected void onResize(final int width, final int height) {
+ center();
+ }
+}