Example usage for com.google.gwt.dom.client NodeList getItem

List of usage examples for com.google.gwt.dom.client NodeList getItem

Introduction

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

Prototype

public T getItem(int index) 

Source Link

Usage

From source file:strat.mining.multipool.stats.client.component.TwitterTimelineWidget.java

License:Open Source License

public void setSize(int width, int height) {
    NodeList<Element> iframeNodes = container.getElement().getElementsByTagName("iframe");

    if (iframeNodes != null && iframeNodes.getLength() > 0) {
        int iFrameHeight = height - 30;
        iFrameHeight = iFrameHeight > 0 ? iFrameHeight : 0;

        iframeNodes.getItem(0).setAttribute("width", width + "px");
        iframeNodes.getItem(0).setAttribute("height", iFrameHeight + "px");

        int streamHeight = iFrameHeight - 87;
        streamHeight = streamHeight > 0 ? streamHeight : 0;

        setHeight(streamHeight);/* ww  w.j a  v a 2 s .c o m*/
    }
}

From source file:stroom.cell.valuespinner.client.ValueSpinnerCell.java

License:Apache License

@Override
public void onBrowserEvent(final Context context, final Element parent, final Number value,
        final NativeEvent event, final ValueUpdater<Number> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);

    // Get the target element.
    final Element target = event.getEventTarget().cast();

    final String eventType = event.getType();
    if ("focus".equals(eventType)) {
        // Ignore change events that don't target the input.
        final InputElement input = getInputElement(parent);
        if (input == null || !input.isOrHasChild(target)) {
            return;
        }//  w w  w  .j  a v a2 s  . co m

        focusedKey = context.getKey();

    } else if ("blur".equals(eventType)) {
        // Ignore change events that don't target the input.
        final InputElement input = getInputElement(parent);
        if (input == null || !input.isOrHasChild(target)) {
            return;
        }

        focusedKey = null;

    } else if ("change".equals(eventType)) {
        // Ignore change events that don't target the input.
        final InputElement input = getInputElement(parent);
        if (input == null || !input.isOrHasChild(target)) {
            return;
        }

        // The input has changed so finish editing.
        finishEditing(parent, value, context.getKey(), valueUpdater);

    } else if ("keyup".equals(eventType)) {
        // Ignore key up events that don't target the input.
        final InputElement input = getInputElement(parent);
        if (input == null || !input.isOrHasChild(target)) {
            return;
        }

        // Record keys as they are typed.
        final Object key = context.getKey();
        ViewData vd = getViewData(key);
        if (vd == null) {
            vd = new ViewData(String.valueOf(value));
            setViewData(key, vd);
        }

        vd.setCurrentValue(input.getValue());

    } else {
        final NodeList<Element> nodes = parent.getElementsByTagName("img");
        ImagePrototypeElement upArrow = null;
        ImagePrototypeElement downArrow = null;
        if (nodes != null && nodes.getLength() > 1) {
            upArrow = nodes.getItem(0).cast();
            downArrow = nodes.getItem(1).cast();

            if (upArrow.isOrHasChild(target)) {
                if ("mouseover".equals(eventType)) {
                    arrowUpHover.applyTo(upArrow);

                } else if ("mouseout".equals(eventType)) {
                    arrowUp.applyTo(upArrow);
                    stopSpinning(context, parent, value, valueUpdater);

                } else if ("mouseup".equals(eventType)) {
                    arrowUpHover.applyTo(upArrow);
                    stopSpinning(context, parent, value, valueUpdater);

                } else if ("mousedown".equals(eventType)) {
                    arrowUpPressed.applyTo(upArrow);
                    ensureSpinner();

                    // Get the object that we are going to use to apply
                    // value constraints.
                    HasSpinnerConstraints constraints = this;
                    if (value instanceof HasSpinnerConstraints) {
                        constraints = (HasSpinnerConstraints) value;
                    }

                    final InputElement input = getInputElement(parent);
                    if (input == null) {
                        spinner.start(constraints, true, 0, input);
                    } else {
                        final String constrainedValue = constrainValue(constraints, input.getValue());
                        spinner.start(constraints, true, Long.valueOf(constrainedValue), input);
                    }
                }
            } else if (downArrow.isOrHasChild(target)) {
                if ("mouseover".equals(eventType)) {
                    arrowDownHover.applyTo(downArrow);

                } else if ("mouseout".equals(eventType)) {
                    arrowDown.applyTo(downArrow);
                    stopSpinning(context, parent, value, valueUpdater);

                } else if ("mouseup".equals(eventType)) {
                    arrowDownHover.applyTo(downArrow);
                    stopSpinning(context, parent, value, valueUpdater);

                } else if ("mousedown".equals(eventType)) {
                    arrowDownPressed.applyTo(downArrow);
                    ensureSpinner();

                    // Get the object that we are going to use to apply
                    // value constraints.
                    HasSpinnerConstraints constraints = this;
                    if (value instanceof HasSpinnerConstraints) {
                        constraints = (HasSpinnerConstraints) value;
                    }

                    final InputElement input = getInputElement(parent);
                    final String constrainedValue = constrainValue(constraints, input.getValue());
                    spinner.start(constraints, false, Long.valueOf(constrainedValue), input);
                }
            }
        }
    }
}

