Search in sources :

Example 26 with Component

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

the class TableLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
public void layoutContainer(Container parent) {
    try {
        verticalSpanningExists = false;
        horizontalSpanningExists = false;
        // column and row size in pixels
        Style s = parent.getStyle();
        int top = s.getPaddingTop();
        int left = s.getPaddingLeft(parent.isRTL());
        int bottom = s.getPaddingBottom();
        int right = s.getPaddingRight(parent.isRTL());
        boolean rtl = parent.isRTL();
        columnSizes = new int[columns];
        if (modifableColumnSize == null || columns != modifableColumnSize.length) {
            modifableColumnSize = new boolean[columns];
        }
        columnPositions = new int[columns];
        int[] rowSizes = new int[rows];
        rowPositions = new int[rows];
        int pWidth = parent.getLayoutWidth() - parent.getSideGap() - left - right;
        int pHeight = parent.getLayoutHeight() - parent.getBottomGap() - top - bottom;
        int currentX = left;
        int availableReminder = pWidth;
        int cslen = columnSizes.length;
        for (int iter = 0; iter < cslen; iter++) {
            columnSizes[iter] = getColumnWidthPixels(iter, pWidth, availableReminder);
            availableReminder -= columnSizes[iter];
        }
        // so they are distributed sensibly if no room is available
        if (!parent.isScrollableX()) {
            int totalWidth = 0;
            int totalModifyablePixels = 0;
            // check how many columns we can modify (the user hasn't requested a specific size for those)
            for (int iter = 0; iter < modifableColumnSize.length; iter++) {
                if (modifableColumnSize[iter]) {
                    totalModifyablePixels += columnSizes[iter];
                }
                totalWidth += columnSizes[iter];
            }
            if (pWidth < totalWidth) {
                int totalPixelsToRemove = totalWidth - pWidth;
                int totalPixelsNecessary = totalModifyablePixels - totalPixelsToRemove;
                // Go over the modifyable columns and remove the right pixels according to the ratio
                for (int iter = 0; iter < modifableColumnSize.length; iter++) {
                    if (modifableColumnSize[iter]) {
                        columnSizes[iter] = (int) (((float) columnSizes[iter]) / ((float) totalModifyablePixels) * totalPixelsNecessary);
                    }
                }
            }
        }
        for (int iter = 0; iter < columnSizes.length; iter++) {
            if (rtl) {
                currentX += columnSizes[iter];
                columnPositions[iter] = pWidth - currentX;
            } else {
                columnPositions[iter] = currentX;
                currentX += columnSizes[iter];
            }
        }
        int currentY = top;
        int rlen = rowSizes.length;
        for (int iter = 0; iter < rlen; iter++) {
            if (parent.isScrollableY()) {
                rowSizes[iter] = getRowHeightPixels(iter, pHeight, -1);
            } else {
                rowSizes[iter] = getRowHeightPixels(iter, pHeight, pHeight - currentY + top);
            }
            rowPositions[iter] = currentY;
            currentY += rowSizes[iter];
        }
        int clen = columnSizes.length;
        for (int r = 0; r < rlen; r++) {
            for (int c = 0; c < clen; c++) {
                Constraint con = tablePositions[r * columns + c];
                int conX, conY, conW, conH;
                if (con != null && con != H_SPAN_CONSTRAINT && con != V_SPAN_CONSTRAINT && con != VH_SPAN_CONSTRAINT) {
                    Style componentStyle = con.parent.getStyle();
                    int leftMargin = componentStyle.getMarginLeft(parent.isRTL());
                    int topMargin = componentStyle.getMarginTop();
                    // conX = left + leftMargin + columnPositions[c]; // bugfix table with padding not drawn correctly
                    // conY = top + topMargin + rowPositions[r]; // bugfix table with padding not drawn correctly
                    conX = leftMargin + columnPositions[c];
                    conY = topMargin + rowPositions[r];
                    if (con.spanHorizontal > 1) {
                        horizontalSpanningExists = true;
                        int w = columnSizes[c];
                        for (int sh = 1; sh < con.spanHorizontal; sh++) {
                            w += columnSizes[Math.min(c + sh, columnSizes.length - 1)];
                        }
                        // for RTL we need to move the component to the side so spanning will work
                        if (rtl) {
                            conX = left + leftMargin + columnPositions[c + con.spanHorizontal - 1];
                        }
                        conW = w - leftMargin - componentStyle.getMarginLeft(parent.isRTL());
                    } else {
                        conW = columnSizes[c] - leftMargin - componentStyle.getMarginRight(parent.isRTL());
                    }
                    if (con.spanVertical > 1) {
                        verticalSpanningExists = true;
                        int h = rowSizes[r];
                        for (int sv = 1; sv < con.spanVertical; sv++) {
                            h += rowSizes[Math.min(r + sv, rowSizes.length - 1)];
                        }
                        conH = h - topMargin - componentStyle.getMarginBottom();
                    } else {
                        conH = rowSizes[r] - topMargin - componentStyle.getMarginBottom();
                    }
                    placeComponent(rtl, con, conX, conY, conW, conH);
                }
            }
        }
    } catch (ArrayIndexOutOfBoundsException err) {
        Log.e(err);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 27 with Component

use of com.codename1.ui.Component 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 28 with Component

use of com.codename1.ui.Component 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 29 with Component

use of com.codename1.ui.Component 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 30 with Component

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

Aggregations

Component (com.codename1.ui.Component)152 Style (com.codename1.ui.plaf.Style)61 Container (com.codename1.ui.Container)55 Form (com.codename1.ui.Form)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)40 TextArea (com.codename1.ui.TextArea)31 ActionEvent (com.codename1.ui.events.ActionEvent)28 Dimension (com.codename1.ui.geom.Dimension)28 Label (com.codename1.ui.Label)25 Point (com.codename1.ui.geom.Point)22 ArrayList (java.util.ArrayList)22 Rectangle (com.codename1.ui.geom.Rectangle)21 Vector (java.util.Vector)18 Button (com.codename1.ui.Button)16 Dialog (com.codename1.ui.Dialog)16 Hashtable (java.util.Hashtable)16 Image (com.codename1.ui.Image)15 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)13 BoxLayout (com.codename1.ui.layouts.BoxLayout)13