use of com.codename1.ui.ComponentSelector.$ in project CodenameOne by codenameone.
the class ComponentSelector method animateStyle.
/**
* Animates this set of components, replacing any modified style properties of the
* destination style to the components.
* @param destStyle The style to apply to the components via animation.
* @param duration The duration of the animation (ms)
* @param callback Callback to call after animation is complete.
* @return Self for chaining
* @see Component#createStyleAnimation(java.lang.String, int)
*/
public ComponentSelector animateStyle(Style destStyle, int duration, final SuccessCallback<ComponentSelector> callback) {
ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
AnimationManager mgr = null;
for (Component c : this) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Style sourceStyle = c.getUnselectedStyle();
destStyle.merge(sourceStyle);
animations.add(c.createStyleAnimation(sourceStyle, destStyle, duration, null));
}
}
if (mgr != null) {
ComponentAnimation anim = ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()]));
mgr.addAnimation(anim, 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 ComponentSelector method setMarginPercent.
/**
* Sets margin on all components in found set as a percentage of their respective parents' dimensions.
* @param top Top margin as percentage of parent height.
* @param right Right margin as percentage of parent width.
* @param bottom Bottom margin as percentage of parent height.
* @param left Left margin as percentage of parent width.
* @return
*/
public ComponentSelector setMarginPercent(double top, double right, double bottom, double left) {
for (Component c : this) {
Component parent = c.getParent();
if (parent != null) {
Style s = getStyle(c);
s.setMarginUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
s.setMargin(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 setMargin.
/**
* Sets margin to all components in found set.
* @param top Top margin in pixels.
* @param right Right margin in pixels
* @param bottom Bottom margin in pixels.
* @param left Left margin in pixels.
* @return
* @see #getStyle(com.codename1.ui.Component)
*/
public ComponentSelector setMargin(int top, int right, int bottom, int left) {
Style s = currentStyle();
s.setMarginUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
s.setMargin(top, bottom, left, right);
return this;
}
use of com.codename1.ui.ComponentSelector.$ in project CodenameOne by codenameone.
the class ComponentSelector method fadeOutAndWait.
/**
* Hide the matched elements by fading them to transparent. Blocks thread until animation is complete.
* @param duration Duration of animation.
* @return Self for chaining.
*/
public ComponentSelector fadeOutAndWait(int duration) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations = 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.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));
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createFade(duration));
animations.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])));
for (final Component c : animatingComponents) {
c.setVisible(false);
final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
c.putClientProperty(placeholderProperty, null);
if (placeholder != null) {
Container parent = placeholder.getParent();
if (parent != null) {
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
}
}
}
return this;
}
use of com.codename1.ui.ComponentSelector.$ in project CodenameOne by codenameone.
the class ComponentSelector method setFontSize.
/**
* Sets the font size of all components in found set. In pixels.
* @param size Font size in pixels.
* @return
* @see #getStyle(com.codename1.ui.Component)
*/
public ComponentSelector setFontSize(float size) {
for (Component c : this) {
Style style = getStyle(c);
Font curr = style.getFont();
if (curr == null || !curr.isTTFNativeFont()) {
curr = c.getStyle().getFont();
}
if (curr == null || !curr.isTTFNativeFont()) {
Component parent = c.getParent();
while (parent != null && (curr == null || !curr.isTTFNativeFont())) {
curr = parent.getStyle().getFont();
parent = parent.getParent();
}
}
if (curr == null || !curr.isTTFNativeFont()) {
curr = Font.create("native:MainRegular");
}
if (curr != null && curr.isTTFNativeFont()) {
curr = curr.derive(size, 0);
style.setFont(curr);
}
}
return this;
}
Aggregations