use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class Component method setPreferredSize.
/**
* Sets the Component Preferred Size, there is no guarantee the Component will
* be sized at its Preferred Size. The final size of the component may be
* smaller than its preferred size or even larger than the size.<br>
* The Layout manager can take this value into consideration, but there is
* no guarantee or requirement.
*
* @param d the component dimension
* @deprecated this method shouldn't be used, use sameWidth/Height, padding, margin or override calcPeferredSize
* to reach similar functionality
*/
public void setPreferredSize(Dimension d) {
if (d == null) {
sizeRequestedByUser = false;
preferredSize = null;
shouldCalcPreferredSize = true;
return;
}
Dimension dim = preferredSize();
dim.setWidth(d.getWidth());
dim.setHeight(d.getHeight());
sizeRequestedByUser = true;
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class ComponentSelector method parent.
/**
* Creates a new set of components consisting of all of the parents of components in this set.
* Only parent components matching the provided selector will be included in the set.
* @param selector Selector to filter the parent components.
* @return New set with parents of elements in current set.
*/
public ComponentSelector parent(String selector) {
ComponentSelector matcher = new ComponentSelector(selector, new Label());
HashSet<Component> matches = new HashSet<Component>();
for (Component c : this) {
Component parent = c.getParent();
if (parent != null && matcher.match(parent)) {
matches.add(parent);
}
}
return matcher.addAll(matches, true);
}
use of com.codename1.ui.Component 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 each label as the icon's foreground color.
* @param materialIcon The icon charcode.
* @param size The size of the icon (in mm)
* @return Self for chaining
* @see FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
*/
public ComponentSelector setIcon(char materialIcon, float size) {
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, size));
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, size));
}
}
}
return this;
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class ComponentSelector method parents.
/**
* Creates new set of components consisting of all of the ancestors of components in this set which
* match the provided selector.
* @param selector The selector to filter the ancestors.
* @return New set with ancestors of elements in current set.
*/
public ComponentSelector parents(String selector) {
ComponentSelector matcher = new ComponentSelector(selector, new Label());
HashSet<Component> matches = new HashSet<Component>();
for (Component c : this) {
Component parent = c.getParent();
while (parent != null) {
if (matcher.match(parent)) {
matches.add(parent);
}
parent = parent.getParent();
}
}
return matcher.addAll(matches, true);
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class ComponentSelector method fadeOut.
/**
* Fades out components in this set.
* @param duration Duration of animation.
* @param callback Callback to run when animation completes.
* @return Self for chaining.
*/
public ComponentSelector fadeOut(int duration, final SuccessCallback<ComponentSelector> callback) {
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.addAnimation(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])), new Runnable() {
public void run() {
for (final Component c : animatingComponents) {
// c.setHidden(true);
c.setVisible(false);
final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
c.putClientProperty(placeholderProperty, null);
if (placeholder != null) {
Container parent = placeholder.getParent();
/*
if (parent == null) {
System.out.println("Deferring replace back");
$(new Runnable() {
public void run() {
Container parent = placeholder.getParent();
if (parent != null) {
System.out.println("Found parent after deferral");
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
}
});
} else {
*/
if (parent != null) {
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
// }
}
}
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
return this;
}
Aggregations