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

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

Introduction

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

Prototype

public static int getScrollTop() 

Source Link

Usage

From source file:com.google.appinventor.client.RpcStatusPopup.java

License:Open Source License

private void positionPopup(int offsetWidth) {
    // make sure the popup is on-screen
    // if the top of the window is scrolled off the screen
    setPopupPosition((Window.getClientWidth() - offsetWidth) >> 1, Window.getScrollTop());
}

From source file:com.google.appinventor.client.widgets.properties.AdditionalChoicePropertyEditor.java

License:Open Source License

/**
 * Opens the additional choice dialog./* w  ww .java 2s .  co m*/
 */
protected void openAdditionalChoiceDialog() {
    popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            // adjust the x and y positions so that the entire panel
            // is on-screen
            int xPosition = getAbsoluteLeft();
            int yPosition = getAbsoluteTop();
            int xExtrude = xPosition + offsetWidth - Window.getClientWidth() - Window.getScrollLeft();
            int yExtrude = yPosition + offsetHeight - Window.getClientHeight() - Window.getScrollTop();
            if (xExtrude > 0) {
                xPosition -= (xExtrude + ADDITIONAL_CHOICE_ONSCREEN_PADDING);
            }
            if (yExtrude > 0) {
                yPosition -= (yExtrude + ADDITIONAL_CHOICE_ONSCREEN_PADDING);
            }
            popup.setPopupPosition(xPosition, yPosition);
        }
    });
}

From source file:com.google.code.p.gwtchismes.client.GWTCDatePickerAbstract.java

License:Apache License

private void moveIntoVisibleArea() {
    if (calendarDlg != null) {
        int w = Window.getClientWidth() + Window.getScrollLeft();
        int xd = calendarDlg.getAbsoluteLeft();
        int wd = calendarGrid.getOffsetWidth() + 40;
        if ((xd + wd) > w) {
            xd = xd - ((xd + wd) - w);/*from   ww w.j ava 2  s. c o  m*/
        }

        int h = Window.getClientHeight() + Window.getScrollTop();
        int yd = calendarDlg.getAbsoluteTop();
        int hd = calendarDlg.getOffsetHeight() + 20;
        if ((yd + hd) > h) {
            yd = yd - ((yd + hd) - h);
        }
        calendarDlg.setPopupPosition(xd, yd);
    }
}

From source file:com.google.gerrit.client.ErrorDialog.java

License:Apache License

protected ErrorDialog() {
    super(/* auto hide */false, /* modal */true);
    setGlassEnabled(true);/*from ww w. j a  v a2  s. c om*/
    getGlassElement().addClassName(Gerrit.RESOURCES.css().errorDialogGlass());

    text = new Label();
    text.setStyleName(Gerrit.RESOURCES.css().errorDialogTitle());

    body = new FlowPanel();

    final FlowPanel buttons = new FlowPanel();
    buttons.setStyleName(Gerrit.RESOURCES.css().errorDialogButtons());

    closey = new Button();
    closey.setText(Gerrit.C.errorDialogContinue());
    closey.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            hide();
        }
    });
    closey.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            // if the close button is triggered by a key we need to consume the key
            // event, otherwise the key event would be propagated to the parent
            // screen and eventually trigger some unwanted action there after the
            // error dialog was closed
            event.stopPropagation();
        }
    });
    buttons.add(closey);

    final FlowPanel center = new FlowPanel();
    center.add(text);
    center.add(body);
    center.add(buttons);

    setText(Gerrit.C.errorDialogTitle());
    addStyleName(Gerrit.RESOURCES.css().errorDialog());
    add(center);

    int l = Window.getScrollLeft() + 20;
    int t = Window.getScrollTop() + 20;
    setPopupPosition(l, t);
}

From source file:com.google.gerrit.client.patches.PatchBrowserPopup.java

License:Apache License

@Override
public void setPosition(final int myWidth, int myHeight) {
    final int dLeft = (Window.getClientWidth() - myWidth) >> 1;
    final int cHeight = Window.getClientHeight();
    final int cHeight2 = 2 * cHeight / 3;
    final int sLeft = Window.getScrollLeft();
    final int sTop = Window.getScrollTop();

    if (myHeight > cHeight2) {
        sp.setHeight((cHeight2 - 50) + "px");
        myHeight = getOffsetHeight();//from  ww w . j  a  va2  s .c  o m
    }
    setPopupPosition(sLeft + dLeft, (sTop + cHeight) - (myHeight + 10));
}

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

License:Apache License

