Java Code Examples for com.codename1.ui.Form#getClientProperty()

The following examples show how to use com.codename1.ui.Form#getClientProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToastBar.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private ToastBarComponent getToastBarComponent() {
    Form f = Display.getInstance().getCurrent();
    if (f != null && !(f instanceof Dialog)) {
        ToastBarComponent c = (ToastBarComponent)f.getClientProperty("ToastBarComponent");
        if (c == null || c.getParent() == null) {
            c = new ToastBarComponent();
            c.hidden = true;
            f.putClientProperty("ToastBarComponent", c);
            Container layered = f.getLayeredPane(this.getClass(), true);
            layered.setLayout(new BorderLayout());
            layered.addComponent(position==Component.TOP ? BorderLayout.NORTH : BorderLayout.SOUTH, c);
            updateStatus();
        }
        if(position == Component.BOTTOM && f.getInvisibleAreaUnderVKB() > 0) {
            Style s = c.getAllStyles();
            s.setMarginUnit(Style.UNIT_TYPE_PIXELS);
            s.setMarginBottom(f.getInvisibleAreaUnderVKB());
        }
        return c;
    }
    return null;
}
 
Example 2
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
Form createForm(Form f) {
    Form currentForm = Display.getInstance().getCurrent();
    if(currentForm != null && currentForm instanceof Dialog) {
        ((Dialog)Display.getInstance().getCurrent()).dispose();
        currentForm = Display.getInstance().getCurrent();
    }
    Vector formNavigationStack = baseFormNavigationStack;
    if(formNavigationStack != null && !(f instanceof Dialog) && !f.getName().equals(homeForm)) {
        if(currentForm != null) {
            String nextForm = (String)f.getClientProperty("%next_form%");

            // we are in the sidemenu view we should really be using the parent form
            SideMenuBar b = (SideMenuBar)currentForm.getClientProperty("cn1$sideMenuParent");
            if(b != null) {
                currentForm = b.getParentForm();
            }

            // don't add back commands to transitional forms
            if(nextForm == null) {
                String commandAction = currentForm.getName();
                if(allowBackTo(commandAction) && f.getBackCommand() == null) {
                    Command backCommand;
                    if(isSameBackDestination(currentForm, f)) {
                        backCommand = currentForm.getBackCommand();
                    } else {
                        backCommand = createCommandImpl(getBackCommandText(currentForm.getTitle()), null,
                            BACK_COMMAND_ID, commandAction, true, "");
                        backCommand.putClientProperty(COMMAND_ARGUMENTS, "");
                        backCommand.putClientProperty(COMMAND_ACTION, commandAction);
                    }
                    if(backCommand != null) {
                        setBackCommand(f, backCommand);
                    }

                    // trigger listener creation if this is the only command in the form
                    getFormListenerInstance(f, null);
                    formNavigationStack.addElement(getFormState(currentForm));
                }
            }
        }
    }
    return f;
}
 
Example 3
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private void showForm(Form f, Command sourceCommand, Component sourceComponent) {
    Form currentForm = Display.getInstance().getCurrent();
    if(currentForm != null && currentForm instanceof Dialog) {
        ((Dialog)Display.getInstance().getCurrent()).dispose();
        currentForm = Display.getInstance().getCurrent();
    }
    Vector formNavigationStack = baseFormNavigationStack;
    if(sourceCommand != null && currentForm != null && currentForm.getBackCommand() == sourceCommand) {
        if(currentForm != null) {
            exitForm(currentForm);
        }
        if(formNavigationStack != null && formNavigationStack.size() > 0) {
            String name = f.getName();
            if(name != null && name.equals(homeForm)) {
                if(formNavigationStack.size() > 0) {
                    setFormState(f, (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1));
                }
                formNavigationStack.clear();
            } else {
                initBackForm(f);
            }
        }
        onBackNavigation();
        beforeShow(f, sourceCommand);
        f.showBack();
        postShowImpl(f);
    } else {
        if(currentForm != null) {
            exitForm(currentForm);
        }
        if(formNavigationStack != null && !(f instanceof Dialog) && !f.getName().equals(homeForm)) {
            if(currentForm != null) {
                String nextForm = (String)f.getClientProperty("%next_form%");
                
                // we are in the sidemenu view we should really be using the parent form
                SideMenuBar b = (SideMenuBar)currentForm.getClientProperty("cn1$sideMenuParent");
                if(b != null) {
                    currentForm = b.getParentForm();
                }
                
                // don't add back commands to transitional forms
                if(nextForm == null) {
                    String commandAction = currentForm.getName();
                    if(allowBackTo(commandAction) && f.getBackCommand() == null) {
                        Command backCommand;
                        if(isSameBackDestination(currentForm, f)) {
                            backCommand = currentForm.getBackCommand();
                        } else {
                            backCommand = createCommandImpl(getBackCommandText(currentForm.getTitle()), null,
                                BACK_COMMAND_ID, commandAction, true, "");
                            backCommand.putClientProperty(COMMAND_ARGUMENTS, "");
                            backCommand.putClientProperty(COMMAND_ACTION, commandAction);
                        }
                        if(backCommand != null) {
                            setBackCommand(f, backCommand);
                        }

                        // trigger listener creation if this is the only command in the form
                        getFormListenerInstance(f, null);
                        formNavigationStack.addElement(getFormState(currentForm));
                    }
                }
            }
        }
        if(f instanceof Dialog) {
            beforeShow(f, sourceCommand);
            if(sourceComponent != null) {
                // we are cheating with the post show here since we are using a modal
                // dialog to prevent the "double clicking button" problem by using
                // a modal dialog
                sourceComponent.setEnabled(false);
                postShowImpl(f);
                f.show();
                sourceComponent.setEnabled(true);
                exitForm(f);
            } else {
                ((Dialog)f).showModeless();
                postShowImpl(f);
            }
        } else {
            beforeShow(f, sourceCommand);
            f.show();
            postShowImpl(f);
        }
    }
}