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;
}
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);
}
}
}
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;
}
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;
}
Aggregations