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

xworker.javafx.scene.image.ImageViewActions Maven / Gradle / Ivy

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

import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.scene.NodeActions;
import xworker.javafx.util.JavaFXUtils;

public class ImageViewActions {
    static{
        PropertyFactory.regist(ImageView.class, "xProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.xProperty();
        });
        PropertyFactory.regist(ImageView.class, "yProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.yProperty();
        });
        PropertyFactory.regist(ImageView.class, "imageProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.imageProperty();
        });
        PropertyFactory.regist(ImageView.class, "fitWidthProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.fitWidthProperty();
        });
        PropertyFactory.regist(ImageView.class, "fitHeightProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.fitHeightProperty();
        });
        PropertyFactory.regist(ImageView.class, "smoothProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.smoothProperty();
        });
        PropertyFactory.regist(ImageView.class, "viewportProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.viewportProperty();
        });
        PropertyFactory.regist(ImageView.class, "preserveRatioProperty", o -> {
            ImageView obj = (ImageView) o;
            return obj.preserveRatioProperty();
        });
    }

    public static void init(ImageView node, Thing thing, ActionContext actionContext){
        NodeActions.init(node, thing, actionContext);

        if(thing.valueExists("fitHeight")){
            node.setFitHeight(thing.getDouble("fitHeight"));
        }
        if(thing.valueExists("fitWidth")){
            node.setFitWidth(thing.getDouble("fitWidth"));
        }
        if(thing.valueExists("image")){
            Image image = JavaFXUtils.getImage(thing, "image", actionContext);
            if(image != null) {
                node.setImage(image);
            }
        }
        if(thing.valueExists("preserveRatio")){
            node.setPreserveRatio(thing.getBoolean("preserveRatio"));
        }
        if(thing.valueExists("smooth")){
            node.setSmooth(thing.getBoolean("smooth"));
        }
        if(thing.valueExists("viewport")){
            Rectangle2D viewport = JavaFXUtils.getRectangle2D(thing, "viewport", actionContext);
            if(viewport != null) {
                node.setViewport(viewport);
            }
        }
        if(thing.valueExists("x")){
            node.setX(thing.getDouble("x"));
        }
        if(thing.valueExists("y")){
            node.setY(thing.getDouble("y"));
        }
    }

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

        ImageView node = new ImageView();
        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 Image){
                node.setImage((Image) obj);
            }
        }

        return node;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy