List of usage examples for com.google.gwt.user.client Window getScrollTop
public static int getScrollTop()
From source file:asquare.gwt.tk.client.ui.behavior.MouseEventImpl.java
License:Apache License
/** * @param source the widget which is receiving the mouse event * @param mouseEvent a <code>mousedown</code>, <code>mousemove</code> or <code>mouseup</code> event * @param type the DOM event type//w ww. j a v a2s .c om * @param previewPhase <code>true</code> if the event was caught in event preview */ public MouseEventImpl(Widget source, Event mouseEvent, int type, boolean previewPhase) { super(source, mouseEvent, type, previewPhase); Element e = source.getElement(); m_clientX = DOM.eventGetClientX(mouseEvent); m_clientY = DOM.eventGetClientY(mouseEvent); m_absoluteX = Window.getScrollLeft() + m_clientX; m_absoluteY = Window.getScrollTop() + m_clientY; m_widgetLeft = DOM.getAbsoluteLeft(source.getElement()); m_widgetTop = DOM.getAbsoluteTop(source.getElement()); /* * Translate the coordinates into the source widget's coordinate space * see MouseListenerCollection.fireMouseEvent() */ m_widgetX = m_absoluteX - m_widgetLeft + DOM.getElementPropertyInt(e, "scrollLeft"); m_widgetY = m_absoluteY - m_widgetTop + DOM.getElementPropertyInt(e, "scrollTop"); }
From source file:asquare.gwt.tk.client.util.DomUtil.java
License:Apache License
/** * Get the vertical scroll offset of the GWT application's primary window. * Measured from the top-most position in the document (i.e. * document.documentElement origin) to the top edge of the viewport. * /*from w w w . j a v a2 s.c o m*/ * @return 0 or a positive value in screen pixels * @see Window#getScrollTop() */ public static int getViewportScrollY() { return Window.getScrollTop(); }
From source file:asquare.gwt.tk.client.util.DomUtil.java
License:Apache License
/** * Get the mouse y coordinate relative to the document's origin. This method * differs from {@link DOM#eventGetClientY(Event)} in that it includes the * area hidden by document scroll./*from w w w.j a v a2 s.co m*/ * * @param event a native DOM event object * @return the y coordinate in screen pixels */ public static int eventGetAbsoluteY(Event event) { return DOM.eventGetClientY(event) + Window.getScrollTop(); }
From source file:asquare.gwt.tk.uitest.alertdialog.client.Demo.java
License:Apache License
public void onModuleLoad() { Debug.enable();/* ww w . ja va2 s . c o m*/ new DebugEventListener('x', Event.ONMOUSEDOWN, null) { @Override protected void doEvent(Event event) { Element target = DOM.eventGetTarget(event); Debug.println("target=" + DebugUtil.prettyPrintElement(target)); int screenX = DOM.eventGetScreenX(event); int screenY = DOM.eventGetScreenY(event); int clientX = DOM.eventGetClientX(event); int clientY = DOM.eventGetClientY(event); int absLeft = DOM.getAbsoluteLeft(target); int absTop = DOM.getAbsoluteTop(target); int offsetLeft = getOffsetLeft(target); int offsetTop = getOffsetTop(target); int docScrollX = Window.getScrollLeft(); int docScrollY = Window.getScrollTop(); Debug.println("screenX=" + screenX + ",screenY=" + screenY + ",clientX=" + clientX + ",clientY=" + clientY + ",absLeft=" + absLeft + ",absTop=" + absTop + ",offsetLeft=" + offsetLeft + ",offsetTop=" + offsetTop + ",docScrollX=" + docScrollX + ",docScrollY=" + docScrollY); } }.install(); new DebugEventListener('z', Event.ONMOUSEDOWN, "Offset hierarchy inspector") { @Override protected void doEvent(Event event) { Element target = DOM.eventGetTarget(event); printOffsetTopHierarchy(target); } }.install(); new DebugHierarchyInspector().install(); new DebugElementDumpInspector().install(); new DebugEventListener(Event.ONMOUSEDOWN | Event.ONMOUSEUP).install(); if (!GWT.isScript()) { DebugConsole.getInstance().disable(); } final Button button = new Button(); button.setText("Default Info dialog"); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final AlertDialog alert = AlertDialog.createInfo(new Command() { public void execute() { Debug.println("OK clicked"); } }, "Info Dialog", "this is a default info dialog"); alert.show(); } }); RootPanel.get().add(button); Command showDialog = new Command() { private AlertDialog m_dialog; public void execute() { if (m_dialog == null) { m_dialog = AlertDialog.createWarning(this, "Caption text", null); ScrollPanel message = new ScrollPanel(); message.setAlwaysShowScrollBars(true); message.setWidth("100%"); message.setHeight("100px"); message.setWidget(new Label( "These packages contain reference information about the main GWT user interface and utility classes. For higher-level explanations of how to take advantage of all this stuff, check out the Developer Guide. Among other things, there's a handy widget gallery and an explanation of how remote procedure calls work.These packages contain reference information about the main GWT user interface and utility classes. For higher-level explanations of how to take advantage of all this stuff, check out the Developer Guide. Among other things, there's a handy widget gallery and an explanation of how remote procedure calls work.")); m_dialog.setMessage(message); m_dialog.setSize("400px", "300px"); m_dialog.addController(new ControllerAdaptor(Controller.class, Event.ONMOUSEDOWN) { @Override public void onBrowserEvent(Widget widget, Event event) { int x = DomUtil.eventGetAbsoluteX(event) - DOM.getAbsoluteLeft(widget.getElement()); int y = DomUtil.eventGetAbsoluteY(event) - DOM.getAbsoluteTop(widget.getElement()); Debug.println("onMouseDown(" + x + "," + y + ")"); } }); } m_dialog.show(); } }; showDialog.execute(); }
From source file:at.ait.dme.yuma.client.colorpicker.SliderBar.java
License:Artistic License
/** * Fired whenever a browser event is received. * @param event Event to process/*from w ww .j a va2 s .co m*/ */ @Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEUP: Event.releaseCapture(this.getElement()); capturedMouse = false; break; case Event.ONMOUSEDOWN: Event.setCapture(this.getElement()); capturedMouse = true; case Event.ONMOUSEMOVE: if (capturedMouse) { DOM.eventPreventDefault(event); int y = DOM.eventGetClientY(event) - getAbsoluteTop() + Window.getScrollTop(); if (y < 0) y = 0; if (y > 256) y = 256; DOM.setStyleAttribute(slider.getElement(), "top", y - 4 + "px"); if (parent != null) { parent.onBarSelected(y); } } } }
From source file:at.ait.dme.yuma.client.colorpicker.SliderMap.java
License:Artistic License
/** * Fired whenever a browser event is received. * @param event Event to process/*from w w w .j a va2 s . c o m*/ */ @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); switch (DOM.eventGetType(event)) { case Event.ONMOUSEUP: Event.releaseCapture(this.getElement()); capturedMouse = false; break; case Event.ONMOUSEDOWN: Event.setCapture(this.getElement()); capturedMouse = true; case Event.ONMOUSEMOVE: if (capturedMouse) { DOM.eventPreventDefault(event); int x = DOM.eventGetClientX(event) - colorUnderlay.getAbsoluteLeft() + 1 + Window.getScrollLeft(); int y = DOM.eventGetClientY(event) - colorUnderlay.getAbsoluteTop() + 1 + Window.getScrollTop(); if (x < 0) x = 0; if (x > 256) x = 256; if (y < 0) y = 0; if (y > 256) y = 256; DOM.setStyleAttribute(slider.getElement(), "left", x - 7 + "px"); DOM.setStyleAttribute(slider.getElement(), "top", y - 7 + "px"); if (parent != null) { parent.onMapSelected(x, y); } } } }
From source file:bufferings.ktr.wjr.client.ui.WjrPopupPanel.java
License:Apache License
/** * Adjusts the position of the panel./*from ww w . j a v a 2s. c o m*/ */ private void adjustPosition() { int left = 13; int top = (Window.getClientHeight() - 48); left += Window.getScrollLeft(); top += Window.getScrollTop(); getElement().getStyle().setPropertyPx("left", left); getElement().getStyle().setPropertyPx("top", top); }
From source file:burrito.client.Burrito.java
License:Apache License
private static void updateEditFormButtons() { if (currentEditForm != null) { int bottomOfWindow = Window.getClientHeight() + Window.getScrollTop(); int bottomOfEditForm = currentEditForm.getAbsoluteTop() + currentEditForm.getOffsetHeight(); if (bottomOfEditForm > bottomOfWindow) { currentEditForm.makeButtonsStick(true); } else {/*from w ww. j a va 2 s . c o m*/ currentEditForm.makeButtonsStick(false); } } }
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);// w w w . j av a 2 s . c o m }
From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java
License:Apache License
public static void scrollIntoView(Element elem, int fromTop, boolean forceFromTop) { int y1 = Document.get().getBodyOffsetTop() + Window.getScrollTop(); int y2 = y1 + Window.getClientHeight(); Element parent = elem.getParentElement(); int absoluteTop = elem.getAbsoluteTop(); int offsetHeight = elem.getOffsetHeight(); int absoluteBottom = absoluteTop + offsetHeight; boolean recalcAbsoluteTopAfterScroll = true; if (absoluteTop == 0) { Text tptCopy = tempPositioningText; tempPositioningText = null;/*w w w . ja v a2s . com*/ Element positioning = WidgetUtils.getElementForPositioning0(elem); if (positioning != null) { absoluteTop = positioning.getAbsoluteTop(); recalcAbsoluteTopAfterScroll = false; } releaseTempPositioningText(); tempPositioningText = tptCopy; } if (!forceFromTop && (absoluteTop >= y1 && absoluteTop < y2)) { return; } if (forceFromTop && LooseContext.is(CONTEXT_REALLY_ABSOLUTE_TOP)) { int to = absoluteTop - fromTop; scrollBodyTo(to); return; } scrollElementIntoView(elem); y1 = Document.get().getBodyOffsetTop() + Window.getScrollTop(); y2 = y1 + Window.getClientHeight(); // not sure why...but I feel there's a reason if (recalcAbsoluteTopAfterScroll) { absoluteTop = elem.getAbsoluteTop(); } if (absoluteTop < y1 || absoluteTop > y2 || fromTop != 0) { scrollBodyTo((Math.max(0, absoluteTop - fromTop))); } }