Example usage for com.google.gwt.user.client.ui Widget getOffsetWidth

List of usage examples for com.google.gwt.user.client.ui Widget getOffsetWidth

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget getOffsetWidth.

Prototype

@Override
    public int getOffsetWidth() 

Source Link

Usage

From source file:com.thingtrack.com.vaadin.addons.slidedata.gwt.client.VIkarusListItem.java

License:Apache License

public RenderSpace getAllocatedSpace(Widget child) {
    return new RenderSpace(child.getOffsetWidth(), child.getOffsetHeight());
}

From source file:com.threerings.gwt.ui.Popups.java

License:Open Source License

/**
 * Shows the supplied popup in the specified position relative to the specified target widget.
 *//*from   w w  w  . j  a v  a2  s.  c o  m*/
public static <T extends PopupPanel> T show(T popup, Position pos, Widget target) {
    popup.setVisible(false);
    popup.show();

    int left, top;
    switch (pos) {
    case RIGHT:
        left = target.getAbsoluteLeft() + target.getOffsetWidth() + NEAR_GAP;
        break;
    default:
        left = target.getAbsoluteLeft();
        break;
    }
    if (left + popup.getOffsetWidth() > Window.getClientWidth()) {
        left = Math.max(0, Window.getClientWidth() - popup.getOffsetWidth());
    }

    switch (pos) {
    case ABOVE:
        top = target.getAbsoluteTop() - popup.getOffsetHeight() - NEAR_GAP;
        break;
    case OVER:
        top = target.getAbsoluteTop();
        break;
    case RIGHT:
        top = target.getAbsoluteTop() + (target.getOffsetHeight() - popup.getOffsetHeight()) / 2;
        break;
    default:
    case BELOW:
        top = target.getAbsoluteTop() + target.getOffsetHeight() + NEAR_GAP;
        break;
    }

    popup.setPopupPosition(left, top);
    popup.setVisible(true);
    return popup;
}

From source file:com.totsp.gwittir.client.validator.PopupValidationFeedback.java

License:Open Source License

public void handleException(Object source, ValidationException exception) {
    final Widget w = (Widget) source;
    final PopupPanel p = new PopupPanel(false);
    popups.put(source, p);/*  w  ww . ja  v  a  2  s .  c  om*/
    p.setStyleName("gwittir-ValidationPopup");
    p.setWidget(new Label(this.getMessage(exception)));
    p.setPopupPosition(-5000, -5000);
    p.show();
    if (this.position == BOTTOM) {
        p.setPopupPosition(w.getAbsoluteLeft(), w.getAbsoluteTop() + w.getOffsetHeight());
    } else if (this.position == RIGHT) {
        p.setPopupPosition(w.getAbsoluteLeft() + w.getOffsetWidth(), w.getAbsoluteTop());
    } else if (this.position == LEFT) {
        p.setPopupPosition(w.getAbsoluteLeft() - p.getOffsetWidth(), w.getAbsoluteTop());
    } else if (this.position == TOP) {
        p.setPopupPosition(w.getAbsoluteLeft(), w.getAbsoluteTop() - p.getOffsetHeight());
    }
    if (w instanceof SourcesPropertyChangeEvents) {
        GWT.log("is PCE", null);
        PropertyChangeListener attachListener = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                if (((Boolean) propertyChangeEvent.getNewValue()).booleanValue()) {
                    p.setVisible(true);
                } else {
                    p.setVisible(false);
                }
            }

        };
        listeners.put(w, attachListener);
        ((SourcesPropertyChangeEvents) w).addPropertyChangeListener("attached", attachListener);
        ((SourcesPropertyChangeEvents) w).addPropertyChangeListener("visible", attachListener);
    }
}

From source file:com.vaadin.client.ui.orderedlayout.VAbstractOrderedLayout.java

License:Apache License

/**
 * Updates the expand compensation based on the measured sizes of children
 * without expand./*  w ww  .j a  v a  2 s .c  o m*/
 */
