use of com.codename1.rad.nodes.ViewNode in project CodeRAD by shannah.
the class ProfileAvatarsTitleComponent method createAvatar.
/**
* Creates individual avatar component.
* @param row
* @return
*/
private ProfileAvatarView createAvatar(Entity row) {
// We will intercept the individual avatar actions by inserting our own actions here.
// We will then handle the clicks and long presses ourselves, because
// we may need to expand the list of avatars and allow the user to
// choose an avatar from the list.
ViewNode childNode = new ViewNode(UI.actions(ProfileAvatarView.PROFILE_AVATAR_CLICKED, interceptAvatarClicked), UI.actions(ProfileAvatarView.PROFILE_AVATAR_LONG_PRESS, interceptAvatarLongPress));
childNode.setParent(getViewNode());
ProfileAvatarView v = new ProfileAvatarView(row, childNode, avatarSizeMM);
return v;
}
use of com.codename1.rad.nodes.ViewNode in project CodeRAD by shannah.
the class ProfileAvatarsTitleComponentBuilder method build.
@Override
public ProfileAvatarsTitleComponent build() {
ViewNode node = new ViewNode();
node.setParent(getContext().getNode());
EntityList l = (entity instanceof EntityList) ? (EntityList) entity : new EntityList();
if (entity != l) {
l.add(entity);
}
if (avatarSize <= 0) {
avatarSize = CN.convertToPixels(1f, Style.UNIT_TYPE_REM);
}
return new ProfileAvatarsTitleComponent(l, node, avatarSize / (float) CN.convertToPixels(1f));
}
use of com.codename1.rad.nodes.ViewNode in project CodeRAD by shannah.
the class Controller method createViewNode.
/**
* Creates the view node that should be used as the node for the controller's view. This method should
* be overridden by subclasses to define the default view node, but this method shouldn't be called directly. Rather
* the {@link #getViewNode()} method should be called so that the view node is only created once. {@link #getViewNode() }
* will also set the parent node to the view node of the parent controller to more easily benefit from inherited attributes
* in the UI descriptor hierarchy.
* @return A ViewNode
*/
protected ViewNode createViewNode() {
startControllerInternal();
ViewNode n = new ViewNode();
if (actionMap != null) {
for (ActionNode.Category c : actionMap.keySet()) {
n.setAttributes(UI.actions(c, actionMap.get(c)));
}
}
return n;
}
use of com.codename1.rad.nodes.ViewNode in project CodenameOne by codenameone.
the class RADStatusViewSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
Tag TAG_ONLINE = new Tag("online");
class User extends Entity {
}
entityTypeBuilder(User.class).Boolean(TAG_ONLINE).string(Thing.name).factory(cls -> {
return new User();
}).build();
/**
* A view that displays the status (online/offline) of an entity using
* the TAG_ONLINE tag.
*/
class StatusView extends AbstractEntityView {
// ViewNode. Not used;
ViewNode node;
// Flag to indicate the current state online/offline of the view
private boolean online;
// Label used
private Label label = new Label();
/**
* Creates a new StatusView for user model.
*/
StatusView(User user) {
super(user);
this.node = new ViewNode(new Attribute[] {});
setLayout(new BorderLayout());
$(this).setMargin(0).setPadding(0);
this.add(CENTER, label);
update();
}
@Override
public void update() {
// Check to see if the model is online.
boolean modelOnline = !getEntity().isFalsey(TAG_ONLINE);
if (modelOnline != online) {
// Model state has changed since last update
online = modelOnline;
if (online) {
label.setText("Online");
label.setUIID("OnlineLabel");
FontImage.setMaterialIcon(label, FontImage.MATERIAL_CONNECTED_TV);
} else {
label.setText("Offline");
label.setUIID("OfflineLabel");
FontImage.setMaterialIcon(label, FontImage.MATERIAL_OFFLINE_BOLT);
}
Form f = getComponentForm();
if (f != null) {
// Changing the text in this case may change the layout size
// of the status view here, so it is best to just issue a revalidate
// for the whole form. If the status change didn't change
// the layout size, then we could have just skipped this step.
f.revalidateWithAnimationSafety();
}
}
}
@Override
public void commit() {
// Don't need to implement commit() because this view doesn't
// "update" the model - it only shows model stats.
}
@Override
public Node getViewNode() {
return node;
}
}
// Create a new user
User user = new User();
// Create a status view for the user
StatusView statusView = new StatusView(user);
// Add a UI switch to toggle user state between online and offline
Switch onlineSwitch = new Switch("Online");
onlineSwitch.addChangeListener(e -> {
// Set the user TAG_ONLINE status. This will trigger a property
// change in the model and update the view.
user.set(TAG_ONLINE, onlineSwitch.isOn());
});
hi.add(onlineSwitch);
hi.add(statusView);
hi.show();
}
use of com.codename1.rad.nodes.ViewNode in project CodeRAD by shannah.
the class FormNode method setAttributes.
public void setAttributes(Attribute... atts) {
if (sections == null) {
sections = new Sections();
}
// super.setAttributes(atts);
for (Attribute att : atts) {
if (att.getClass() == SectionNode.class) {
sections.add((SectionNode) att);
((SectionNode) att).setParent(this);
} else if (att.getClass() == FieldNode.class) {
if (globalSection == null) {
globalSection = new SectionNode();
globalSection.setParent(this);
}
globalSection.setAttributes(att);
} else if (att instanceof ListNode) {
rootList = (ListNode) att;
super.setAttributes(att);
} else if (att instanceof ViewNode) {
rootView = (ViewNode) att;
super.setAttributes(att);
} else {
super.setAttributes(att);
}
}
}
Aggregations