Search in sources :

Example 16 with Component

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

the class LazyValueC method restoreComponentState.

/**
 * By default Codename One stores the states of components in the navigation graph
 * as it moves between forms. However, some components aren't recognized by Codename One
 * by default to enable smaller executable size. This method can be overriden to enable
 * storing the state of custom components
 *
 * @param c the component whose state should be restored
 * @param destination the hashtable containing the state
 */
protected void restoreComponentState(Component c, Hashtable destination) {
    if (shouldAutoStoreState()) {
        Enumeration e = destination.keys();
        while (e.hasMoreElements()) {
            String currentKey = (String) e.nextElement();
            Component cmp = findByName(currentKey, c);
            if (cmp != null) {
                Object value = destination.get(currentKey);
                if (value instanceof Integer) {
                    if (cmp instanceof List) {
                        ((List) cmp).setSelectedIndex(((Integer) value).intValue());
                        continue;
                    }
                    if (cmp instanceof Tabs) {
                        int val = ((Integer) value).intValue();
                        Tabs t = (Tabs) cmp;
                        if (t.getTabCount() > val) {
                            t.setSelectedIndex(val);
                        }
                        continue;
                    }
                }
                cmp.setComponentState(value);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Tabs(com.codename1.ui.Tabs) List(com.codename1.ui.List) ContainerList(com.codename1.ui.list.ContainerList) Component(com.codename1.ui.Component)

Example 17 with Component

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

the class LazyValueC method setContainerStateImpl.

private void setContainerStateImpl(Container cnt, Hashtable state) {
    if (state != null) {
        restoreComponentState(cnt, state);
        String cmpName = (String) state.get(FORM_STATE_KEY_FOCUS);
        if (cmpName == null) {
            return;
        }
        Component c = findByName(cmpName, cnt);
        if (c != null) {
            c.requestFocus();
            if (c instanceof List) {
                Integer i = (Integer) state.get(FORM_STATE_KEY_SELECTION);
                if (i != null) {
                    ((List) c).setSelectedIndex(i.intValue());
                }
            }
        }
    }
}
Also used : List(com.codename1.ui.List) ContainerList(com.codename1.ui.list.ContainerList) Component(com.codename1.ui.Component)

Example 18 with Component

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

the class LazyValueC method formToContainer.

Container formToContainer(Form f) {
    Container cnt = new Container(f.getContentPane().getLayout());
    if (f.getContentPane().getLayout() instanceof BorderLayout || f.getContentPane().getLayout() instanceof TableLayout) {
        while (f.getContentPane().getComponentCount() > 0) {
            Component src = f.getContentPane().getComponentAt(0);
            Object o = f.getContentPane().getLayout().getComponentConstraint(src);
            f.getContentPane().removeComponent(src);
            cnt.addComponent(o, src);
        }
    } else {
        while (f.getContentPane().getComponentCount() > 0) {
            Component src = f.getContentPane().getComponentAt(0);
            f.getContentPane().removeComponent(src);
            cnt.addComponent(src);
        }
    }
    return cnt;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component) TableLayout(com.codename1.ui.table.TableLayout)

Example 19 with Component

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

the class LazyValueC method createComponentType.

Component createComponentType(String name) throws IllegalAccessException, InstantiationException, RuntimeException {
    Class c = (Class) getComponentRegistry().get(name);
    Component cmp = createComponentInstance(name, c);
    if (cmp == null) {
        if (c == null) {
            throw new RuntimeException("Component not found use UIBuilder.registerCustomComponent(" + name + ", class);");
        }
        cmp = (Component) c.newInstance();
    }
    return cmp;
}
Also used : Component(com.codename1.ui.Component)

Example 20 with Component

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

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