Search in sources :

Example 21 with Label

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

the class ComponentSelector method parent.

/**
 * Creates a new set of components consisting of all of the parents of components in this set.
 * Only parent components matching the provided selector will be included in the set.
 * @param selector Selector to filter the parent components.
 * @return New set with parents of elements in current set.
 */
public ComponentSelector parent(String selector) {
    ComponentSelector matcher = new ComponentSelector(selector, new Label());
    HashSet<Component> matches = new HashSet<Component>();
    for (Component c : this) {
        Component parent = c.getParent();
        if (parent != null && matcher.match(parent)) {
            matches.add(parent);
        }
    }
    return matcher.addAll(matches, true);
}
Also used : SpanLabel(com.codename1.components.SpanLabel) HashSet(java.util.HashSet)

Example 22 with Label

use of com.codename1.ui.Label 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 each label as the icon's foreground color.
 * @param materialIcon The icon charcode.
 * @param size The size of the icon (in mm)
 * @return Self for chaining
 * @see FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
 */
public ComponentSelector setIcon(char materialIcon, float size) {
    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, size));
            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, size));
            }
        }
    }
    return this;
}
Also used : SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) Style(com.codename1.ui.plaf.Style)

Example 23 with Label

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

the class ComponentSelector method parents.

/**
 * Creates new set of components consisting of all of the ancestors of components in this set which
 * match the provided selector.
 * @param selector The selector to filter the ancestors.
 * @return New set with ancestors of elements in current set.
 */
public ComponentSelector parents(String selector) {
    ComponentSelector matcher = new ComponentSelector(selector, new Label());
    HashSet<Component> matches = new HashSet<Component>();
    for (Component c : this) {
        Component parent = c.getParent();
        while (parent != null) {
            if (matcher.match(parent)) {
                matches.add(parent);
            }
            parent = parent.getParent();
        }
    }
    return matcher.addAll(matches, true);
}
Also used : SpanLabel(com.codename1.components.SpanLabel) HashSet(java.util.HashSet)

Example 24 with Label

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

the class ComponentSelector method closest.

/**
 * Creates a new set of components consistng of all "closest" ancestors of components
 * in this set which match the provided selector.
 * @param selector The selector to use to match the nearest ancestor.
 * @return New set with ancestors of components in current set.
 */
public ComponentSelector closest(String selector) {
    ComponentSelector matcher = new ComponentSelector(selector, new Label());
    HashSet<Component> matches = new HashSet<Component>();
    for (Component c : this) {
        Component parent = c.getParent();
        while (parent != null) {
            if (matcher.match(parent)) {
                matches.add(parent);
                break;
            }
            parent = parent.getParent();
        }
    }
    return matcher.addAll(matches, true);
}
Also used : SpanLabel(com.codename1.components.SpanLabel) HashSet(java.util.HashSet)

Example 25 with Label

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

the class Dialog method show.

/**
 * Shows a modal dialog with the given component as its "body" placed in the
 * center.
 *
 * @param title title for the dialog
 * @param body component placed in the center of the dialog
 * @param defaultCommand command to be assigned as the default command or null
 * @param cmds commands that are added to the form any click on any command
 * will dispose the form
 * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO,
 * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM
 * @param icon the icon for the dialog, can be null
 * @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used
 * @param transition the transition installed when the dialog enters/leaves
 * @return the command pressed by the user
 */
public static Command show(String title, Component body, Command defaultCommand, Command[] cmds, int type, Image icon, long timeout, Transition transition) {
    Dialog dialog = new Dialog(title);
    dialog.dialogType = type;
    dialog.setTransitionInAnimator(transition);
    dialog.setTransitionOutAnimator(transition);
    dialog.lastCommandPressed = null;
    dialog.setLayout(new BorderLayout());
    if (cmds != null) {
        if (commandsAsButtons) {
            dialog.placeButtonCommands(cmds);
        } else {
            for (int iter = 0; iter < cmds.length; iter++) {
                dialog.addCommand(cmds[iter]);
            }
        }
        // maps the first command to back
        if (cmds.length == 1 || cmds.length == 2) {
            dialog.setBackCommand(cmds[0]);
        }
    }
    if (defaultCommand != null) {
        dialog.setDefaultCommand(defaultCommand);
    }
    dialog.addComponent(BorderLayout.CENTER, body);
    if (icon != null) {
        dialog.addComponent(BorderLayout.EAST, new Label(icon));
    }
    if (timeout != 0) {
        dialog.setTimeout(timeout);
    }
    if (body.isScrollable() || disableStaticDialogScrolling) {
        dialog.setScrollable(false);
    }
    dialog.show();
    return dialog.lastCommandPressed;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Aggregations

Label (com.codename1.ui.Label)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)22 Container (com.codename1.ui.Container)21 Component (com.codename1.ui.Component)16 Form (com.codename1.ui.Form)15 Button (com.codename1.ui.Button)14 TextArea (com.codename1.ui.TextArea)14 Style (com.codename1.ui.plaf.Style)13 ActionListener (com.codename1.ui.events.ActionListener)12 ActionEvent (com.codename1.ui.events.ActionEvent)11 Image (com.codename1.ui.Image)10 Dimension (com.codename1.ui.geom.Dimension)10 Vector (java.util.Vector)10 BoxLayout (com.codename1.ui.layouts.BoxLayout)9 EncodedImage (com.codename1.ui.EncodedImage)8 RadioButton (com.codename1.ui.RadioButton)7 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Hashtable (java.util.Hashtable)6 Paint (com.codename1.charts.compat.Paint)5 Font (com.codename1.ui.Font)5