public void updateExpandCompensation() {
    boolean isExpanding = false;
    for (Widget slot : getChildren()) {
        // FIXME expandRatio might be <0
        if (((Slot) slot).getExpandRatio() != 0) {
            isExpanding = true;
            break;
        }
    }

    if (isExpanding) {
        /*
         * Expanded slots have relative sizes that together add up to 100%.
         * To make room for slots without expand, we will add padding that
         * is not considered for relative sizes and a corresponding negative
         * margin for the unexpanded slots. We calculate the size by summing
         * the size of all non-expanded non-relative slots.
         * 
         * Relatively sized slots without expansion are considered to get
         * 0px, but we still keep them visible (causing overflows) to help
         * the developer see what's happening. Forcing them to only get 0px
         * would make them disappear which would avoid overflows but would
         * instead cause confusion as they would then just disappear without
         * any obvious reason.
         */
        int totalSize = 0;
        for (Widget w : getChildren()) {
            Slot slot = (Slot) w;
            if (slot.getExpandRatio() == 0 && !slot.isRelativeInDirection(vertical)) {

                if (layoutManager != null) {
                    // TODO check caption position
                    if (vertical) {
                        int size = layoutManager.getOuterHeight(slot.getWidget().getElement());
                        if (slot.hasCaption()) {
                            size += layoutManager.getOuterHeight(slot.getCaptionElement());
                        }
                        if (size > 0) {
                            totalSize += size;
                        }
                    } else {
                        int max = -1;
                        max = layoutManager.getOuterWidth(slot.getWidget().getElement());
                        if (slot.hasCaption()) {
                            int max2 = layoutManager.getOuterWidth(slot.getCaptionElement());
                            max = Math.max(max, max2);
                        }
                        if (max > 0) {
                            totalSize += max;
                        }
                    }
                } else {
                    // FIXME expandRatio might be <0
                    totalSize += vertical ? slot.getOffsetHeight() : slot.getOffsetWidth();
                }
            }
            // TODO fails in Opera, always returns 0
            int spacingSize = vertical ? slot.getVerticalSpacing() : slot.getHorizontalSpacing();
            if (spacingSize > 0) {
                totalSize += spacingSize;
            }
        }

        // When we set the margin to the first child, we don't need
        // overflow:hidden in the layout root element, since the wrapper
        // would otherwise be placed outside of the layout root element
        // and block events on elements below it.
        if (vertical) {
            expandWrapper.getStyle().setPaddingTop(totalSize, Unit.PX);
            expandWrapper.getFirstChildElement().getStyle().setMarginTop(-totalSize, Unit.PX);
        } else {
            expandWrapper.getStyle().setPaddingLeft(totalSize, Unit.PX);
            expandWrapper.getFirstChildElement().getStyle().setMarginLeft(-totalSize, Unit.PX);
        }

        // Measure expanded children again if their size might have changed
        if (totalSize != lastExpandSize) {
            lastExpandSize = totalSize;
            for (Widget w : getChildren()) {
                Slot slot = (Slot) w;
                // FIXME expandRatio might be <0
                if (slot.getExpandRatio() != 0) {
                    if (layoutManager != null) {
                        layoutManager.setNeedsMeasure(Util.findConnectorFor(slot.getWidget()));
                    } else if (slot.getWidget() instanceof RequiresResize) {
                        ((RequiresResize) slot.getWidget()).onResize();
                    }
                }
            }
        }
    }
    WidgetUtil.forceIE8Redraw(getElement());
}

From source file:com.vaadin.client.VUIDLBrowser.java

License:Apache License

static void highlight(ComponentConnector paintable) {
    if (paintable != null) {
        Widget w = paintable.getWidget();
        Style style = highlight.getStyle();
        style.setTop(w.getAbsoluteTop(), Unit.PX);
        style.setLeft(w.getAbsoluteLeft(), Unit.PX);
        style.setWidth(w.getOffsetWidth(), Unit.PX);
        style.setHeight(w.getOffsetHeight(), Unit.PX);
        RootPanel.getBodyElement().appendChild(highlight);
    }/*from  ww w . j ava  2  s . c  om*/
}

From source file:com.vaadin.client.WidgetUtil.java

License:Apache License

