1 16 package com.google.gwt.user.client; 17 18 import com.google.gwt.core.client.GWT; 19 import com.google.gwt.core.client.GWT.UncaughtExceptionHandler; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 24 28 public class Window { 29 30 private static ArrayList closingListeners = new ArrayList (); 31 private static ArrayList resizeListeners = new ArrayList (); 32 33 static { 34 init(); 35 } 36 37 42 public static void addWindowCloseListener(WindowCloseListener listener) { 43 closingListeners.add(listener); 44 } 45 46 51 public static void addWindowResizeListener(WindowResizeListener listener) { 52 resizeListeners.add(listener); 53 } 54 55 60 public static native void alert(String msg) ; 63 64 72 public static native boolean confirm(String msg) ; 75 76 83 public static native void enableScrolling(boolean enable) ; 86 87 92 public static native int getClientHeight() ; 97 98 103 public static native int getClientWidth() ; 107 108 113 public static native int getScrollLeft() ; 117 118 123 public static native int getScrollTop() ; 127 128 133 public static native String getTitle() ; 136 137 146 public static native void open(String url, String name, String features) ; 149 150 159 public static native String prompt(String msg, String initialValue) ; 162 163 168 public static void removeWindowCloseListener(WindowCloseListener listener) { 169 closingListeners.remove(listener); 170 } 171 172 177 public static void removeWindowResizeListener(WindowResizeListener listener) { 178 resizeListeners.remove(listener); 179 } 180 181 189 public static native void setMargin(String size) ; 192 193 198 public static native void setTitle(String title) ; 201 202 static void onClosed() { 203 UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler(); 204 if (handler != null) { 205 fireClosedAndCatch(handler); 206 } else { 207 fireClosedImpl(); 208 } 209 } 210 211 static String onClosing() { 212 UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler(); 213 if (handler != null) { 214 return fireClosingAndCatch(handler); 215 } else { 216 return fireClosingImpl(); 217 } 218 } 219 220 static void onResize() { 221 UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler(); 222 if (handler != null) { 223 fireResizedAndCatch(handler); 224 } else { 225 fireResizedImpl(); 226 } 227 } 228 229 private static void fireClosedAndCatch(UncaughtExceptionHandler handler) { 230 try { 231 fireClosedImpl(); 232 } catch (Throwable e) { 233 handler.onUncaughtException(e); 234 } 235 } 236 237 private static void fireClosedImpl() { 238 for (Iterator it = closingListeners.iterator(); it.hasNext();) { 239 WindowCloseListener listener = (WindowCloseListener) it.next(); 240 listener.onWindowClosed(); 241 } 242 } 243 244 private static String fireClosingAndCatch(UncaughtExceptionHandler handler) { 245 try { 246 return fireClosingImpl(); 247 } catch (Throwable e) { 248 handler.onUncaughtException(e); 249 return null; 250 } 251 } 252 253 private static String fireClosingImpl() { 254 String ret = null; 255 for (Iterator it = closingListeners.iterator(); it.hasNext();) { 256 WindowCloseListener listener = (WindowCloseListener) it.next(); 257 258 String msg = listener.onWindowClosing(); 260 if (ret == null) { 261 ret = msg; 262 } 263 } 264 265 return ret; 266 } 267 268 private static void fireResizedAndCatch(UncaughtExceptionHandler handler) { 269 try { 270 fireResizedImpl(); 271 } catch (Throwable e) { 272 handler.onUncaughtException(e); 273 } 274 } 275 276 private static void fireResizedImpl() { 277 for (Iterator it = resizeListeners.iterator(); it.hasNext();) { 278 WindowResizeListener listener = (WindowResizeListener) it.next(); 279 listener.onWindowResized(getClientWidth(), getClientHeight()); 280 } 281 } 282 283 private static native void init() ; 300 301 private Window() { 302 } 303 } 304 | Popular Tags |