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 setIcon.
/**
* Sets the icon of all elements in this set to a material icon. This will use
* the foreground color of the label.
* @param materialIcon The material icon charcode.
* @return Self for chaining.
*/
public ComponentSelector setIcon(char materialIcon) {
for (Component c : this) {
if (c instanceof Label) {
Label l = (Label) c;
Style style = new Style();
Style cStyle = c.getUnselectedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
l.setIcon(FontImage.createMaterial(materialIcon, style, 3));
if (c instanceof Button) {
Button b = (Button) c;
style = new Style();
cStyle = c.getPressedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
b.setPressedIcon(FontImage.createMaterial(materialIcon, style, 3));
}
}
}
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;
}
use of com.codename1.ui.ComponentSelector in project CodenameOne by codenameone.
the class ComponentSelector method filter.
/**
* Filters the current found set against the given selector.
* @param selector The selector to filter the found set on.
* @return A new set of elements matching the selector.
*/
public ComponentSelector filter(String selector) {
ComponentSelector matcher = new ComponentSelector(selector, new Label());
LinkedHashSet<Component> matches = new LinkedHashSet<Component>();
for (Component c : this) {
if (matcher.match(c)) {
matches.add(c);
}
}
return matcher.addAll(matches, true);
}
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;
}
Aggregations