litesoft
@ 750
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
/* * Copyright 2010 Daniel Kurka * * 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.googlecode.mgwt.ui.client.dialog; import java.util.Iterator; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.dom.client.Node; import com.google.gwt.event.shared.GwtEvent; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.googlecode.mgwt.dom.client.event.mouse.HandlerRegistrationCollection; import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers; import com.googlecode.mgwt.dom.client.event.tap.TapHandler; import com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers; import com.googlecode.mgwt.dom.client.event.touch.TouchCancelEvent; import com.googlecode.mgwt.dom.client.event.touch.TouchCancelHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchEndEvent; import com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchMoveEvent; import com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchStartEvent; import com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler; import com.googlecode.mgwt.mvp.client.AnimatableDisplay; import com.googlecode.mgwt.mvp.client.Animation; import com.googlecode.mgwt.mvp.client.AnimationEndCallback; import com.googlecode.mgwt.ui.client.theme.base.DialogCss; import com.googlecode.mgwt.ui.client.widget.touch.TouchDelegate; /** * Baseclass for creating dialogs that are animated * * @author Daniel Kurka */ public abstract class AnimatableDialogBase implements HasWidgets, HasTouchHandlers, HasTapHandlers, Dialog { private final class InternalTouchHandler implements TouchHandler { private final com.google.gwt.user.client.Element shadow; private Element startTarget; private InternalTouchHandler(com.google.gwt.user.client.Element shadow) { this.shadow = shadow; } @Override public void onTouchCanceled(TouchCancelEvent event) { startTarget = null; } @Override public void onTouchEnd(TouchEndEvent event) { EventTarget eventTarget = event.getNativeEvent().getEventTarget(); if (eventTarget != null) { // no textnode or element node if (Node.is(eventTarget)) { if (Element.is(eventTarget)) { Element endTarget = eventTarget.cast(); if (endTarget == shadow && startTarget == shadow) { maybeHide(); } } } } startTarget = null; } @Override public void onTouchMove(TouchMoveEvent event) { } @Override public void onTouchStart(TouchStartEvent event) { EventTarget eventTarget = event.getNativeEvent().getEventTarget(); if (eventTarget != null) { // no textnode or element node if (Node.is(eventTarget)) { if (Element.is(eventTarget)) { startTarget = eventTarget.cast(); } } } } } protected FlowPanel container; protected HasWidgets panelToOverlay; protected final DialogCss css; private AnimatableDisplay display; private boolean centerContent; private boolean hideOnBackgroundClick; private boolean isVisible; private TouchDelegate touchDelegate; /** * Create an instance of an animated dialog * * @param css a {@link com.googlecode.mgwt.ui.client.theme.base.DialogCss} * object. */ public AnimatableDialogBase(DialogCss css) { this.css = css; css.ensureInjected(); display = GWT.create(AnimatableDisplay.class); display.asWidget().addStyleName(css.animationContainerShadow()); display.asWidget().addStyleName(css.z_index()); touchDelegate = new TouchDelegate(display.asWidget()); container = new FlowPanel(); container.addStyleName(css.animationContainer()); final com.google.gwt.user.client.Element shadow = container.getElement(); addTouchHandler(new InternalTouchHandler(shadow)); } /* * (non-Javadoc) * @see com.google.gwt.user.client.ui.HasWidgets#add(com.google.gwt.user.client.ui.Widget) */ /** {@inheritDoc} */ @Override public void add(Widget w) { container.add(w); } /* * (non-Javadoc) * @see com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers#addTouchStartHandler(com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler) */ /** {@inheritDoc} */ @Override public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) { return touchDelegate.addTouchStartHandler(handler); } /* * (non-Javadoc) * @see com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers#addTouchMoveHandler(com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler) */ /** {@inheritDoc} */ @Override public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) { return touchDelegate.addTouchMoveHandler(handler); } /* * (non-Javadoc) * @see com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers#addTouchCancelHandler(com.googlecode.mgwt.dom.client.event.touch.TouchCancelHandler) */ /** {@inheritDoc} */ @Override public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) { return touchDelegate.addTouchCancelHandler(handler); } /* * (non-Javadoc) * @see com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers#addTouchEndHandler(com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler) */ /** {@inheritDoc} */ @Override public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) { return touchDelegate.addTouchEndHandler(handler); } /* * (non-Javadoc) * @see com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers#addTouchHandler(com.googlecode.mgwt.dom.client.event.touch.TouchHandler) */ /** {@inheritDoc} */ @Override public HandlerRegistration addTouchHandler(TouchHandler handler) { HandlerRegistrationCollection handlerRegistrationCollection = new HandlerRegistrationCollection(); handlerRegistrationCollection.addHandlerRegistration(addTouchCancelHandler(handler)); handlerRegistrationCollection.addHandlerRegistration(addTouchStartHandler(handler)); handlerRegistrationCollection.addHandlerRegistration(addTouchEndHandler(handler)); handlerRegistrationCollection.addHandlerRegistration(addTouchMoveHandler(handler)); return handlerRegistrationCollection; } /* * (non-Javadoc) * @see com.googlecode.mgwt.dom.client.event.touch.simple.HasSimpleTouchHandler#addSimpleTouchHandler(com.googlecode.mgwt.dom.client.event.touch.simple.SimpleTouchHandler) */ /** {@inheritDoc} */ public HandlerRegistration addTapHandler(TapHandler handler) { return touchDelegate.addTapHandler(handler); } /** * Show the dialog centered */ public void center() { centerContent = true; show(); } /* * (non-Javadoc) * @see com.google.gwt.user.client.ui.HasWidgets#clear() */ /** {@inheritDoc} */ @Override public void clear() { container.clear(); } /** * get the panel that the dialog overlays * * @return the panel that is overlayed by this dialog */ public HasWidgets getPanelToOverlay() { if (panelToOverlay == null) { panelToOverlay = RootPanel.get(); } return panelToOverlay; } /** * hide the dialog if it is visible */ public void hide() { if (!isVisible) return; isVisible = false; Animation animation = getHideAnimation(); display.animate(animation, false, new AnimationEndCallback() { @Override public void onAnimationEnd() { HasWidgets panel = getPanelToOverlay(); panel.remove(display.asWidget()); } }); } /** * Should the dialog hide itself if there is a tap outside the dialog * * @return true if the dialog automatically hides, otherwise false */ public boolean isHideOnBackgroundClick() { return hideOnBackgroundClick; } /* * (non-Javadoc) * @see com.google.gwt.user.client.ui.HasWidgets#iterator() */ /** {@inheritDoc} */ @Override public Iterator<Widget> iterator() { return container.iterator(); } /* * (non-Javadoc) * @see com.google.gwt.user.client.ui.HasWidgets#remove(com.google.gwt.user.client.ui.Widget) */ /** {@inheritDoc} */ @Override public boolean remove(Widget w) { return container.remove(w); } /** * Should the content of the dialog be centered * * @param centerContent true to center content */ public void setCenterContent(boolean centerContent) { this.centerContent = centerContent; } /** * Should the dialog hide itself if there is a tap outside the dialog * * @param hideOnBackgroundClick true if the dialog automatically hides, * otherwise false */ public void setHideOnBackgroundClick(boolean hideOnBackgroundClick) { this.hideOnBackgroundClick = hideOnBackgroundClick; } /** * set the panel that should be overlayed by the dialog * * @param panel the area to be overlayed */ public void setPanelToOverlay(HasWidgets panel) { this.panelToOverlay = panel; } /** * should the dialog add a shadow over the area that it covers * * @param shadow true to add a shadow */ public void setShadow(boolean shadow) { if (shadow) { display.asWidget().addStyleName(css.animationContainerShadow()); } else { display.asWidget().removeStyleName(css.animationContainerShadow()); } } /* * (non-Javadoc) * @see com.googlecode.mgwt.ui.client.dialog.Dialog#show() */ /** * <p> * show * </p> */ public void show() { if (isVisible) { return; } isVisible = true; // add overlay to DOM HasWidgets panel = getPanelToOverlay(); panel.add(display.asWidget()); if (centerContent) { container.addStyleName(css.animationContainerCenter()); } display.setFirstWidget(container); // and animiate Animation animation = getShowAnimation(); display.animate(animation, true, new AnimationEndCallback() { @Override public void onAnimationEnd() { } }); } /** * <p> * getShowAnimation * </p> * * @return a {@link com.googlecode.mgwt.mvp.client.Animation} object. */ protected abstract Animation getShowAnimation(); /** * <p> * getHideAnimation * </p> * * @return a {@link com.googlecode.mgwt.mvp.client.Animation} object. */ protected abstract Animation getHideAnimation(); /** * <p> * maybeHide * </p> */ protected void maybeHide() { if (hideOnBackgroundClick) { hide(); } } @Override public void fireEvent(GwtEvent<?> event) { display.asWidget().fireEvent(event); } } |
Commits for litesoft/trunk/mobileGWT/mgwt/zOrig_src_main_java_com_googlecode_mgwt_ui_client_dialog/AnimatableDialogBase.java
Revision | Author | Commited | Message |
---|---|---|---|
741 | GeorgeS | Tue 26 Jun, 2012 01:21:28 +0000 | Update Dialogs to support replaceable button text (for i18n) and to isolate the references to the default CSS to JUST the actual Dialog implementations (Alert, Confirm, and Options for now). |