use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.
the class GenericListCellRenderer method setComponentValue.
/**
* Initializes the given component with the given value
*
* @param cmp one of the components that is or is a part of the renderer
* @param value the value to install into the component
*/
private void setComponentValue(Component cmp, Object value, Component parent, Component rootRenderer) {
// process so renderer selected/unselected styles are applied
if (cmp.getName().toLowerCase().endsWith("fixed")) {
return;
}
if (cmp instanceof Label) {
if (value instanceof Image) {
Image i = (Image) value;
if (i.isAnimation()) {
if (pendingAnimations == null) {
pendingAnimations = new ArrayList<Image>();
}
if (!pendingAnimations.contains(i)) {
pendingAnimations.add(i);
if (parentList == null) {
parentList = parent;
}
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
} else {
waitingForRegisterAnimation = true;
}
}
} else {
if (waitingForRegisterAnimation) {
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
}
}
}
}
}
Image oldImage = ((Label) cmp).getIcon();
((Label) cmp).setIcon(i);
((Label) cmp).setText("");
if (oldImage == null || oldImage.getWidth() != i.getWidth() || oldImage.getHeight() != i.getHeight()) {
((Container) rootRenderer).revalidate();
}
return;
} else {
((Label) cmp).setIcon(null);
}
if (cmp instanceof CheckBox) {
((CheckBox) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof RadioButton) {
((RadioButton) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof Slider) {
((Slider) cmp).setProgress(((Integer) value).intValue());
return;
}
Label l = (Label) cmp;
if (value == null) {
l.setText("");
} else {
if (value instanceof Label) {
l.setText(((Label) value).getText());
l.setIcon(((Label) value).getIcon());
} else {
l.setText(value.toString());
}
}
if (firstCharacterRTL) {
String t = l.getText();
if (t.length() > 0) {
l.setRTL(Display.getInstance().isRTL(t.charAt(0)));
}
}
return;
}
if (cmp instanceof TextArea) {
if (value == null) {
((TextArea) cmp).setText("");
} else {
((TextArea) cmp).setText(value.toString());
}
}
}
use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.
the class GenericListCellRenderer method findComponentsOfInterest.
private void findComponentsOfInterest(Component cmp, ArrayList dest) {
if (cmp instanceof Container) {
Container c = (Container) cmp;
int count = c.getComponentCount();
for (int iter = 0; iter < count; iter++) {
findComponentsOfInterest(c.getComponentAt(iter), dest);
}
return;
}
// performance optimization for fixed images in lists
if (cmp.getName() != null) {
if (cmp instanceof Label) {
Label l = (Label) cmp;
if (l.getName().toLowerCase().endsWith("fixed") && l.getIcon() != null) {
l.getIcon().lock();
}
dest.add(cmp);
return;
}
if (cmp instanceof TextArea) {
dest.add(cmp);
return;
}
}
}
use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.
the class GenericListCellRenderer method setComponentValueWithTickering.
private void setComponentValueWithTickering(Component cmp, Object value, Component l, Component rootRenderer) {
setComponentValue(cmp, value, l, rootRenderer);
if (cmp instanceof Label) {
if (selectionListener) {
if (l instanceof List) {
((List) l).addActionListener(mon);
}
parentList = l;
}
Label label = (Label) cmp;
if (label.shouldTickerStart() && Display.getInstance().shouldRenderSelection()) {
if (!label.isTickerRunning()) {
parentList = l;
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
label.startTicker(cmp.getUIManager().getLookAndFeel().getTickerSpeed(), true);
}
}
}
} else {
if (label.isTickerRunning()) {
label.stopTicker();
}
label.setTextPosition(0);
}
}
}
use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.
the class InfiniteContainerSafeAreaTest method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("InfiniteContainer", new BorderLayout());
Style s = UIManager.getInstance().getComponentStyle("MultiLine1");
FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s);
EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 3), false);
InfiniteContainer ic = new InfiniteContainer() {
@Override
public Component[] fetchComponents(int index, int amount) {
java.util.List<Map<String, Object>> data = fetchPropertyData("Leeds");
MultiButton[] cmps = new MultiButton[data.size()];
for (int iter = 0; iter < cmps.length; iter++) {
Map<String, Object> currentListing = data.get(iter);
if (currentListing == null) {
return null;
}
String thumb_url = (String) currentListing.get("thumb_url");
String guid = (String) currentListing.get("guid");
String summary = (String) currentListing.get("summary");
cmps[iter] = new MultiButton(summary);
// cmps[iter].setIcon(URLImage.createToStorage(placeholder, guid, thumb_url));
}
return cmps;
}
};
ic.setUIID("Blue");
ic.setSafeArea(true);
ic.addComponent(new Label("This is a test"));
hi.add(BorderLayout.CENTER, ic);
hi.show();
}
use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.
the class LandscapeToolbarHiddenSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Test 2387", BoxLayout.y());
hi.add(new Label("Hi World"));
if (!CN.isPortrait()) {
hi.getToolbar().hideToolbar();
}
Button hide = new Button("Hide");
Button show = new Button("Show");
hide.addActionListener(e -> hi.getToolbar().hideToolbar());
show.addActionListener(e -> hi.getToolbar().showToolbar());
hi.addOrientationListener(e -> {
if (CN.isPortrait()) {
hi.getToolbar().showToolbar();
} else {
hi.getToolbar().hideToolbar();
}
});
hi.addAll(hide, show);
hi.show();
}
Aggregations