Search in sources :

Example 96 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class BorderLayout method addLayoutComponent.

/**
 * {@inheritDoc}
 */
public void addLayoutComponent(Object name, Component comp, Container c) {
    // helper check for a common mistake...
    if (name == null) {
        throw new IllegalArgumentException("Cannot add component to BorderLayout Container without constraint parameter");
    }
    // allows us to work with Component constraints too which makes some code simpler
    if (name instanceof Integer) {
        switch(((Integer) name).intValue()) {
            case Component.TOP:
                name = NORTH;
                break;
            case Component.BOTTOM:
                name = SOUTH;
                break;
            case Component.LEFT:
                name = WEST;
                break;
            case Component.RIGHT:
                name = EAST;
                break;
            case Component.CENTER:
                name = CENTER;
                break;
            default:
                throw new IllegalArgumentException("BorderLayout Container expects one of the constraints BorderLayout.NORTH/SOUTH/EAST/WEST/CENTER");
        }
    }
    Component previous = null;
    /* Assign the component to one of the known regions of the layout.
         */
    if (CENTER.equals(name)) {
        previous = portraitCenter;
        portraitCenter = comp;
    } else if (NORTH.equals(name)) {
        previous = portraitNorth;
        portraitNorth = comp;
    } else if (SOUTH.equals(name)) {
        previous = portraitSouth;
        portraitSouth = comp;
    } else if (EAST.equals(name)) {
        previous = portraitEast;
        portraitEast = comp;
    } else if (WEST.equals(name)) {
        previous = portraitWest;
        portraitWest = comp;
    } else if (OVERLAY.equals(name)) {
        previous = overlay;
        overlay = comp;
    } else {
        throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);
    }
    if (previous != null && previous != comp) {
        c.removeComponent(previous);
    }
}
Also used : Component(com.codename1.ui.Component)

Example 97 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class MorphTransition method initTransition.

/**
 * {@inheritDoc}
 */
public final void initTransition() {
    animationMotion = Motion.createEaseInOutMotion(0, 255, duration);
    animationMotion.start();
    Container s = (Container) getSource();
    Container d = (Container) getDestination();
    Iterator<String> keyIterator = fromTo.keySet().iterator();
    int size = fromTo.size();
    fromToComponents = new CC[size];
    Form destForm = d.getComponentForm();
    Form sourceForm = s.getComponentForm();
    for (int iter = 0; iter < size; iter++) {
        String k = keyIterator.next();
        String v = fromTo.get(k);
        Component sourceCmp = findByName(s, k);
        Component destCmp = findByName(d, v);
        if (sourceCmp == null || destCmp == null) {
            continue;
        }
        CC cc = new CC(sourceCmp, destCmp, sourceForm, destForm);
        fromToComponents[iter] = cc;
        cc.placeholderDest = new Label();
        cc.placeholderDest.setVisible(false);
        Container destParent = cc.dest.getParent();
        cc.placeholderDest.setX(cc.dest.getX());
        cc.placeholderDest.setY(cc.dest.getY() - destForm.getContentPane().getY());
        cc.placeholderDest.setWidth(cc.dest.getWidth());
        cc.placeholderDest.setHeight(cc.dest.getHeight());
        cc.placeholderDest.setPreferredSize(new Dimension(cc.dest.getWidth(), cc.dest.getHeight()));
        destParent.replace(cc.dest, cc.placeholderDest, null);
        destForm.getLayeredPane().addComponent(cc.dest);
        cc.placeholderSrc = new Label();
        cc.placeholderSrc.setVisible(false);
        cc.placeholderSrc.setX(cc.source.getX());
        cc.placeholderSrc.setY(cc.source.getY() - sourceForm.getContentPane().getY());
        cc.placeholderSrc.setWidth(cc.source.getWidth());
        cc.placeholderSrc.setHeight(cc.source.getHeight());
        cc.placeholderSrc.setPreferredSize(new Dimension(cc.source.getWidth(), cc.source.getHeight()));
        cc.originalContainer = cc.source.getParent();
        cc.originalConstraint = cc.originalContainer.getLayout().getComponentConstraint(cc.source);
        cc.originalOffset = cc.originalContainer.getComponentIndex(cc.source);
        cc.originalContainer.replace(cc.source, cc.placeholderSrc, null);
        cc.originalContainer.getComponentForm().getLayeredPane().addComponent(cc.source);
    }
}
Also used : Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 98 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class MorphTransition method findByName.

