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

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

Introduction

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

Prototype

@Override
    public int getClientWidth() 

Source Link

Usage

From source file:com.ait.toolkit.clientio.canvg.client.CanVgParser.java

License:Open Source License

public static ByteArray getFromSgvElement(Element chartElement) {
    assert chartElement != null : "Element cant be null";
    int width = chartElement.getClientWidth();
    int height = chartElement.getClientHeight();
    return getFromSgvElement(chartElement, width, height);
}

From source file:com.alkacon.geranium.client.dnd.DNDHandler.java

License:Open Source License

/**
 * Convenience method to get the appropriate scroll direction.<p>
 * //from  w  ww  . j av  a 2s  . c o m
 * @param offset the scroll parent border offset, if the cursor is within the border offset, scrolling should be triggered
 * 
 * @return the scroll direction
 */
private Direction getScrollDirection(int offset) {

    if (m_scrollElement == null) {
        Element body = RootPanel.getBodyElement();
        int windowHeight = Window.getClientHeight();
        int bodyHeight = body.getClientHeight();
        if (windowHeight < bodyHeight) {
            if (((windowHeight - m_clientY) < offset)
                    && (Window.getScrollTop() < (bodyHeight - windowHeight))) {
                return Direction.down;
            }
            if ((m_clientY < offset) && (Window.getScrollTop() > 0)) {
                return Direction.up;
            }
        }

        int windowWidth = Window.getClientWidth();
        int bodyWidth = body.getClientWidth();
        if (windowWidth < bodyWidth) {
            if (((windowWidth - m_clientX) < offset) && (Window.getScrollLeft() < (bodyWidth - windowWidth))) {
                return Direction.right;
            }
            if ((m_clientX < offset) && (Window.getScrollLeft() > 0)) {
                return Direction.left;
            }
        }

        return null;
    } else {
        int outerHeight = m_scrollElement.getClientHeight();
        int innerHeight = m_scrollElement.getScrollHeight();
        if (outerHeight < innerHeight) {
            if ((((outerHeight + m_scrollElement.getAbsoluteTop()) - m_clientY) < offset)
                    && (m_scrollElement.getScrollTop() < (innerHeight - outerHeight))) {
                return Direction.down;
            }
            if (((m_clientY - m_scrollElement.getAbsoluteTop()) < offset)
                    && (m_scrollElement.getScrollTop() > 0)) {
                return Direction.up;
            }
        }
        int outerWidth = m_scrollElement.getClientWidth();
        int innerWidth = m_scrollElement.getScrollWidth();
        if (outerWidth < innerWidth) {
            if ((((outerWidth + m_scrollElement.getAbsoluteLeft()) - m_clientX) < offset)
                    && (m_scrollElement.getScrollLeft() < (innerWidth - outerWidth))) {
                return Direction.right;
            }
            if (((m_clientX - m_scrollElement.getAbsoluteLeft()) < offset)
                    && (m_scrollElement.getScrollLeft() > 0)) {
                return Direction.left;
            }
        }
        return null;
    }
}

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

License:Apache License

