Search in sources :

Example 46 with Button

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

the class OnOffSwitch method initialize.

private void initialize() {
    iosMode = UIManager.getInstance().isThemeConstant("onOffIOSModeBool", false);
    removeAll();
    setFocusable(true);
    if (iosMode) {
        button = null;
        switchMaskImage = UIManager.getInstance().getThemeImageConstant("switchMaskImage");
        switchOnImage = UIManager.getInstance().getThemeImageConstant("switchOnImage");
        switchOffImage = UIManager.getInstance().getThemeImageConstant("switchOffImage");
        noTextMode = UIManager.getInstance().isThemeConstant("noTextModeBool", false);
    } else {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        button = new CheckBox(on);
        button.setToggle(true);
        button.setUIID("Button");
        button.setEndsWith3Points(false);
        button.getUnselectedStyle().setFont(getUnselectedStyle().getFont());
        button.getSelectedStyle().setFont(getSelectedStyle().getFont());
        button.getPressedStyle().setFont(getSelectedStyle().getFont());
        Dimension d = button.getPreferredSize();
        button.setText(off);
        int pw = button.getPreferredW();
        d.setWidth(Math.max(pw, d.getWidth()));
        // prevents the button from growing/shrinking as its states flip
        button.setPreferredSize(d);
        buttonWidth = button.getPreferredW();
        button.setFocusable(false);
        updateButton();
        addComponent(button);
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                flip();
            }
        });
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) CheckBox(com.codename1.ui.CheckBox) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Dimension(com.codename1.ui.geom.Dimension)

Example 47 with Button

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

the class Progress method actionCommand.

/**
 * {@inheritDoc}
 */
protected void actionCommand(Command cmd) {
    if (Display.getInstance().isTouchScreenDevice() || getSoftButtonCount() < 2) {
        for (int iter = 0; iter < getComponentCount(); iter++) {
            Component c = getComponentAt(iter);
            if (c instanceof Button) {
                c.setEnabled(false);
            }
        }
    } else {
        removeAllCommands();
    }
    // cancel was pressed
    request.kill();
    dispose();
}
Also used : Button(com.codename1.ui.Button) Component(com.codename1.ui.Component)

Example 48 with Button

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

the class FloatingActionButton method bindFabToContainer.

/**
 * This is a utility method to bind the FAB to a given Container, it will return a new container to add or will
 * use the layered pane if the container is a content pane.
 *
 * @param cnt the Container to add the FAB to
 * @param orientation one of Component.RIGHT/LEFT/CENTER
 * @param valign one of Component.TOP/BOTTOM/CENTER
 *
 * @return a new Container that contains the cnt and the FAB on top or null in the case of a content pane
 */
public Container bindFabToContainer(Component cnt, int orientation, int valign) {
    FlowLayout flow = new FlowLayout(orientation);
    flow.setValign(valign);
    Form f = cnt.getComponentForm();
    if (f != null && (f.getContentPane() == cnt || f == cnt)) {
        // special case for content pane installs the button directly on the content pane
        Container layers = f.getLayeredPane(getClass(), true);
        layers.setLayout(flow);
        layers.add(this);
        return null;
    }
    Container conUpper = new Container(flow);
    conUpper.add(this);
    return LayeredLayout.encloseIn(cnt, conUpper);
}
Also used : Container(com.codename1.ui.Container) FlowLayout(com.codename1.ui.layouts.FlowLayout) Form(com.codename1.ui.Form)

Example 49 with Button

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

the class ClearableTextField method wrap.

/**
 * Wraps the given text field with a UI that will allow us to clear it
 * @param tf the text field
 * @param iconSize size in millimeters for the clear icon, -1 for default size
 * @return a Container that should be added to the UI instead of the actual text field
 */
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
    ClearableTextField cf = new ClearableTextField();
    Button b = new Button("", tf.getUIID());
    if (iconSize > 0) {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
    } else {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
    }
    removeCmpBackground(tf);
    removeCmpBackground(b);
    cf.setUIID(tf.getUIID());
    cf.add(BorderLayout.CENTER, tf);
    cf.add(BorderLayout.EAST, b);
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            tf.stopEditing();
            tf.setText("");
            tf.startEditingAsync();
        }
    });
    return cf;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 50 with Button

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

the class DefaultLookAndFeel method getCheckBoxPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getCheckBoxPreferredSize(Button cb) {
    if (cb.isToggle()) {
        return getButtonPreferredSize(cb);
    }
    threeImageCache[0] = cb.getMaskedIcon();
    threeImageCache[1] = cb.getRolloverIcon();
    threeImageCache[2] = cb.getPressedIcon();
    if (chkBoxImages != null) {
        return getPreferredSize(cb, threeImageCache, chkBoxImages[0]);
    }
    Dimension d = getPreferredSize(cb, threeImageCache, null);
    // checkbox square needs to be the height and width of the font height even
    // when no text is in the check box this is a good indication of phone DPI
    int checkBoxSquareSize = cb.getStyle().getFont().getHeight();
    // allow for checkboxes without a string within them
    d.setHeight(Math.max(checkBoxSquareSize, d.getHeight()));
    d.setWidth(d.getWidth() + checkBoxSquareSize + cb.getGap());
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

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