List of usage examples for com.google.gwt.user.client Window getClientWidth
public static int getClientWidth()
From source file:asquare.gwt.debug.client.DebugConsole.java
License:Apache License
/** * Creates the console, installs the enabler key listener. * The console is not yet attached to the DOM. */// w w w . j a v a2 s. co m protected DebugConsole() { super(false, false); setStyleName("tk-DebugConsole"); DOM.setStyleAttribute(getElement(), "border", "solid black 1px"); DOM.setStyleAttribute(getElement(), "background", "white"); setHTML("<div style='margin: 2px; padding: 3px; background-color: rgb(195, 217, 255); font-weight: bold; font-size: smaller; cursor: default;'>Debug Console</div>"); m_content.setWordWrap(false); DOM.setStyleAttribute(m_content.getElement(), "margin", "2px"); DOM.setStyleAttribute(m_content.getElement(), "padding", "3px"); VerticalPanel outer = new VerticalPanel(); ScrollPanel scrollPanel = new ScrollPanel(m_content); scrollPanel.setAlwaysShowScrollBars(true); scrollPanel.setSize("40em", "20em"); outer.add(scrollPanel); HorizontalPanel controls = new HorizontalPanel(); DOM.setStyleAttribute(controls.getElement(), "margin", "2px"); controls.setWidth("100%"); outer.add(controls); HorizontalPanel controlsLeft = new HorizontalPanel(); controls.add(controlsLeft); controls.setCellHorizontalAlignment(controlsLeft, HorizontalPanel.ALIGN_LEFT); HorizontalPanel controlsRight = new HorizontalPanel(); controls.add(controlsRight); controls.setCellHorizontalAlignment(controlsRight, HorizontalPanel.ALIGN_RIGHT); final Button toggleDebugButton = new Button("Toggle Debug"); DOM.setElementProperty(toggleDebugButton.getElement(), "title", "Toggles output of debug statements"); controlsLeft.add(toggleDebugButton); updateDisableButtonText(); DOM.setElementProperty(m_disableButton.getElement(), "title", "Prevents this console from appearing when debug statements are printed"); controlsLeft.add(m_disableButton); final Button clearButton = new Button("Clear"); DOM.setElementProperty(clearButton.getElement(), "title", "Clears all messages in the console"); controlsRight.add(clearButton); final Button hideButton = new Button("Hide"); DOM.setStyleAttribute(hideButton.getElement(), "textAlign", "right"); controlsRight.add(hideButton); setWidget(outer); m_left = Window.getClientWidth() / 2 - 640 / 2; m_top = Window.getClientHeight() / 2; m_enabler.install(); ClickHandler handler = new ClickHandler() { public void onClick(ClickEvent event) { Widget sender = (Widget) event.getSource(); if (sender == clearButton) { clearMessages(); } else if (sender == hideButton) { hide(); } else if (sender == m_disableButton) { disable(); } else if (sender == toggleDebugButton) { if (Debug.isEnabled()) { Debug.disable(); } else { Debug.enable(); } } else { assert false; } } }; toggleDebugButton.addClickHandler(handler); m_disableButton.addClickHandler(handler); clearButton.addClickHandler(handler); hideButton.addClickHandler(handler); sinkEvents(Event.ONMOUSEDOWN); preventSelectionInIE(getElement()); }
From source file:au.com.gworks.gwt.petstore.client.AccountSignInController.java
License:Apache License
public void showView() { int xPos = (Window.getClientWidth() / 3); int yPos = (Window.getClientHeight() / 3); view.setPopupPosition(xPos, yPos);//from w w w . j a v a 2s . co m view.clearForm(); view.show(); }
From source file:burrito.client.widgets.InfoMessagePopup.java
License:Apache License
private void position() { int w = Window.getClientWidth(); int left = (w / 2) - 100; int scrollTop = Window.getScrollTop(); setPopupPosition(left, scrollTop);/*www . j a v a 2 s .co m*/ }
From source file:ca.wimsc.client.common.widgets.google.TouchHandler.java
License:Apache License
/** * Touch move handler.//from ww w . ja v a2 s .c o m * * @param e The touchmove event. */ @SuppressWarnings("unused") private void onMove(final TouchEvent e) { if (!tracking || dragDelegate == null) { return; } // Prevent native scrolling. e.preventDefault(); com.google.gwt.dom.client.Touch touch = getTouchFromEvent(e); Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY()); double moveX = lastTouchPosition.x - touchCoordinate.x; double moveY = lastTouchPosition.y - touchCoordinate.y; totalMoveX += Math.abs(moveX); totalMoveY += Math.abs(moveY); lastTouchPosition.x = touchCoordinate.x; lastTouchPosition.y = touchCoordinate.y; // Handle case where they are getting close to leaving the window. // End events are unreliable when the touch is leaving the viewport area. // If they are close to the bottom or the right, and we don't get any other // touch events for another 100ms, assume they have left the screen. This // does not seem to be a problem for scrolling off the top or left of the // viewport area. if (scrollOffTimer != null) { scrollOffTimer.cancel(); } if ((Window.getClientHeight() - touchCoordinate.y) < TOUCH_END_WORKAROUND_THRESHOLD || (Window.getClientWidth() - touchCoordinate.x) < TOUCH_END_WORKAROUND_THRESHOLD) { scrollOffTimer = new Timer() { @Override public void run() { e.setTimeStamp(Duration.currentTimeMillis()); onEnd(e); } }; scrollOffTimer.schedule(100); } boolean firstDrag = false; if (!dragging) { if (totalMoveY > MIN_TRACKING_FOR_DRAG || totalMoveX > MIN_TRACKING_FOR_DRAG) { dragging = true; firstDrag = true; dragDelegate.onDragStart(e); } } if (dragging) { dragDelegate.onDragMove(e); lastEvent = e; // This happens when they are dragging slowly. If they are dragging slowly // then we should reset the start time and position to where they are now. // This will be important during the drag end when we report to the // draggable delegate what kind of drag just happened. if (e.getTimeStamp() - recentTime > MAX_TRACKING_TIME) { recentTime = e.getTimeStamp(); recentTouchPosition = touchCoordinate; } } }
From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java
License:Apache License
/** * Centers the popup in the browser window and shows it. If the popup was * already showing, then the popup is centered. */// w w w . j a v a 2 s . co m public void center() { boolean initiallyShowing = showing; boolean initiallyAnimated = isAnimationEnabled; if (!initiallyShowing) { setVisible(false); setAnimationEnabled(false); show(); } int left = (Window.getClientWidth() - getOffsetWidth()) >> 1; int top = (Window.getClientHeight() - getOffsetHeight()) >> 1; setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0)); if (!initiallyShowing) { setAnimationEnabled(initiallyAnimated); // Run the animation. The popup is already visible, so we can skip // the // call to setState. if (initiallyAnimated) { impl.setClip(getElement(), "rect(0px, 0px, 0px, 0px)"); setVisible(true); resizeAnimation.run(ANIMATION_DURATION); } else { setVisible(true); } } }
From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java
License:Apache License
/** * Positions the popup, called after the offset width and height of the * popup are known./*from www .j av a 2s .co m*/ * * @param relativeObject * the ui object to position relative to * @param offsetWidth * the drop down's offset width * @param offsetHeight * the drop down's offset height */ private void position(final UIObject relativeObject, int offsetWidth, int offsetHeight) { // Calculate left position for the popup. The computation for // the left position is bidi-sensitive. int textBoxOffsetWidth = relativeObject.getOffsetWidth(); // Compute the difference between the popup's width and the // textbox's width int offsetWidthDiff = offsetWidth - textBoxOffsetWidth; int left; if (LocaleInfo.getCurrentLocale().isRTL()) { // RTL case int textBoxAbsoluteLeft = relativeObject.getAbsoluteLeft(); // Right-align the popup. Note that this computation is // valid in the case where offsetWidthDiff is negative. left = textBoxAbsoluteLeft - offsetWidthDiff; // If the suggestion popup is not as wide as the text box, always // align to the right edge of the text box. Otherwise, figure out // whether // to right-align or left-align the popup. if (offsetWidthDiff > 0) { // Make sure scrolling is taken into account, since // box.getAbsoluteLeft() takes scrolling into account. int windowRight = Window.getClientWidth() + Window.getScrollLeft(); int windowLeft = Window.getScrollLeft(); // Compute the left value for the right edge of the textbox int textBoxLeftValForRightEdge = textBoxAbsoluteLeft + textBoxOffsetWidth; // Distance from the right edge of the text box to the right // edge // of the window int distanceToWindowRight = windowRight - textBoxLeftValForRightEdge; // Distance from the right edge of the text box to the left edge // of the // window int distanceFromWindowLeft = textBoxLeftValForRightEdge - windowLeft; // If there is not enough space for the overflow of the popup's // width to the right of the text box and there IS enough space // for the // overflow to the right of the text box, then left-align the // popup. // However, if there is not enough space on either side, stick // with // right-alignment. if (distanceFromWindowLeft < offsetWidth && distanceToWindowRight >= offsetWidthDiff) { // Align with the left edge of the text box. left = textBoxAbsoluteLeft; } } } else { // LTR case // Left-align the popup. left = relativeObject.getAbsoluteLeft(); // If the suggestion popup is not as wide as the text box, always // align to // the left edge of the text box. Otherwise, figure out whether to // left-align or right-align the popup. if (offsetWidthDiff > 0) { // Make sure scrolling is taken into account, since // box.getAbsoluteLeft() takes scrolling into account. int windowRight = Window.getClientWidth() + Window.getScrollLeft(); int windowLeft = Window.getScrollLeft(); // Distance from the left edge of the text box to the right edge // of the window int distanceToWindowRight = windowRight - left; // Distance from the left edge of the text box to the left edge // of the // window int distanceFromWindowLeft = left - windowLeft; // If there is not enough space for the overflow of the popup's // width to the right of hte text box, and there IS enough space // for the // overflow to the left of the text box, then right-align the // popup. // However, if there is not enough space on either side, then // stick with // left-alignment. if (distanceToWindowRight < offsetWidth && distanceFromWindowLeft >= offsetWidthDiff) { // Align with the right edge of the text box. left -= offsetWidthDiff; } } } // Calculate top position for the popup int top = relativeObject.getAbsoluteTop(); // Make sure scrolling is taken into account, since // box.getAbsoluteTop() takes scrolling into account. int windowTop = Window.getScrollTop(); int windowBottom = Window.getScrollTop() + Window.getClientHeight(); // Distance from the top edge of the window to the top edge of the // text box int distanceFromWindowTop = top - windowTop; // Distance from the bottom edge of the window to the bottom edge of // the text box int distanceToWindowBottom = windowBottom - (top + relativeObject.getOffsetHeight()); // If there is not enough space for the popup's height below the text // box and there IS enough space for the popup's height above the text // box, then then position the popup above the text box. However, if // there // is not enough space on either side, then stick with displaying the // popup below the text box. if (distanceToWindowBottom < offsetHeight && distanceFromWindowTop >= offsetHeight) { top -= offsetHeight; } else { // Position above the text box top += relativeObject.getOffsetHeight(); } setPopupPosition(left, top); }
From source file:cc.alcina.framework.gwt.client.widget.GlassDisplayer.java
License:Apache License
public void show(boolean show) { RootPanel.get().setStyleName("glass-showing", show); if (!show) {// w ww. ja v a 2 s .co m if (glass != null) { glass.hide(); } return; } if (glass == null) { glass = new PopupPanel(); fp = new FlowPanelClickable(); fp.setStyleName("alcina-GlassPanel"); fp.setWidth(Window.getClientWidth() + "px"); fp.setHeight(Math.max(Document.get().getBody().getOffsetHeight(), Window.getClientHeight()) + "px"); Style style = fp.getElement().getStyle(); style.setBackgroundColor("#000"); updateOpacity(); glass.setStyleName("alcina-GlassPopup"); glass.add(fp); glass.setAnimationEnabled(false); } glass.show(); }
From source file:cc.kune.common.client.notify.SimpleUserMessage.java
License:GNU Affero Public License
/** * Show./*from www. j a va2 s .c om*/ * * @param message the message */ public void show(final String message) { msg.setText(message); popupPalette = new PopupPanel(true, false); popupPalette.setWidget(rp); popupPalette.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(final int offsetWidth, final int offsetHeight) { popupPalette.setPopupPosition((Window.getClientWidth() - msg.getOffsetWidth()) / 2, Window.getClientHeight() / 3); } }); popupPalette.setStyleName("oc-user-msg-popup"); popupPalette.setAnimationEnabled(true); timer.schedule(SHOWTIME); }
From source file:cc.kune.common.client.tooltip.Tooltip.java
License:GNU Affero Public License
/** * Calculate position.// w w w . j a v a 2 s .c o m * * @return the tooltip position */ private TooltipPosition calculatePosition(final Widget forWidget) { return TooltipPositionCalculator.calculate(Window.getClientWidth(), Window.getClientHeight(), forWidget.getAbsoluteLeft(), forWidget.getAbsoluteTop(), forWidget.getOffsetWidth(), forWidget.getOffsetHeight(), getTip().getWidth(), getTip().getHeight()); }
From source file:cc.kune.common.client.tooltip.Tooltip.java
License:GNU Affero Public License
public void show(final Widget forWidget, final String text) { if (current != null && !current.equals(forWidget) && getTip().isShowing()) { Tooltip.getTip().hide();/* w w w . j av a 2s . com*/ } setText(text); if (forWidget.isAttached() && forWidget.isVisible() && (TextUtils.notEmpty(text) && !"undefined".equals(text))) { Tooltip.super.show(); current = forWidget; final int clientWidth = Window.getClientWidth(); if (mainPanel.getOffsetWidth() >= clientWidth) { mainPanel.getElement().getStyle().setWidth(clientWidth - 20, Unit.PX); } else if (mainPanel.getOffsetWidth() > 430) { mainPanel.getElement().getStyle().setWidth(430, Unit.PX); } else { mainPanel.getElement().getStyle().clearWidth(); } showAt(forWidget); } }