Search in sources :

Example 31 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class MenuBar method createMenuSelectCommand.

/**
 * Factory method that returns the Form Menu select Command.
 * This method can be overridden to customize the Command on the Form.
 *
 * @return Command
 */
protected Command createMenuSelectCommand() {
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    return new Command(manager.localize("select", "Select"), lf.getMenuIcons()[0]);
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel)

Example 32 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class DefaultCrashReporter method exception.

/**
 * {@inheritDoc}
 */
public void exception(Throwable t) {
    Preferences.set("$CN1_pendingCrash", true);
    if (promptUser) {
        Dialog error = new Dialog("Error");
        error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        TextArea txt = new TextArea(errorText);
        txt.setEditable(false);
        txt.setUIID("DialogBody");
        error.addComponent(txt);
        CheckBox cb = new CheckBox(checkboxText);
        cb.setUIID("DialogBody");
        error.addComponent(cb);
        Container grid = new Container(new GridLayout(1, 2));
        error.addComponent(grid);
        Command ok = new Command(sendButtonText);
        Command dont = new Command(dontSendButtonText);
        Button send = new Button(ok);
        Button dontSend = new Button(dont);
        grid.addComponent(send);
        grid.addComponent(dontSend);
        Command result = error.showPacked(BorderLayout.CENTER, true);
        if (result == dont) {
            if (cb.isSelected()) {
                Preferences.set("$CN1_crashBlocked", true);
            }
            Preferences.set("$CN1_pendingCrash", false);
            return;
        } else {
            if (cb.isSelected()) {
                Preferences.set("$CN1_prompt", false);
            }
        }
    }
    Log.sendLog();
    Preferences.set("$CN1_pendingCrash", false);
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) TextArea(com.codename1.ui.TextArea) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) Dialog(com.codename1.ui.Dialog) CheckBox(com.codename1.ui.CheckBox) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 33 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class EmailShare method share.

/**
 * {@inheritDoc}
 */
public void share(final String toShare, final String image, final String mimeType) {
    final Form currentForm = Display.getInstance().getCurrent();
    final Form contactsForm = new Form("Contacts");
    contactsForm.setLayout(new BorderLayout());
    contactsForm.setScrollable(false);
    contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
    contactsForm.show();
    Display.getInstance().startThread(new Runnable() {

        public void run() {
            String[] ids = ContactsManager.getAllContacts();
            if (ids == null || ids.length == 0) {
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
                        currentForm.showBack();
                    }
                });
                return;
            }
            ContactsModel model = new ContactsModel(ids);
            final List contacts = new List(model);
            contacts.setRenderer(createListRenderer());
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    contacts.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent evt) {
                            final ShareForm[] f = new ShareForm[1];
                            Hashtable contact = (Hashtable) contacts.getSelectedItem();
                            if (image == null) {
                                f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, new ActionListener() {

                                    public void actionPerformed(ActionEvent evt) {
                                        String[] recieptents = new String[1];
                                        recieptents[0] = f[0].getTo();
                                        Message msg = new Message(toShare);
                                        Message.sendMessage(recieptents, "share", msg);
                                        finish();
                                    }
                                });
                                f[0].show();
                            } else {
                                f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, image, new ActionListener() {

                                    public void actionPerformed(ActionEvent evt) {
                                        String[] recieptents = new String[1];
                                        recieptents[0] = f[0].getTo();
                                        Message msg = new Message(toShare);
                                        msg.setAttachment(image);
                                        msg.setMimeType(mimeType);
                                        Message.sendMessage(recieptents, "share", msg);
                                        finish();
                                    }
                                });
                                f[0].show();
                            }
                        }
                    });
                    contactsForm.addComponent(BorderLayout.CENTER, contacts);
                    Command back = new Command("Back") {

                        public void actionPerformed(ActionEvent evt) {
                            currentForm.showBack();
                        }
                    };
                    contactsForm.addCommand(back);
                    contactsForm.setBackCommand(back);
                    contactsForm.revalidate();
                }
            });
        }
    }, "Email Thread").start();
}
Also used : Message(com.codename1.messaging.Message) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ContactsModel(com.codename1.contacts.ContactsModel)

Example 34 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class TestUtils method executeToolbarCommandAtOffset.

/**
 * Executes a command from the offset returned by {@link #getToolbarCommands()}
 *
 * @param offset the offset of the command we want to execute
 */
public static void executeToolbarCommandAtOffset(final int offset) {
    Form f = Display.getInstance().getCurrent();
    if (!Display.getInstance().isEdt()) {
        Display.getInstance().callSerially(new Runnable() {

            public void run() {
                executeToolbarCommandAtOffset(offset);
            }
        });
        return;
    }
    Command cmd = getToolbarCommands()[offset];
    f.dispatchCommand(cmd, new ActionEvent(cmd));
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 35 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class TestComponent method testNestedScrollingLabels.

private void testNestedScrollingLabels() {
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("Scrolling Labels");
    Toolbar tb = new Toolbar();
    f.setToolbar(tb);
    final Form backForm = Display.getInstance().getCurrent();
    tb.addCommandToSideMenu(new Command("Back") {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (backForm != null) {
                backForm.showBack();
            }
        }
    });
    f.setTitle("Scrolling Labels");
    Container cnt = new Container(BoxLayout.y());
    cnt.setScrollableY(true);
    for (String l : new String[] { "Red", "Green", "Blue", "Orange", "Indigo" }) {
        for (int i = 0; i < 20; i++) {
            cnt.add(l + i);
        }
    }
    f.setLayout(new BorderLayout());
    f.add(BorderLayout.CENTER, LayeredLayout.encloseIn(new Button("Press me"), BorderLayout.center(BorderLayout.center(cnt))));
    f.show();
    TestUtils.waitForFormTitle("Scrolling Labels", 2000);
    Component res = f.getComponentAt(w / 2, h / 2);
    assertTrue(res == cnt || res.getParent() == cnt, "getComponentAt(x,y) should return scrollable container on top of button when in layered pane.");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)25 Command (com.codename1.ui.Command)24 ActionEvent (com.codename1.ui.events.ActionEvent)22 Form (com.codename1.ui.Form)20 Hashtable (java.util.Hashtable)13 UIManager (com.codename1.ui.plaf.UIManager)11 Container (com.codename1.ui.Container)10 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)9 Button (com.codename1.ui.Button)8 Style (com.codename1.ui.plaf.Style)8 IOException (java.io.IOException)7 Vector (java.util.Vector)7 Component (com.codename1.ui.Component)6 Dialog (com.codename1.ui.Dialog)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ArrayList (java.util.ArrayList)6 RadioButton (com.codename1.ui.RadioButton)5 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)5 CheckBox (com.codename1.ui.CheckBox)4