public static int setWidthExcludingPaddingAndBorder(Widget widget, String width, int paddingBorderGuess) {
    if (width.equals("")) {
        setWidth(widget, "");
        return paddingBorderGuess;
    } else if (width.endsWith("px")) {
        int pixelWidth = Integer.parseInt(width.substring(0, width.length() - 2));
        return setWidthExcludingPaddingAndBorder(widget.getElement(), pixelWidth, paddingBorderGuess, false);
    } else {//from w  w  w.  j  a v a2  s .c  o  m
        setWidth(widget, width);
        return setWidthExcludingPaddingAndBorder(widget.getElement(), widget.getOffsetWidth(),
                paddingBorderGuess, true);
    }
}

From source file:com.vaadin.client.WidgetUtil.java

License:Apache License

/**
 * Kind of stronger version of isAttached(). In addition to std isAttached,
 * this method checks that this widget nor any of its parents is hidden. Can
 * be e.g used to check whether component should react to some events or
 * not.//from w  w  w.  ja v  a  2  s .co m
 * 
 * @param widget
 * @return true if attached and displayed
 */
public static boolean isAttachedAndDisplayed(Widget widget) {
    if (widget.isAttached()) {
        /*
         * Failfast using offset size, then by iterating the widget tree
         */
        boolean notZeroSized = widget.getOffsetHeight() > 0 || widget.getOffsetWidth() > 0;
        return notZeroSized || checkVisibilityRecursively(widget);
    } else {
        return false;
    }
}

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

License:Open Source License

