Search in sources :

Example 11 with ComponentSelector

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

the class ComponentSelector method setMargin.

/**
 * Sets margin to all components in found set.
 * @param top Top margin in pixels.
 * @param right Right margin in pixels
 * @param bottom Bottom margin in pixels.
 * @param left Left margin in pixels.
 * @return
 * @see #getStyle(com.codename1.ui.Component)
 */
public ComponentSelector setMargin(int top, int right, int bottom, int left) {
    Style s = currentStyle();
    s.setMarginUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
    s.setMargin(top, bottom, left, right);
    return this;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 12 with ComponentSelector

use of com.codename1.ui.ComponentSelector 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 13 with ComponentSelector

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

the class ComponentSelector method setFontSize.

/**
 * Sets the font size of all components in found set.  In pixels.
 * @param size Font size in pixels.
 * @return
 * @see #getStyle(com.codename1.ui.Component)
 */
public ComponentSelector setFontSize(float size) {
    for (Component c : this) {
        Style style = getStyle(c);
        Font curr = style.getFont();
        if (curr == null || !curr.isTTFNativeFont()) {
            curr = c.getStyle().getFont();
        }
        if (curr == null || !curr.isTTFNativeFont()) {
            Component parent = c.getParent();
            while (parent != null && (curr == null || !curr.isTTFNativeFont())) {
                curr = parent.getStyle().getFont();
                parent = parent.getParent();
            }
        }
        if (curr == null || !curr.isTTFNativeFont()) {
            curr = Font.create("native:MainRegular");
        }
        if (curr != null && curr.isTTFNativeFont()) {
            curr = curr.derive(size, 0);
            style.setFont(curr);
        }
    }
    return this;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 14 with ComponentSelector

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

the class ComponentSelector method filter.

/**
 * Filters the current found set against the given selector.
 * @param selector The selector to filter the found set on.
 * @return A new set of elements matching the selector.
 */
public ComponentSelector filter(String selector) {
    ComponentSelector matcher = new ComponentSelector(selector, new Label());
    LinkedHashSet<Component> matches = new LinkedHashSet<Component>();
    for (Component c : this) {
        if (matcher.match(c)) {
            matches.add(c);
        }
    }
    return matcher.addAll(matches, true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SpanLabel(com.codename1.components.SpanLabel)

Example 15 with ComponentSelector

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

the class ComponentSelector method animateStyle.

/**
 * Animates this set of components, replacing any modified style properties of the
 * destination style to the components.
 * @param destStyle The style to apply to the components via animation.
 * @param duration The duration of the animation (ms)
 * @param callback Callback to call after animation is complete.
 * @return Self for chaining
 * @see Component#createStyleAnimation(java.lang.String, int)
 */
public ComponentSelector animateStyle(Style destStyle, int duration, final SuccessCallback<ComponentSelector> callback) {
    ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
    AnimationManager mgr = null;
    for (Component c : this) {
        AnimationManager cmgr = c.getAnimationManager();
        if (cmgr != null) {
            mgr = cmgr;
            Style sourceStyle = c.getUnselectedStyle();
            destStyle.merge(sourceStyle);
            animations.add(c.createStyleAnimation(sourceStyle, destStyle, duration, null));
        }
    }
    if (mgr != null) {
        ComponentAnimation anim = ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()]));
        mgr.addAnimation(anim, new Runnable() {

            public void run() {
                if (callback != null) {
                    callback.onSucess(ComponentSelector.this);
                }
            }
        });
    }
    return this;
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) ArrayList(java.util.ArrayList) Style(com.codename1.ui.plaf.Style)

Aggregations

Style (com.codename1.ui.plaf.Style)10 SpanLabel (com.codename1.components.SpanLabel)6 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)5 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)4 SpanButton (com.codename1.components.SpanButton)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 CollapsibleHeaderContainer (ca.weblite.shared.components.CollapsibleHeaderContainer)1 Button (com.codename1.ui.Button)1 Component (com.codename1.ui.Component)1 ComponentSelector (com.codename1.ui.ComponentSelector)1 Container (com.codename1.ui.Container)1 Form (com.codename1.ui.Form)1 Label (com.codename1.ui.Label)1