From source file:stroom.cell.valuespinner.client.ValueSpinnerCell.java

License:Apache License

private InputElement getInputElement(final Element parent) {
    Element vsDiv = null;/*w  w w .  j  a va  2 s  .  com*/
    if (parent.hasTagName("div") && parent.hasClassName("valueSpinner")) {
        vsDiv = parent;
    } else {
        final NodeList<Element> divs = parent.getElementsByTagName("div");
        for (int i = 0; i < divs.getLength(); i++) {
            final Element div = divs.getItem(i);
            if (div.hasClassName("valueSpinner")) {
                vsDiv = div;
                break;
            }
        }
    }

    if (vsDiv != null) {
        final Element inputElement = vsDiv.getFirstChildElement();
        if (inputElement != null) {
            return inputElement.cast();
        }
    }

    return null;
}

From source file:stroom.svg.client.SvgImage.java

License:Apache License

private Element getSvg(final Element parent) {
    final NodeList<Element> nodes = parent.getElementsByTagName("svg");
    if (nodes != null && nodes.getLength() > 0) {
        return nodes.getItem(0);
    }//from   www  .  j  a va 2  s . c  om
    return null;
}

From source file:stroom.widget.button.client.ImageButton.java

License:Apache License

public void hide(final boolean hide) {
    final NodeList<Element> images = getElement().getElementsByTagName("img");
    if (images.getLength() > 0) {
        final Element img = images.getItem(0);
        if (hide) {
            img.getStyle().setVisibility(Visibility.HIDDEN);
        } else {/*from   w  w w .ja  v  a 2  s.com*/
            img.getStyle().setVisibility(Visibility.VISIBLE);
        }
    }
}

From source file:stroom.xmleditor.client.view.XMLArea.java

License:Apache License

public void scrollHighlightIntoView() {
    try {/*from w  ww .  j  av  a2s .c  o  m*/
        if (container != null) {
            final NodeList<com.google.gwt.dom.client.Element> domElem = container.getElementsByTagName("hl");

            if (domElem != null && domElem.getLength() > 0) {
                // Get the highlight rect.
                int left = Integer.MAX_VALUE;
                int right = 0;
                int top = Integer.MAX_VALUE;
                int bottom = 0;

                // Establish a bounding rect for the highlight area.
                for (int i = 0; i < domElem.getLength(); i++) {
                    final Element element = domElem.getItem(i).cast();
                    if (element.getOffsetLeft() < left) {
                        left = element.getOffsetLeft();
                    }
                    if (element.getOffsetLeft() + element.getOffsetWidth() > right) {
                        right = element.getOffsetLeft() + element.getOffsetWidth();
                    }
                    if (element.getOffsetTop() < top) {
                        top = element.getOffsetTop();
                    }
                    if (element.getOffsetTop() + element.getOffsetHeight() > bottom) {
                        bottom = element.getOffsetTop() + element.getOffsetHeight();
                    }
                }

                // Get the body rect.
                final int bodyLeft = container.getScrollLeft();
                final int bodyRight = bodyLeft + container.getClientWidth();
                final int bodyTop = container.getScrollTop();
                final int bodyBottom = bodyTop + container.getClientHeight();

                // Position the body scroll so that as much of the highlight
                // is shown as possible.
                if (bodyLeft > left) {
                    container.setScrollLeft(left);
                } else if (bodyRight < right) {
                    final int width = right - left;
                    final int bodyWidth = bodyRight - bodyLeft;

                    if (width > bodyWidth) {
                        // The highlight section is too big to fit so show
                        // the leftmost part.
                        container.setScrollLeft(left);
                    } else {
                        // It will fit so show the rightmost part.
                        container.setScrollLeft(right - bodyWidth);
                    }
                }

                if (bodyTop > top) {
                    container.setScrollTop(top);
                } else if (bodyBottom < bottom) {
                    final int height = bottom - top;
                    final int bodyHeight = bodyBottom - bodyTop;

                    if (height > bodyHeight) {
                        // The highlight section is too big to fit so show
                        // the topmost part.
                        container.setScrollTop(top);
                    } else {
                        // It will fit so show the bottommost part.
                        container.setScrollTop(bottom - bodyHeight);
                    }
                }
            }
        }
    } catch (final Exception e) {
        // Fails when source is not visible. This is not important so do
        // nothing.
    }
}

From source file:virtuozo.infra.Elements.java

License:Apache License

public static Element byTagName(Element parent, String tagName) {
    NodeList<Element> nodeList = parent.getElementsByTagName(tagName);

    if (nodeList.getLength() > 0) {
        return nodeList.getItem(0);
    }/*from w w w .  j  a v  a2  s  . c o  m*/

    return null;
}