Search in sources :

Example 61 with Button

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

Example 62 with Button

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

the class MenuBar method updateGridCommands.

private void updateGridCommands(int startOffset) {
    int cmdCount = getCommandCount() - startOffset;
    if (cmdCount <= 0 || getCommandBehavior() == Display.COMMAND_BEHAVIOR_ICS) {
        return;
    }
    setLayout(new GridLayout(1, cmdCount));
    while (cmdCount < getComponentCount()) {
        removeComponent(getComponentAt(getComponentCount() - 1));
    }
    int off = startOffset;
    while (getComponentCount() < cmdCount) {
        Button btn = new Button(getCommand(off));
        btn.setUIID("TouchCommand");
        off++;
        addComponent(btn);
    }
    for (int iter = 0; iter < cmdCount; iter++) {
        Button btn = (Button) getComponentAt(iter);
        if (btn.getCommand() != getCommand(iter + startOffset)) {
            btn.setCommand(getCommand(iter + startOffset));
        }
    }
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout)

Example 63 with Button

use of com.codename1.ui.Button 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 64 with Button

use of com.codename1.ui.Button 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 65 with Button

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icon constants) to the given label using the
 * styling of the label. Notice that when the argument is a button the pressed/selected &amp; disabled states
 * will be set appropriately.</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 *
 * @param l a label or subclass (e.g. Button etc.)
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(Label l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
        if (l instanceof Button) {
            Button b = (Button) l;
            Style sel = b.getSelectedStyle();
            Style pre = b.getPressedStyle();
            Style dis = b.getDisabledStyle();
            if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
                sel = new Style(sel);
                sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
                b.setRolloverIcon(FontImage.create("" + icon, sel));
            }
            if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
                pre = new Style(pre);
                pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
                b.setPressedIcon(FontImage.create("" + icon, pre));
                b.setRolloverPressedIcon(FontImage.create("" + icon, pre));
            }
            if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
                dis = new Style(dis);
                dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
                b.setDisabledIcon(FontImage.create("" + icon, dis));
            }
        }
    }
}
Also used : SpanButton(com.codename1.components.SpanButton) MultiButton(com.codename1.components.MultiButton) Style(com.codename1.ui.plaf.Style)

Aggregations

Button (com.codename1.ui.Button)31 BorderLayout (com.codename1.ui.layouts.BorderLayout)25 ActionEvent (com.codename1.ui.events.ActionEvent)21 Container (com.codename1.ui.Container)18 ActionListener (com.codename1.ui.events.ActionListener)17 Component (com.codename1.ui.Component)14 RadioButton (com.codename1.ui.RadioButton)14 Form (com.codename1.ui.Form)12 Label (com.codename1.ui.Label)11 BoxLayout (com.codename1.ui.layouts.BoxLayout)11 TextArea (com.codename1.ui.TextArea)10 Hashtable (java.util.Hashtable)9 Command (com.codename1.ui.Command)8 Image (com.codename1.ui.Image)8 TextField (com.codename1.ui.TextField)8 FlowLayout (com.codename1.ui.layouts.FlowLayout)8 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)8 CheckBox (com.codename1.ui.CheckBox)7 Style (com.codename1.ui.plaf.Style)7