Search in sources :

Example 1 with ViewNode

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;
}
Also used : ViewNode(com.codename1.rad.nodes.ViewNode)

Example 2 with ViewNode

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));
}
Also used : EntityList(com.codename1.rad.models.EntityList) ViewNode(com.codename1.rad.nodes.ViewNode) ProfileAvatarsTitleComponent(com.codename1.rad.ui.entityviews.ProfileAvatarsTitleComponent)

Example 3 with ViewNode

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;
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode) ViewNode(com.codename1.rad.nodes.ViewNode)

Example 4 with ViewNode

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();
}
Also used : Switch(com.codename1.components.Switch) ViewNode(com.codename1.rad.nodes.ViewNode) Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) Resources(com.codename1.ui.util.Resources) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) EntityTypeBuilder.entityTypeBuilder(com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder) Form(com.codename1.ui.Form) Log(com.codename1.io.Log) BorderLayout(com.codename1.ui.layouts.BorderLayout) UIManager(com.codename1.ui.plaf.UIManager) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) Dialog(com.codename1.ui.Dialog) FontImage(com.codename1.ui.FontImage) Label(com.codename1.ui.Label) Node(com.codename1.rad.nodes.Node) CN(com.codename1.ui.CN) Thing(com.codename1.rad.schemas.Thing) Attribute(com.codename1.rad.models.Attribute) Entity(com.codename1.rad.models.Entity) Tag(com.codename1.rad.models.Tag) Entity(com.codename1.rad.models.Entity) Form(com.codename1.ui.Form) Attribute(com.codename1.rad.models.Attribute) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) Label(com.codename1.ui.Label) BorderLayout(com.codename1.ui.layouts.BorderLayout) Switch(com.codename1.components.Switch) ViewNode(com.codename1.rad.nodes.ViewNode) Tag(com.codename1.rad.models.Tag)

Example 5 with ViewNode

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);
        }
    }
}
Also used : Attribute(com.codename1.rad.models.Attribute)

Aggregations

ViewNode (com.codename1.rad.nodes.ViewNode)9 MultiButtonEntityView (com.codename1.rad.ui.entityviews.MultiButtonEntityView)3 WrapperEntityView (com.codename1.rad.ui.entityviews.WrapperEntityView)3 Attribute (com.codename1.rad.models.Attribute)2 Entity (com.codename1.rad.models.Entity)2 ActionNode (com.codename1.rad.nodes.ActionNode)2 SwipeContainer (com.codename1.rad.nodes.SwipeContainer)2 Container (com.codename1.ui.Container)2 SwipeableContainer (com.codename1.ui.SwipeableContainer)2 Switch (com.codename1.components.Switch)1 Log (com.codename1.io.Log)1 ViewType (com.codename1.rad.attributes.ViewType)1 EntityList (com.codename1.rad.models.EntityList)1 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)1 PropertySelector (com.codename1.rad.models.PropertySelector)1 Tag (com.codename1.rad.models.Tag)1 ListNode (com.codename1.rad.nodes.ListNode)1 Node (com.codename1.rad.nodes.Node)1 Thing (com.codename1.rad.schemas.Thing)1 AbstractEntityView (com.codename1.rad.ui.AbstractEntityView)1