Search in sources :

Example 21 with Component

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

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

the class LazyValueC method readRendererer.

private GenericListCellRenderer readRendererer(Resources res, DataInputStream in) throws IOException {
    int rendererComponentCount = in.readByte();
    String f = in.readUTF();
    String s = in.readUTF();
    if (rendererComponentCount == 2) {
        Component selected = createContainer(res, f);
        Component unselected = createContainer(res, s);
        GenericListCellRenderer g = new GenericListCellRenderer(selected, unselected);
        g.setFisheye(!f.equals(s));
        return g;
    } else {
        Component selected = createContainer(res, f);
        Component unselected = createContainer(res, s);
        Component even = createContainer(res, in.readUTF());
        Component evenU = createContainer(res, in.readUTF());
        GenericListCellRenderer g = new GenericListCellRenderer(selected, unselected, even, evenU);
        g.setFisheye(!f.equals(s));
        return g;
    }
}
Also used : GenericListCellRenderer(com.codename1.ui.list.GenericListCellRenderer) Component(com.codename1.ui.Component)

Example 23 with Component

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

the class LazyValueC method getFormListenerInstance.

private FormListener getFormListenerInstance(Component cmp, EmbeddedContainer embedded) {
    if (embedded != null) {
        FormListener fc = (FormListener) embedded.getClientProperty("!FormListener!");
        if (fc != null) {
            return fc;
        }
        fc = new FormListener();
        embedded.putClientProperty("!FormListener!", fc);
        return fc;
    }
    Form f = cmp.getComponentForm();
    if (f == null) {
        return null;
    }
    FormListener fc = (FormListener) f.getClientProperty("!FormListener!");
    if (fc != null) {
        return fc;
    }
    fc = new FormListener();
    f.putClientProperty("!FormListener!", fc);
    f.addCommandListener(fc);
    return fc;
}
Also used : Form(com.codename1.ui.Form)

Example 24 with Component

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

the class TableLayout method removeLayoutComponent.

/**
 * {@inheritDoc}
 */
public void removeLayoutComponent(Component comp) {
    // reflow the table
    Vector comps = new Vector();
    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < columns; c++) {
            if (tablePositions[r * columns + c] != null) {
                if (tablePositions[r * columns + c].parent != comp) {
                    comps.addElement(tablePositions[r * columns + c]);
                } else {
                    tablePositions[r * columns + c].parent = null;
                }
            }
            tablePositions[r * columns + c] = null;
        }
    }
    currentRow = 0;
    currentColumn = 0;
    int count = comps.size();
    for (int iter = 0; iter < count; iter++) {
        Constraint con = (Constraint) comps.elementAt(iter);
        if (con == H_SPAN_CONSTRAINT || con == V_SPAN_CONSTRAINT || con == VH_SPAN_CONSTRAINT) {
            continue;
        }
        Component c = con.parent;
        con.parent = null;
        addLayoutComponent(con, c, c.getParent());
    }
}
Also used : Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 25 with Component

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

the class TableLayout method placeComponent.

/**
 * Places the component/constraint in the proper alignment within the cell whose bounds are given
 */
private void placeComponent(boolean rtl, Constraint con, int x, int y, int width, int height) {
    con.parent.setX(x);
    con.parent.setY(y);
    con.parent.setWidth(width);
    con.parent.setHeight(height);
    Dimension pref = con.parent.getPreferredSize();
    int pWidth = pref.getWidth();
    int pHeight = pref.getHeight();
    if (pWidth < width) {
        int d = (width - pWidth);
        int a = con.align;
        if (rtl) {
            switch(a) {
                case Component.LEFT:
                    a = Component.RIGHT;
                    break;
                case Component.RIGHT:
                    a = Component.LEFT;
                    break;
            }
        }
        switch(a) {
            case Component.LEFT:
                con.parent.setX(x);
                con.parent.setWidth(width - d);
                break;
            case Component.RIGHT:
                con.parent.setX(x + d);
                con.parent.setWidth(width - d);
                break;
            case Component.CENTER:
                con.parent.setX(x + d / 2);
                con.parent.setWidth(width - d);
                break;
        }
    }
    if (pHeight < height) {
        int d = (height - pHeight);
        switch(con.valign) {
            case Component.TOP:
                con.parent.setY(y);
                con.parent.setHeight(height - d);
                break;
            case Component.BOTTOM:
                con.parent.setY(y + d);
                con.parent.setHeight(height - d);
                break;
            case Component.CENTER:
                con.parent.setY(y + d / 2);
                con.parent.setHeight(height - d);
                break;
        }
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

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