Search in sources :

Example 1 with ComponentSelector

use of com.codename1.ui.ComponentSelector in project CodeRAD by shannah.

the class FormController method setView.

/**
 * Overrides parent setView().  Delegates to {@link #setView(com.codename1.ui.Form) } if cmp is
 * a form.  Throws IllegalArgumentException otherwise.
 * @param cmp
 */
public void setView(Component cmp) {
    if (cmp == null) {
        setView((Form) null);
        return;
    }
    Form currView = getView();
    if (currView != null) {
        currView.removeShowListener(showListener());
    }
    if (cmp instanceof Form) {
        ((Form) cmp).addShowListener(showListener());
        setView((Form) cmp);
    } else {
        Form f = new Form(new BorderLayout()) {

            @Override
            public void setTitle(String title) {
                super.setTitle(title);
                if (titleLbl != null) {
                    titleLbl.setText(title);
                    revalidateLater();
                }
            }

            @Override
            public void layoutContainer() {
                super.layoutContainer();
                if (true)
                    return;
                int maxLeftX = 0;
                ComponentSelector cmps = $(".left-inset", this);
                for (Component c : cmps) {
                    if (!c.isVisible() || c.isHidden() || c.getWidth() == 1 || c.getHeight() == 0) {
                        continue;
                    }
                    Component wrap = $(c).parents(".left-edge").first().asComponent();
                    if (wrap == null) {
                        continue;
                    }
                    int thisLeftX = c.getAbsoluteX() + c.getStyle().getPaddingLeftNoRTL() - wrap.getAbsoluteX();
                    maxLeftX = Math.max(maxLeftX, thisLeftX);
                }
                for (Component c : cmps) {
                    if (!c.isVisible() || c.isHidden() || c.getWidth() == 1 || c.getHeight() == 0) {
                        continue;
                    }
                    Component wrap = $(c).parents(".left-edge").first().asComponent();
                    if (wrap == null) {
                        continue;
                    }
                    int absX = c.getAbsoluteX() + c.getStyle().getPaddingLeftNoRTL() - wrap.getAbsoluteX();
                    if (absX < maxLeftX) {
                        int marginLeft = c.getStyle().getMarginLeftNoRTL();
                        c.getAllStyles().setMarginUnitLeft(Style.UNIT_TYPE_PIXELS);
                        c.getAllStyles().setMarginLeft(marginLeft + maxLeftX - absX);
                    }
                }
            }
        };
        boolean hasTitle = !addTitleBar;
        Component titleBarEast = null;
        Component titleBarWest = null;
        if (!hasTitle) {
            for (Component c : $("*", cmp).add(cmp, true)) {
                if (c instanceof CollapsibleHeaderContainer) {
                    hasTitle = true;
                    break;
                }
                if ("Title".equals(c)) {
                    hasTitle = true;
                    break;
                }
                if ("TitleBarEast".equalsIgnoreCase(c.getName())) {
                    titleBarEast = c;
                } else if ("TitleBarWest".equalsIgnoreCase(c.getName())) {
                    titleBarWest = c;
                }
            }
        }
        if (titleBarEast != null)
            titleBarEast.remove();
        if (titleBarWest != null)
            titleBarWest.remove();
        f.addShowListener(showListener());
        f.getToolbar().hideToolbar();
        Container titleBar = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
        titleBar.setSafeArea(true);
        titleBar.setUIID("TitleArea");
        if (hasBackCommand()) {
            Button back = new Button();
            FontImage.setIcon(back, FontImage.MATERIAL_ARROW_BACK_IOS, -1);
            titleBarWest = titleBarWest == null ? back : BoxLayout.encloseX(back, titleBarWest);
            // titleBar.add(BorderLayout.WEST, back);
            back.addActionListener(evt -> {
                evt.consume();
                ActionSupport.dispatchEvent(new FormController.FormBackEvent(back));
            });
        }
        AppSectionController sectionCtl = getSectionController();
        if (sectionCtl != null) {
            Button done = new Button("Done");
            done.addActionListener(evt -> {
                evt.consume();
                ActionSupport.dispatchEvent(new AppSectionController.ExitSectionEvent(done));
            });
            titleBarEast = titleBarEast == null ? done : BoxLayout.encloseX(titleBarEast, done);
        // titleBar.add(BorderLayout.EAST, done);
        }
        if (titleComponent != null) {
            titleBar.add(BorderLayout.CENTER, titleComponent);
        } else {
            titleLbl = new Label();
            titleLbl.setUIID("Title");
            if (getTitle() != null) {
                titleLbl.setText(getTitle());
            }
            titleBar.add(BorderLayout.CENTER, titleLbl);
        }
        if (titleBarEast != null)
            titleBar.add(BorderLayout.EAST, titleBarEast);
        if (titleBarWest != null)
            titleBar.add(BorderLayout.WEST, titleBarWest);
        if (!hasTitle)
            f.add(BorderLayout.NORTH, titleBar);
        f.add(BorderLayout.CENTER, decorateView(cmp));
        f.revalidateLater();
        setView(f);
    }
}
Also used : Form(com.codename1.ui.Form) ComponentSelector(com.codename1.ui.ComponentSelector) Label(com.codename1.ui.Label) CollapsibleHeaderContainer(ca.weblite.shared.components.CollapsibleHeaderContainer) Container(com.codename1.ui.Container) CollapsibleHeaderContainer(ca.weblite.shared.components.CollapsibleHeaderContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) Component(com.codename1.ui.Component)

Example 2 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());
    LinkedHashSet<Component> matches = new LinkedHashSet<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 : LinkedHashSet(java.util.LinkedHashSet) SpanLabel(com.codename1.components.SpanLabel)

Example 3 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 4 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 5 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());
    LinkedHashSet<Component> matches = new LinkedHashSet<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 : LinkedHashSet(java.util.LinkedHashSet) SpanLabel(com.codename1.components.SpanLabel)

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