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

The following examples show how to use com.codename1.ui.Form#showBack() . 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: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 2
Source File: UserForm.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
public UserForm(String name, EncodedImage placeHolder, String imageURL) {
    this.name = name;
    this.imageURL = imageURL;
    setTitle("Welcome!");
    setLayout(new BorderLayout());
    
    Label icon = new Label(placeHolder);
    icon.setUIID("Picture");
    if(imageURL != null){
        icon.setIcon(URLImage.createToStorage(placeHolder, name, imageURL, null));
    }
    addComponent(BorderLayout.CENTER, icon);
    Label nameLbl = new Label(name);
    nameLbl.setUIID("Name");
    addComponent(BorderLayout.SOUTH, nameLbl);
    final Form current = Display.getInstance().getCurrent();
    Command back = new Command("Back"){

        @Override
        public void actionPerformed(ActionEvent evt) {
            current.showBack();;
        }

    };
    addCommand(back);
    setBackCommand(back);
    
}
 
Example 3
Source File: TestRunnerComponent.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs all of the tests in the test running.
 */
public void runTests() {
    Form f = getComponentForm();
    resultsPane.removeAll();
    resultsPane.revalidate();
    for (final AbstractTest test : tests) {
        final Button statusLabel = new Button(test+": Running...");
        if (f != CN.getCurrentForm()) {
            
            f.showBack();
        }
        $(statusLabel).selectAllStyles().setBgColor(0xffff00).setBgTransparency(0xff);
        resultsPane.add(statusLabel);
        resultsPane.revalidate();
        if (test.shouldExecuteOnEDT()) {
            runTest(test, statusLabel);
        } else {
            CN.invokeAndBlock(new Runnable() {
                public void run() {
                    runTest(test, statusLabel);
                }
            });
        }
        resultsPane.revalidate();
    }
    if (f != CN.getCurrentForm()) {
        f.showBack();
    }
}
 
Example 4
Source File: UserForm.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public UserForm(String name, EncodedImage placeHolder, String imageURL) {
    this.name = name;
    this.imageURL = imageURL;
    setTitle("Welcome!");
    setLayout(new BorderLayout());
    
    Label icon = new Label(placeHolder);
    icon.setUIID("Picture");
    if(imageURL != null){
        icon.setIcon(URLImage.createToStorage(placeHolder, name, imageURL, null));
    }
    addComponent(BorderLayout.CENTER, icon);
    Label nameLbl = new Label(name);
    nameLbl.setUIID("Name");
    addComponent(BorderLayout.SOUTH, nameLbl);
    final Form current = Display.getInstance().getCurrent();
    Command back = new Command("Back"){

        @Override
        public void actionPerformed(ActionEvent evt) {
            current.showBack();;
        }

    };
    addCommand(back);
    setBackCommand(back);
    
}
 
Example 5
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);
        }
    }
}
 
Example 6
Source File: Oauth2.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method shows an authentication for login form
 *
 * @param al a listener that will receive at its source either a token for
 * the service or an exception in case of a failure
 * @return a component that should be displayed to the user in order to
 * perform the authentication
 */
public void showAuthentication(final ActionListener al) {
    
    if (useBrowserWindow) {
        final BrowserWindow win = new BrowserWindow(buildURL());
        win.setTitle("Login");
        win.addLoadListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String url = (String)evt.getSource();
                if (url.startsWith(redirectURI)) {
                    win.close();
                    handleURL((String)evt.getSource(), null, al, null, null, null);
                }    
            }
        });

        win.show(); 
        return;
        
    }
    
    final Form old = Display.getInstance().getCurrent();
    InfiniteProgress inf = new InfiniteProgress();
    final Dialog progress = inf.showInifiniteBlocking();
    Form authenticationForm = new Form("Login");
    authenticationForm.setScrollable(false);
    if (old != null) {
        Command cancel = new Command("Cancel") {
            public void actionPerformed(ActionEvent ev) {
                if (Display.getInstance().getCurrent() == progress) {
                    progress.dispose();
                }
                old.showBack();
            }
        };
        if (authenticationForm.getToolbar() != null){
            authenticationForm.getToolbar().addCommandToLeftBar(cancel);
        } else {
            authenticationForm.addCommand(cancel);
        }
        authenticationForm.setBackCommand(cancel);
    }
    authenticationForm.setLayout(new BorderLayout());
    authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress));
}