Search in sources :

Example 1 with EmbeddedContainer

use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.

the class LazyValueC method getFormNavigationStackForComponent.

private Vector getFormNavigationStackForComponent(Component c) {
    if (baseFormNavigationStack == null) {
        return null;
    }
    if (c == null) {
        return baseFormNavigationStack;
    }
    Component root = getRootAncestor(c);
    if (root.getParent() instanceof EmbeddedContainer) {
        Vector nav = (Vector) root.getParent().getClientProperty("$baseNav");
        if (nav == null) {
            nav = new Vector();
            root.getParent().putClientProperty("$baseNav", nav);
        }
        return nav;
    }
    return baseFormNavigationStack;
}
Also used : Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 2 with EmbeddedContainer

use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.

the class LazyValueC method showContainerImpl.

private Container showContainerImpl(String resourceName, Command sourceCommand, Component sourceComponent, boolean forceBack) {
    if (sourceComponent != null) {
        Form currentForm = sourceComponent.getComponentForm();
        // avoid the overhead of searching if no embedding is used
        if (currentForm.getClientProperty(EMBEDDED_FORM_FLAG) != null) {
            Container destContainer = sourceComponent.getParent();
            while (!(destContainer instanceof EmbeddedContainer || destContainer instanceof Form)) {
                // race condition, container was already removed by someone else
                if (destContainer == null) {
                    return null;
                }
                destContainer = destContainer.getParent();
            }
            if (destContainer instanceof EmbeddedContainer) {
                Container cnt = createContainer(fetchResourceFile(), resourceName, (EmbeddedContainer) destContainer);
                if (cnt instanceof Form) {
                    // Form f = (Form)cnt;
                    // cnt = formToContainer(f);
                    showForm((Form) cnt, sourceCommand, sourceComponent);
                    return cnt;
                }
                Component fromCmp = destContainer.getComponentAt(0);
                // This seems to be no longer necessary now that we have the replaceAndWait version that drops events
                // block the user from the ability to press the button twice by mistake
                // fromCmp.setEnabled(false);
                boolean isBack = forceBack;
                Transition t = fromCmp.getUIManager().getLookAndFeel().getDefaultFormTransitionOut();
                if (forceBack) {
                    initBackContainer(cnt, destContainer.getComponentForm(), getFormNavigationStackForComponent(sourceComponent));
                    t = t.copy(true);
                } else {
                    if (sourceCommand != null) {
                        if (t != null && backCommands != null && backCommands.contains(sourceCommand) || Display.getInstance().getCurrent().getBackCommand() == sourceCommand) {
                            isBack = true;
                            t = t.copy(true);
                        }
                    }
                }
                // create a back command if supported
                String commandAction = cnt.getName();
                Vector formNavigationStack = getFormNavigationStackForComponent(fromCmp);
                if (formNavigationStack != null && !isBack && allowBackTo(commandAction) && !isSameBackDestination((Container) fromCmp, cnt)) {
                    // trigger listener creation if this is the only command in the form
                    getFormListenerInstance(destContainer.getComponentForm(), null);
                    formNavigationStack.addElement(getContainerState((com.codename1.ui.Container) fromCmp));
                }
                beforeShowContainer(cnt);
                destContainer.replaceAndWait(fromCmp, cnt, t, true);
                postShowContainer(cnt);
                return cnt;
            } else {
                Container cnt = createContainer(fetchResourceFile(), resourceName);
                showForm((Form) cnt, sourceCommand, sourceComponent);
                return cnt;
            }
        }
    }
    Container cnt = createContainer(fetchResourceFile(), resourceName);
    if (cnt instanceof Form) {
        showForm((Form) cnt, sourceCommand, sourceComponent);
    } else {
        Form f = new Form();
        f.setLayout(new BorderLayout());
        f.addComponent(BorderLayout.CENTER, cnt);
        f.setName("Form" + cnt.getName());
        showForm(f, sourceCommand, sourceComponent);
    }
    return cnt;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Transition(com.codename1.ui.animations.Transition) Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 3 with EmbeddedContainer

use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.

the class LazyValueC method createContainer.

Container createContainer(Resources res, String resourceName, EmbeddedContainer parentContainer) {
    onCreateRoot(resourceName);
    InputStream source = res.getUi(resourceName);
    if (source == null) {
        throw new RuntimeException("Resource doesn't exist within the current resource object: " + resourceName);
    }
    DataInputStream in = new DataInputStream(source);
    try {
        Hashtable h = null;
        if (localComponentListeners != null) {
            h = (Hashtable) localComponentListeners.get(resourceName);
        }
        Container c = (Container) createComponent(in, null, null, res, h, parentContainer);
        c.setName(resourceName);
        postCreateComponents(in, c, res);
        // try to be smart about initializing the home form
        if (homeForm == null) {
            if (c instanceof Form) {
                String nextForm = (String) c.getClientProperty("%next_form%");
                if (nextForm != null) {
                    homeForm = nextForm;
                } else {
                    homeForm = resourceName;
                }
            }
        }
        return c;
    } catch (Exception ex) {
        // If this happens its probably a serious bug
        ex.printStackTrace();
        return null;
    }
}
Also used : Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException)

Example 4 with EmbeddedContainer

use of com.codename1.ui.util.EmbeddedContainer 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 5 with EmbeddedContainer

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

Aggregations

Form (com.codename1.ui.Form)6 Container (com.codename1.ui.Container)5 BorderLayout (com.codename1.ui.layouts.BorderLayout)5 Hashtable (java.util.Hashtable)5 Component (com.codename1.ui.Component)4 TableLayout (com.codename1.ui.table.TableLayout)4 Vector (java.util.Vector)4 ArrayList (java.util.ArrayList)3 Button (com.codename1.ui.Button)2 CheckBox (com.codename1.ui.CheckBox)2 Dialog (com.codename1.ui.Dialog)2 Label (com.codename1.ui.Label)2 List (com.codename1.ui.List)2 RadioButton (com.codename1.ui.RadioButton)2 Slider (com.codename1.ui.Slider)2 Tabs (com.codename1.ui.Tabs)2 TextArea (com.codename1.ui.TextArea)2 BoxLayout (com.codename1.ui.layouts.BoxLayout)2 FlowLayout (com.codename1.ui.layouts.FlowLayout)2 GridLayout (com.codename1.ui.layouts.GridLayout)2