All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xworker.javafx.scene.layout.FlowPaneActions Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package xworker.javafx.scene.layout;

import javafx.geometry.*;
import javafx.scene.Node;
import javafx.scene.layout.FlowPane;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

public class FlowPaneActions {
    static{
        PropertyFactory.regist(FlowPane.class, "vgapProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.vgapProperty();
        });
        PropertyFactory.regist(FlowPane.class, "hgapProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.hgapProperty();
        });
        PropertyFactory.regist(FlowPane.class, "prefWrapLengthProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.prefWrapLengthProperty();
        });
        PropertyFactory.regist(FlowPane.class, "columnHalignmentProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.columnHalignmentProperty();
        });
        PropertyFactory.regist(FlowPane.class, "rowValignmentProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.rowValignmentProperty();
        });
        PropertyFactory.regist(FlowPane.class, "alignmentProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.alignmentProperty();
        });
        PropertyFactory.regist(FlowPane.class, "orientationProperty", o -> {
            FlowPane obj = (FlowPane) o;
            return obj.orientationProperty();
        });
    }

    public static void init(FlowPane node, Thing thing, ActionContext actionContext){
        PaneActions.init(node, thing, actionContext);

        if(thing.valueExists("alignment")){
            node.setAlignment(Pos.valueOf(thing.getString("alignment")));
        }
        if(thing.valueExists("columnHalignment")){
            node.setColumnHalignment(HPos.valueOf(thing.getString("columnHalignment")));
        }
        if(thing.valueExists("hgap")){
            node.setHgap(thing.getDouble("hgap"));
        }
        if(thing.valueExists("orientation")){
            node.setOrientation(Orientation.valueOf(thing.getString("orientation")));
        }
        if(thing.valueExists("prefWrapLength")){
            node.setPrefWrapLength(thing.getDouble("prefWrapLength"));
        }
        if(thing.valueExists("rowValignment")){
            node.setRowValignment(VPos.valueOf(thing.getString("rowValignment")));
        }
        if(thing.valueExists("vgap")){
            node.setVgap(thing.getDouble("vgap"));
        }
    }

    public static FlowPane create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");

        FlowPane node = new FlowPane();
        init(node, self, actionContext);
        actionContext.g().put(self.getMetadata().getName(), node);

        actionContext.peek().put("parent", node);
        for(Thing child : self.getChilds()){
            Object obj = child.doAction("create", actionContext);
            if(obj instanceof Node){
                node.getChildren().add((Node) obj);
            }
        }

        return node;
    }

    public static void createConstraints(ActionContext actionContext){
        Thing thing = actionContext.getObject("self");
        Node node = actionContext.getObject("parent");

        if(thing.valueExists("margin")){
            Insets margin = JavaFXUtils.getInsets(thing,"margin", actionContext);
            if(margin != null){
                FlowPane.setMargin(node, margin);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy