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

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

Introduction

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

Prototype

public static HandlerRegistration addResizeHandler(ResizeHandler handler) 

Source Link

Usage

From source file:com.google.collide.client.util.dom.FontDimensionsCalculator.java

License:Open Source License

private FontDimensionsCalculator(String fontClassName) {
    this.fontClassName = fontClassName;
    // This handler will be called when the browser window zooms
    Window.addResizeHandler(new ResizeHandler() {
        @Override/*from  ww w .j  ava2 s .co m*/
        public void onResize(ResizeEvent arg0) {
            measureAndDispatch();
        }
    });

    // Build a multirow text block so we can measure it
    StringBuilder htmlContent = new StringBuilder(SAMPLE_TEXT);
    for (int i = 1; i < SAMPLE_ROWS; i++) {
        htmlContent.append("<br/>");
        htmlContent.append(SAMPLE_TEXT);
    }

    dummyElement = Elements.createSpanElement(fontClassName);
    dummyElement.setInnerHTML(htmlContent.toString());
    dummyElement.getStyle().setVisibility(CSSStyleDeclaration.Visibility.HIDDEN);
    dummyElement.getStyle().setPosition(CSSStyleDeclaration.Position.ABSOLUTE);
    Elements.getBody().appendChild(dummyElement);

    fontDimensions = new FontDimensionsImpl();

    repeater.schedule(pollingDelay);

    /*
     * Force an initial measure (the dispatch won't happen since no one is
     * attached)
     */
    measureAndDispatch();
}

From source file:com.google.gerrit.client.diff.CodeMirrorDemo.java

License:Apache License

private void display(DiffInfo diff) {
    cmA = displaySide(diff.meta_a(), diff.text_a(), diffTable.getCmA());
    cmB = displaySide(diff.meta_b(), diff.text_b(), diffTable.getCmB());
    render(diff);/*from ww  w.j a va  2 s  . co m*/
    resizeHandler = Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            if (cmA != null) {
                cmA.setHeight(event.getHeight() - HEADER_FOOTER);
                cmA.refresh();
            }
            if (cmB != null) {
                cmB.setHeight(event.getHeight() - HEADER_FOOTER);
                cmB.refresh();
            }
        }
    });
}

From source file:com.google.gerrit.client.diff.DiffScreen.java

License:Apache License

@Override
public void onShowView() {
    super.onShowView();

    Window.enableScrolling(false);
    if (prefs.hideTopMenu()) {
        Gerrit.setHeaderVisible(false);/*from   w w  w.  j av  a  2s .co  m*/
    }
    resizeHandler = Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            resizeCodeMirror();
        }
    });
}

From source file:com.google.gerrit.client.diff.SideBySide2.java

License:Apache License

@Override
public void onShowView() {
    super.onShowView();
    Window.enableScrolling(false);
    JumpKeys.enable(false);//from w w  w . j  a  v  a  2s  .c om
    if (prefs.hideTopMenu()) {
        Gerrit.setHeaderVisible(false);
    }
    resizeHandler = Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            resizeCodeMirror();
        }
    });

    final int height = getCodeMirrorHeight();
    operation(new Runnable() {
        @Override
        public void run() {
            cmA.setHeight(height);
            cmB.setHeight(height);
            cmA.refresh();
            cmB.refresh();
        }
    });
    setLineLength(prefs.lineLength());
    diffTable.refresh();

    if (startLine == 0) {
        DiffChunkInfo d = chunkManager.getFirst();
        if (d != null) {
            if (d.isEdit() && d.getSide() == DisplaySide.A) {
                startSide = DisplaySide.B;
                startLine = lineOnOther(d.getSide(), d.getStart()).getLine() + 1;
            } else {
                startSide = d.getSide();
                startLine = d.getStart() + 1;
            }
        }
    }
    if (startSide != null && startLine > 0) {
        int line = startLine - 1;
        CodeMirror cm = getCmFromSide(startSide);
        if (cm.lineAtHeight(height - 20) < line) {
            cm.scrollToY(cm.heightAtLine(line, "local") - 0.5 * height);
        }
        cm.setCursor(LineCharacter.create(line));
        cm.focus();
    } else {
        cmA.setCursor(LineCharacter.create(0));
        cmA.focus();
    }
    if (Gerrit.isSignedIn() && prefs.autoReview()) {
        header.autoReview();
    }
    prefetchNextFile();
}

From source file:com.google.gerrit.client.editor.EditScreen.java

License:Apache License

@Override
public void onShowView() {
    super.onShowView();
    Window.enableScrolling(false);
    JumpKeys.enable(false);/*ww w . j a v a2  s  .com*/
    if (prefs.hideTopMenu()) {
        Gerrit.setHeaderVisible(false);
    }
    resizeHandler = Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            adjustHeight();
        }
    });
    closeHandler = Window.addWindowClosingHandler(new ClosingHandler() {
        @Override
        public void onWindowClosing(ClosingEvent event) {
            if (!cmEdit.isClean(generation)) {
                event.setMessage(EditConstants.I.closeUnsavedChanges());
            }
        }
    });

    generation = cmEdit.changeGeneration(true);
    setClean(true);
    cmEdit.on(new ChangesHandler() {
        @Override
        public void handle(CodeMirror cm) {
            setClean(cm.isClean(generation));
        }
    });

    adjustHeight();
    cmEdit.on("cursorActivity", updateCursorPosition());
    setShowTabs(prefs.showTabs());
    setLineLength(prefs.lineLength());
    cmEdit.refresh();
    cmEdit.focus();

    if (startLine > 0) {
        cmEdit.scrollToLine(startLine);
    }
    updateActiveLine();
    editPrefsAction = new EditPreferencesAction(this, prefs);
}

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

