Package com.ardor3d.extension.ui

Examples of com.ardor3d.extension.ui.UIComponent


        List<UIComponent> comps = Lists.newArrayList();
        List<UIComponent> compsBack = Lists.newArrayList();
        for (int i = 0; i < content.size(); i++) {
            final Spatial spat = content.get(i);
            if (spat instanceof UIComponent) {
                final UIComponent comp = (UIComponent) spat;
                final Rectangle2 rect = comp.getRelativeComponentBounds(storeA);
                final Rectangle2 minRect = comp.getRelativeMinComponentBounds(storeB);
                if (_horizontal) {
                    comp.fitComponentIn(minRect.getWidth(), rect.getHeight());
                } else {
                    comp.fitComponentIn(rect.getWidth(), minRect.getHeight());
                }
                comps.add(comp);
            }
        }

        // if we have components to layout...
        if (!comps.isEmpty()) {

            // Determine how much space we feel we need.
            final int reqSpace = _horizontal ? getSumOfAllWidths(content) : getSumOfAllHeights(content);

            // How much extra space do we have?
            int freeSpace = (_horizontal ? container.getContentWidth() : container.getContentHeight()) - reqSpace;

            int relaxIndex = 0;
            // cycle through until we've given away all of the space
            while ((freeSpace > 0 || relaxIndex == 0) && !comps.isEmpty() && relaxIndex < RowLayout.MAX_RELAX) {
                final int extraPerComp = freeSpace / comps.size();
                while (!comps.isEmpty()) {
                    final UIComponent comp = comps.remove(0);
                    Rectangle2 rect = comp.getRelativeComponentBounds(storeA);
                    final Rectangle2 origRect = storeB.set(rect);
                    if (freeSpace < 0) {
                        freeSpace = 0;
                    }
                    if (_horizontal) {
                        final int height = _expandsVertically ? container.getContentHeight() : rect.getHeight();
                        final int width = (_expandsHorizontally ? extraPerComp : 0) + rect.getWidth();
                        if (height == rect.getHeight() && width == rect.getWidth()) {
                            continue;
                        }

                        comp.fitComponentIn(width, height);
                        rect = comp.getRelativeComponentBounds(storeA);
                        if (Math.abs(rect.getWidth() - width) <= 1) {
                            compsBack.add(comp);
                        }
                        freeSpace -= rect.getWidth() - origRect.getWidth();
                    } else {
                        final int width = _expandsHorizontally ? container.getContentWidth() : rect.getWidth();
                        final int height = (_expandsVertically ? extraPerComp : 0) + rect.getHeight();
                        if (height == rect.getHeight() && width == rect.getWidth()) {
                            continue;
                        }

                        comp.fitComponentIn(width, height);
                        rect = comp.getRelativeComponentBounds(storeA);
                        if (Math.abs(rect.getHeight() - height) <= 1) {
                            compsBack.add(comp);
                        }
                        freeSpace -= rect.getHeight() - origRect.getHeight();
                    }
                }
                final List<UIComponent> compsTemp = comps;
                comps = compsBack;
                compsBack = compsTemp;
                relaxIndex++;
            }

            int x = 0;
            int y = !_expandsVertically && !_horizontal ? container.getContentHeight() - reqSpace : 0;

            // Now, go through children and set proper location.
            for (int i = 0; i < content.size(); i++) {
                final Spatial spat = _horizontal ? content.get(i) : content.get(content.size() - i - 1);

                if (!(spat instanceof UIComponent)) {
                    continue;
                }
                final UIComponent comp = (UIComponent) spat;
                final Rectangle2 rect = comp.getRelativeComponentBounds(storeA);

                if (_horizontal) {
                    comp.setLocalXY(x - rect.getX(), Math.max(container.getContentHeight() / 2 - rect.getHeight() / 2
                            - rect.getY(), 0));
                    x += rect.getWidth();
                } else {
                    comp.setLocalXY(Math.max(container.getContentWidth() / 2 - rect.getWidth() / 2 - rect.getX(), 0), y
                            - rect.getY());
                    y += rect.getHeight();
                }
            }
        }
