Search in sources :

Example 56 with Command

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

the class MenuBar method calculateTouchCommandGridColumns.

/**
 * Calculates the amount of columns to give to the touch commands within the
 * grid
 *
 * @param grid container that will be arranged in the grid containing the
 * components
 * @return an integer representing the touch command grid size
 */
protected int calculateTouchCommandGridColumns(Container grid) {
    int count = grid.getComponentCount();
    int maxWidth = 10;
    for (int iter = 0; iter < count; iter++) {
        Component c = grid.getComponentAt(iter);
        Style s = c.getUnselectedStyle();
        // bidi doesn't matter since this is just a summary of width
        maxWidth = Math.max(maxWidth, c.getPreferredW() + s.getHorizontalMargins());
    }
    return Math.max(2, Display.getInstance().getDisplayWidth() / maxWidth);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 57 with Command

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

the class MenuBar method addCommand.

/**
 * Add a Command to the MenuBar
 *
 * @param cmd Command to Add
 * @param index determines the order of the added commands
 */
protected void addCommand(Command cmd, int index) {
    if (getCommandCount() == 0 && parent != null) {
        installMenuBar();
    }
    // with the select command
    if (commands.contains(cmd)) {
        return;
    }
    commands.insertElementAt(cmd, index);
    if (!(parent instanceof Dialog)) {
        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 || behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) {
            if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK && cmd == parent.getBackCommand()) {
                return;
            }
            if (behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) {
                return;
            }
            if ((behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_ICS) && parent.getTitle() != null && parent.getTitle().length() > 0) {
                synchronizeCommandsWithButtonsInBackbutton();
                return;
            }
            if (parent.getBackCommand() != cmd) {
                if (behavior != Display.COMMAND_BEHAVIOR_ICS) {
                    setLayout(new GridLayout(1, getComponentCount() + 1));
                    addComponent(Math.min(getComponentCount(), index), createTouchCommandButton(cmd));
                    revalidate();
                }
            } else {
                commands.removeElement(cmd);
            }
            return;
        }
    }
    updateCommands();
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout)

Example 58 with Command

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

the class TextField method createSymbolTable.

/**
 * Creates a symbol table container used by the showSymbolDialog method.
 * This method is designed for subclases to override and customize.
 *
 * @return container for the symbol table.
 */
protected Container createSymbolTable() {
    char[] symbolArray = getSymbolTable();
    Container symbols = new Container(new GridLayout(symbolArray.length / 5, 5));
    int slen = symbolArray.length;
    for (int iter = 0; iter < slen; iter++) {
        Button button = new Button(new Command("" + symbolArray[iter]));
        button.setUIID("VKBButton");
        button.setAlignment(CENTER);
        symbols.addComponent(button);
    }
    return symbols;
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout)

Example 59 with Command

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

the class Toolbar method addComponentToSideMenu.

/**
 * Adds a Component to the side navigation menu. The Component is added to
 * the navigation menu and the command gets the events once the Component is
 * being pressed.
 *
 * @param cmp c Component to be added to the menu
 * @param cmd a Command to handle the events
 */
public void addComponentToSideMenu(Component cmp, Command cmd) {
    checkIfInitialized();
    if (permanentSideMenu) {
        constructPermanentSideMenu();
        Container cnt = new Container(new BorderLayout());
        cnt.addComponent(BorderLayout.CENTER, cmp);
        Button btn = new Button(cmd);
        btn.setParent(cnt);
        cnt.setLeadComponent(btn);
        addComponentToSideMenu(permanentSideMenuContainer, cnt);
    } else {
        if (onTopSideMenu) {
            constructOnTopSideMenu();
            Container cnt = new Container(new BorderLayout());
            cnt.addComponent(BorderLayout.CENTER, cmp);
            Button btn = new Button(cmd);
            btn.setParent(cnt);
            cnt.setLeadComponent(btn);
            addComponentToSideMenu(permanentSideMenuContainer, cnt);
        } else {
            cmd.putClientProperty(SideMenuBar.COMMAND_SIDE_COMPONENT, cmp);
            cmd.putClientProperty(SideMenuBar.COMMAND_ACTIONABLE, Boolean.TRUE);
            sideMenu.addCommand(cmd);
            sideMenu.installMenuBar();
        }
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 60 with Command

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

the class Toolbar method showOverflowMenu.

/*
     * A Overflow Menu is implemented as a dialog, this method allows you to 
     * override the dialog display in order to customize the dialog menu in 
     * various ways
     * 
     * @param menu a dialog containing Overflow Menu options that can be 
     * customized
     * @return the command selected by the user in the dialog
     */
protected Command showOverflowMenu(Dialog menu) {
    Form parent = sideMenu.getParentForm();
    int height;
    int marginLeft;
    int marginRight = 0;
    Container dialogContentPane = menu.getDialogComponent();
    marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
    marginLeft = Math.max(0, marginLeft);
    if (parent.getSoftButtonCount() > 1) {
        height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
    } else {
        height = parent.getHeight() - dialogContentPane.getPreferredH();
    }
    height = Math.max(0, height);
    int th = getHeight();
    Transition transitionIn;
    Transition transitionOut;
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        if (transitionIn instanceof BubbleTransition) {
            ((BubbleTransition) transitionIn).setComponentName("OverflowButton");
        }
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createEmpty();
        transitionOut = CommonTransitions.createEmpty();
    }
    menu.setTransitionInAnimator(transitionIn);
    menu.setTransitionOutAnimator(transitionOut);
    if (isRTL()) {
        marginRight = marginLeft;
        marginLeft = 0;
    }
    int tint = parent.getTintColor();
    parent.setTintColor(0x00FFFFFF);
    parent.tint = false;
    boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
    int topPadding = 0;
    Component statusBar = ((BorderLayout) getLayout()).getNorth();
    if (statusBar != null) {
        topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
    }
    if (showBelowTitle) {
        topPadding = th;
    }
    Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
    parent.setTintColor(tint);
    return r;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Transition(com.codename1.ui.animations.Transition) BubbleTransition(com.codename1.ui.animations.BubbleTransition) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel) BubbleTransition(com.codename1.ui.animations.BubbleTransition)

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