public ContainerStreamView(T containerContentItem,
        Map<ContentItemType, List<BaseContentItem>> linkedContentItemsByType) {
    this.contentItem = containerContentItem;
    this.linkedContentItemsByType = linkedContentItemsByType;
    boolean lowImportance = contentItem.getImportance() == Importance.LOW;

    initWidget(uiBinder.createAndBindUi(this));

    if (contentItem.getRenderAsSeen()) {
        this.addStyleName(Resources.INSTANCE.css().read());
    }//  w  w w .  j av  a  2s  . c  o m

    title.setHTML(getHeadline());

    GlobalUtil.addIfNotNull(byline, BylineWidget.makeContextSensitive(contentItem, new HashSet<Long>()));
    timestamp.setDateTime(getStartDate(), getEndDate());

    if (lowImportance) {
        title.removeStyleName(Resources.INSTANCE.css().headline());
        byline.setVisible(false);
        timestamp.setTimeVisible(false);
    }

    ShortContainerView<T> shortView = new ShortContainerView<T>(contentItem, linkedContentItemsByType);
    LongContainerView<T> longView = getLongContainerView();

    if (longView.hasExtraContent()) {
        title.addStyleName(Resources.INSTANCE.css().clickable());
        title.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                EventBus.INSTANCE.fireEvent(new BlockToggledEvent(!content.isOpen(), contentItem.getId()));
            }
        });
        content.setContent(shortView, longView);
        content.handleContentItemEvents(contentItem.getId());
        ContainerStreamViewFooter disclosurePanelHeader = new ContainerStreamViewFooter(contentItem);
        disclosurePanelHeader.addNavLinks(longView.getExtraContentNavLinks(), content);
        content.setHeader(disclosurePanelHeader);
    } else {
        content.setContent(shortView, null);
    }

    toggleEventHandler = EventBus.INSTANCE.addHandler(BlockToggledEvent.TYPE, new BlockToggledEvent.Handler() {
        @Override
        public void onToggle(BlockToggledEvent e) {
            if (contentItem.getId().equals(e.getContentItemId()) && !e.isOpened() && e.shouldScrollOnClose()) {
                // Scroll to the top of this event if it's being closed
                // and the window is below the event.
                int blockPosition = title.getAbsoluteTop();
                if (blockPosition < Window.getScrollTop()) {
                    WindowScroll.scrollTo(blockPosition, new Command() {
                        @Override
                        public void execute() {
                            LivingStoryControls.repositionAnchoredPanel();
                        }
                    });
                }
            }
        }
    });
}

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

License:Apache License

/**
 * "Jumps to" the event indicated by contentItemId, scrolling it into view and opening its
 * contents.//from   w  w  w  .j  av a  2 s. c o  m
 * Only works for event and standalone narrative content items. 
 * Sets a history token when called.
 */
public void highlightEvent(int contentItemId) {
    // Save the current scroll position in the history so that when the user clicks 'back',
    // they're scrolled back here.
    HistoryManager.changeState(SCROLL_POSITION_STATE, String.valueOf(Window.getScrollTop()));
    highlightEvent(contentItemId, true);
}

From source file:com.google.livingstories.client.ui.AnchoredPanel.java

License:Apache License

public void reposition() {
    Widget content = getWidget();//from  w  w  w . ja  v a  2 s  .  c  o  m
    Element boundingBox = getElement().getParentElement();
    int windowTop = Window.getScrollTop();
    int windowLeft = Window.getScrollLeft();
    int topBound = boundingBox.getAbsoluteTop();
    int bottomBound = topBound + boundingBox.getOffsetHeight() - content.getOffsetHeight();
    if (!scrolling) {
        if (windowTop > topBound && windowTop < bottomBound) {
            scrolling = true;
            Style style = content.getElement().getStyle();
            style.setProperty("position", "fixed");
            style.setPropertyPx("top", 0);
            style.setPropertyPx("left", boundingBox.getAbsoluteLeft() - windowLeft);
        }
    } else {
        if (windowTop < topBound) {
            scrolling = false;
            Style style = content.getElement().getStyle();
            style.setProperty("position", "relative");
            style.setPropertyPx("top", 0);
            style.setPropertyPx("left", 0);
        } else if (windowTop > bottomBound) {
            scrolling = false;
            Style style = content.getElement().getStyle();
            style.setProperty("position", "relative");
            // Can't use bottom:0px here because the spacer has no height.
            // Even if we set the spacer's height to be 100%, it won't necessarily
            // work if this panel is in a table cell.
            style.setPropertyPx("top", bottomBound - topBound);
            style.setPropertyPx("left", 0);
        } else {
            content.getElement().getStyle().setPropertyPx("left", boundingBox.getAbsoluteLeft() - windowLeft);
        }
    }
}

From source file:com.google.livingstories.client.ui.Lightbox.java

License:Apache License

/**
 * Reimplementation of center() that does not allow the popup to extend above or to the left
 * of the current scroll position.//  www  .j a v  a 2 s.c  o m
 */
@Override
public void center() {
    setPopupPositionAndShow(new PositionCallback() {
        @Override
        public void setPosition(int offsetWidth, int offsetHeight) {
            int left = Math.max(0, (Window.getClientWidth() - getOffsetWidth()) / 2);
            int top = Math.max(0, (Window.getClientHeight() - getOffsetHeight()) / 2);
            setPopupPosition(Window.getScrollLeft() + left, Window.getScrollTop() + top);
        }
    });
}

From source file:com.google.livingstories.client.ui.Slideshow.java

License:Apache License

private void showFilmstrip() {
    if (allImages.size() > 1) {
        filmstripPopup.setPopupPositionAndShow(new PositionCallback() {
            @Override//from   w w  w.java  2 s  . co  m
            public void setPosition(int offsetWidth, int offsetHeight) {
                filmstripPopup.setPopupPosition(
                        Window.getScrollLeft() + (Window.getClientWidth() - offsetWidth) / 2,
                        Window.getScrollTop() + (Window.getClientHeight() - offsetHeight));
            }
        });
    }
}