/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ package test; import javafx.beans.binding.DoubleBinding; import javafx.beans.binding.ObjectExpression; import javafx.geometry.Bounds; import javafx.scene.Node; import javafx.scene.shape.Circle; /** * * @author akouznet */ public class BindableBounds { private ObjectExpression bounds; public BindableBounds(ObjectExpression bounds) { this.bounds = bounds; } DoubleBinding width() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getWidth(); } }; } DoubleBinding height() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getHeight(); } }; } DoubleBinding minX() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getMinX(); } }; } DoubleBinding minY() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getMinY(); } }; } DoubleBinding minZ() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getMinZ(); } }; } DoubleBinding maxX() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getMaxX(); } }; } DoubleBinding maxY() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getMaxY(); } }; } DoubleBinding maxZ() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getMaxZ(); } }; } DoubleBinding depth() { return new DoubleBinding() { { bind(bounds); } @Override protected double computeValue() { return bounds.get().getDepth(); } }; } public static void main(String[] args) { final Node node = new Circle(); node.translateXProperty().bind(new BindableBounds(node.layoutBoundsProperty()).width()); } }