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:rocket.widget.client.splitter.HorizontalSplitterPanel.java

License:Apache License

/**
 * This is the most important event handler that takes care of adjusting the
 * widths of the widgets before and after the splitter being moved.
 * /*from  www. ja  v a  2  s.  c om*/
 * @param event
 */
protected void onMouseMove(final MouseMoveEvent event) {
    Checker.notNull("parameter:event", event);

    while (true) {
        final Splitter splitter = (Splitter) event.getWidget();

        // need to figure out if mouse has moved to the right or left...
        final int mouseX = event.getPageX();
        final int splitterX = splitter.getElement().getAbsoluteLeft();

        // if the mouse has not moved horizontally but vertically so exit...
        int delta = mouseX - splitterX;
        if (0 == delta) {
            break;
        }

        // grab the widgets before and after the splitter being dragged...
        final InternalPanel panel = this.getPanel();
        final int panelIndex = panel.indexOf(splitter);
        final Widget beforeWidget = panel.get(panelIndex - 1);
        int beforeWidgetWidth = beforeWidget.getOffsetWidth() + delta;

        final Widget afterWidget = panel.get(panelIndex + 1);
        int afterWidgetWidth = afterWidget.getOffsetWidth() - delta;

        final int widthSum = beforeWidgetWidth + afterWidgetWidth;

        final List<SplitterItem> items = this.getItems();

        // if the mouse moved left make sure the beforeWidget width is not
        // less than its minimumWidth.
        if (delta < 0) {
            final SplitterItem beforeWidgetItem = items.get(panelIndex / 2);
            final int minimumWidth = beforeWidgetItem.getMinimumSize();

            if (beforeWidgetWidth < minimumWidth) {
                delta = minimumWidth - (beforeWidgetWidth - delta);
                beforeWidgetWidth = minimumWidth;
                afterWidgetWidth = widthSum - beforeWidgetWidth;
            }
        }

        // since the mouse moved right make sure the afterWidget width is
        // not less than its minimumWidth
        if (delta > 0) {
            final SplitterItem afterWidgetItem = items.get(panelIndex / 2 + 1);
            final int minimumWidth = afterWidgetItem.getMinimumSize();
            if (afterWidgetWidth < minimumWidth) {
                delta = afterWidgetWidth + delta - minimumWidth;
                afterWidgetWidth = minimumWidth;
                beforeWidgetWidth = widthSum - afterWidgetWidth;
            }
        }

        // save!
        beforeWidget.setWidth(beforeWidgetWidth + "px");
        afterWidget.setWidth(afterWidgetWidth + "px");

        // update the coordinates of both the splitter and after widget...
        adjustXCoordinate(splitter, delta);
        adjustXCoordinate(afterWidget, delta);

        beforeWidget.setHeight("100%");
        splitter.setHeight("100%");
        afterWidget.setHeight("100%");

        // its necessary to prevent the event to stop text selection in
        // opera.
        event.stop();
        break;
    }
}

From source file:ru.fly.client.ui.panel.HLayout.java

License:Apache License

@Override
protected void doLayout() {
    int w = getWidth(true);
    int h = getHeight(true);
    int freeW = w;
    for (Widget child : getWidgets()) {
        Object ld = child.getLayoutData();
        if (ld != null && ld instanceof VHLayoutData) {
            VHLayoutData vld = (VHLayoutData) ld;
            if (vld.getW() < 0) {
                freeW -= child.getOffsetWidth();
            } else if (vld.getW() > 1) {
                freeW -= vld.getW();/* w ww  .  j  a v  a 2  s .co m*/
                Margin m = vld.getMargin();
                if (m != null) {
                    freeW = freeW - m.getLeft() - m.getRight();
                }
            }
        } else {
            freeW -= child.getOffsetHeight();
        }
    }
    int left = 0;
    for (Widget child : getWidgets()) {
        FElement el = child.getElement().cast();
        el.getStyle().setPosition(Style.Position.ABSOLUTE);
        el.getStyle().setMargin(0, Style.Unit.PX);
        Object ld = child.getLayoutData();
        if (ld != null && ld instanceof VHLayoutData) {
            VHLayoutData vld = (VHLayoutData) ld;
            int cw = vld.getChildWidth(freeW);
            int ch = vld.getChildHeight(h);
            child.setPixelSize(cw, ch);
            el.setTop(vld.getMargin() == null ? 0 : vld.getMargin().getTop());
            left += vld.getMargin() == null ? 0 : vld.getMargin().getLeft();
            el.setLeft(left);
            left += vld.getMargin() == null ? 0 : vld.getMargin().getRight();
            if (cw < 0) {
                left += child.getOffsetWidth();
            } else {
                left += cw;
            }
        } else {
            left += child.getOffsetWidth();
        }
    }
    rebuildSplits();
}

From source file:ru.fly.client.ui.panel.HLayout.java

License:Apache License