private static Component findByName(Container root, String componentName) {
    int count = root.getComponentCount();
    for (int iter = 0; iter < count; iter++) {
        Component c = root.getComponentAt(iter);
        String n = c.getName();
        if (n != null && n.equals(componentName)) {
            return c;
        }
        if (c instanceof Container) {
            c = findByName((Container) c, componentName);
            if (c != null) {
                return c;
            }
        }
    }
    return null;
}
Also used : Container(com.codename1.ui.Container) Component(com.codename1.ui.Component)

Example 99 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class MorphTransition method animate.

/**
 * {@inheritDoc}
 */
public boolean animate() {
    if (!finished) {
        // animate one last time
        if (animationMotion.isFinished()) {
            finished = true;
            // restore forms to orignial states
            for (CC c : fromToComponents) {
                if (c == null) {
                    continue;
                }
                Container p = c.placeholderDest.getParent();
                c.dest.getParent().removeComponent(c.dest);
                p.replace(c.placeholderDest, c.dest, null);
                p = c.placeholderSrc.getParent();
                c.source.getParent().removeComponent(c.source);
                p.replace(c.placeholderSrc, c.source, null);
            }
            // remove potential memory leak
            fromToComponents = null;
            return true;
        }
        for (CC c : fromToComponents) {
            if (c == null) {
                continue;
            }
            int x = c.xMotion.getValue();
            int y = c.yMotion.getValue();
            int w = c.wMotion.getValue();
            int h = c.hMotion.getValue();
            c.source.setX(x);
            c.source.setY(y);
            c.source.setWidth(w);
            c.source.setHeight(h);
            c.dest.setX(x);
            c.dest.setY(y);
            c.dest.setWidth(w);
            c.dest.setHeight(h);
        }
        return true;
    }
    return false;
}
Also used : Container(com.codename1.ui.Container)

Example 100 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class LayeredLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    int numOfcomponents = parent.getComponentCount();
    tmpLaidOut.clear();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        calcPreferredValues(cmp);
        LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
        int vInsets = 0;
        int hInsets = 0;
        if (constraint != null) {
            vInsets += constraint.insets[Component.TOP].preferredValue + constraint.insets[Component.BOTTOM].preferredValue;
            hInsets += constraint.insets[Component.LEFT].preferredValue + constraint.insets[Component.RIGHT].preferredValue;
        }
        maxHeight = Math.max(maxHeight, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom() + vInsets);
        maxWidth = Math.max(maxWidth, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL() + hInsets);
    }
    Style s = parent.getStyle();
    Dimension d = new Dimension(maxWidth + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), maxHeight + s.getPaddingTop() + s.getPaddingBottom());
    if (preferredWidthMM > 0) {
        int minW = Display.getInstance().convertToPixels(preferredWidthMM);
        if (d.getWidth() < minW) {
            d.setWidth(minW);
        }
    }
    if (preferredHeightMM > 0) {
        int minH = Display.getInstance().convertToPixels(preferredHeightMM);
        if (d.getHeight() < Display.getInstance().convertToPixels(preferredHeightMM)) {
            d.setHeight(minH);
        }
    }
    return d;
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Aggregations

Container (com.codename1.ui.Container)85 Component (com.codename1.ui.Component)65 BorderLayout (com.codename1.ui.layouts.BorderLayout)46 Style (com.codename1.ui.plaf.Style)38 ActionEvent (com.codename1.ui.events.ActionEvent)29 Form (com.codename1.ui.Form)26 Label (com.codename1.ui.Label)21 BoxLayout (com.codename1.ui.layouts.BoxLayout)21 Dimension (com.codename1.ui.geom.Dimension)20 ActionListener (com.codename1.ui.events.ActionListener)19 Button (com.codename1.ui.Button)15 FlowLayout (com.codename1.ui.layouts.FlowLayout)15 ArrayList (java.util.ArrayList)14 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)12 TextArea (com.codename1.ui.TextArea)11 Point (com.codename1.ui.geom.Point)11 Rectangle (com.codename1.ui.geom.Rectangle)11 Dialog (com.codename1.ui.Dialog)10 RadioButton (com.codename1.ui.RadioButton)10 Vector (java.util.Vector)9