Search in sources :

Example 1 with InterFormContainer

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

the class InterFormContainer method findCommonContainers.

/**
 * Finds common InterFormContainers in two different component trees.
 * @param root1 The root of the first component tree to search.
 * @param root2 The root of the second component tree to search.
 * @return A Map that maps an InterFormContainer from the first tree to its corresponding container from the second
 * tree.
 */
public static Map<InterFormContainer, InterFormContainer> findCommonContainers(Component root1, Component root2) {
    final Map<Component, InterFormContainer> set1 = new HashMap<Component, InterFormContainer>();
    final Map<Component, InterFormContainer> set2 = new HashMap<Component, InterFormContainer>();
    final Map<InterFormContainer, InterFormContainer> out = new HashMap<InterFormContainer, InterFormContainer>();
    ComponentSelector.select("*", root1).filter(new Filter() {

        @Override
        public boolean filter(Component c) {
            if (c.getClass() == InterFormContainer.class) {
                set1.put(((InterFormContainer) c).content, (InterFormContainer) c);
                return true;
            }
            return false;
        }
    });
    ComponentSelector.select("*", root2).filter(new Filter() {

        @Override
        public boolean filter(Component c) {
            if (c.getClass() == InterFormContainer.class) {
                set2.put(((InterFormContainer) c).content, (InterFormContainer) c);
                return true;
            }
            return false;
        }
    });
    for (Component c : set1.keySet()) {
        if (set2.containsKey(c)) {
            out.put(set1.get(c), set2.get(c));
        }
    }
    return out;
}
Also used : HashMap(java.util.HashMap) Filter(com.codename1.ui.ComponentSelector.Filter)

Example 2 with InterFormContainer

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

the class InterFormContainerSample method start_old.

public void start_old() {
    if (current != null) {
        current.show();
        return;
    }
    Form f1 = new Form("Form 1", new BorderLayout());
    f1.setTransitionOutAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 300));
    Form f2 = new Form("Form 2", new BorderLayout());
    f2.setTransitionOutAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 300));
    Form f3 = new Form("Form 3", new BorderLayout());
    Button f3Back = new Button("Back");
    f3Back.addActionListener(e -> {
        f2.showBack();
    });
    f3.add(BorderLayout.CENTER, new SpanLabel("This form doesn't have an interform container"));
    f3.add(BorderLayout.SOUTH, f3Back);
    f1.add(BorderLayout.CENTER, new Label("Hi World"));
    Button sharedButton = new Button("Shared Button");
    sharedButton.addActionListener(e -> {
        if (sharedButton.getComponentForm() == f1) {
            f2.show();
        } else {
            f1.showBack();
        }
    });
    InterFormContainer cnt = new InterFormContainer(sharedButton);
    f1.add(BorderLayout.SOUTH, cnt);
    Button goto3 = new Button("Goto Form 3");
    goto3.addActionListener(e -> {
        f3.show();
    });
    InterFormContainer cnt2 = new InterFormContainer(sharedButton);
    f2.add(BorderLayout.CENTER, BoxLayout.encloseY(new Label("Now on Form 2"), goto3));
    f2.add(BorderLayout.SOUTH, cnt2);
    f1.show();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) SpanLabel(com.codename1.components.SpanLabel) Label(com.codename1.ui.Label) SpanLabel(com.codename1.components.SpanLabel) InterFormContainer(com.codename1.ui.InterFormContainer)

Example 3 with InterFormContainer

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

the class InterFormContainerSample method start.