License:Apache License

@Override
public void show() {
    super.show();
    if (regWindowResize == null) {
        regWindowResize = Window.addResizeHandler(this);
    }//w  ww.ja  va 2s .com

    GlobalKey.dialog(this);
    GlobalKey.addApplication(this, new HidePopupPanelCommand(0, 'f', this));

    if (!fileList.isLoaded()) {
        fileList.onTableLoaded(new Command() {
            @Override
            public void execute() {
                sp.setHeight("");
                setPosition(getOffsetWidth(), getOffsetHeight());
                fileList.setRegisterKeys(true);
                fileList.movePointerTo(callerKey);
            }
        });
    }
}

From source file:com.google.gwt.language.sample.hellolanguage.client.HelloLanguage.java

License:Apache License

/**
 * The onModuleLoad() method is called when the body of the document is
 * finished loading. The JavaScript APIs are not loaded unless they were
 * included in the body of the .html file. Use the LanguageUtils.loadXXX()
 * methods to load them after the app starts, but before any API calls are
 * made.//from  ww w. j  a va 2 s.  c o m
 */
public void onModuleLoad() {

    final TabPanel demoTabPanel = new TabPanel();
    demoTabPanel.getDeckPanel().setPixelSize(Window.getClientWidth() - 30, DEMO_PANEL_HEIGHT);
    RootPanel.get().add(demoTabPanel);

    Window.addResizeHandler(new ResizeHandler() {
        public void onResize(ResizeEvent event) {
            demoTabPanel.getDeckPanel().setPixelSize(Window.getClientWidth() - 30, DEMO_PANEL_HEIGHT);
        }
    });

    final VerticalPanel transDemoPanel = new VerticalPanel();
    transDemoPanel.add(loadingLabel());

    final VerticalPanel langDetectDemoPanel = new VerticalPanel();
    langDetectDemoPanel.add(loadingLabel());

    final VerticalPanel translitDemoPanel = new VerticalPanel();
    translitDemoPanel.add(loadingLabel());

    demoTabPanel.add(transDemoPanel, "Translation demo");
    demoTabPanel.add(langDetectDemoPanel, "Language detection demo");
    demoTabPanel.add(translitDemoPanel, "Transliteration demo");
    demoTabPanel.selectTab(0);

    LanguageUtils.loadTranslation(new Runnable() {
        public void run() {
            transDemoPanel.clear();
            transDemoPanel.add(new TranslationDemo());

            langDetectDemoPanel.clear();
            langDetectDemoPanel.add(new LanguageDetectionDemo());
        }
    });

    LanguageUtils.loadTransliteration(new Runnable() {
        public void run() {
            translitDemoPanel.clear();
            TransliterationDemo translitDemo = new TransliterationDemo();
            translitDemoPanel.add(translitDemo);
        }
    });
}

From source file:com.google.gwt.sample.mobilewebapp.client.ui.WindowBasedOrientationHelper.java

License:Apache License

public WindowBasedOrientationHelper() {
    isPortrait = calculateIsPortrait();/*from   w w  w  .  j a  va 2  s.com*/
    windowResizeReg = Window.addResizeHandler(new ResizeHandler() {
        public void onResize(ResizeEvent event) {
            update();
        }
    });
}

From source file:com.google.gwt.sample.showcase.client.Application.java

License:Apache License

/**
 * Constructor.//from   ww w  . j  av a  2  s  .  c  o  m
 */
public Application() {
    // Setup the main layout widget
    FlowPanel layout = new FlowPanel();
    initWidget(layout);

    // Setup the top panel with the title and links
    createTopPanel();
    layout.add(topPanel);

    // Add the main menu
    bottomPanel = new HorizontalPanel();
    bottomPanel.setWidth("100%");
    bottomPanel.setSpacing(0);
    bottomPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
    layout.add(bottomPanel);
    createMainMenu();
    bottomPanel.add(mainMenu);

    // Setup the content layout
    contentLayout = new Grid(2, 1);
    contentLayout.setCellPadding(0);
    contentLayout.setCellSpacing(0);
    contentDecorator = new DecoratorPanel();
    contentDecorator.setWidget(contentLayout);
    contentDecorator.addStyleName(DEFAULT_STYLE_NAME + "-content-decorator");
    bottomPanel.add(contentDecorator);
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        bottomPanel.setCellHorizontalAlignment(contentDecorator, HasHorizontalAlignment.ALIGN_LEFT);
        contentDecorator.getElement().setAttribute("align", "LEFT");
    } else {
        bottomPanel.setCellHorizontalAlignment(contentDecorator, HasHorizontalAlignment.ALIGN_RIGHT);
        contentDecorator.getElement().setAttribute("align", "RIGHT");
    }
    CellFormatter formatter = contentLayout.getCellFormatter();

    // Add the content title
    setContentTitle(new HTML("Content"));
    formatter.setStyleName(0, 0, DEFAULT_STYLE_NAME + "-content-title");

    // Add the content wrapper
    contentWrapper = new SimplePanel();
    contentLayout.setWidget(1, 0, contentWrapper);
    formatter.setStyleName(1, 0, DEFAULT_STYLE_NAME + "-content-wrapper");
    setContent(null);

    // Add a window resize handler
    Window.addResizeHandler(this);
}

From source file:com.google.gwt.sample.showcase.client.content.cell.WindowFiller.java

private WindowFiller(CellList<?> cellList) {
    Handler handler = new Handler(cellList);
    Window.addResizeHandler(handler);
    cellList.addLoadingStateChangeHandler(handler);
}