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

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

Introduction

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

Prototype

public static void scrollTo(int left, int top) 

Source Link

Usage

From source file:com.arcbees.website.client.application.ApplicationView.java

License:Apache License

private void bind() {
    $("a", menuToggle).click(new Function() {
        @Override/*from  w  w  w .  j a  va2  s . c  om*/
        public boolean f(Event event) {
            Window.scrollTo(0, 0);

            $(sidebar).toggleClass(appResources.style().active());

            $(menuToggle).removeClass(appResources.style().active());
            if ($(sidebar).hasClass(appResources.style().active())) {
                $(menuToggle).addClass(appResources.style().active());
                $(menuToggle).addClass(appResources.style().clicked());
                $(sidebar).addClass(appResources.style().clicked());
            }

            return false;
        }
    });

    // Always call watchMenu, the filtering is done by the function, fixing the multiple calls bug
    $(sidebar).hover(new Function() {
        @Override
        public void f() {
            watchMenu();
        }
    }, new Function() {
        @Override
        public void f() {
            watchMenu();
        }
    });

    $("a", sidebar).click(new Function() {
        @Override
        public void f() {
            Window.scrollTo(0, 0);

            removeActiveStyle();

            analytics.sendEvent("Menu", "Click").eventLabel($(this).attr("data-label")).go();

            setMenuState(STATE_CLICKED);
        }
    });

    $(content).click(new Function() {
        @Override
        public void f() {
            removeActiveStyle();
        }
    });

    $(langToggle).click(new Function() {
        @Override
        public void f() {
            analytics.sendEvent("Meta", "Click").eventLabel("Switch lang").go();
        }
    });

    $(githubLink).click(new Function() {
        @Override
        public void f() {
            analytics.sendEvent("Meta", "Click").eventLabel("Github").go();
        }
    });

    $("#monId").toggleClass("myClass", isFrench());

    $(backTop).click(new Function() {
        @Override
        public void f() {
            $("html, body").each(new Function() {
                @Override
                public void f(Element element) {
                    new ScrollTopAnimation(element).run(ANIMATION_DURATION);
                }
            });
        }
    });
}

From source file:com.axlight.gbrain.client.MainPane.java

License:Apache License

private void relocateCenter(int posX, int posY) {
    final Style glassStyle = Document.get().getElementById("gbrain-glass").getStyle();
    glassStyle.setWidth(viewWidth, Unit.PX);
    glassStyle.setHeight(viewHeight, Unit.PX);
    glassStyle.setVisibility(Visibility.VISIBLE);
    viewX = posX - viewWidth / 2;//from w w  w  . j  a v a2  s.c  om
    viewY = posY - viewHeight / 2;
    nodeManager.updateView(viewX, viewY);
    coordinate.updateView(viewX, viewY);
    new Timer() {
        public void run() {
            int screenWidth = getWindowScreenWidth();
            int screenHeight = getWindowScreenHeight();
            int left = viewWidth / 2 - screenWidth / 2;
            int top = viewHeight / 2 - screenHeight / 2;
            Window.scrollTo(left, top);
            setWidgetPosition(buttonPanel, left, top + screenHeight - buttonPanel.getOffsetHeight());
            glassStyle.setVisibility(Visibility.HIDDEN);
        }
    }.schedule(500);
}

From source file:com.axlight.gbrain.client.MainPane.java

License:Apache License

private void slideToPosition(int posX, int posY) {
    final int lastLeft = getWindowScrollLeft();
    final int lastTop = getWindowScrollTop();
    final int screenWidth = getWindowScreenWidth();
    final int screenHeight = getWindowScreenHeight();
    if (posX < viewX + screenWidth / 2 || posX > viewX + viewWidth - screenWidth / 2
            || posY < viewY + screenHeight / 2 || posY > viewY + viewHeight - screenHeight / 2) {
        // outside of the view, can't scroll.
        relocateCenter(posX, posY);/*from  w w w  .j  a  va 2s  .  c om*/
        return;
    }
    int prevCenterPosX = viewX + lastLeft + screenWidth / 2;
    int prevCenterPosY = viewY + lastTop + screenHeight / 2;
    final int diffX = posX - prevCenterPosX;
    final int diffY = posY - prevCenterPosY;
    new Animation() {
        protected void onUpdate(double progress) {
            progress = interpolate(progress);
            Window.scrollTo((int) (lastLeft + diffX * progress), (int) (lastTop + diffY * progress));
        }

        protected void onComplete() {
            Window.scrollTo(lastLeft + diffX, lastTop + diffY);
            setWidgetPosition(buttonPanel, lastLeft + diffX,
                    lastTop + diffY + screenHeight - buttonPanel.getOffsetHeight());
        }
    }.run(2000);
}

From source file:com.axlight.gbrain.client.MainPane.java

License:Apache License