public void start() {
    Button sharedButton = new Button("Shared Button");
    InterFormContainer cnt = new InterFormContainer(sharedButton);
    InterFormContainer cnt2 = new InterFormContainer(sharedButton);
    Toolbar.setGlobalToolbar(true);
    Form hi = new Form("Transitions", new BorderLayout());
    Container c = new Container(BoxLayout.y());
    hi.add(BorderLayout.CENTER, c);
    hi.add(BorderLayout.SOUTH, cnt);
    Style bg = hi.getContentPane().getUnselectedStyle();
    bg.setBgTransparency(255);
    bg.setBgColor(0xff0000);
    Button showTransition = new Button("Show");
    Picker pick = new Picker();
    pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip");
    pick.setSelectedString("Slide");
    TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC);
    CheckBox horizontal = CheckBox.createToggle("Horizontal");
    pick.addActionListener((e) -> {
        String s = pick.getSelectedString().toLowerCase();
        horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1);
    });
    horizontal.setSelected(true);
    c.add(showTransition).add(pick).add(duration).add(horizontal);
    Form dest = new Form("Destination", new BorderLayout());
    sharedButton.addActionListener(e -> {
        if (sharedButton.getComponentForm() == hi) {
            dest.show();
        } else {
            hi.showBack();
        }
    });
    dest.add(BorderLayout.SOUTH, cnt2);
    bg = dest.getContentPane().getUnselectedStyle();
    bg.setBgTransparency(255);
    bg.setBgColor(0xff);
    dest.setBackCommand(dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack()));
    showTransition.addActionListener((e) -> {
        int h = CommonTransitions.SLIDE_HORIZONTAL;
        if (!horizontal.isSelected()) {
            h = CommonTransitions.SLIDE_VERTICAL;
        }
        switch(pick.getSelectedString()) {
            case "Slide":
                hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000)));
                dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000)));
                break;
            case "SlideFade":
                hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000)));
                dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000)));
                break;
            case "Cover":
                hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000)));
                dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000)));
                break;
            case "Uncover":
                hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000)));
                dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000)));
                break;
            case "Fade":
                hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000)));
                dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000)));
                break;
            case "Flip":
                hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000)));
                dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000)));
                break;
        }
        dest.show();
    });
    hi.show();
}
Also used : Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException) Form(com.codename1.ui.Form) Log(com.codename1.io.Log) Picker(com.codename1.ui.spinner.Picker) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Style(com.codename1.ui.plaf.Style) NetworkEvent(com.codename1.io.NetworkEvent) UIManager(com.codename1.ui.plaf.UIManager) CommonTransitions(com.codename1.ui.animations.CommonTransitions) SpanLabel(com.codename1.components.SpanLabel) TextField(com.codename1.ui.TextField) Dialog(com.codename1.ui.Dialog) Display(com.codename1.ui.Display) Label(com.codename1.ui.Label) Button(com.codename1.ui.Button) CN(com.codename1.ui.CN) TextArea(com.codename1.ui.TextArea) CheckBox(com.codename1.ui.CheckBox) InterFormContainer(com.codename1.ui.InterFormContainer) FlipTransition(com.codename1.ui.animations.FlipTransition) Form(com.codename1.ui.Form) FlipTransition(com.codename1.ui.animations.FlipTransition) InterFormContainer(com.codename1.ui.InterFormContainer) Container(com.codename1.ui.Container) InterFormContainer(com.codename1.ui.InterFormContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) CheckBox(com.codename1.ui.CheckBox) Picker(com.codename1.ui.spinner.Picker) Style(com.codename1.ui.plaf.Style) TextField(com.codename1.ui.TextField)

Example 4 with InterFormContainer

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

the class InterFormContainer method inject.

/**
 * Injects the given "content" as an InterFormContainer inside the component hierarchy
 * rooted at "root"
 * @param selector A selector to identify the component to add the container to.  See {@link ComponentSelector}.
 * @param root The root container serving as a starting point for the selector search.
 * @param content The content to inject.
 * @return The InterFormContainer that was injected, or null if the selector didn't match any containers.
 */
public static InterFormContainer inject(String selector, Container root, Component content) {
    for (Component c : $(selector, root)) {
        if (c instanceof Container) {
            Container slotCnt = (Container) c;
            if (!(slotCnt.getLayout() instanceof BorderLayout)) {
                slotCnt.setLayout(new BorderLayout());
            }
            slotCnt.getStyle().stripMarginAndPadding();
            slotCnt.removeAll();
            InterFormContainer ifc = new InterFormContainer(content);
            slotCnt.add(BorderLayout.CENTER, ifc);
            return ifc;
        }
    }
    return null;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)3 SpanLabel (com.codename1.components.SpanLabel)2 Button (com.codename1.ui.Button)2 Form (com.codename1.ui.Form)2 InterFormContainer (com.codename1.ui.InterFormContainer)2 Label (com.codename1.ui.Label)2 Log (com.codename1.io.Log)1 NetworkEvent (com.codename1.io.NetworkEvent)1 CN (com.codename1.ui.CN)1 CheckBox (com.codename1.ui.CheckBox)1 Filter (com.codename1.ui.ComponentSelector.Filter)1 Container (com.codename1.ui.Container)1 Dialog (com.codename1.ui.Dialog)1 Display (com.codename1.ui.Display)1 TextArea (com.codename1.ui.TextArea)1 TextField (com.codename1.ui.TextField)1 Toolbar (com.codename1.ui.Toolbar)1 CommonTransitions (com.codename1.ui.animations.CommonTransitions)1 FlipTransition (com.codename1.ui.animations.FlipTransition)1 BoxLayout (com.codename1.ui.layouts.BoxLayout)1