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

The following examples show how to use com.codename1.ui.Form#getToolbar() . 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: AddComponentToRightBarSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Toolbar toolbar = hi.getToolbar();
    Command cmd = toolbar.addCommandToRightBar("Test", null, evt->{
        System.out.println("Hello");
    });
    
    Component cmp = toolbar.findCommandComponent(cmd);
    cmp.getParent().replace(cmp, new Button("Replaced cmp"), null);
    System.out.println("Command component: "+cmp);
    
    
    hi.add(new Label("Hi World"));
    hi.show();
}
 
Example 2
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 3
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns all the command objects from the toolbar in the order of left, right, overflow & sidemenu
 * @return the set of commands
 */
public static Command[] getToolbarCommands() {
    Form f = Display.getInstance().getCurrent();
    Toolbar tb = f.getToolbar();
    ArrayList<Command> result = new ArrayList<Command>();
    addAllCommands(tb.getLeftBarCommands(), result);
    addAllCommands(tb.getRightBarCommands(), result);
    addAllCommands(tb.getOverflowCommands(), result);
    addAllCommands(tb.getSideMenuCommands(), result);
    Command[] carr = new Command[result.size()];
    result.toArray(carr);
    return carr;
}
 
Example 4
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Shows the sidemenu UI
 */
public static void showSidemenu() {
    Form f = Display.getInstance().getCurrent();
    Toolbar tb = f.getToolbar();
    if(tb != null) {
        tb.openSideMenu();
    } else {
        ((SideMenuBar)f.getMenuBar()).openMenu(null);
    }
}
 
Example 5
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private static String getFormTitle(Form f) {
    if(f.getToolbar() != null) {
        Component c = f.getToolbar().getTitleComponent();
        if(c instanceof Label) {
            return ((Label)c).getText();
        }
        return null;
    } else {
        return f.getTitle();
    }
}
 
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));
}