Search in sources :

Example 16 with Container

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

the class Tree method expandNodeImpl.

private Container expandNodeImpl(boolean animate, Component c, boolean revalidate) {
    Container p = c.getParent().getLeadParent();
    if (p != null) {
        c = p;
    }
    c.putClientProperty(KEY_EXPANDED, "true");
    if (openFolder == null) {
        FontImage.setMaterialIcon(c, FontImage.MATERIAL_FOLDER, 3);
    } else {
        setNodeIcon(openFolder, c);
    }
    int depth = ((Integer) c.getClientProperty(KEY_DEPTH)).intValue();
    Container parent = c.getParent();
    Object o = c.getClientProperty(KEY_OBJECT);
    Container dest = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    parent.addComponent(BorderLayout.CENTER, dest);
    buildBranch(o, depth, dest);
    if (isInitialized() && animate) {
        // prevent a race condition on node expansion contraction
        parent.animateHierarchyAndWait(300);
        if (multilineMode) {
            revalidate();
        }
    } else {
        if (revalidate) {
            parent.revalidate();
        }
    }
    return dest;
}
Also used : Container(com.codename1.ui.Container) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 17 with Container

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

the class Tree method buildBranch.

/**
 * Adds the child components of a tree branch to the given container.
 */
private void buildBranch(Object parent, int depth, Container destination) {
    Vector children = model.getChildren(parent);
    int size = children.size();
    Integer depthVal = new Integer(depth + 1);
    for (int iter = 0; iter < size; iter++) {
        final Object current = children.elementAt(iter);
        Component nodeComponent = createNode(current, depth);
        if (model.isLeaf(current)) {
            destination.addComponent(nodeComponent);
            bindNodeListener(new Handler(current), nodeComponent);
        } else {
            Container componentArea = new Container(new BorderLayout());
            componentArea.addComponent(BorderLayout.NORTH, nodeComponent);
            destination.addComponent(componentArea);
            bindNodeListener(expansionListener, nodeComponent);
        }
        nodeComponent.putClientProperty(KEY_OBJECT, current);
        nodeComponent.putClientProperty(KEY_PARENT, parent);
        nodeComponent.putClientProperty(KEY_DEPTH, depthVal);
    }
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 18 with Container

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

the class Tree method collapsePathNode.

private void collapsePathNode(Container parent, Object node) {
    int cc = parent.getComponentCount();
    for (int iter = 0; iter < cc; iter++) {
        Component current = parent.getComponentAt(iter);
        if (isExpanded(current)) {
            BorderLayout bl = (BorderLayout) ((Container) current).getLayout();
            // the tree component is always at north expanded or otherwise
            current = bl.getNorth();
            Object o = current.getClientProperty(KEY_OBJECT);
            if (o != null && o.equals(node)) {
                if (isExpanded(current)) {
                    collapseNode(current, null);
                }
                return;
            }
        }
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component)

Example 19 with Container

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

the class Tree method collapseNode.

private void collapseNode(Component c, Transition t) {
    Container lead = c.getParent().getLeadParent();
    if (lead != null) {
        c = lead;
    }
    c.putClientProperty(KEY_EXPANDED, null);
    setNodeIcon(folder, c);
    Container p = c.getParent();
    for (int iter = 0; iter < p.getComponentCount(); iter++) {
        if (p.getComponentAt(iter) != c) {
            if (t == null) {
                p.removeComponent(p.getComponentAt(iter));
                // there should only be one container with all children
                break;
            } else {
                Label dummy = new Label();
                p.replaceAndWait(p.getComponentAt(iter), dummy, t, true);
                p.removeComponent(dummy);
            }
        }
    }
}
Also used : Container(com.codename1.ui.Container) Label(com.codename1.ui.Label)

Example 20 with Container

use of com.codename1.ui.Container 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)

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