List of usage examples for com.google.gwt.user.client Window getClientWidth
public static int getClientWidth()
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
private void setHyperlinkTooltipPosition(int offsetWidth, int offsetHeight, DivElement element) { // Calculate left position for the popup. The computation for // the left position is bidi-sensitive. int textBoxOffsetWidth = element.getOffsetWidth(); // Compute the difference between the popup's width and the // textbox's width int offsetWidthDiff = offsetWidth - textBoxOffsetWidth; int left;/*from w w w.ja v a2 s. co m*/ if (LocaleInfo.getCurrentLocale().isRTL()) { // RTL case int textBoxAbsoluteLeft = element.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 = element.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 = element.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 + element.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 += element.getOffsetHeight(); } hyperlinkTooltip.setPopupPosition(left, top); }
From source file:com.vaadin.client.debug.internal.VDebugWindow.java
License:Apache License
/** * Applies the appropriate instance variables for width, height, x, y * depending on if the window is minimized or not. * /*from ww w .j a v a 2 s. c o m*/ * If the value is negative, the window is positioned that amount of pixels * from the right/bottom instead of left/top. * * Finally, the position is bounds-checked so that the window is not moved * off-screen (the adjusted values are not saved). */ private void applyPositionAndSize() { int x = 0; int y = 0; if (minimized) { x = minX; if (minX < 0) { x = Window.getClientWidth() + minX; } y = minY; if (minY < 0) { y = Window.getClientHeight() + minY; } } else { x = fullX; if (fullX < 0) { x = Window.getClientWidth() + fullX; } y = fullY; if (y < 0) { y = Window.getClientHeight() + fullY; } content.setWidth(fullW + "px"); content.setHeight(fullH + "px"); } applyBounds(x, y); }
From source file:com.vaadin.client.debug.internal.VDebugWindow.java
License:Apache License
private void applyBounds(int x, int y) { // bounds check if (x < 0) { x = 0;/*from ww w. j a va2 s . com*/ } if (x > Window.getClientWidth() - getOffsetWidth()) { // not allowed off-screen to the right x = Window.getClientWidth() - getOffsetWidth(); } if (y > Window.getClientHeight() - getOffsetHeight()) { y = Window.getClientHeight() - getOffsetHeight(); } if (y < 0) { y = 0; } setPopupPosition(x, y); }
From source file:com.vaadin.client.debug.internal.VDebugWindow.java
License:Apache License
/** * Reads position and size from the DOM to local variables (which in turn * can be stored to localStorage)/*from w w w . j a va 2 s. c om*/ */ private void readPositionAndSize() { int x = getPopupLeft(); int fromRight = Window.getClientWidth() - x - getOffsetWidth(); if (fromRight < x) { x -= Window.getClientWidth(); } int y = getPopupTop(); int fromBottom = Window.getClientHeight() - y - getOffsetHeight(); if (fromBottom < y) { y -= Window.getClientHeight(); } if (minimized) { minY = y; minX = x; } else { fullY = y; fullX = x; fullW = content.getOffsetWidth(); fullH = content.getOffsetHeight(); } }
From source file:com.vaadin.client.ui.ui.UIConnector.java
License:Apache License
@Override protected void init() { super.init(); registerRpc(PageClientRpc.class, new PageClientRpc() { @Override/*from w ww. j ava2 s. com*/ public void reload() { Window.Location.reload(); } }); registerRpc(ScrollClientRpc.class, new ScrollClientRpc() { @Override public void setScrollTop(int scrollTop) { getWidget().getElement().setScrollTop(scrollTop); } @Override public void setScrollLeft(int scrollLeft) { getWidget().getElement().setScrollLeft(scrollLeft); } }); registerRpc(UIClientRpc.class, new UIClientRpc() { @Override public void uiClosed(final boolean sessionExpired) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { // Only notify user if we're still running and not eg. // navigating away (#12298) if (getConnection().isApplicationRunning()) { if (sessionExpired) { getConnection().showSessionExpiredError(null); } else { getState().enabled = false; updateEnabledState(getState().enabled); } getConnection().setApplicationRunning(false); } } }); } }); registerRpc(DebugWindowClientRpc.class, new DebugWindowClientRpc() { @Override public void reportLayoutProblems(String json) { VConsole.printLayoutProblems(getValueMap(json), getConnection()); } private native ValueMap getValueMap(String json) /*-{ return JSON.parse(json); }-*/; }); getWidget().addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { getRpcProxy(UIServerRpc.class).resize(event.getHeight(), event.getWidth(), Window.getClientWidth(), Window.getClientHeight()); if (getState().immediate || getPageState().hasResizeListeners) { getConnection().getServerRpcQueue().flush(); } } }); getWidget().addScrollHandler(new ScrollHandler() { private int lastSentScrollTop = Integer.MAX_VALUE; private int lastSentScrollLeft = Integer.MAX_VALUE; @Override public void onScroll(ScrollEvent event) { Element element = getWidget().getElement(); int newScrollTop = element.getScrollTop(); int newScrollLeft = element.getScrollLeft(); if (newScrollTop != lastSentScrollTop || newScrollLeft != lastSentScrollLeft) { lastSentScrollTop = newScrollTop; lastSentScrollLeft = newScrollLeft; getRpcProxy(UIServerRpc.class).scroll(newScrollTop, newScrollLeft); } } }); }
From source file:com.vaadin.client.ui.VContextMenu.java
License:Apache License
/** * Shows context menu at given location IF it contain at least one item. * //from w ww. j av a 2 s. c om * @param left * @param top */ public void showAt(int left, int top) { final Action[] actions = actionOwner.getActions(); if (actions == null || actions.length == 0) { // Only show if there really are actions return; } this.left = left; this.top = top; menu.clearItems(); for (int i = 0; i < actions.length; i++) { final Action a = actions[i]; menu.addItem(new MenuItem(a.getHTML(), true, a)); } // Attach onload listeners to all images WidgetUtil.sinkOnloadForImages(menu.getElement()); // Store the currently focused element, which will be re-focused when // context menu is closed focusedElement = WidgetUtil.getFocusedElement(); // reset height (if it has been previously set explicitly) setHeight(""); setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { // mac FF gets bad width due GWT popups overflow hacks, // re-determine width offsetWidth = menu.getOffsetWidth(); int left = VContextMenu.this.left; int top = VContextMenu.this.top; if (offsetWidth + left > Window.getClientWidth()) { left = left - offsetWidth; if (left < 0) { left = 0; } } if (offsetHeight + top > Window.getClientHeight()) { top = Math.max(0, Window.getClientHeight() - offsetHeight); } if (top == 0) { setHeight(Window.getClientHeight() + "px"); } setPopupPosition(left, top); /* * Move keyboard focus to menu, deferring the focus setting so * the focus is certainly moved to the menu in all browser after * the positioning has been done. */ Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { // Focus the menu. menu.setFocus(true); // Unselect previously selected items menu.selectItem(null); } }); } }); }
From source file:com.vaadin.client.ui.VUI.java
License:Apache License
/** * Called when the window or parent div might have been resized. * // w w w. j a va 2 s. c o m * This immediately checks the sizes of the window and the parent div (if * monitoring it) and triggers layout recalculation if they have changed. */ protected void performSizeCheck() { windowSizeMaybeChanged(Window.getClientWidth(), Window.getClientHeight()); }
From source file:com.vaadin.client.ui.VWindow.java
License:Apache License
/** * TODO check if we need to support this with touch based devices. * /*from w w w. j a v a 2 s .c o m*/ * Checks if the cursor was inside the browser content area when the event * happened. * * @param event * The event to be checked * @return true, if the cursor is inside the browser content area * * false, otherwise */ private boolean cursorInsideBrowserContentArea(Event event) { if (event.getClientX() < 0 || event.getClientY() < 0) { // Outside to the left or above return false; } if (event.getClientX() > Window.getClientWidth() || event.getClientY() > Window.getClientHeight()) { // Outside to the right or below return false; } return true; }
From source file:com.vaadin.client.ui.window.WindowConnector.java
License:Apache License
@Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); VWindow window = getWidget();/*from w w w.jav a2 s .c o m*/ WindowState state = getState(); if (state.modal != window.vaadinModality) { window.setVaadinModality(!window.vaadinModality); } boolean resizeable = state.resizable && state.windowMode == WindowMode.NORMAL; window.setResizable(resizeable); window.resizeLazy = state.resizeLazy; window.setDraggable(state.draggable && state.windowMode == WindowMode.NORMAL); window.updateMaximizeRestoreClassName(state.resizable, state.windowMode); // Caption must be set before required header size is measured. If // the caption attribute is missing the caption should be cleared. String iconURL = null; if (getIconUri() != null) { iconURL = getIconUri(); } window.setAssistivePrefix(state.assistivePrefix); window.setAssistivePostfix(state.assistivePostfix); window.setCaption(state.caption, iconURL, getState().captionAsHtml); window.setWaiAriaRole(getState().role); window.setAssistiveDescription(state.contentDescription); window.setTabStopEnabled(getState().assistiveTabStop); window.setTabStopTopAssistiveText(getState().assistiveTabStopTopText); window.setTabStopBottomAssistiveText(getState().assistiveTabStopBottomText); clickEventHandler.handleEventHandlerRegistration(); window.immediate = state.immediate; window.setClosable(!isReadOnly()); // initialize position from state updateWindowPosition(); // setting scrollposition must happen after children is rendered window.contentPanel.setScrollPosition(state.scrollTop); window.contentPanel.setHorizontalScrollPosition(state.scrollLeft); // Center this window on screen if requested // This had to be here because we might not know the content size before // everything is painted into the window // centered is this is unset on move/resize window.centered = state.centered; // Ensure centering before setting visible (#16486) if (window.centered && getState().windowMode != WindowMode.MAXIMIZED) { Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { getWidget().center(); } }); } window.setVisible(true); // ensure window is not larger than browser window if (window.getOffsetWidth() > Window.getClientWidth()) { window.setWidth(Window.getClientWidth() + "px"); } if (window.getOffsetHeight() > Window.getClientHeight()) { window.setHeight(Window.getClientHeight() + "px"); } }
From source file:com.vaadin.client.VDebugConsole.java
License:Apache License
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: if (DOM.eventGetShiftKey(event)) { resizing = true;//from ww w . j a va 2 s . c o m DOM.setCapture(getElement()); startX = DOM.eventGetScreenX(event); startY = DOM.eventGetScreenY(event); initialW = VDebugConsole.this.getOffsetWidth(); initialH = VDebugConsole.this.getOffsetHeight(); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); DOM.addEventPreview(dragpreview); } else if (DOM.eventGetTarget(event) == caption) { moving = true; startX = DOM.eventGetScreenX(event); startY = DOM.eventGetScreenY(event); origTop = getAbsoluteTop(); origLeft = getAbsoluteLeft(); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); DOM.addEventPreview(dragpreview); } break; case Event.ONMOUSEMOVE: if (resizing) { int deltaX = startX - DOM.eventGetScreenX(event); int detalY = startY - DOM.eventGetScreenY(event); int w = initialW - deltaX; if (w < 30) { w = 30; } int h = initialH - detalY; if (h < 40) { h = 40; } VDebugConsole.this.setPixelSize(w, h); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); } else if (moving) { int deltaX = startX - DOM.eventGetScreenX(event); int detalY = startY - DOM.eventGetScreenY(event); int left = origLeft - deltaX; if (left < 0) { left = 0; } int top = origTop - detalY; if (top < 0) { top = 0; } VDebugConsole.this.setPopupPosition(left, top); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); } break; case Event.ONLOSECAPTURE: case Event.ONMOUSEUP: if (resizing) { DOM.releaseCapture(getElement()); resizing = false; } else if (moving) { DOM.releaseCapture(getElement()); moving = false; } DOM.removeEventPreview(dragpreview); break; case Event.ONDBLCLICK: if (DOM.eventGetTarget(event) == caption) { if (collapsed) { panel.setVisible(true); setToDefaultSizeAndPos(); } else { panel.setVisible(false); setPixelSize(120, 20); setPopupPosition(Window.getClientWidth() - 125, Window.getClientHeight() - 25); } collapsed = !collapsed; } break; default: break; } }