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

The following examples show how to use com.codename1.ui.Form#addCommand() . 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: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
private void showMainForm() {
    final Form photos = new Form("Photos");
    photos.setLayout(new BorderLayout());
    GridLayout gr = new GridLayout(1, 1);
    final Container grid = new Container(gr);
    gr.setAutoFit(true);
    grid.setScrollableY(true);
    grid.addPullToRefresh(new Runnable() {
        public void run() {
            refreshGrid(grid);
        }
    });

    grid.addComponent(new InfiniteProgress());
    photos.addComponent(BorderLayout.CENTER, grid);

    photos.removeAllCommands();
    photos.setBackCommand(null);
    photos.addCommand(createPictureCommand(grid));

    photos.show();
    refreshGrid(grid);
}
 
Example 2
Source File: Log.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Places a form with the log as a TextArea on the screen, this method can
 * be attached to appear at a given time or using a fixed global key. Using
 * this method might cause a problem with further log output
 * @deprecated this method is an outdated method that's no longer supported
 */
public static void showLog() {
    try {
        String text = getLogContent();
        TextArea area = new TextArea(text, 5, 20);
        Form f = new Form("Log");
        f.setScrollable(false);
        final Form current = Display.getInstance().getCurrent();
        Command back = new Command("Back") {
            public void actionPerformed(ActionEvent ev) {
                current.show();
            }
        };
        f.addCommand(back);
        f.setBackCommand(back);
        f.setLayout(new BorderLayout());
        f.addComponent(BorderLayout.CENTER, area);
        f.show();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 3
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoked internally to set the back command on the form, this method allows subclasses
 * to change the behavior of back command adding or disable it
 * @param f the form
 * @param backCommand the back command 
 */
protected void setBackCommand(Form f, Command backCommand) {
    if(f.getToolbar() != null) {
        f.getToolbar().setBackCommand(backCommand);
    } else {
        if(shouldAddBackCommandToMenu()) {
            f.addCommand(backCommand, f.getCommandCount());
        }
        f.setBackCommand(backCommand);
    }
}
 
Example 4
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Useful tool to refresh the current state of a form shown using show form
 * without pushing another instance to the back stack
 */
public void reloadForm() {
    Form currentForm = Display.getInstance().getCurrent();
    Command backCommand = currentForm.getBackCommand(); 
    Form newForm = (Form)createContainer(fetchResourceFile(), currentForm.getName());
    newForm.setSourceCommand(currentForm.getSourceCommand());
    if (backCommand != null) {
        setBackCommand(newForm, backCommand);

        // trigger listener creation if this is the only command in the form
        getFormListenerInstance(newForm, null);
        
        for(int iter = 0 ; iter < currentForm.getCommandCount() ; iter++) {
            if(backCommand == currentForm.getCommand(iter)) {
                newForm.addCommand(backCommand, newForm.getCommandCount());
                break;
            }
        }
    }
    
    beforeShow(newForm);
    Transition tin = newForm.getTransitionInAnimator();
    Transition tout = newForm.getTransitionOutAnimator();
    currentForm.setTransitionInAnimator(CommonTransitions.createEmpty());
    currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
    newForm.setTransitionInAnimator(CommonTransitions.createEmpty());
    newForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
    newForm.layoutContainer();
    newForm.show();
    postShowImpl(newForm);
    newForm.setTransitionInAnimator(tin);
    newForm.setTransitionOutAnimator(tout);
}
 
Example 5
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));
}
 
Example 6
Source File: MasterDetail.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated this was a half baked idea that made it into the public API
 */
public static void bindTabletLandscapeMaster(final Form rootForm, Container parentContainer, Component landscapeUI, final Component portraitUI, final String commandTitle, Image commandIcon) {
    landscapeUI.setHideInPortrait(true);
    parentContainer.addComponent(BorderLayout.WEST, landscapeUI);

    final Command masterCommand = new Command(commandTitle, commandIcon) {
        public void actionPerformed(ActionEvent ev) {
            Dialog dlg = new Dialog();
            dlg.setLayout(new BorderLayout());
            dlg.setDialogUIID("Container");
            dlg.getContentPane().setUIID("Container");
            Container titleArea = new Container(new BorderLayout());
            dlg.addComponent(BorderLayout.NORTH, titleArea);
            titleArea.setUIID("TitleArea");
            Label title = new Label(commandTitle);
            titleArea.addComponent(BorderLayout.CENTER, title);
            title.setUIID("Title");
            Container body = new Container(new BorderLayout());
            body.setUIID("Form");
            body.addComponent(BorderLayout.CENTER, portraitUI);
            dlg.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 250));
            dlg.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 250));
            dlg.addComponent(BorderLayout.CENTER, body);
            dlg.setDisposeWhenPointerOutOfBounds(true);
            dlg.showStetched(BorderLayout.WEST, true);
            dlg.removeComponent(portraitUI);
        }
    };
    if(Display.getInstance().isPortrait()) {
        if(rootForm.getCommandCount() > 0) {
            rootForm.addCommand(masterCommand, 1);
        } else {
            rootForm.addCommand(masterCommand);                
        }
    }
    rootForm.addOrientationListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if(portraitUI.getParent() != null) {
                Form f = Display.getInstance().getCurrent();
                if(f instanceof Dialog) {
                    ((Dialog)f).dispose();
                }
            }
            if(Display.getInstance().isPortrait()) {
                rootForm.addCommand(masterCommand, 1);
            } else {
                rootForm.removeCommand(masterCommand);
                rootForm.revalidate();
            }
        }
    });        
}