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;
}
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();
}
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();
}
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;
}
Aggregations