Search in sources :

Example 26 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class MenuBar method adaptTitleLayoutBackCommandStructure.

void adaptTitleLayoutBackCommandStructure() {
    Container t = getTitleAreaContainer();
    if (t.getComponentCount() - componentCountOffset(t) == 3) {
        return;
    }
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
        titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        getTitleComponent().getUnselectedStyle().setAlignment(Component.LEFT, true);
    } else {
        titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    }
    t.removeAll();
    t.addComponent(BorderLayout.CENTER, getTitleComponent());
    Container leftContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    Container rightContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    t.addComponent(BorderLayout.EAST, rightContainer);
    t.addComponent(BorderLayout.WEST, leftContainer);
    initTitleBarStatus();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 27 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout 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 28 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout 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)

Example 29 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_button.

private void getComponentAt_int_int_button() {
    log("Testing getComponentAt(x, y) with button");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Label l = new Button("Hello");
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form");
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 30 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_label.

private void getComponentAt_int_int_label() {
    log("Testing getComponentAt(x, y) with label");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Label l = new Label("Hello");
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form", 2000);
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)64 ActionEvent (com.codename1.ui.events.ActionEvent)27 Container (com.codename1.ui.Container)21 Form (com.codename1.ui.Form)18 ActionListener (com.codename1.ui.events.ActionListener)18 Component (com.codename1.ui.Component)15 BoxLayout (com.codename1.ui.layouts.BoxLayout)14 Label (com.codename1.ui.Label)12 Button (com.codename1.ui.Button)10 IOException (java.io.IOException)9 Dialog (com.codename1.ui.Dialog)8 Hashtable (java.util.Hashtable)8 Command (com.codename1.ui.Command)6 TextArea (com.codename1.ui.TextArea)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Vector (java.util.Vector)6 RadioButton (com.codename1.ui.RadioButton)5 Animation (com.codename1.ui.animations.Animation)4 Style (com.codename1.ui.plaf.Style)4