Search in sources :

Example 56 with Form

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

the class MenuBar method createMenuCancelCommand.

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

Example 57 with Form

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

the class MenuBar method showMenu.

/**
 * This method shows the menu on the Form.
 * The method creates a Dialog with the commands and calls showMenuDialog.
 * The method blocks until the user dispose the dialog.
 */
public void showMenu() {
    final Dialog d = new Dialog("Menu", "");
    d.setDisposeWhenPointerOutOfBounds(true);
    d.setMenu(true);
    d.addOrientationListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            d.dispose();
        }
    });
    d.setTransitionInAnimator(transitionIn);
    d.setTransitionOutAnimator(transitionOut);
    d.setLayout(new BorderLayout());
    d.setScrollable(false);
    // calling parent.createCommandComponent is done only for backward
    // compatability reasons, in the next version this call be replaced with
    // calling directly to createCommandComponent
    ((Form) d).getMenuBar().commandList = createCommandComponent(commands);
    if (menuCellRenderer != null && ((Form) d).getMenuBar().commandList instanceof List) {
        ((List) ((Form) d).getMenuBar().commandList).setListCellRenderer(menuCellRenderer);
    }
    d.getContentPane().getStyle().setMargin(0, 0, 0, 0);
    d.addComponent(BorderLayout.CENTER, ((Form) d).getMenuBar().commandList);
    if (thirdSoftButton) {
        d.addCommand(selectMenuItem);
        d.addCommand(cancelMenuItem);
    } else {
        d.addCommand(cancelMenuItem);
        if (soft.length > 1) {
            d.addCommand(selectMenuItem);
        }
    }
    d.setClearCommand(cancelMenuItem);
    d.setBackCommand(cancelMenuItem);
    if (((Form) d).getMenuBar().commandList instanceof List) {
        ((List) ((Form) d).getMenuBar().commandList).addActionListener(((Form) d).getMenuBar());
    }
    menuDisplaying = true;
    Command result = showMenuDialog(d);
    menuDisplaying = false;
    if (result != cancelMenuItem) {
        Command c = null;
        if (result == selectMenuItem) {
            c = getComponentSelectedCommand(((Form) d).getMenuBar().commandList);
            if (c != null) {
                ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
                c.actionPerformed(e);
            }
        } else {
            c = result;
            // a touch menu will always send its commands on its own...
            if (!isTouchMenus()) {
                c = result;
                if (c != null) {
                    ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
                    c.actionPerformed(e);
                }
            }
        }
        // menu item was handled internally in a touch interface that is not a touch menu
        if (c != null) {
            parent.actionCommandImpl(c);
        }
    }
    if (((Form) d).getMenuBar().commandList instanceof List) {
        ((List) ((Form) d).getMenuBar().commandList).removeActionListener(((Form) d).getMenuBar());
    }
    Form upcoming = Display.getInstance().getCurrentUpcoming();
    if (upcoming == parent) {
        d.disposeImpl();
    } else {
        parent.tint = (upcoming instanceof Dialog);
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 58 with Form

use of com.codename1.ui.Form 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 59 with Form

use of com.codename1.ui.Form 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 60 with Form

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

the class TestUtils method ensureVisible.

/**
 * Scrolls to show the component in case it is invisible currently
 * @param c the component
 */
public static void ensureVisible(Component c) {
    if (verbose) {
        log("ensureVisible(" + c + ")");
    }
    Form f = Display.getInstance().getCurrent();
    f.scrollComponentToVisible(c);
}
Also used : Form(com.codename1.ui.Form)

Aggregations

Form (com.codename1.ui.Form)90 ActionEvent (com.codename1.ui.events.ActionEvent)41 Component (com.codename1.ui.Component)38 BorderLayout (com.codename1.ui.layouts.BorderLayout)38 Container (com.codename1.ui.Container)26 ActionListener (com.codename1.ui.events.ActionListener)25 Dialog (com.codename1.ui.Dialog)21 Command (com.codename1.ui.Command)19 Hashtable (java.util.Hashtable)17 Label (com.codename1.ui.Label)14 Style (com.codename1.ui.plaf.Style)14 IOException (java.io.IOException)14 TextArea (com.codename1.ui.TextArea)13 Vector (java.util.Vector)12 Button (com.codename1.ui.Button)11 Graphics (com.codename1.ui.Graphics)9 RadioButton (com.codename1.ui.RadioButton)9 Animation (com.codename1.ui.animations.Animation)9 Image (com.codename1.ui.Image)8 UIManager (com.codename1.ui.plaf.UIManager)8