Search in sources :

Example 6 with GridLayout

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

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

the class Tabs method setTabsLayout.

private void setTabsLayout(int tabPlacement) {
    if (tabPlacement == TOP || tabPlacement == BOTTOM) {
        if (tabsFillRows) {
            FlowLayout f = new FlowLayout();
            f.setFillRows(true);
            tabsContainer.setLayout(f);
        } else {
            if (tabsGridLayout) {
                tabsContainer.setLayout(new GridLayout(1, Math.max(1, getTabCount())));
            } else {
                tabsContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
            }
        }
        tabsContainer.setScrollableX(true);
        tabsContainer.setScrollableY(false);
    } else {
        // LEFT Or RIGHT
        if (tabsGridLayout) {
            tabsContainer.setLayout(new GridLayout(Math.max(1, getTabCount()), 1));
        } else {
            tabsContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        }
        tabsContainer.setScrollableX(false);
        tabsContainer.setScrollableY(true);
    }
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 8 with GridLayout

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

the class MenuBar method initMenuBar.

/**
 * Initialize the MenuBar
 *
 * @param parent the associated Form
 */
protected void initMenuBar(Form parent) {
    this.parent = parent;
    selectMenuItem = createMenuSelectCommand();
    cancelMenuItem = createMenuCancelCommand();
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    // don't minimize the app if it's a Dialog
    minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
    hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
    menuStyle = manager.getComponentStyle("Menu");
    setUIID("SoftButton");
    menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
    // use the slide transition by default
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
        transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
    }
    menuCellRenderer = lf.getMenuRenderer();
    int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
    thirdSoftButton = Display.getInstance().isThirdSoftButton();
    int commandBehavior = getCommandBehavior();
    if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(main);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(main);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            setLayout(new GridLayout(1, 2));
            soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[0];
            right = soft[1];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[0];
                soft[0] = soft[1];
                soft[1] = b;
            }
        }
        // It doesn't make sense for softbuttons to have ... at the end
        for (int iter = 0; iter < soft.length; iter++) {
            soft[iter].setEndsWith3Points(false);
        }
    } else {
        // special case for touch screens we still want the 3 softbutton areas...
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            addComponent(left);
            addComponent(main);
            addComponent(right);
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            soft = new Button[] { createSoftButton("SoftButtonCenter") };
        }
    }
    softCommand = new Command[soft.length];
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel)

Example 9 with GridLayout

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

the class MenuBar method createCommandComponent.

/**
 * Creates the component containing the commands within the given vector
 * used for showing the menu dialog, this method calls the createCommandList
 * method by default however it allows more elaborate menu creation.
 *
 * @param commands list of command objects
 * @return Component that will result in the parent menu dialog recieving a command event
 */
protected Component createCommandComponent(Vector commands) {
    UIManager manager = parent.getUIManager();
    // Create a touch based menu interface
    if (manager.getLookAndFeel().isTouchMenus()) {
        Container menu = new Container();
        menu.setScrollableY(true);
        for (int iter = 0; iter < commands.size(); iter++) {
            Command c = (Command) commands.elementAt(iter);
            menu.addComponent(createTouchCommandButton(c));
        }
        if (!manager.isThemeConstant("touchCommandFlowBool", false)) {
            int cols = calculateTouchCommandGridColumns(menu);
            if (cols > getCommandCount()) {
                cols = getCommandCount();
            }
            int rows = Math.max(1, getCommandCount() / cols + (getCommandCount() % cols != 0 ? 1 : 0));
            if (rows > 1) {
                // try to prevent too many columns concentraiting within a single row
                int remainingColumns = (rows * cols) % getCommandCount();
                int newCols = cols;
                int newRows = rows;
                while (remainingColumns != 0 && remainingColumns > 1 && newCols >= 2) {
                    newCols--;
                    newRows = Math.max(1, getCommandCount() / newCols + (getCommandCount() % newCols != 0 ? 1 : 0));
                    if (newRows != rows) {
                        break;
                    }
                    remainingColumns = (newRows * newCols) % getCommandCount();
                }
                if (newRows == rows) {
                    cols = newCols;
                    rows = newRows;
                }
            }
            GridLayout g = new GridLayout(rows, cols);
            g.setFillLastRow(manager.isThemeConstant("touchCommandFillBool", true));
            menu.setLayout(g);
        } else {
            ((FlowLayout) menu.getLayout()).setFillRows(true);
        }
        menu.setPreferredW(Display.getInstance().getDisplayWidth());
        return menu;
    }
    return createCommandList(commands);
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) UIManager(com.codename1.ui.plaf.UIManager)

Example 10 with GridLayout

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

the class MenuBar method removeCommand.

/**
 * Removes a Command from the MenuBar
 *
 * @param cmd Command to remove
 */
protected void removeCommand(Command cmd) {
    int behavior = getCommandBehavior();
    if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR || behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || behavior == Display.COMMAND_BEHAVIOR_ICS) {
        int i = commands.indexOf(cmd);
        if (i > -1) {
            commands.removeElementAt(i);
            Button b = findCommandComponent(cmd);
            if (b != null && b.getParent() != null) {
                b.getParent().removeComponent(b);
            }
            if (getCommandCount() > 0) {
                setLayout(new GridLayout(1, getCommandCount()));
            }
        }
        return;
    }
    commands.removeElement(cmd);
    updateCommands();
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout)

Aggregations

GridLayout (com.codename1.ui.layouts.GridLayout)13 FlowLayout (com.codename1.ui.layouts.FlowLayout)5 CheckBox (com.codename1.ui.CheckBox)4 Container (com.codename1.ui.Container)4 BoxLayout (com.codename1.ui.layouts.BoxLayout)4 TableLayout (com.codename1.ui.table.TableLayout)4 Button (com.codename1.ui.Button)3 Component (com.codename1.ui.Component)3 Dialog (com.codename1.ui.Dialog)3 RadioButton (com.codename1.ui.RadioButton)3 TextArea (com.codename1.ui.TextArea)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 ArrayList (java.util.ArrayList)3 Command (com.codename1.ui.Command)2 Form (com.codename1.ui.Form)2 Label (com.codename1.ui.Label)2 List (com.codename1.ui.List)2 Slider (com.codename1.ui.Slider)2 Tabs (com.codename1.ui.Tabs)2 TextField (com.codename1.ui.TextField)2