private static <T extends Circular> ObservableDoubleValue calculateXBinding(final T source, final Point target) { return new DoubleBinding() { { super.bind(source.xProperty(), source.yProperty()); super.bind(target.xProperty(), target.yProperty()); super.bind(source.radiusProperty()); super.bind(source.scaleProperty()); } @Override protected double computeValue() { final double angle = Math.atan2(source.yProperty().get() - target.yProperty().get(), source.xProperty().get() - target.xProperty().get()) - Math.toRadians(180); return source.xProperty().get() + source.radiusProperty().get() * source.scaleProperty().get() * Math.cos(angle); } }; }
private static <T extends Circular> ObservableDoubleValue calculateYBinding(final T source, final Point target) { return new DoubleBinding() { { super.bind(source.xProperty(), source.yProperty()); super.bind(target.xProperty(), target.yProperty()); super.bind(source.radiusProperty()); super.bind(source.scaleProperty()); } @Override protected double computeValue() { final double angle = Math.atan2(source.yProperty().get() - target.yProperty().get(), source.xProperty().get() - target.xProperty().get()) - Math.toRadians(180); return source.yProperty().get() + source.radiusProperty().get() * source.scaleProperty().get() * Math.sin(angle); } }; }
private IntegerBinding convertXModelCoordinateToXPixelCoordinate(ObservableDoubleValue xModel) { return new IntegerBinding() { { this.bind(xModel,oneUnitInModelEqualsHowManyPixels,pixelOffsetToSimulateNegativeXCoordinate); } @Override protected int computeValue() { int newValue = (int) Math.round(xModel.get() * oneUnitInModelEqualsHowManyPixels.get() + pixelOffsetToSimulateNegativeXCoordinate.doubleValue()); assert newValue >= 0; //new value must always be positive! return newValue; } }; }
private IntegerBinding convertYModelCoordinateToYPixelCoordinate(ObservableDoubleValue yModel) { return new IntegerBinding() { { this.bind(yModel,oneUnitInModelEqualsHowManyPixels,pixelOffsetToSimulateNegativeYCoordinate); } @Override protected int computeValue() { int newValue = (int) Math.round(yModel.get() * oneUnitInModelEqualsHowManyPixels.get() + pixelOffsetToSimulateNegativeYCoordinate.doubleValue()); assert newValue >= 0; //new value must always be positive! return newValue; } }; }
public static void bind(final Link subject, final Circular source, final ObservableDoubleValue x, final ObservableDoubleValue y) { // Calculate the bindings (so that the line will be based on the circle circumference instead of in its center) final LineBinding lineBinding = LineBinding.getCircularBindings(source, CanvasPresentation.mouseTracker, x, y); // Bind the subjects properties accordingly to our calculations subject.startXProperty().bind(lineBinding.startX); subject.startYProperty().bind(lineBinding.startY); subject.endXProperty().bind(lineBinding.endX); subject.endYProperty().bind(lineBinding.endY); }
public static void bind(final ArrowHead subject, final Circular source, final Circular target) { // Calculate the bindings (so that the line will be based on the circle circumference instead of in its center) final LineBinding lineBinding = LineBinding.getCircleBindings(source, target); ObservableDoubleValue startX = lineBinding.startX; ObservableDoubleValue startY = lineBinding.startY; ObservableDoubleValue endX = lineBinding.endX; ObservableDoubleValue endY = lineBinding.endY; subject.xProperty().bind(endX); subject.yProperty().bind(endY); DoubleBinding rotationBinding = new DoubleBinding() { { super.bind(startX, startY, endX, endY); super.bind(source.scaleProperty()); } @Override protected double computeValue() { double angle = Math.atan2(startY.get() - endY.get(), startX.get() - endX.get()); return Math.toDegrees(angle) + 90; } }; subject.rotateProperty().bind(rotationBinding); }
public static void bind(final ArrowHead subject, final Circular source, final ObservableDoubleValue x, final ObservableDoubleValue y) { // Calculate the bindings (so that the line will be based on the circle circumference instead of in its center) final LineBinding lineBinding = LineBinding.getCircularBindings(source, CanvasPresentation.mouseTracker, x, y); ObservableDoubleValue startX = lineBinding.startX; ObservableDoubleValue startY = lineBinding.startY; ObservableDoubleValue endX = lineBinding.endX; ObservableDoubleValue endY = lineBinding.endY; subject.xProperty().bind(endX); subject.yProperty().bind(endY); DoubleBinding rotationBinding = new DoubleBinding() { { super.bind(startX, startY, endX, endY); } @Override protected double computeValue() { double angle = Math.atan2(startY.get() - endY.get(), startX.get() - endX.get()); return Math.toDegrees(angle) + 90; } }; subject.rotateProperty().bind(rotationBinding); }
LineBinding(final ObservableDoubleValue startX, final ObservableDoubleValue startY, final ObservableDoubleValue endX, final ObservableDoubleValue endY) { this.startX = startX; this.startY = startY; this.endX = endX; this.endY = endY; }
private static LineBinding getCircularBindings(final Circular source, final MouseTracker target, final ObservableDoubleValue x, final ObservableDoubleValue y) { final ObservableDoubleValue mouseX = target.gridXProperty().subtract(x); final ObservableDoubleValue mouseY = target.gridYProperty().subtract(y); final Point point = new Point(mouseX, mouseY); return new BindingHelper.LineBinding( calculateXBinding(source, point), calculateYBinding(source, point), mouseX, mouseY ); }
private static ObservableDoubleValue calculateXBinding(final Circle source, final Point target) { return new DoubleBinding() { { super.bind(source.centerXProperty(), source.centerYProperty()); super.bind(target.xProperty(), target.yProperty()); super.bind(source.radiusProperty()); } @Override protected double computeValue() { double angle = Math.atan2(source.centerYProperty().get() - target.yProperty().get(), source.centerXProperty().get() - target.xProperty().get()) - Math.toRadians(180); return source.centerXProperty().get() + source.radiusProperty().get() * Math.cos(angle); } }; }
private static ObservableDoubleValue calculateYBinding(final Circle source, final Point target) { return new DoubleBinding() { { super.bind(source.centerXProperty(), source.centerYProperty()); super.bind(target.xProperty(), target.yProperty()); super.bind(source.radiusProperty()); } @Override protected double computeValue() { double angle = Math.atan2(source.centerYProperty().get() - target.yProperty().get(), source.centerXProperty().get() - target.xProperty().get()) - Math.toRadians(180); return source.centerYProperty().get() + source.radiusProperty().get() * Math.sin(angle); } }; }
@Override public ItemDragHelper.DragBounds getDragBounds() { final ObservableDoubleValue minX = new SimpleDoubleProperty(CanvasPresentation.GRID_SIZE); final ObservableDoubleValue maxX = getComponent().widthProperty().subtract(JorkPresentation.JORK_WIDTH + CanvasPresentation.GRID_SIZE); final ObservableDoubleValue minY = new SimpleDoubleProperty(ComponentPresentation.TOOL_BAR_HEIGHT + CanvasPresentation.GRID_SIZE); final ObservableDoubleValue maxY = getComponent().heightProperty().subtract(JorkPresentation.JORK_HEIGHT + CanvasPresentation.GRID_SIZE); return new ItemDragHelper.DragBounds(minX, maxX, minY, maxY); }
@Override public ItemDragHelper.DragBounds getDragBounds() { final ObservableDoubleValue minX = new SimpleDoubleProperty(CanvasPresentation.GRID_SIZE); final ObservableDoubleValue maxX = getParentComponent().widthProperty().subtract(getSubComponent().widthProperty().add(CanvasPresentation.GRID_SIZE)); final ObservableDoubleValue minY = new SimpleDoubleProperty(ComponentPresentation.TOOL_BAR_HEIGHT + CanvasPresentation.GRID_SIZE); final ObservableDoubleValue maxY = getParentComponent().heightProperty().subtract(getSubComponent().heightProperty().add(CanvasPresentation.GRID_SIZE)); return new ItemDragHelper.DragBounds(minX, maxX, minY, maxY); }
@Override public ItemDragHelper.DragBounds getDragBounds() { final ObservableDoubleValue minX = new SimpleDoubleProperty(CanvasPresentation.GRID_SIZE); final ObservableDoubleValue maxX = getComponent().widthProperty().subtract(CanvasPresentation.GRID_SIZE); final ObservableDoubleValue minY = new SimpleDoubleProperty(ComponentPresentation.TOOL_BAR_HEIGHT + CanvasPresentation.GRID_SIZE); final ObservableDoubleValue maxY = getComponent().heightProperty().subtract(CanvasPresentation.GRID_SIZE); return new ItemDragHelper.DragBounds(minX, maxX, minY, maxY); }
@Override public ItemDragHelper.DragBounds getDragBounds() { final ObservableDoubleValue minX = new SimpleDoubleProperty(GRID_SIZE * 2); final ObservableDoubleValue maxX = getComponent().widthProperty().subtract(GRID_SIZE * 2); final ObservableDoubleValue minY = new SimpleDoubleProperty(ComponentPresentation.TOOL_BAR_HEIGHT + GRID_SIZE * 2); final ObservableDoubleValue maxY = getComponent().heightProperty().subtract(GRID_SIZE * 2); return new ItemDragHelper.DragBounds(minX, maxX, minY, maxY); }
@SuppressWarnings("unchecked") @Activate public void active(ComponentContext compCtx) { ctx = compCtx.getBundleContext(); register(GlobalVariables.VALUE_ANIMATION_TIME_MULTIPLIER, new SimpleDoubleProperty(1.0), ObservableDoubleValue.class, DoubleProperty.class); }
/** * Creates a new instance of FunctionDoubleBinding with a given {@link java.util.function.Function} on a supplied dependency. * @param function Function to modify the dependency value * @param dependency The dependency */ public FunctionDoubleBinding(Function<Double, Double> function, ObservableDoubleValue dependency) { requireNonNull(dependency, "Parameter 'dependency' is null"); requireNonNull(function, "Parameter 'function' is null"); this.dependency = dependency; this.function = function; bind(dependency); }
/** * Creates a new instance of ReductionDoubleBonding with a given {@link java.util.function.BinaryOperator} and an optional set of initial dependencies. * @param binaryOperator The associative accumulation function (see {@link java.util.function.BinaryOperator} for more details) * @param dependencies An optional set of dependencies to be initially bound */ public ReductionDoubleBinding(BinaryOperator<Double> binaryOperator, ObservableDoubleValue... dependencies) { requireNonNull(binaryOperator, "Parameter 'binaryOperator' is null"); this.binaryOperator = binaryOperator; for (ObservableDoubleValue dependency : dependencies) { requireNonNull(dependency, "At least one of the dependecies is null"); add(dependency); } }
/** * Bind the new (not previously bound) dependency. * @param dependency The dependency to be bound */ public final void add(ObservableDoubleValue dependency) { requireNonNull(dependency, "Parameter 'dependency' is null"); if (!dependencies.contains(dependency)) { dependencies.add(dependency); bind(dependency); invalidate(); } else { LOGGER.warn("Dependency already included: " + dependency + ", Skipping."); } }
/** * Unbind the existing (previously bound) dependency. * @param dependency The dependency to be unbound */ public final void remove(ObservableDoubleValue dependency) { requireNonNull(dependency, "Parameter 'dependency' is null"); if (dependencies.contains(dependency)) { dependencies.remove(dependency); unbind(dependency); invalidate(); } else { LOGGER.warn("Dependency not included: " + dependency + ", Skipping."); } }
public SearchController(ClientAPI client, StringProperty input, ObservableDoubleValue x, ObservableDoubleValue y, ObservableDoubleValue width) { this.client = client; this.input = input; this.x = x; this.y = y; this.width = width; }
@Test public void testObservableDoubleValue(){ ObservableDoubleValue actual = new SimpleDoubleProperty(10.2); assertThat(actual).hasValue(10.2); assertThat(actual).hasSameValue(actual); }
@Test public void should_fail_if_actual_has_wrong_value(){ try{ ObservableDoubleValue actual = new SimpleDoubleProperty(10.123); new ObservableValueAssertions<>(actual).hasValue(10.12); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("<10.12> but was <10.123>"); } }
/** * get the latest observation of a sales department datum that updates itself * @param goodType the good being sold * @param salesDataType the kind of datum you are looking form * @return an observable (and so listeneable) object updating */ public ObservableDoubleValue getLatestObservableObservation( GoodType goodType, SalesDataType salesDataType) { SalesDepartment department = getSalesDepartment(goodType); Preconditions.checkState(department != null); return department.getLatestObservationObservable(salesDataType); }
public Item(String label, @Nullable ObservableDoubleValue progress) { this.label = new SimpleStringProperty(label); this.progress = progress; }
public Item pushItem(String string, @Nullable ObservableDoubleValue progress) { Item i = new Item(string, progress); items.add(i); return i; }
public Nail(final ObservableDoubleValue x, final ObservableDoubleValue y) { this(x.get(), y.get()); }
public static void bind(final Circular subject, final ObservableDoubleValue x, final ObservableDoubleValue y) { subject.xProperty().bind(CanvasPresentation.mouseTracker.gridXProperty().subtract(x)); subject.yProperty().bind(CanvasPresentation.mouseTracker.gridYProperty().subtract(y)); }
public static void bind(final Link lineSubject, final ArrowHead arrowHeadSubject, final Circular source, final ObservableDoubleValue x, final ObservableDoubleValue y) { BindingHelper.bind(lineSubject, source, x, y); BindingHelper.bind(arrowHeadSubject, source, x, y); BindingHelper.bind(lineSubject, arrowHeadSubject); }
Point(final ObservableDoubleValue x, final ObservableDoubleValue y) { this.x = x; this.y = y; }
private ObservableDoubleValue xProperty() { return x; }
private ObservableDoubleValue yProperty() { return y; }
public DragBounds(final ObservableDoubleValue minX, final ObservableDoubleValue maxX, final ObservableDoubleValue minY, final ObservableDoubleValue maxY) { this.minX = minX; this.maxX = maxX; this.minY = minY; this.maxY = maxY; }
public double trimX(final ObservableDoubleValue x) { return trimX(x.get()); }
public double trimY(final ObservableDoubleValue y) { return trimY(y.get()); }
public DoubleBinding selectDouble(Function<S, ? extends ObservableDoubleValue> childPropertyAccessor) { return selectDouble(childPropertyAccessor, 0.0); }
public DoubleBinding selectDouble(Function<S, ? extends ObservableDoubleValue> childPropertyAccessor, double defaultValue) { return new DoubleBindingAdapter(new ChainBinding<>(rootProperty, childPropertyAccessor), defaultValue); }