public MainPane() {
    nodeManager = new NodeManager();

    nullCallback = new AsyncCallback<Void>() {
        public void onFailure(Throwable caught) {
            GWT.log("Network error!", caught);
            showAlertDialog("Network error!");
        }/*from   w  w w  .  j  a  v a 2s  .c  om*/

        public void onSuccess(Void ignored) {
            // nothing
        }
    };

    ClickHandler borderClickHandler = new ClickHandler() {
        public void onClick(ClickEvent event) {
            int left = getWindowScrollLeft();
            int top = getWindowScrollTop();
            int screenWidth = getWindowScreenWidth();
            int screenHeight = getWindowScreenHeight();
            int prevCenterPosX = viewX + left + screenWidth / 2;
            int prevCenterPosY = viewY + top + screenHeight / 2;
            relocateCenter(prevCenterPosX, prevCenterPosY);
        }
    };

    borderNorth = new SimplePanel();
    borderNorth.addDomHandler(borderClickHandler, ClickEvent.getType());
    borderNorth.getElement().getStyle().setBackgroundColor("#445566");
    borderEast = new SimplePanel();
    borderEast.addDomHandler(borderClickHandler, ClickEvent.getType());
    borderEast.getElement().getStyle().setBackgroundColor("#445566");
    borderSouth = new SimplePanel();
    borderSouth.addDomHandler(borderClickHandler, ClickEvent.getType());
    borderSouth.getElement().getStyle().setBackgroundColor("#445566");
    borderWest = new SimplePanel();
    borderWest.addDomHandler(borderClickHandler, ClickEvent.getType());
    borderWest.getElement().getStyle().setBackgroundColor("#445566");

    Image image;
    if (GBrain.isIPhone) {
        image = new Image("images/create_button.svg");
    } else {
        image = new Image("images/create_button.png");
    }
    PushButton createButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            showCreateDialog();
        }
    });
    createButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    createButton.setTitle("Create a new text");

    if (GBrain.isIPhone) {
        image = new Image("images/delete_button.svg");
    } else {
        image = new Image("images/delete_button.png");
    }
    PushButton deleteButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            if (selectNode.getChildren() > 0) {
                showAlertDialog("You can't delete it with children.");
                return;
            }
            final NeuronNode tmpSelectNode = selectNode;
            String content = tmpSelectNode.getContent();
            final long id = tmpSelectNode.getId();
            showConfirmDialog("Are you sure you want to delete\n'" + content + "' ?", new ClickHandler() {
                public void onClick(ClickEvent event) {
                    gbrainService.deleteNeuron(id, new AsyncCallback<Void>() {
                        public void onFailure(Throwable caught) {
                            GWT.log("Network error!", caught);
                            showAlertDialog("Network error!");
                        }

                        public void onSuccess(Void ignored) {
                            Long parentId = tmpSelectNode.getParentId();
                            if (parentId != null) {
                                NeuronNode parentNode = nodeManager.getNode(parentId);
                                if (parentNode != null) {
                                    parentNode.decreaseChildren();
                                }
                            }
                            removeNode(tmpSelectNode);
                        }
                    });
                }
            });
        }
    });
    deleteButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    deleteButton.setTitle("Delete text");

    if (GBrain.isIPhone) {
        image = new Image("images/noparent_button.svg");
    } else {
        image = new Image("images/noparent_button.png");
    }
    PushButton noparentButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = selectNode;
            if (n.getParentId() != null) {
                replaceParent(n, null);
                gbrainService.removeParent(n.getId(), nullCallback);
            }
        }
    });
    noparentButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    noparentButton.setTitle("Remove parent link");

    if (GBrain.isIPhone) {
        image = new Image("images/open_button.svg");
    } else {
        image = new Image("images/open_button.png");
    }
    PushButton openButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            refreshChildNeurons(selectNode.getId());
        }
    });
    openButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    openButton.setTitle("Open children");

    if (GBrain.isIPhone) {
        image = new Image("images/close_button.svg");
    } else {
        image = new Image("images/close_button.png");
    }
    PushButton closeButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            removeChildNodes(selectNode);
        }
    });
    closeButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    closeButton.setTitle("Close children");

    if (GBrain.isIPhone) {
        image = new Image("images/arrange_button.svg");
    } else {
        image = new Image("images/arrange_button.png");
    }
    PushButton arrangeButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = selectNode;
            nodeManager.arrangeAllChildNodes(n);
            updatePositionNodeAndChildNodes(n);
        }
    });
    arrangeButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    arrangeButton.setTitle("Arrange children");

    if (GBrain.isIPhone) {
        image = new Image("images/up_button.svg");
    } else {
        image = new Image("images/up_button.png");
    }
    PushButton upButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = nodeManager.getParentNode(selectNode.getId());
            if (n == null) {
                return;
            }
            handleNodeClick(n);
            slideToPosition(n.getPosX(), n.getPosY());
        }
    });
    upButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    upButton.setTitle("Jump to parent");

    if (GBrain.isIPhone) {
        image = new Image("images/down_button.svg");
    } else {
        image = new Image("images/down_button.png");
    }
    PushButton downButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = nodeManager.getFirstChildNode(selectNode.getId());
            if (n == null) {
                return;
            }
            handleNodeClick(n);
            slideToPosition(n.getPosX(), n.getPosY());
        }
    });
    downButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    downButton.setTitle("Jump to a child");

    if (GBrain.isIPhone) {
        image = new Image("images/prev_button.svg");
    } else {
        image = new Image("images/prev_button.png");
    }
    PushButton prevButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = nodeManager.getPreviousSiblingNode(selectNode.getId());
            if (n == null) {
                return;
            }
            handleNodeClick(n);
            slideToPosition(n.getPosX(), n.getPosY());
        }
    });
    prevButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    prevButton.setTitle("Jump to previous sibling");

    if (GBrain.isIPhone) {
        image = new Image("images/next_button.svg");
    } else {
        image = new Image("images/next_button.png");
    }
    PushButton nextButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = nodeManager.getNextSiblingNode(selectNode.getId());
            if (n == null) {
                return;
            }
            handleNodeClick(n);
            slideToPosition(n.getPosX(), n.getPosY());
        }
    });
    nextButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    nextButton.setTitle("Jump to next sibling");

    if (GBrain.isIPhone) {
        image = new Image("images/jump_button.svg");
    } else {
        image = new Image("images/jump_button.png");
    }
    PushButton jumpButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            jumpToUrl(selectNode);
        }
    });
    jumpButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    jumpButton.setTitle("Jump to URL");

    if (GBrain.isIPhone) {
        image = new Image("images/color_button.svg");
    } else {
        image = new Image("images/color_button.png");
    }
    PushButton colorButton = new PushButton(image, new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (selectNode == null) {
                showAlertDialog("Nothing is selected.");
                return;
            }
            NeuronNode n = selectNode;
            n.setNextColor();
            gbrainService.updateColor(n.getId(), n.getColor(), nullCallback);
        }
    });
    colorButton.setPixelSize(BUTTON_SIZE, BUTTON_SIZE);
    colorButton.setTitle("Change color");

    buttonPanel = new FlowPanel();
    buttonPanel.add(createButton);
    buttonPanel.add(deleteButton);
    buttonPanel.add(noparentButton);
    buttonPanel.add(openButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(arrangeButton);
    buttonPanel.add(upButton);
    buttonPanel.add(downButton);
    buttonPanel.add(prevButton);
    buttonPanel.add(nextButton);
    buttonPanel.add(jumpButton);
    buttonPanel.add(colorButton);

    drawArea = new DrawingArea(0, 0);
    drawArea.getElement().setId("gbrain-svgpanel");
    drawArea.getElement().getStyle().setBackgroundColor("#000000");

    this.add(drawArea, 0, 0);
    this.add(borderNorth, -100, -100); // initially not visible
    this.add(borderEast, -100, -100); // initially not visible
    this.add(borderSouth, -100, -100); // initially not visible
    this.add(borderWest, -100, -100); // initially not visible
    this.add(buttonPanel, -100, -100); // initially not visible

    coordinate = new Coordinate(drawArea);
    drawArea.add(coordinate);

    supportDragAndDrop();
    refreshTopNeurons();

    onResize();
    Element welcome = Document.get().getElementById("gbrain-welcome");
    welcome.getStyle().setLeft(viewWidth / 2 - welcome.getClientWidth() / 2, Unit.PX);
    welcome.getStyle().setTop(viewHeight / 2 - welcome.getClientHeight() / 2, Unit.PX);
    Window.addWindowScrollHandler(this);
}

