Search in sources :

Example 86 with Component

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

the class Component method setPreferredSize.

/**
 * Sets the Component Preferred Size, there is no guarantee the Component will
 * be sized at its Preferred Size. The final size of the component may be
 * smaller than its preferred size or even larger than the size.<br>
 * The Layout manager can take this value into consideration, but there is
 * no guarantee or requirement.
 *
 * @param d the component dimension
 * @deprecated this method shouldn't be used, use sameWidth/Height, padding, margin or override calcPeferredSize
 * to reach similar functionality
 */
public void setPreferredSize(Dimension d) {
    if (d == null) {
        sizeRequestedByUser = false;
        preferredSize = null;
        shouldCalcPreferredSize = true;
        return;
    }
    Dimension dim = preferredSize();
    dim.setWidth(d.getWidth());
    dim.setHeight(d.getHeight());
    sizeRequestedByUser = true;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 87 with Component

use of com.codename1.ui.Component 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 88 with Component

use of com.codename1.ui.Component 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 89 with Component

use of com.codename1.ui.Component 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 90 with Component

use of com.codename1.ui.Component 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

Component (com.codename1.ui.Component)152 Style (com.codename1.ui.plaf.Style)61 Container (com.codename1.ui.Container)55 Form (com.codename1.ui.Form)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)40 TextArea (com.codename1.ui.TextArea)31 ActionEvent (com.codename1.ui.events.ActionEvent)28 Dimension (com.codename1.ui.geom.Dimension)28 Label (com.codename1.ui.Label)25 Point (com.codename1.ui.geom.Point)22 ArrayList (java.util.ArrayList)22 Rectangle (com.codename1.ui.geom.Rectangle)21 Vector (java.util.Vector)18 Button (com.codename1.ui.Button)16 Dialog (com.codename1.ui.Dialog)16 Hashtable (java.util.Hashtable)16 Image (com.codename1.ui.Image)15 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)13 BoxLayout (com.codename1.ui.layouts.BoxLayout)13