Search in sources :

Example 1 with CollapsibleHeaderContainer

use of ca.weblite.shared.components.CollapsibleHeaderContainer 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)

Aggregations

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 BorderLayout (com.codename1.ui.layouts.BorderLayout)1