Example usage for com.google.gwt.dom.client FrameElement getClientWidth

List of usage examples for com.google.gwt.dom.client FrameElement getClientWidth

Introduction

In this page you can find the example usage for com.google.gwt.dom.client FrameElement getClientWidth.

Prototype

@Override
    public int getClientWidth() 

Source Link

Usage

From source file:org.unitime.timetable.gwt.client.widgets.UniTimeFrameDialogImpl.java

License:Apache License

public UniTimeFrameDialogImpl() {
    super(true, true);

    setEscapeToHide(true);/*from w ww . j a v a  2  s  . com*/
    iFrame = new Frame();
    iFrame.getElement().getStyle().setBorderWidth(0, Unit.PX);
    hookFrameLoaded((FrameElement) iFrame.getElement().cast());
    setWidget(iFrame);

    iCheckLoadingWidgetIsShowing = new Timer() {
        @Override
        public void run() {
            if (LoadingWidget.getInstance().isShowing()) {
                LoadingWidget.getInstance().hide();
                UniTimeNotifications.error(
                        getText() + " does not seem to load, " + "please check <a href='" + iFrame.getUrl()
                                + "' style='white-space: nowrap;'>" + iFrame.getUrl() + "</a> for yourself.");
            }
        }
    };

    addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            if (LoadingWidget.getInstance().isShowing())
                LoadingWidget.getInstance().hide();
            RootPanel.getBodyElement().getStyle().setOverflow(Overflow.AUTO);
        }
    });

    iFrame.addLoadHandler(new LoadHandler() {
        @Override
        public void onLoad(LoadEvent event) {
            LoadingWidget.getInstance().hide();
            try {
                FrameElement frame = (FrameElement) iFrame.getElement().cast();
                BodyElement body = frame.getContentDocument().getBody();
                if (body.getScrollWidth() > body.getClientWidth()) {
                    iFrame.setWidth(
                            Math.min(frame.getClientWidth() + body.getScrollWidth() - body.getClientWidth(),
                                    Window.getClientWidth() * 95 / 100) + "px");
                    setPopupPosition(
                            Math.max(Window.getScrollLeft() + (Window.getClientWidth() - getOffsetWidth()) / 2,
                                    0),
                            Math.max(Window.getScrollTop() + (Window.getClientHeight() - getOffsetHeight()) / 2,
                                    0));
                }
            } catch (Exception e) {
            }
        }
    });
}