private void supportDragAndDrop() {
    drawArea.addMouseDownHandler(new MouseDownHandler() {
        public void onMouseDown(MouseDownEvent event) {
            // XXX workaround for iPad, which fires mouse events even with
            // preventDefault.
            if (touchHandlerEnabled) {
                return;
            }//  w  w  w.  jav a  2s.co  m

            int eventX = event.getX();
            int eventY = event.getY();
            if (selectNode != null && selectNode.containsPoint(eventX, eventY)) {
                startDrag(selectNode, eventX, eventY);
            } else {
                sliding = true;
                slideStartX = eventX;
                slideStartY = eventY;
            }
        }
    });
    drawArea.addMouseUpHandler(new MouseUpHandler() {
        public void onMouseUp(MouseUpEvent event) {
            stopDrag();
            sliding = false;
        }
    });
    drawArea.addMouseMoveHandler(new MouseMoveHandler() {
        public void onMouseMove(MouseMoveEvent event) {
            int eventX = event.getX();
            int eventY = event.getY();
            updateDrag(eventX, eventY);
            if (sliding) {
                int left = Window.getScrollLeft();
                int top = Window.getScrollTop();
                left -= eventX - slideStartX;
                top -= eventY - slideStartY;
                Window.scrollTo(left, top);
            }
        }
    });
}

From source file:com.bedatadriven.renjin.appengine.client.CommandPrompt.java

License:Apache License

private void resizeInputArea(boolean shrink) {
    int numLines = countLines(inputArea);

    inputArea.setVisibleLines(shrink ? numLines + 1 : Math.max(inputArea.getVisibleLines(), numLines + 1));
    Window.scrollTo(0, 100000);
}

From source file:com.bedatadriven.renjin.appengine.client.LotREPLs.java

License:Apache License

/**
 * This is the entry point method.//w w  w.j  a  v  a  2s . c  om
 */
public void onModuleLoad() {
    doWarmUpRequest();

    commandPrompt = new CommandPrompt(new CommandPrompt.CommandEnteredCallback() {
        /**
         * The command entered handler does a little switch-a-roo. It removes the
         * input area and prompt, replacing them with immutable copies, and then
         * waits for the response. Once the script results (or error) are ready,
         * it inserts a result area and then re-adds the command prompt.
         */
        public void onCommandEntered(InterpreterType type, String script) {
            content.remove(commandPrompt.panel());

            Widget enteredScript = commandPrompt.createImmutablePanel();
            content.add(enteredScript);

            commandPrompt.clearInputArea();

            Window.scrollTo(0, 100000);

            api.eval(script, new ScriptCallback());
        }
    });

    String script = Location.getParameter("script");
    if (script != null && !script.equals("")) {
        commandPrompt.setScript(script);
    }

    content.add(commandPrompt.panel());

    content.setWidth("100%");
    RootPanel.get("root").add(content);
    commandPrompt.claimFocus();
}

From source file:com.bedatadriven.renjin.appengine.client.LotREPLs.java

License:Apache License

private void setResult(String result, boolean succeeded) {
    Element e = Document.get().createPreElement();
    e.setInnerText(result);/*from www.  j  a v a  2 s. c o  m*/
    e.setClassName(succeeded ? "result" : "error");
    e.setAttribute("tabIndex", "-1");
    content.getElement().appendChild(e);
    content.add(commandPrompt.panel());
    commandPrompt.claimFocus();
    Window.scrollTo(0, 100000);
}

From source file:com.google.gerrit.client.change.ReplyAction.java

License:Apache License

void onReply(MessageInfo msg) {
    if (popup != null) {
        popup.hide();/* ww w .j  a  v a 2 s. c  o m*/
        return;
    }

    if (replyBox == null) {
        replyBox = new ReplyBox(clp, psId, revision, allLabels, permittedLabels);
        allLabels = null;
        permittedLabels = null;
    }
    if (msg != null) {
        replyBox.replyTo(msg);
    }

    final PopupPanel p = new PopupPanel(true, false);
    p.setStyleName(style.replyBox());
    p.addAutoHidePartner(replyButton.getElement());
    p.addAutoHidePartner(quickApproveButton.getElement());
    p.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            if (popup == p) {
                popup = null;
                if (hasDraftComments || replyBox.hasMessage()) {
                    replyButton.setStyleName(style.highlight());
                }
            }
        }
    });
    p.add(replyBox);
    Window.scrollTo(0, 0);
    replyButton.removeStyleName(style.highlight());
    p.showRelativeTo(replyButton);
    GlobalKey.dialog(p);
    popup = p;
}

From source file:com.google.livingstories.client.lsp.views.LivingStoryPage.java

License:Apache License

public void goToPage(Widget page) {
    Window.scrollTo(0, 0);
    canvas.setWidget(page);
}

From source file:com.google.livingstories.client.lsp.views.OverviewPage.java

License:Apache License

@Override
public void changeState(String key, String value) {
    if (key.equals(SCROLL_POSITION_STATE)) {
        Window.scrollTo(0, Integer.valueOf(value));
        repositionAnchoredPanel();//from w  w w  .  j a  va  2  s  .c  om
    }
}