Search in sources :

Example 56 with Container

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

the class MenuBar method updateTitleCommandPlacement.

private void updateTitleCommandPlacement() {
    int commandBehavior = getCommandBehavior();
    Container t = getTitleAreaContainer();
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    if (getParent() == null) {
        installMenuBar();
    } else {
        if (getParent() == getTitleAreaContainer() && commandBehavior != Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT && commandBehavior != Display.COMMAND_BEHAVIOR_ICS) {
            getParent().removeComponent(this);
            installMenuBar();
        }
    }
    if (!(parent instanceof Dialog)) {
        if ((commandBehavior == Display.COMMAND_BEHAVIOR_ICS || commandBehavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) && parent.getTitle() != null && parent.getTitle().length() > 0) {
            synchronizeCommandsWithButtonsInBackbutton();
            return;
        } else {
            if (commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) {
                if (getParent() != null) {
                    if (getParent() == getTitleAreaContainer()) {
                        return;
                    }
                    getParent().removeComponent(this);
                }
                // getTitleAreaContainer().addComponent(BorderLayout.EAST, findRightTitleContainer());
                return;
            }
        }
    }
    if (t.getComponentCount() - componentCountOffset(t) > 1) {
        if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
            titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        } else {
            titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
        }
        Component l = getTitleComponent();
        if (l.getParent() != null) {
            l.getParent().removeComponent(l);
        }
        t.removeAll();
        t.addComponent(BorderLayout.CENTER, l);
        initTitleBarStatus();
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 57 with Container

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

the class MenuBar method actionPerformed.

/**
 * Invoked when a softbutton is pressed
 */
public void actionPerformed(ActionEvent evt) {
    if (evt.isConsumed()) {
        return;
    }
    Object src = evt.getSource();
    if (commandList == null) {
        Button source = (Button) src;
        for (int iter = 0; iter < soft.length; iter++) {
            if (source == soft[iter]) {
                if (softCommand[iter] == menuCommand) {
                    showMenu();
                    return;
                }
                if (softCommand[iter] != null) {
                    ActionEvent e = new ActionEvent(softCommand[iter], ActionEvent.Type.Command);
                    softCommand[iter].actionPerformed(e);
                    if (!e.isConsumed()) {
                        parent.actionCommandImpl(softCommand[iter]);
                    }
                }
                return;
            }
        }
    } else {
        // the list for the menu sent the event
        if (src instanceof Button) {
            for (int iter = 0; iter < soft.length; iter++) {
                if (src == soft[iter]) {
                    Container parent = commandList.getParent();
                    while (parent != null) {
                        if (parent instanceof Dialog) {
                            ((Dialog) parent).actionCommand(softCommand[iter]);
                            return;
                        }
                        parent = parent.getParent();
                    }
                }
            }
        }
        Command c = getComponentSelectedCommand(commandList);
        if (!c.isEnabled()) {
            return;
        }
        Container p = commandList.getParent();
        while (p != null) {
            if (p instanceof Dialog) {
                ((Dialog) p).actionCommand(c);
                return;
            }
            p = p.getParent();
        }
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 58 with Container

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

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

use of com.codename1.ui.Container 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

Container (com.codename1.ui.Container)85 Component (com.codename1.ui.Component)65 BorderLayout (com.codename1.ui.layouts.BorderLayout)46 Style (com.codename1.ui.plaf.Style)38 ActionEvent (com.codename1.ui.events.ActionEvent)29 Form (com.codename1.ui.Form)26 Label (com.codename1.ui.Label)21 BoxLayout (com.codename1.ui.layouts.BoxLayout)21 Dimension (com.codename1.ui.geom.Dimension)20 ActionListener (com.codename1.ui.events.ActionListener)19 Button (com.codename1.ui.Button)15 FlowLayout (com.codename1.ui.layouts.FlowLayout)15 ArrayList (java.util.ArrayList)14 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)12 TextArea (com.codename1.ui.TextArea)11 Point (com.codename1.ui.geom.Point)11 Rectangle (com.codename1.ui.geom.Rectangle)11 Dialog (com.codename1.ui.Dialog)10 RadioButton (com.codename1.ui.RadioButton)10 Vector (java.util.Vector)9