use of com.codename1.ui.Label 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.Label 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.Label 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.Label in project CodenameOne by codenameone.
the class ComponentSelector method closest.
/**
* Creates a new set of components consistng of all "closest" ancestors of components
* in this set which match the provided selector.
* @param selector The selector to use to match the nearest ancestor.
* @return New set with ancestors of components in current set.
*/
public ComponentSelector closest(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);
break;
}
parent = parent.getParent();
}
}
return matcher.addAll(matches, true);
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class Dialog method show.
/**
* Shows a modal dialog with the given component as its "body" placed in the
* center.
*
* @param title title for the dialog
* @param body component placed in the center of the dialog
* @param defaultCommand command to be assigned as the default command or null
* @param cmds commands that are added to the form any click on any command
* will dispose the form
* @param type the type of the alert one of TYPE_WARNING, TYPE_INFO,
* TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM
* @param icon the icon for the dialog, can be null
* @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used
* @param transition the transition installed when the dialog enters/leaves
* @return the command pressed by the user
*/
public static Command show(String title, Component body, Command defaultCommand, Command[] cmds, int type, Image icon, long timeout, Transition transition) {
Dialog dialog = new Dialog(title);
dialog.dialogType = type;
dialog.setTransitionInAnimator(transition);
dialog.setTransitionOutAnimator(transition);
dialog.lastCommandPressed = null;
dialog.setLayout(new BorderLayout());
if (cmds != null) {
if (commandsAsButtons) {
dialog.placeButtonCommands(cmds);
} else {
for (int iter = 0; iter < cmds.length; iter++) {
dialog.addCommand(cmds[iter]);
}
}
// maps the first command to back
if (cmds.length == 1 || cmds.length == 2) {
dialog.setBackCommand(cmds[0]);
}
}
if (defaultCommand != null) {
dialog.setDefaultCommand(defaultCommand);
}
dialog.addComponent(BorderLayout.CENTER, body);
if (icon != null) {
dialog.addComponent(BorderLayout.EAST, new Label(icon));
}
if (timeout != 0) {
dialog.setTimeout(timeout);
}
if (body.isScrollable() || disableStaticDialogScrolling) {
dialog.setScrollable(false);
}
dialog.show();
return dialog.lastCommandPressed;
}
Aggregations