use of com.codename1.ui.ComponentSelector in project CodenameOne by codenameone.
the class ComponentSelector method fadeInAndWait.
/**
* Fades in this component and blocks until animation is complete.
* @param duration The duration of the animation.
* @return Self for chaining.
*/
public ComponentSelector fadeInAndWait(final int duration) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations1 = new ArrayList<ComponentAnimation>();
final ArrayList<ComponentAnimation> animations2 = 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.getStyle().setBgColor(0xff0000);
// placeholder.getStyle().setBgTransparency(255);
// 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));
// System.out.println("Placeholder height "+c.getHeight());
// parent.replace(c, placeholder, false);
// c.setHidden(false);
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createEmpty());
animations1.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations1.toArray(new ComponentAnimation[animations1.size()])));
for (final Component c : animatingComponents) {
Container placeholder = (Container) c.getClientProperty(placeholderProperty);
if (placeholder != null) {
// System.out.println("Placeholder height after replace "+(c.getHeight() + c.getStyle().getMarginBottom() + c.getStyle().getMarginTop()));
// System.out.println("Placeholder not null");
c.putClientProperty(placeholderProperty, null);
AnimationManager cmgr = placeholder.getAnimationManager();
if (cmgr != null) {
// System.out.println("Animation manager not null");
mgr = cmgr;
c.setVisible(true);
Container parent = placeholder.getParent();
if (parent != null) {
// System.out.println("Parent not null");
ComponentAnimation a = parent.createReplaceTransition(placeholder, c, CommonTransitions.createFade(duration));
animations2.add(a);
}
}
}
}
if (mgr != null) {
mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations2.toArray(new ComponentAnimation[animations2.size()])));
}
}
return this;
}
use of com.codename1.ui.ComponentSelector in project CodenameOne by codenameone.
the class ComponentSelector method setPaddingPercent.
/**
* Sets padding on all components in found set as a percentage of their respective parents' dimensions.
* @param top Top padding as percentage of parent height.
* @param right Right padding as percentage of parent width.
* @param bottom Bottom padding as percentage of parent height.
* @param left Left padding as percentage of parent width.
* @return
*/
public ComponentSelector setPaddingPercent(double top, double right, double bottom, double left) {
for (Component c : this) {
Component parent = c.getParent();
if (parent != null) {
// TODO : Change to currentStyle api... more complex with percents.
Style s = getStyle(c);
s.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
s.setPadding(percentHeight(top, parent), percentHeight(bottom, parent), percentWidth(left, parent), percentWidth(right, parent));
}
}
return this;
}
use of com.codename1.ui.ComponentSelector in project CodenameOne by codenameone.
the class ComponentSelector method stripMarginAndPadding.
/**
* Strips margin and padding from components in found set.
*
* @return Self for chaining.
* @see Style#stripMarginAndPadding()
*
* @since 7.0
*/
public ComponentSelector stripMarginAndPadding() {
Style s = currentStyle();
s.stripMarginAndPadding();
return this;
}
use of com.codename1.ui.ComponentSelector in project CodenameOne by codenameone.
the class ComponentSelector method fadeIn.
/**
* Fade in this set of components. Prior to calling this, the component visibility should
* be set to "false".
* @param duration The duration of the fade in.
* @param callback Callback to run when animation completes.
* @return
*/
public ComponentSelector fadeIn(final int duration, final SuccessCallback<ComponentSelector> callback) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations1 = new ArrayList<ComponentAnimation>();
final ArrayList<ComponentAnimation> animations2 = 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.getStyle().setBgColor(0xff0000);
// placeholder.getStyle().setBgTransparency(255);
// 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));
// System.out.println("Placeholder height "+c.getHeight());
// parent.replace(c, placeholder, false);
// c.setHidden(false);
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createEmpty());
animations1.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimation(ComponentAnimation.compoundAnimation(animations1.toArray(new ComponentAnimation[animations1.size()])), new Runnable() {
public void run() {
AnimationManager mgr = null;
for (final Component c : animatingComponents) {
Container placeholder = (Container) c.getClientProperty(placeholderProperty);
if (placeholder != null) {
// System.out.println("Placeholder height after replace "+(c.getHeight() + c.getStyle().getMarginBottom() + c.getStyle().getMarginTop()));
// System.out.println("Placeholder not null");
c.putClientProperty(placeholderProperty, null);
AnimationManager cmgr = placeholder.getAnimationManager();
if (cmgr != null) {
// System.out.println("Animation manager not null");
mgr = cmgr;
c.setVisible(true);
Container parent = placeholder.getParent();
if (parent != null) {
// System.out.println("Parent not null");
ComponentAnimation a = parent.createReplaceTransition(placeholder, c, CommonTransitions.createFade(duration));
animations2.add(a);
}
}
}
}
if (mgr != null) {
final AnimationManager fmgr = mgr;
$(new Runnable() {
public void run() {
fmgr.addAnimation(ComponentAnimation.compoundAnimation(animations2.toArray(new ComponentAnimation[animations2.size()])), new Runnable() {
public void run() {
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
});
}
}
});
}
return this;
}
use of com.codename1.ui.ComponentSelector 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