Search in sources :

Example 1 with ComponentWrapper

use of com.codename1.ui.layouts.mig.ComponentWrapper in project CodenameOne by codenameone.

the class MigLayout method checkCache.

/**
 * Check if something has changed and if so recreate it to the cached
 * objects.
 *
 * @param parent The parent that is the target for this layout manager.
 */
private void checkCache(Container parent) {
    if (parent == null) {
        return;
    }
    if (dirty) {
        grid = null;
    }
    cleanConstraintMaps(parent);
    // Check if the grid is valid
    int mc = PlatformDefaults.getModCount();
    if (lastModCount != mc) {
        grid = null;
        lastModCount = mc;
    }
    // if (!parent.isValid()) {
    if (!lastWasInvalid) {
        lastWasInvalid = true;
        int hash = 0;
        // Added in 3.7.3 to resolve a timing regression introduced in 3.7.1
        boolean resetLastInvalidOnParent = false;
        for (ComponentWrapper wrapper : ccMap.keySet()) {
            Object component = wrapper.getComponent();
            if (component instanceof TextArea) {
                resetLastInvalidOnParent = true;
            }
            hash ^= wrapper.getLayoutHashCode();
            hash += 285134905;
        }
        if (resetLastInvalidOnParent) {
            resetLastInvalidOnParent(parent);
        }
        if (hash != lastHash) {
            grid = null;
            lastHash = hash;
        }
        Dimension ps = new Dimension(parent.getWidth(), parent.getHeight());
        if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
            grid = null;
            lastInvalidSize = ps;
        }
    }
    /*} else {
         lastWasInvalid = false;
         }*/
    ContainerWrapper par = checkParent(parent);
    setDebug(par, getDebugMillis() > 0);
    if (grid == null) {
        grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
    }
    dirty = false;
}
Also used : TextArea(com.codename1.ui.TextArea) Grid(com.codename1.ui.layouts.mig.Grid) Dimension(com.codename1.ui.geom.Dimension) ContainerWrapper(com.codename1.ui.layouts.mig.ContainerWrapper) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 2 with ComponentWrapper

use of com.codename1.ui.layouts.mig.ComponentWrapper in project CodenameOne by codenameone.

the class MigLayout method cleanConstraintMaps.

/**
 * Checks so all components in ccMap actually exist in the parent's
 * collection. Removes any references that don't.
 *
 * @param parent The parent to compare ccMap against. Never null.
 */
private void cleanConstraintMaps(Container parent) {
    HashSet<Component> parentCompSet = new HashSet<Component>();
    for (int iter = 0; iter < parent.getComponentCount(); iter++) {
        parentCompSet.add(parent.getComponentAt(iter));
    }
    Iterator<Map.Entry<ComponentWrapper, CC>> it = ccMap.entrySet().iterator();
    while (it.hasNext()) {
        Component c = (Component) it.next().getKey().getComponent();
        if (parentCompSet.contains(c) == false) {
            it.remove();
            scrConstrMap.remove(c);
        }
    }
}
Also used : Component(com.codename1.ui.Component) HashSet(java.util.HashSet)

Example 3 with ComponentWrapper

use of com.codename1.ui.layouts.mig.ComponentWrapper in project CodenameOne by codenameone.

the class MigLayout method setComponentConstraintsImpl.

/**
 * Sets the component constraint for the component that already must be
 * handled by this layout manager.
 * <p>
 * See the class JavaDocs for information on how this string is formatted.
 *
 * @param constr The component constraints as a String or
 * {@link net.miginfocom.layout.CC}. <code>null</code> is ok.
 * @param comp The component to set the constraints for.
 * @param noCheck Doe not check if the component is handled if true
 * @throws RuntimeException if the constraint was not valid.
 * @throws IllegalArgumentException If the component is not handling the
 * component.
 */
private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck) {
    Container parent = comp.getParent();
    if (noCheck == false && scrConstrMap.containsKey(comp) == false) {
        throw new IllegalArgumentException("Component must already be added to parent!");
    }
    ComponentWrapper cw = new CodenameOneMiGComponentWrapper(comp);
    if (constr == null || constr instanceof String) {
        String cStr = ConstraintParser.prepare((String) constr);
        scrConstrMap.put(comp, constr);
        ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr));
    } else if (constr instanceof CC) {
        scrConstrMap.put(comp, constr);
        ccMap.put(cw, (CC) constr);
    } else {
        throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString());
    }
    dirty = true;
}
Also used : CC(com.codename1.ui.layouts.mig.CC) Container(com.codename1.ui.Container) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 4 with ComponentWrapper

use of com.codename1.ui.layouts.mig.ComponentWrapper in project CodenameOne by codenameone.

the class CodenameOneMiGContainerWrapper method getComponents.

public ComponentWrapper[] getComponents() {
    Container c = (Container) getComponent();
    ComponentWrapper[] cws = new ComponentWrapper[c.getComponentCount()];
    for (int i = 0; i < cws.length; i++) cws[i] = new CodenameOneMiGComponentWrapper(c.getComponentAt(i));
    return cws;
}
Also used : Container(com.codename1.ui.Container) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Aggregations

ComponentWrapper (com.codename1.ui.layouts.mig.ComponentWrapper)3 Container (com.codename1.ui.Container)2 Component (com.codename1.ui.Component)1 TextArea (com.codename1.ui.TextArea)1 Dimension (com.codename1.ui.geom.Dimension)1 CC (com.codename1.ui.layouts.mig.CC)1 ContainerWrapper (com.codename1.ui.layouts.mig.ContainerWrapper)1 Grid (com.codename1.ui.layouts.mig.Grid)1 HashSet (java.util.HashSet)1