protected List makeSubJobs()

in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/FitToParentObjectJob.java [85:170]


    protected List<Job> makeSubJobs() {

        final List<Job> result = new ArrayList<>();

        // Object cannot be root
        if (parentProperty == null) {
            return result; // subJobs is empty => isExecutable will return false
        }
        // Object must be a node
        final Object childObject = fxomInstance.getSceneGraphObject();
        if ((childObject instanceof Node) == false) {
            return result; // subJobs is empty => isExecutable will return false
        }
        // Preview version : Node must be resizable (as in SB 1.1)
        // TODO : if the object is not resizable, 
        // update its bounds but do not anchor it.
        final Node childNode = (Node) childObject;
        if (childNode.isResizable() == false) {
            return result; // subJobs is empty => isExecutable will return false
        }
        // Preview version : Parent node must be an AnchorPane (as in SB 1.1)
        // TODO : if the object container is a Pane, 
        // update its bounds but do not anchor it.
        final Object parentObject = parentInstance.getSceneGraphObject();
        if ((parentObject instanceof AnchorPane) == false) {
            return result; // subJobs is empty => isExecutable will return false
        }

        final AnchorPane parentNode = (AnchorPane) parentObject;
        final Bounds childBounds = childNode.getLayoutBounds();
        final Bounds parentBounds = parentNode.getLayoutBounds();
        Scale scale = null;
        for (Transform transform : childNode.getTransforms()) {
            if (transform instanceof Scale) {
                scale = (Scale) transform;
            }
        }
        double scaleX = scale == null ? 1.0 : scale.getX();
        double scaleY = scale == null ? 1.0 : scale.getY();
        final Set<Sizing> sizing = getSizingMask(childNode);
        final boolean isResizableX = sizing.contains(Sizing.HORIZONTAL);
        final boolean isResizableY = sizing.contains(Sizing.VERTICAL);
        double leftAnchorValue = isResizableX ? 0
                : (parentBounds.getWidth() - childBounds.getWidth() * scaleX) / 2.0;
        double topAnchorValue = isResizableY ? 0
                : (parentBounds.getHeight() - childBounds.getHeight() * scaleY) / 2.0;
        double prefWidthValue = isResizableX ? parentBounds.getWidth() / scaleY
                : childBounds.getWidth();
        double prefHeightValue = isResizableY ? parentBounds.getHeight() / scaleY
                : childBounds.getHeight();

        // Modify pref size jobs
        //----------------------------------------------------------------------
        final Job prefWidthJob = modifyJob("prefWidth", prefWidthValue);
        if (prefWidthJob.isExecutable()) { // Update if new value differs from old one
            result.add(prefWidthJob);
        }
        final Job prefHeightJob = modifyJob("prefHeight", prefHeightValue);
        if (prefHeightJob.isExecutable()) { // Update if new value differs from old one
            result.add(prefHeightJob);
        }

        // Modify Anchors Jobs
        //----------------------------------------------------------------------
        final Job leftAnchorJob = modifyAnchorJob(Anchor.LEFT, leftAnchorValue);
        if (leftAnchorJob.isExecutable()) { // Update if new value differs from old one
            result.add(leftAnchorJob);
        }
        final Job topAnchorJob = modifyAnchorJob(Anchor.TOP, topAnchorValue);
        if (topAnchorJob.isExecutable()) { // Update if new value differs from old one
            result.add(topAnchorJob);
        }
        if (isResizableX) {
            final Job rightAnchorJob = modifyAnchorJob(Anchor.RIGHT, 0.0);
            if (rightAnchorJob.isExecutable()) { // Update if new value differs from old one
                result.add(rightAnchorJob);
            }
        }
        if (isResizableY) {
            final Job bottomAnchorJob = modifyAnchorJob(Anchor.BOTTOM, 0.0);
            if (bottomAnchorJob.isExecutable()) { // Update if new value differs from old one
                result.add(bottomAnchorJob);
            }
        }
        return result;
    }