Example usage for com.google.gwt.user.client Element getClientWidth

List of usage examples for com.google.gwt.user.client Element getClientWidth

Introduction

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

Prototype

@Override
    public int getClientWidth() 

Source Link

Usage

From source file:com.googlecode.kanbanik.client.components.WindowBox.java

License:Apache License

/**
 * Calculates the position of the mouse relative to the dialog box, and returns the corresponding "drag-mode"
 * integer, which describes which area of the box is being resized.
 *
 * @param clientX The x-coordinate of the mouse in screen pixels
 * @param clientY The y-coordinate of the mouse in screen pixels
 * @return A value in range [-1..8] describing the position of the mouse (see {@link #updateCursor(int)} for more
 *         information)/*from  w  ww  .j  a  v  a  2  s .  c  om*/
 */
protected int calcDragMode(int clientX, int clientY) {
    com.google.gwt.dom.client.Element resize = this.getCellElement(2, 2).getParentElement();
    int xr = this.getRelX(resize, clientX);
    int yr = this.getRelY(resize, clientY);

    int w = resize.getClientWidth();
    int h = resize.getClientHeight();

    if ((xr >= 0 && xr < w && yr >= -5 && yr < h) || (yr >= 0 && yr < h && xr >= -5 && xr < w))
        return 8;

    resize = this.getCellElement(2, 0).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if ((xr >= 0 && xr < w && yr >= -5 && yr < h) || (yr >= 0 && yr < h && xr >= 0 && xr < w + 5))
        return 6;

    resize = this.getCellElement(0, 2).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if ((xr >= 0 && xr < w && yr >= 0 && yr < h + 5) || (yr >= 0 && yr < h && xr >= -5 && xr < w))
        return 2;

    resize = this.getCellElement(0, 0).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if ((xr >= 0 && xr < w && yr >= 0 && yr < h + 5) || (yr >= 0 && yr < h && xr >= 0 && xr < w + 5))
        return 0;

    resize = this.getCellElement(0, 1).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (yr >= 0 && yr < h)
        return 1;

    resize = this.getCellElement(1, 0).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (xr >= 0 && xr < w)
        return 3;

    resize = this.getCellElement(2, 1).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (yr >= 0 && yr < h)
        return 7;

    resize = this.getCellElement(1, 2).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (xr >= 0 && xr < w)
        return 5;

    return -1;
}

From source file:com.vaadin.terminal.gwt.client.Util.java

License:Open Source License

public static int measureHorizontalBorder(Element element) {
    int borders;//from   w  w  w . java  2  s . c  om

    if (BrowserInfo.get().isIE()) {
        String width = element.getStyle().getProperty("width");
        String height = element.getStyle().getProperty("height");

        int offsetWidth = element.getOffsetWidth();
        int offsetHeight = element.getOffsetHeight();
        if (offsetHeight < 1) {
            offsetHeight = 1;
        }
        if (offsetWidth < 1) {
            offsetWidth = 10;
        }
        element.getStyle().setPropertyPx("height", offsetHeight);
        element.getStyle().setPropertyPx("width", offsetWidth);

        borders = element.getOffsetWidth() - element.getClientWidth();

        element.getStyle().setProperty("width", width);
        element.getStyle().setProperty("height", height);
    } else {
        borders = element.getOffsetWidth() - element.getPropertyInt("clientWidth");
    }
    assert borders >= 0;

    return borders;
}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

/**
 * Proveravam u DOM-u koji se widgeti trenutno vide
 * @param mainWidget To je u stvari ova komponenta
 * @param child//from   w  w  w.  j  a v  a 2  s. co  m
 * @param proximity
 * @return
 */
private static boolean isBeingShown(final Widget mainWidget, final Widget child, final int proximity) {

    final Element element = child.getElement();

    /*
     * track the original element's position as we iterate through the DOM
     * tree
     */
    int originalTopAdjusted = 0;
    final int originalHeight = element.getOffsetHeight();
    int originalLeftAdjusted = 0;
    final int originalWidth = element.getOffsetWidth();

    com.google.gwt.dom.client.Element childElement = element;
    com.google.gwt.dom.client.Element parentElement = element.getParentElement();

    // What part of its canvas the parent shows, relative to its own
    // coordinates (0,0 is the top left corner)
    //            final int parentTop = parentElement.getScrollTop();            
    //VEROVATNO MORA DA SE UZME I SKROL POZICIJA ELEMENTA KOJI SKROLUJE
    final int parentTop = mainWidget.getElement().getScrollTop();

    //OVO JE VISINA CELOG KONTEJNERA - ONE JE MAKSIMALNA - MOZDA TREBA MERITI SAMO VISINU KOJA SE VIDI 
    //            final int parentBottom = parentTop + parentElement.getClientHeight();
    final int parentBottom = parentTop + mainWidget.getElement().getClientHeight();

    //        debug("Box: top: " + parentTop+ "px, btm: " + parentBottom + "px");

    final int parentLeft = parentElement.getScrollLeft();
    final int parentRight = parentLeft + parentElement.getClientWidth();

    /*
     * renderbox is the target box that is checked for visibility. If
     * the renderbox and parent's viewport don't overlap, it should not
     * be rendered. The renderbox is the child's position with an
     * adjusted margin.
     */
    final int renderBoxTop = childElement.getOffsetTop() - proximity;
    final int renderBoxBottom = childElement.getOffsetTop() + childElement.getOffsetHeight() + proximity;
    final int renderBoxLeft = childElement.getOffsetLeft() - proximity;
    final int renderBoxRight = childElement.getOffsetLeft() + childElement.getOffsetWidth() + proximity;

    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, renderBoxTop, renderBoxRight,
            renderBoxBottom, renderBoxLeft)) {
        return false;
    }

    /*
     * see if the original component is visible from the parent. Move
     * the object around to correspond the relative changes in position.
     * The offset is always relative to the parent - not the canvas.
     */
    originalTopAdjusted += childElement.getOffsetTop() - childElement.getScrollTop();
    originalLeftAdjusted += childElement.getOffsetLeft() - childElement.getScrollLeft();
    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, originalTopAdjusted - proximity,
            originalLeftAdjusted + originalWidth + proximity, originalTopAdjusted + originalHeight + proximity,
            originalLeftAdjusted - proximity)) {
        return false;
    }

    return true;
}