View Full Code Here


            final Rectangle2 store = new Rectangle2();
            for (final Spatial s : content) {
                if (!(s instanceof UIComponent)) {
                    continue;
                }
                final UIComponent comp = (UIComponent) s;
                final Rectangle2 rect = comp.getRelativeMinComponentBounds(store);
                if (_horizontal) {
                    minW += rect.getWidth();
                    if (minH < rect.getHeight()) {
                        minH = rect.getHeight();
                    }
View Full Code Here

        // go through all children of a container
        for (int x = container.getNumberOfChildren(); --x >= 0;) {
            // set them all to relative position 0,0
            final Spatial child = container.getChild(x);
            if (child instanceof UIComponent) {
                final UIComponent childComp = (UIComponent) child;

                // add an anchor for the component, if missing.
                if (_records.get(childComp) == null) {
                    _records.put(childComp, new AnchorRecord());
                }

                // add them to the records container by their dependencies, if any.
                if (childComp.getLayoutData() instanceof AnchorLayoutData) {
                    // resets translation to 0 so we can addTranslation in applyAnchor
                    childComp.setTranslation(0, 0, childComp.getTranslation().getZ());

                    final AnchorLayoutData layData = (AnchorLayoutData) childComp.getLayoutData();
                    AnchorRecord aRecord = _records.get(layData.getParent());
                    if (aRecord == null) {
                        aRecord = new AnchorRecord();
                        _records.put(layData.getParent(), aRecord);
                    }
View Full Code Here

        // get the anchor record (if any) for this component
        final AnchorRecord aRecord = _records.get(toVisit);
        if (aRecord != null) {
            final Rectangle2 rect = new Rectangle2();
            for (int x = aRecord.dependants.size(); --x >= 0;) {
                final UIComponent dep = aRecord.dependants.get(x);
                if (dep.getLayoutData() instanceof AnchorLayoutData) {
                    dep.getRelativeComponentBounds(rect);
                    AnchorLayout.applyAnchor(dep, (AnchorLayoutData) dep.getLayoutData());

                    // update min/max
                    final int posX = Math.round(dep.getTranslation().getXf()) + rect.getWidth() - rect.getX();
                    final int negX = Math.round(dep.getTranslation().getXf()) - rect.getX();
                    final int posY = Math.round(dep.getTranslation().getYf()) + rect.getHeight() - rect.getY();
                    final int negY = Math.round(dep.getTranslation().getYf()) - rect.getY();
                    if (posX > _maxX) {
                        _maxX = posX;
                    }
                    if (posY > _maxY) {
                        _maxY = posY;
View Full Code Here

    }

    private void removeVisited() {
        final Iterator<UIComponent> it = _records.keySet().iterator();
        while (it.hasNext()) {
            final UIComponent comp = it.next();
            final AnchorRecord aRecord = _records.get(comp);
            if (aRecord != null && aRecord.visited) {
                it.remove();
            }
        }
View Full Code Here

        final Rectangle2 store = new Rectangle2();
        for (final Spatial s : content) {
            if (!(s instanceof UIComponent)) {
                continue;
            }
            final UIComponent comp = (UIComponent) s;
            comp.getRelativeMinComponentBounds(store);

            final BorderLayoutData data = (BorderLayoutData) comp.getLayoutData();
            if (data != null) {
                switch (data) {
                    case NORTH:
                        heightNorth = store.getHeight();
                        break;
                    case SOUTH:
                        heightSouth = store.getHeight();
                        break;
                    case EAST:
                        widthEast = store.getWidth();
                        break;
                    case WEST:
                        widthWest = store.getWidth();
                        break;
                    case CENTER:
                        // nothing to do
                        break;
                }
            }
        }

        // Using the information from the last pass, set the position and size of each component in the container.
        for (final Spatial s : content) {
            if (!(s instanceof UIComponent)) {
                continue;
            }
            final UIComponent comp = (UIComponent) s;
            comp.getRelativeMinComponentBounds(store);

            final BorderLayoutData data = (BorderLayoutData) comp.getLayoutData();

            if (data != null) {
                switch (data) {
                    case NORTH:
                        comp.fitComponentIn(container.getContentWidth(), store.getHeight());
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(-store.getX(), container.getContentHeight() - heightNorth - store.getY());
                        break;
                    case SOUTH:
                        comp.fitComponentIn(container.getContentWidth(), store.getHeight());
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(-store.getX(), -store.getY());
                        break;
                    case EAST:
                        comp.fitComponentIn(store.getWidth(), container.getContentHeight() - heightNorth - heightSouth);
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(container.getContentWidth() - store.getWidth() - 1 - store.getX(), heightSouth
                                - store.getY());
                        break;
                    case WEST:
                        comp.fitComponentIn(store.getWidth(), container.getContentHeight() - heightNorth - heightSouth);
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(-store.getX(), heightSouth - store.getY());
                        break;
                    case CENTER:
                        comp.fitComponentIn(container.getContentWidth() - widthEast - widthWest, container
                                .getContentHeight()
                                - heightSouth - heightNorth);
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(widthWest - store.getX(), heightSouth - store.getY());
                }
            }
        }
    }
View Full Code Here

            final Rectangle2 store = new Rectangle2();
            for (final Spatial s : content) {
                if (!(s instanceof UIComponent)) {
                    continue;
                }
                final UIComponent comp = (UIComponent) s;
                comp.getRelativeMinComponentBounds(store);
                final BorderLayoutData bld = (BorderLayoutData) comp.getLayoutData();
                if (bld == null) {
                    continue;
                }
                if (bld == BorderLayoutData.SOUTH || bld == BorderLayoutData.NORTH) {
                    minH += store.getHeight();
View Full Code Here

            final Rectangle2 store = new Rectangle2();
            for (final Spatial s : content) {
                if (!(s instanceof UIComponent)) {
                    continue;
                }
                final UIComponent comp = (UIComponent) s;
                comp.getRelativeMinComponentBounds(store);
                final BorderLayoutData data = (BorderLayoutData) comp.getLayoutData();
                if (data == BorderLayoutData.EAST || data == BorderLayoutData.WEST || data == BorderLayoutData.CENTER
                        || data == null) {
                    minWidth += store.getWidth();
                } else {
                    final int width = store.getWidth();
View Full Code Here

    private void rebuildGrid(final UIContainer container) {
        final List<Spatial> content = container.getChildren();
        grid = new LayoutGrid();
        for (final Spatial spatial : content) {
            if (spatial instanceof UIComponent) {
                final UIComponent c = (UIComponent) spatial;
                grid.add(c);
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.ardor3d.extension.ui.UIComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.