Search in sources :

Example 1 with ComponentSelector.$

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

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

the class ComponentSelector method setPadding.

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

Example 4 with ComponentSelector.$

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

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

the class ComponentSelector method fadeOut.

/**
 * Fades out components in this set.
 * @param duration Duration of animation.
 * @param callback Callback to run when animation completes.
 * @return Self for chaining.
 */
public ComponentSelector fadeOut(int duration, final SuccessCallback<ComponentSelector> callback) {
    final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
    AnimationManager mgr = null;
    ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
    final ArrayList<Component> animatingComponents = new ArrayList<Component>();
    for (Component c : this) {
        Container parent = c.getParent();
        if (parent != null) {
            AnimationManager cmgr = c.getAnimationManager();
            if (cmgr != null) {
                mgr = cmgr;
                Container placeholder = new Container();
                // placeholder.setShowEvenIfBlank(true);
                c.putClientProperty(placeholderProperty, placeholder);
                Component.setSameHeight(placeholder, c);
                Component.setSameWidth(placeholder, c);
                $(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
                ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createFade(duration));
                animations.add(a);
                animatingComponents.add(c);
            }
        // centerBackground.add(BorderLayout.CENTER, boxy);
        }
    }
    if (mgr != null) {
        mgr.addAnimation(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])), new Runnable() {

            public void run() {
                for (final Component c : animatingComponents) {
                    // c.setHidden(true);
                    c.setVisible(false);
                    final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
                    c.putClientProperty(placeholderProperty, null);
                    if (placeholder != null) {
                        Container parent = placeholder.getParent();
                        /*
                            if (parent == null) {
                                System.out.println("Deferring replace back");
                                $(new Runnable() {
                                    public void run() {
                                        Container parent = placeholder.getParent();
                                        if (parent != null) {
                                            System.out.println("Found parent after deferral");
                                            parent.replace(placeholder, c, CommonTransitions.createEmpty());
                                        }
                                    }
                                });
                            } else {
                            */
                        if (parent != null) {
                            parent.replace(placeholder, c, CommonTransitions.createEmpty());
                        }
                    // }
                    }
                }
                if (callback != null) {
                    callback.onSucess(ComponentSelector.this);
                }
            }
        });
    }
    return this;
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) ArrayList(java.util.ArrayList)

Aggregations

Style (com.codename1.ui.plaf.Style)9 SpanLabel (com.codename1.components.SpanLabel)5 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)3 SpanButton (com.codename1.components.SpanButton)2