/** loading constructor */ public VPopupView() { super(); popup = new CustomPopup(); setStyleName(CLASSNAME); popup.setStyleName(CLASSNAME + "-popup"); loading.setStyleName(CLASSNAME + "-loading"); setHTML(""); popup.setWidget(loading); // When we click to open the popup... addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { if (isEnabled()) { preparePopup(popup); showPopup(popup); center(); fireEvent(new VisibilityChangeEvent(true)); } } }); // ..and when we close it popup.addCloseHandler( new CloseHandler<PopupPanel>() { @Override public void onClose(CloseEvent<PopupPanel> event) { fireEvent(new VisibilityChangeEvent(false)); } }); // TODO: Enable animations once GWT fix has been merged popup.setAnimationEnabled(false); popup.setAutoHideOnHistoryEventsEnabled(false); }
/** For internal use only. May be removed or replaced in the future. */ public void center() { int windowTop = RootPanel.get().getAbsoluteTop(); int windowLeft = RootPanel.get().getAbsoluteLeft(); int windowRight = windowLeft + RootPanel.get().getOffsetWidth(); int windowBottom = windowTop + RootPanel.get().getOffsetHeight(); int offsetWidth = popup.getOffsetWidth(); int offsetHeight = popup.getOffsetHeight(); int hostHorizontalCenter = VPopupView.this.getAbsoluteLeft() + VPopupView.this.getOffsetWidth() / 2; int hostVerticalCenter = VPopupView.this.getAbsoluteTop() + VPopupView.this.getOffsetHeight() / 2; int left = hostHorizontalCenter - offsetWidth / 2; int top = hostVerticalCenter - offsetHeight / 2; // Don't show the popup outside the screen. if ((left + offsetWidth) > windowRight) { left -= (left + offsetWidth) - windowRight; } if ((top + offsetHeight) > windowBottom) { top -= (top + offsetHeight) - windowBottom; } if (left < 0) { left = 0; } if (top < 0) { top = 0; } popup.setPopupPosition(left, top); }
/** * Make sure that we remove the popup when the main widget is removed. * * @see com.google.gwt.user.client.ui.Widget#onUnload() */ @Override protected void onDetach() { popup.hide(); super.onDetach(); }
/** * Determines the correct position for a popup and displays the popup at that position. * * <p>By default, the popup is shown centered relative to its host component, ensuring it is * visible on the screen if possible. * * <p>Can be overridden to customize the popup position. * * @param popup */ public void showPopup(final CustomPopup popup) { popup.setPopupPosition(0, 0); }
/** For internal use only. May be removed or replaced in the future. */ public void preparePopup(final CustomPopup popup) { popup.setVisible(true); popup.setWidget(loading); popup.show(); }