Search in sources :

Example 11 with Container

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

the class LazyValueC method back.

/**
 * This method effectively pops the form navigation stack and goes back
 * to the previous form if back navigation is enabled and there is
 * a previous form.
 *
 * @param sourceComponent the component that triggered the back command which effectively
 * allows us to find the EmbeddedContainer for a case of container navigation. Null
 * can be used if not applicable.
 */
public void back(Component sourceComponent) {
    Vector formNavigationStack = getFormNavigationStackForComponent(sourceComponent);
    if (formNavigationStack != null && formNavigationStack.size() > 0) {
        Hashtable h = (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1);
        if (h.containsKey(FORM_STATE_KEY_CONTAINER)) {
            Form currentForm = Display.getInstance().getCurrent();
            if (currentForm != null) {
                exitForm(currentForm);
            }
        }
        String formName = (String) h.get(FORM_STATE_KEY_NAME);
        if (!h.containsKey(FORM_STATE_KEY_CONTAINER)) {
            Form f = (Form) createContainer(fetchResourceFile(), formName);
            initBackForm(f);
            onBackNavigation();
            beforeShow(f);
            f.showBack();
            postShowImpl(f);
        } else {
            showContainerImpl(formName, null, sourceComponent, true);
        }
    }
}
Also used : Form(com.codename1.ui.Form) Hashtable(java.util.Hashtable) Vector(java.util.Vector)

Example 12 with Container

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

the class LazyValueC method getContainerState.

/**
 * This method is the container navigation equivalent of getFormState() see
 * that method for details.
 * @param cnt the container
 * @return the state
 */
protected Hashtable getContainerState(Container cnt) {
    Component c = null;
    Form parentForm = cnt.getComponentForm();
    if (parentForm != null) {
        c = parentForm.getFocused();
    }
    Hashtable h = new Hashtable();
    h.put(FORM_STATE_KEY_NAME, cnt.getName());
    h.put(FORM_STATE_KEY_CONTAINER, "");
    if (c != null && isParentOf(cnt, c)) {
        if (c instanceof List) {
            h.put(FORM_STATE_KEY_SELECTION, new Integer(((List) c).getSelectedIndex()));
        }
        if (c.getName() != null) {
            h.put(FORM_STATE_KEY_FOCUS, c.getName());
        }
        return h;
    }
    storeComponentState(cnt, h);
    return h;
}
Also used : Form(com.codename1.ui.Form) Hashtable(java.util.Hashtable) List(com.codename1.ui.List) ContainerList(com.codename1.ui.list.ContainerList) Component(com.codename1.ui.Component)

Example 13 with Container

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

the class TableLayout method getRowHeightPixels.

private int getRowHeightPixels(int row, int percentageOf, int available) {
    int current = 0;
    for (int iter = 0; iter < columns; iter++) {
        Constraint c = tablePositions[row * columns + iter];
        if (c == null || c == H_SPAN_CONSTRAINT || c == V_SPAN_CONSTRAINT || c == VH_SPAN_CONSTRAINT || c.spanVertical > 1) {
            continue;
        }
        // height in percentage of the parent container
        if (c.height > 0) {
            current = Math.max(current, c.height * percentageOf / 100);
        } else {
            Style s = c.parent.getStyle();
            current = Math.max(current, c.parent.getPreferredH() + s.getMarginTop() + s.getMarginBottom());
        }
        if (available > -1) {
            current = Math.min(available, current);
        }
    }
    return current;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 14 with Container

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

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

the class TableLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    Style s = parent.getStyle();
    int w = s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL();
    int h = s.getPaddingTop() + s.getPaddingBottom();
    int maxW = Display.getInstance().getDisplayWidth() * 2;
    int maxH = Display.getInstance().getDisplayHeight() * 2;
    for (int iter = 0; iter < columns; iter++) {
        w += getColumnWidthPixels(iter, maxW, -1);
    }
    for (int iter = 0; iter < rows; iter++) {
        h += getRowHeightPixels(iter, maxH, -1);
    }
    return new Dimension(w, h);
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

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