From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java

License:Apache License

@Deprecated
private static boolean isBeingShown(final Widget child, final int proximity) {

    final Element element = child.getElement();

    /*//  w w w. ja v  a 2 s . c om
     * track the original element's position as we iterate through the DOM
     * tree
     */
    int originalTopAdjusted = 0;
    final int originalHeight = element.getOffsetHeight();
    int originalLeftAdjusted = 0;
    final int originalWidth = element.getOffsetWidth();

    com.google.gwt.dom.client.Element childElement = element;
    com.google.gwt.dom.client.Element parentElement = element.getParentElement();

    //        while (parentElement != null) {

    // clientheight == the height as seen in browser
    // offsetheight == the DOM element's native height

    // What part of its canvas the parent shows, relative to its own
    // coordinates (0,0 is the top left corner)
    final int parentTop = parentElement.getScrollTop();

    //OVO JE VISINA CELOG KONTEJNERA - ONE JE MAKSIMALNA - MOZDA TREBA MERITI SAMO VISINU KOJA SE VIDI 
    //            final int parentBottom = parentTop + parentElement.getClientHeight();
    final int parentBottom = parentTop + parentElement.getClientHeight();

    final int parentLeft = parentElement.getScrollLeft();
    final int parentRight = parentLeft + parentElement.getClientWidth();

    /*
     * renderbox is the target box that is checked for visibility. If
     * the renderbox and parent's viewport don't overlap, it should not
     * be rendered. The renderbox is the child's position with an
     * adjusted margin.
     */
    final int renderBoxTop = childElement.getOffsetTop() - proximity;
    final int renderBoxBottom = childElement.getOffsetTop() + childElement.getOffsetHeight() + proximity;
    final int renderBoxLeft = childElement.getOffsetLeft() - proximity;
    final int renderBoxRight = childElement.getOffsetLeft() + childElement.getOffsetWidth() + proximity;

    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, renderBoxTop, renderBoxRight,
            renderBoxBottom, renderBoxLeft)) {
        return false;
    }

    /*
     * see if the original component is visible from the parent. Move
     * the object around to correspond the relative changes in position.
     * The offset is always relative to the parent - not the canvas.
     */
    originalTopAdjusted += childElement.getOffsetTop() - childElement.getScrollTop();
    originalLeftAdjusted += childElement.getOffsetLeft() - childElement.getScrollLeft();
    if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft, originalTopAdjusted - proximity,
            originalLeftAdjusted + originalWidth + proximity, originalTopAdjusted + originalHeight + proximity,
            originalLeftAdjusted - proximity)) {
        return false;
    }

    //            debug("Menjam Parent element - OVO NE BI TREBALO DA SE DOGODI!!!");
    //            childElement = parentElement;
    //            parentElement = childElement.getOffsetParent();
    //        }

    //TODO MISLIM DA OVO NE TREBA VISE
    // lastly, check the browser itself.
    //        final int parentTop = Window.getScrollTop();
    //        final int parentBottom = parentTop + Window.getClientHeight();
    //        final int parentLeft = Window.getScrollLeft();
    //        final int parentRight = parentLeft + Window.getClientWidth();
    //
    //        final int renderBoxTop = childElement.getOffsetTop() - proximity;
    //        final int renderBoxBottom = childElement.getOffsetTop() + childElement.getClientHeight() + proximity;
    //
    //        final int renderBoxLeft = childElement.getOffsetLeft() - proximity;
    //        final int renderBoxRight = childElement.getOffsetLeft() + childElement.getClientWidth() + proximity;
    //
    //        if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft,
    //                renderBoxTop, renderBoxRight, renderBoxBottom, renderBoxLeft)) {
    //            return false;
    //        }
    //
    //        originalTopAdjusted += childElement.getOffsetTop();
    //        originalLeftAdjusted += childElement.getOffsetLeft();
    //        if (!colliding2D(parentTop, parentRight, parentBottom, parentLeft,
    //                originalTopAdjusted - proximity, originalLeftAdjusted
    //                        + originalWidth + proximity, originalTopAdjusted
    //                        + originalHeight + proximity, originalLeftAdjusted
    //                        - proximity)) {
    //            return false;
    //        }

    return true;
}

