Example usage for com.google.gwt.user.client Window getScrollLeft

List of usage examples for com.google.gwt.user.client Window getScrollLeft

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window getScrollLeft.

Prototype

public static int getScrollLeft() 

Source Link

Usage

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  w w  . jav a2  s  . co  m*/
 * @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 horizontal scroll offset of the GWT application's primary window.
 * Measured from the left-most position in the document (i.e.
 * document.documentElement origin) to the left edge of the viewport.
 * //from  ww w .  j a v  a 2  s .c o m
 * @return 0 or a positive value in screen pixels 
 * @see Window#getScrollLeft()
 */
public static int getViewportScrollX() {
    return Window.getScrollLeft();
}

From source file:asquare.gwt.tk.client.util.DomUtil.java

License:Apache License

/**
 * Get the mouse x coordinate relative to the document's origin. This method
 * differs from {@link DOM#eventGetClientX(Event)} in that it includes the
 * area hidden by document scroll.//from w w  w .j  av  a 2  s  .c o  m
 * 
 * @param event a native DOM event object
 * @return the x coordinate in screen pixels
 */
public static int eventGetAbsoluteX(Event event) {
    return DOM.eventGetClientX(event) + Window.getScrollLeft();
}

From source file:asquare.gwt.tk.uitest.alertdialog.client.Demo.java

License:Apache License

public void onModuleLoad() {
    Debug.enable();/*from   w  ww .  j  av a  2s . 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.SliderMap.java

License:Artistic License

/**
 * Fired whenever a browser event is received.
 * @param event Event to process/* ww  w.java2s.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 w  ww.j a  va 2 s  .com
 */
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:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

private static void debugScroll(String message) {
    if (debugScroll) {
        ClientNotifications.get()/*from  ww  w  .  j  a  v  a 2 s. com*/
                .log(CommonUtils.formatJ("scroll from: %s,%s", Window.getScrollLeft(), Window.getScrollTop()));
        ClientNotifications.get().log(message);
    }
}

From source file:cc.alcina.framework.gwt.client.widget.complex.SliderBar.java

License:Apache License

/**
 * Slide the knob to a new location./*from ww  w. j a v a  2s . c  o  m*/
 *
 * @param event
 *            the mouse event
 */
private void slideKnob(Event event) {
    int d = vertical ? DOM.eventGetClientY(event) + Window.getScrollTop()
            : DOM.eventGetClientX(event) + Window.getScrollLeft();
    if (d > 0) {
        int lineMajorDimension = getLineMajorDimension();
        int linePreOffset = vertical ? DOM.getAbsoluteTop(lineElement) : DOM.getAbsoluteLeft(lineElement);
        double percent = (double) (d - linePreOffset) / lineMajorDimension * 1.0;
        setCurrentValue(getTotalRange() * percent + minValue, true);
    }
}

From source file:cc.alcina.framework.gwt.client.widget.dialog.GlassDialogBox.java

License:Apache License

@Override
public void show() {
    if (!isGlassHidden()) {
        glass.show(true);//w  w  w  .j av a 2  s .c om
    }
    scrollLeft = Window.getScrollLeft();
    scrollTop = Window.getScrollTop();
    if (this.handlerRegistration == null && !BrowserMod.isMobile()) {
        this.handlerRegistration = Window.addWindowScrollHandler(scrollHandler);
    }
    super.show();
}

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. c om*/
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);
        }
    }
}