protected void handleUIDLMessage(final Date start, final String jsonText, final ValueMap json) {
    // Handle redirect
    if (json.containsKey("redirect")) {
        String url = json.getValueMap("redirect").getString("url");
        VConsole.log("redirecting to " + url);
        redirect(url);/*from w  w w. ja v a2 s.c  om*/
        return;
    }

    // Get security key
    if (json.containsKey(UIDL_SECURITY_TOKEN_ID)) {
        uidlSecurityKey = json.getString(UIDL_SECURITY_TOKEN_ID);
    }

    if (json.containsKey("resources")) {
        ValueMap resources = json.getValueMap("resources");
        JsArrayString keyArray = resources.getKeyArray();
        int l = keyArray.length();
        for (int i = 0; i < l; i++) {
            String key = keyArray.get(i);
            resourcesMap.put(key, resources.getAsString(key));
        }
    }

    if (json.containsKey("typeMappings")) {
        configuration.addComponentMappings(json.getValueMap("typeMappings"), widgetSet);
    }

    Command c = new Command() {
        public void execute() {
            VConsole.dirUIDL(json, configuration);

            if (json.containsKey("locales")) {
                // Store locale data
                JsArray<ValueMap> valueMapArray = json.getJSValueMapArray("locales");
                LocaleService.addLocales(valueMapArray);
            }

            boolean repaintAll = false;
            ValueMap meta = null;
            if (json.containsKey("meta")) {
                meta = json.getValueMap("meta");
                if (meta.containsKey("repaintAll")) {
                    repaintAll = true;
                    view.clear();
                    idToPaintableDetail.clear();
                    if (meta.containsKey("invalidLayouts")) {
                        validatingLayouts = true;
                        zeroWidthComponents = new HashSet<Paintable>();
                        zeroHeightComponents = new HashSet<Paintable>();
                    }
                }
                if (meta.containsKey("timedRedirect")) {
                    final ValueMap timedRedirect = meta.getValueMap("timedRedirect");
                    redirectTimer = new Timer() {
                        @Override
                        public void run() {
                            redirect(timedRedirect.getString("url"));
                        }
                    };
                    sessionExpirationInterval = timedRedirect.getInt("interval");
                }
            }

            if (redirectTimer != null) {
                redirectTimer.schedule(1000 * sessionExpirationInterval);
            }

            // Process changes
            JsArray<ValueMap> changes = json.getJSValueMapArray("changes");

            ArrayList<Paintable> updatedWidgets = new ArrayList<Paintable>();
            relativeSizeChanges.clear();
            componentCaptionSizeChanges.clear();

            int length = changes.length();
            for (int i = 0; i < length; i++) {
                try {
                    final UIDL change = changes.get(i).cast();
                    final UIDL uidl = change.getChildUIDL(0);
                    // TODO optimize
                    final Paintable paintable = getPaintable(uidl.getId());
                    if (paintable != null) {
                        paintable.updateFromUIDL(uidl, ApplicationConnection.this);
                        // paintable may have changed during render to
                        // another
                        // implementation, use the new one for updated
                        // widgets map
                        updatedWidgets.add(idToPaintableDetail.get(uidl.getId()).getComponent());
                    } else {
                        if (!uidl.getTag().equals(configuration.getEncodedWindowTag())) {
                            VConsole.error("Received update for " + uidl.getTag()
                                    + ", but there is no such paintable (" + uidl.getId() + ") rendered.");
                        } else {
                            String pid = uidl.getId();
                            if (!idToPaintableDetail.containsKey(pid)) {
                                registerPaintable(pid, view);
                            }
                            // VView does not call updateComponent so we
                            // register any event listeners here
                            ComponentDetail cd = idToPaintableDetail.get(pid);
                            cd.registerEventListenersFromUIDL(uidl);

                            // Finally allow VView to update itself
                            view.updateFromUIDL(uidl, ApplicationConnection.this);
                        }
                    }
                } catch (final Throwable e) {
                    VConsole.error(e);
                }
            }

            if (json.containsKey("dd")) {
                // response contains data for drag and drop service
                VDragAndDropManager.get().handleServerResponse(json.getValueMap("dd"));
            }

            // Check which widgets' size has been updated
            Set<Paintable> sizeUpdatedWidgets = new HashSet<Paintable>();

            updatedWidgets.addAll(relativeSizeChanges);
            sizeUpdatedWidgets.addAll(componentCaptionSizeChanges);

            for (Paintable paintable : updatedWidgets) {
                ComponentDetail detail = idToPaintableDetail.get(getPid(paintable));
                Widget widget = (Widget) paintable;
                Size oldSize = detail.getOffsetSize();
                Size newSize = new Size(widget.getOffsetWidth(), widget.getOffsetHeight());

                if (oldSize == null || !oldSize.equals(newSize)) {
                    sizeUpdatedWidgets.add(paintable);
                    detail.setOffsetSize(newSize);
                }

            }

            Util.componentSizeUpdated(sizeUpdatedWidgets);

            if (meta != null) {
                if (meta.containsKey("appError")) {
                    ValueMap error = meta.getValueMap("appError");
                    String html = "";
                    if (error.containsKey("caption") && error.getString("caption") != null) {
                        html += "<h1>" + error.getAsString("caption") + "</h1>";
                    }
                    if (error.containsKey("message") && error.getString("message") != null) {
                        html += "<p>" + error.getAsString("message") + "</p>";
                    }
                    String url = null;
                    if (error.containsKey("url")) {
                        url = error.getString("url");
                    }

                    if (html.length() != 0) {
                        /* 45 min */
                        VNotification n = VNotification.createNotification(1000 * 60 * 45);
                        n.addEventListener(new NotificationRedirect(url));
                        n.show(html, VNotification.CENTERED_TOP, VNotification.STYLE_SYSTEM);
                    } else {
                        redirect(url);
                    }
                    applicationRunning = false;
                }
                if (validatingLayouts) {
                    VConsole.printLayoutProblems(meta, ApplicationConnection.this, zeroHeightComponents,
                            zeroWidthComponents);
                    zeroHeightComponents = null;
                    zeroWidthComponents = null;
                    validatingLayouts = false;

                }
            }

            if (repaintAll) {
                /*
                 * idToPaintableDetail is already cleanded at the start of
                 * the changeset handling, bypass cleanup.
                 */
                unregistryBag.clear();
            } else {
                purgeUnregistryBag();
            }

            // TODO build profiling for widget impl loading time

            final long prosessingTime = (new Date().getTime()) - start.getTime();
            VConsole.log(" Processing time was " + String.valueOf(prosessingTime) + "ms for "
                    + jsonText.length() + " characters of JSON");
            VConsole.log("Referenced paintables: " + idToPaintableDetail.size());

            endRequest();

        }
    };
    ApplicationConfiguration.runWhenWidgetsLoaded(c);
}

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

License:Open Source License

/**
 * Converts relative sizes into pixel sizes.
 * // w  w w  .ja va 2s .co  m
 * @param child
 * @return true if the child has a relative size
 */