From source file:edu.kit.ipd.sonar.client.jsxGraph.JSXBoard.java

License:Open Source License

/**
 * Returns the pixel width of the jsxboard.
 *
 * @return the pixel width/*from   w w w . j a v  a  2s .co  m*/
 */
int getWidth() {
    Element b = DOM.getElementById(domElementID);
    if (b != null) {
        return b.getClientWidth();
    }
    GWT.log("board element not find in getWidth", null);
    return 0;
}

From source file:org.cruxframework.crux.widgets.client.grid.AbstractTablelessGridStructure.java

License:Apache License

public void onAfterRender() {
    Element container = this.getElement().getParentElement().cast();
    onResize(container.getClientHeight(), container.getClientWidth());
}

From source file:org.jbpm.console.ng.bd.client.util.DataGridUtils.java

License:Apache License

public static int calculateWidth(final String value) {

    if (value == null || value.length() == 0)
        return 0;
    com.google.gwt.dom.client.Element m = getCharacterMeasuringElement(DEPLOYMENTS_SIZE_CALCULATOR);
    if (m != null) {
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        sb.append(SafeHtmlUtils.fromTrustedString(value));
        m.setInnerHTML(sb.toSafeHtml().asString());
        int a = m.getClientWidth();
        int b = m.getOffsetWidth();
        return a;
    }/*from w w w.j  av a2  s .co m*/
    return 0;
}

From source file:org.kaaproject.kaa.sandbox.web.client.mvp.view.dialog.KaaDialog.java

License:Apache License

/**
 * Calculates the position of the mouse relative to the dialog box, and returns the corresponding "drag-mode"
 * integer, which describes which area of the box is being resized.
 *
 * @param clientX The x-coordinate of the mouse in screen pixels
 * @param clientY The y-coordinate of the mouse in screen pixels
 * @return A value in range [-1..8] describing the position of the mouse (see {@link #updateCursor(int)} for more
 *         information)//from  w  ww .  j a v  a2  s.com
 */
protected int calcDragMode(int clientX, int clientY) {
    com.google.gwt.dom.client.Element resize = this.getCellElement(2, 2).getParentElement();
    int xr = this.getRelX(resize, clientX);
    int yr = this.getRelY(resize, clientY);

    int w = resize.getClientWidth();
    int h = resize.getClientHeight();

    if ((xr >= 0 && xr < w && yr >= -5 && yr < h) || (yr >= 0 && yr < h && xr >= -5 && xr < w))
        return 8;

    resize = this.getCellElement(2, 0).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if ((xr >= 0 && xr < w && yr >= -5 && yr < h) || (yr >= 0 && yr < h && xr >= 0 && xr < w + 5))
        return 6;

    resize = this.getCellElement(0, 2).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if ((xr >= 0 && xr < w && yr >= 0 && yr < h + 5) || (yr >= 0 && yr < h && xr >= -5 && xr < w))
        return 2;

    resize = this.getCellElement(0, 0).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if ((xr >= 0 && xr < w && yr >= 0 && yr < h + 5) || (yr >= 0 && yr < h && xr >= 0 && xr < w + 5))
        return 0;

    resize = this.getCellElement(0, 1).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (yr >= 0 && yr < h)
        return 1;

    resize = this.getCellElement(1, 0).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (xr >= 0 && xr < w)
        return 3;

    resize = this.getCellElement(2, 1).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (yr >= 0 && yr < h)
        return -1;//return 7;

    resize = this.getCellElement(1, 2).getParentElement();
    xr = this.getRelX(resize, clientX);
    yr = this.getRelY(resize, clientY);

    if (xr >= 0 && xr < w)
        return 5;

    return -1;
}

From source file:org.openremote.web.console.util.BrowserUtils.java

License:Open Source License

public static void showAlert(String msg) {
    ConsoleUnit console = WebConsole.getConsoleUnit();
    Element elem = DOM.getElementById("alert_popup");
    DOM.getElementById("alert_popup_msg").setInnerHTML(msg);
    int halfHeight = (int) Math.round((double) elem.getClientHeight() / 2);
    int halfWidth = (int) Math.round((double) elem.getClientWidth() / 2);
    elem.getStyle().setMarginTop(-halfHeight, Unit.PX);
    elem.getStyle().setMarginLeft(-halfWidth, Unit.PX);
    DOM.getElementById("alert_popup").getStyle().setVisibility(Visibility.VISIBLE);
}

From source file:org.openstreetmap.beboj.client.Beboj.java

License:GNU General Public License

public static void log(String s) {
    Element log = RootPanel.get("log").getElement();
    String txt = log.getInnerText();
    if (log.getClientWidth() > 800)
        txt = "";
    log.setInnerText(txt + s);//  ww w  .  ja v a2s .  c  o m
}