From source file:com.cgxlib.core.component.modal.ModalBSViewHandler.java

License:Apache License

protected int measureScrollbar() {
    Element scrollDiv = XQ.document.createElement("div");
    scrollDiv.setClassName("modal-scrollbar-measure");
    $body.append(scrollDiv);/* w w w .ja va 2 s.c  om*/
    int scrollbarWidth = scrollDiv.getOffsetWidth() - scrollDiv.getClientWidth();
    $body.get(0).removeChild(scrollDiv);
    return scrollbarWidth;
}

From source file:com.cgxlib.xq.client.impl.DocumentStyleImpl.java

License:Apache License

private void fixInlineElement(Element e) {
    if (e.getClientHeight() == 0 && e.getClientWidth() == 0 && "inline".equals(curCSS(e, "display", true))) {
        setStyleProperty(e, "display", "inline-block");
        setStyleProperty(e, "width", "auto");
        setStyleProperty(e, "height", "auto");
    }// ww w. j  a v a 2  s  . co m
}

From source file:com.cgxlib.xq.client.impl.DocumentStyleImpl.java

License:Apache License

private int getSize(Element e, String name) {
    int ret = 0;//ww  w.  j  av a 2  s.c o m
    if ("width".equals(name)) {
        ret = getWidth(e);
    } else if ("height".equals(name)) {
        ret = getHeight(e);
    } else if ("clientWidth".equals(name)) {
        ret = e.getClientWidth();
    } else if ("clientHeight".equals(name)) {
        ret = e.getClientHeight();
    } else if ("offsetWidth".equals(name)) {
        ret = e.getOffsetWidth();
    } else if ("offsetHeight".equals(name)) {
        ret = e.getOffsetHeight();
    }
    return ret;
}

From source file:com.cgxlib.xq.client.impl.DocumentStyleImpl.java

License:Apache License

public int getWidth(Element e) {
    fixInlineElement(e);//from   w  ww .jav a 2s.  c  o  m
    return (int) (e.getClientWidth() - num(curCSS(e, "paddingLeft", true))
            - num(curCSS(e, "paddingRight", true)));
}

From source file:com.google.speedtracer.client.visualizations.view.ResourceRow.java

License:Apache License

private void addHintletIndicator(JSOArray<HintRecord> hintRecords) {
    if (hintRecords == null) {
        return;//from  w  ww .j av a  2 s.  c o m
    }

    hintletIndicator = new HintletIndicator(indicatorContainer, hintRecords, resources);
    Element indicatorElem = hintletIndicator.getElement();
    indicatorElem.setId(idCounter++ + "");
    ResourceRow.Css css = resources.resourceRowCss();
    indicatorElem.addClassName(css.hintIndicator());

    // Make room for the HintletIndicator
    textElem.getStyle().setPropertyPx("right", indicatorElem.getClientWidth() + css.headerTextRightPad());
}

From source file:com.gwtm.ui.client.widgets.FlipSwitch.java

License:Apache License

private int getOffPosition() {
    Element flip = getFilpElement();
    Element parent = flip.getParentElement();
    int flipWidth = flip.getScrollWidth();
    int parentWidth = parent.getClientWidth();
    return parentWidth - flipWidth;
}

From source file:com.gwtm.ui.client.widgets.Slider.java

License:Apache License

private int computeNewValue(DraggingEvent e) {
    Element ele = getElement();
    int offset = (int) e.getX() - ele.getAbsoluteLeft();
    int width = ele.getClientWidth();
    int value = offset * 100 / width;
    if (value > 100) {
        value = 100;//from w  w  w  .jav a 2s .co  m
    } else if (value < 0) {
        value = 0;
    }
    return value;
}