private boolean handleComponentRelativeSize(ComponentDetail cd) {
    if (cd == null) {
        return false;
    }
    boolean debugSizes = false;

    FloatSize relativeSize = cd.getRelativeSize();
    if (relativeSize == null) {
        return false;
    }
    Widget widget = (Widget) cd.getComponent();

    boolean horizontalScrollBar = false;
    boolean verticalScrollBar = false;

    Container parent = Util.getLayout(widget);
    RenderSpace renderSpace;

    // Parent-less components (like sub-windows) are relative to browser
    // window.
    if (parent == null) {
        renderSpace = new RenderSpace(Window.getClientWidth(), Window.getClientHeight());
    } else {
        renderSpace = parent.getAllocatedSpace(widget);
    }

    if (relativeSize.getHeight() >= 0) {
        if (renderSpace != null) {

            if (renderSpace.getScrollbarSize() > 0) {
                if (relativeSize.getWidth() > 100) {
                    horizontalScrollBar = true;
                } else if (relativeSize.getWidth() < 0 && renderSpace.getWidth() > 0) {
                    int offsetWidth = widget.getOffsetWidth();
                    int width = renderSpace.getWidth();
                    if (offsetWidth > width) {
                        horizontalScrollBar = true;
                    }
                }
            }

            int height = renderSpace.getHeight();
            if (horizontalScrollBar) {
                height -= renderSpace.getScrollbarSize();
            }
            if (validatingLayouts && height <= 0) {
                zeroHeightComponents.add(cd.getComponent());
            }

            height = (int) (height * relativeSize.getHeight() / 100.0);

            if (height < 0) {
                height = 0;
            }

            if (debugSizes) {
                VConsole.log("Widget " + Util.getSimpleName(widget) + "/" + getPid(widget.getElement())
                        + " relative height " + relativeSize.getHeight() + "% of " + renderSpace.getHeight()
                        + "px (reported by "

                        + Util.getSimpleName(parent) + "/" + (parent == null ? "?" : parent.hashCode()) + ") : "
                        + height + "px");
            }
            widget.setHeight(height + "px");
        } else {
            widget.setHeight(relativeSize.getHeight() + "%");
            VConsole.error(Util.getLayout(widget).getClass().getName() + " did not produce allocatedSpace for "
                    + widget.getClass().getName());
        }
    }

    if (relativeSize.getWidth() >= 0) {

        if (renderSpace != null) {

            int width = renderSpace.getWidth();

            if (renderSpace.getScrollbarSize() > 0) {
                if (relativeSize.getHeight() > 100) {
                    verticalScrollBar = true;
                } else if (relativeSize.getHeight() < 0 && renderSpace.getHeight() > 0
                        && widget.getOffsetHeight() > renderSpace.getHeight()) {
                    verticalScrollBar = true;
                }
            }

            if (verticalScrollBar) {
                width -= renderSpace.getScrollbarSize();
            }
            if (validatingLayouts && width <= 0) {
                zeroWidthComponents.add(cd.getComponent());
            }

            width = (int) (width * relativeSize.getWidth() / 100.0);

            if (width < 0) {
                width = 0;
            }

            if (debugSizes) {
                VConsole.log("Widget " + Util.getSimpleName(widget) + "/" + getPid(widget.getElement())
                        + " relative width " + relativeSize.getWidth() + "% of " + renderSpace.getWidth()
                        + "px (reported by " + Util.getSimpleName(parent) + "/"
                        + (parent == null ? "?" : getPid(parent)) + ") : " + width + "px");
            }
            widget.setWidth(width + "px");
        } else {
            widget.setWidth(relativeSize.getWidth() + "%");
            VConsole.error(Util.getLayout(widget).getClass().getName() + " did not produce allocatedSpace for "
                    + widget.getClass().getName());
        }
    }

    return true;
}

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

License:Open Source License

static void highlight(Paintable paintable) {
    Widget w = (Widget) paintable;
    if (w != null) {
        Style style = highlight.getStyle();
        style.setTop(w.getAbsoluteTop(), Unit.PX);
        style.setLeft(w.getAbsoluteLeft(), Unit.PX);
        style.setWidth(w.getOffsetWidth(), Unit.PX);
        style.setHeight(w.getOffsetHeight(), Unit.PX);
        RootPanel.getBodyElement().appendChild(highlight);
    }/*from w  w  w  .  jav  a 2  s . c om*/
}