Search in sources :

Example 71 with Button

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

the class HTMLForm method reset.

/**
 * Called when a form reset is needed and resets all the form fields to their default values.
 */
void reset() {
    for (Enumeration e = defaultValues.keys(); e.hasMoreElements(); ) {
        Object input = e.nextElement();
        if (input instanceof TextArea) {
            // catches both textareas and text input fields
            String defVal = (String) defaultValues.get(input);
            if (defVal == null) {
                defVal = "";
            }
            ((TextArea) input).setText(defVal);
        } else if (input instanceof ComboBox) {
            OptionItem defVal = (OptionItem) defaultValues.get(input);
            ComboBox combo = ((ComboBox) input);
            if (defVal != null) {
                combo.setSelectedItem(defVal);
            } else if (combo.size() > 0) {
                combo.setSelectedIndex(0);
            }
        }
    }
    for (Enumeration e = defaultCheckedButtons.elements(); e.hasMoreElements(); ) {
        Button b = (Button) e.nextElement();
        if (!b.isSelected()) {
            setButton(b, true);
        }
    }
    for (Enumeration e = defaultUncheckedButtons.elements(); e.hasMoreElements(); ) {
        Button b = (Button) e.nextElement();
        if (b.isSelected()) {
            setButton(b, false);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) TextArea(com.codename1.ui.TextArea) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) ComboBox(com.codename1.ui.ComboBox)

Example 72 with Button

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

the class ComponentSelector method setIcon.

/**
 * Sets the icon of all elements in this set to a material icon.  This will use
 * the foreground color of the label.
 * @param materialIcon The material icon charcode.
 * @return Self for chaining.
 */
public ComponentSelector setIcon(char materialIcon) {
    for (Component c : this) {
        if (c instanceof Label) {
            Label l = (Label) c;
            Style style = new Style();
            Style cStyle = c.getUnselectedStyle();
            style.setBgTransparency(0);
            style.setFgColor(cStyle.getFgColor());
            l.setIcon(FontImage.createMaterial(materialIcon, style, 3));
            if (c instanceof Button) {
                Button b = (Button) c;
                style = new Style();
                cStyle = c.getPressedStyle();
                style.setBgTransparency(0);
                style.setFgColor(cStyle.getFgColor());
                b.setPressedIcon(FontImage.createMaterial(materialIcon, style, 3));
            }
        }
    }
    return this;
}
Also used : SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) Style(com.codename1.ui.plaf.Style)

Example 73 with Button

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

the class Button method pointerReleased.

/**
 * {@inheritDoc}
 */
public void pointerReleased(int x, int y) {
    if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
        ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
        pointerReleasedListeners.fireActionEvent(ev);
        if (ev.isConsumed()) {
            return;
        }
    }
    Form f = getComponentForm();
    // might happen when programmatically triggering press
    if (f != null) {
        if (f.buttonsAwatingRelease != null) {
            f.buttonsAwatingRelease.remove(this);
        }
    }
    // button shouldn't fire an event when a pointer is dragged into it
    if (state == STATE_PRESSED) {
        released(x, y);
    }
    if (restoreDragPercentage > -1) {
        Display.getInstance().setDragStartPercentage(restoreDragPercentage);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 74 with Button

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

the class TestUtils method clickButtonByLabel.

/**
 * Clicks the button with the given label
 * @param text the text on the button
 */
public static void clickButtonByLabel(String text) {
    if (verbose) {
        log("clickButtonByLabel(" + text + ")");
    }
    Button b = (Button) findLabelText(text);
    waitFor(20);
    b.pressed();
    waitFor(20);
    b.released();
    waitFor(20);
}
Also used : Button(com.codename1.ui.Button)

Example 75 with Button

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

the class TestUtils method clickButtonByName.

/**
 * Clicks the button with the given label
 * @param name the name of the button
 */
public static void clickButtonByName(String name) {
    if (verbose) {
        log("clickButtonByName(" + name + ")");
    }
    Button b = (Button) findByName(name);
    waitFor(20);
    b.pressed();
    waitFor(20);
    b.released();
    waitFor(20);
}
Also used : Button(com.codename1.ui.Button)

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