public void rebuildSplits() {
    for (FElement split : splits) {
        split.removeFromParent();/*from   w  ww  . ja  v  a  2s .  c  o m*/
    }
    splits.clear();
    for (final Widget child : getWidgets()) {
        final Object ld = child.getLayoutData();
        if (ld != null && ld instanceof VHLayoutData && ((VHLayoutData) ld).isResizable()) {
            final FElement splitEl = DOM.createDiv().cast();
            splitEl.setClassName(decor.css().split());
            splitEl.setLeft(child.getElement().getOffsetLeft() + child.getOffsetWidth() - 2);
            splits.add(splitEl);
            getElement().appendChild(splitEl);
            DOM.setEventListener(splitEl, new EventListener() {
                @Override
                public void onBrowserEvent(Event event) {
                    if (event.getTypeInt() == Event.ONMOUSEDOWN) {
                        final FElement dragLine = DOM.createDiv().cast();
                        dragLine.setClassName(decor.css().dragLine());
                        getElement().appendChild(dragLine);
                        dragLine.setLeft(splitEl.getOffsetLeft());
                        new Dragger(dragLine, event, new EndCallback<Point>() {
                            @Override
                            public void onEnd(Point result) {
                                dragLine.removeFromParent();
                                doDnDResize(child, result.x);
                            }
                        }).setLockY(true).setBoundingRect(
                                getBoundRect((VHLayoutData) ld, (FElement) child.getElement()));
                        event.stopPropagation();
                    }
                }
            });
            DOM.sinkEvents(splitEl, Event.ONMOUSEDOWN);
        }
    }
}

From source file:ru.fly.client.ui.panel.HLayout.java

License:Apache License

public void doDnDResize(Widget child, int dx) {
    //primary child
    Object ld = child.getLayoutData();
    double w = child.getElement().getOffsetWidth() + dx;
    if (ld != null) {
        if (w < ((VHLayoutData) ld).getMinSize()) {
            w = ((VHLayoutData) ld).getMinSize();
        }/*from  ww  w  .  j a v a 2  s .c  om*/
        if (w > ((VHLayoutData) ld).getMaxSize()) {
            w = ((VHLayoutData) ld).getMaxSize();
        }
    }
    ((VHLayoutData) child.getLayoutData()).setW(w);
    //next child
    int idx = getWidgets().indexOf(child);
    if (idx + 1 < getWidgets().size()) {
        Widget nextChild = getWidgets().get(idx + 1);
        ld = nextChild.getLayoutData();
        if (ld != null && ld instanceof VHLayoutData) {
            ((VHLayoutData) ld).setW(nextChild.getOffsetWidth() - dx);
        } else {
            ((FElement) nextChild.getElement()).setWidth(nextChild.getOffsetWidth() - dx);
        }
    }
    layout(true);
}

From source file:thothbot.parallax.core.client.controls.FirstPersonControls.java

License:Open Source License

public FirstPersonControls(Object3D object, Widget widget) {
    super(object, widget);

    this.viewHalfX = widget.getOffsetWidth() / 2;
    this.viewHalfY = widget.getOffsetHeight() / 2;

    if (getWidget().getClass() != RootPanel.class)
        getWidget().getElement().setAttribute("tabindex", "-1");

    this.target = new Vector3();

    getWidget().addDomHandler(this, ContextMenuEvent.getType());

    getWidget().addDomHandler(this, MouseMoveEvent.getType());
    getWidget().addDomHandler(this, MouseDownEvent.getType());
    getWidget().addDomHandler(this, MouseUpEvent.getType());
    RootPanel.get().addDomHandler(this, KeyDownEvent.getType());
    RootPanel.get().addDomHandler(this, KeyUpEvent.getType());
}

From source file:thothbot.parallax.core.client.controls.FlyControls.java

License:Open Source License

public FlyControls(Object3D object, Widget widget) {
    super(object, widget);

    if (getWidget().getClass() != RootPanel.class)
        getWidget().getElement().setAttribute("tabindex", "-1");

    this.viewHalfX = widget.getOffsetWidth() / 2.0;
    this.viewHalfY = widget.getOffsetHeight() / 2.0;

    // disable default target object behavior
    this.tmpQuaternion = new Quaternion();

    this.mouseStatus = 0;
    this.moveState = new MoveState();

    this.moveVector = new Vector3(0, 0, 0);
    this.rotationVector = new Vector3(0, 0, 0);

    getWidget().addDomHandler(this, ContextMenuEvent.getType());

    getWidget().addDomHandler(this, MouseMoveEvent.getType());
    getWidget().addDomHandler(this, MouseDownEvent.getType());
    getWidget().addDomHandler(this, MouseUpEvent.getType());
    RootPanel.get().addDomHandler(this, KeyDownEvent.getType());
    RootPanel.get().addDomHandler(this, KeyUpEvent.getType());
}

From source file:thothbot.parallax.core.client.controls.TrackballControls.java

License:Open Source License

public TrackballControls(Object3D object, Widget widget) {
    super(object, widget);

    this.radius = (widget.getOffsetWidth() + widget.getOffsetHeight()) / 4.0;

    if (getWidget().getClass() != RootPanel.class)
        getWidget().getElement().setAttribute("tabindex", "-1");

    this.target = new Vector3();
    this.lastPosition = new Vector3();
    this.eye = new Vector3();
    this.rotateStart = new Vector3();
    this.rotateEnd = new Vector3();
    this.zoomStart = new Vector2();
    this.zoomEnd = new Vector2();
    this.panStart = new Vector2();
    this.panEnd = new Vector2();

    getWidget().addDomHandler(this, ContextMenuEvent.getType());

    getWidget().addDomHandler(this, MouseMoveEvent.getType());
    getWidget().addDomHandler(this, MouseDownEvent.getType());
    getWidget().addDomHandler(this, MouseUpEvent.getType());
    RootPanel.get().addDomHandler(this, KeyDownEvent.getType());
    RootPanel.get().addDomHandler(this, KeyUpEvent.getType());
}