当前位置: 首页>>代码示例>>Java>>正文


Java DoubleExpression.add方法代码示例

本文整理汇总了Java中javafx.beans.binding.DoubleExpression.add方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleExpression.add方法的具体用法?Java DoubleExpression.add怎么用?Java DoubleExpression.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.beans.binding.DoubleExpression的用法示例。


在下文中一共展示了DoubleExpression.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initProgressBinding

import javafx.beans.binding.DoubleExpression; //导入方法依赖的package包/类
private void initProgressBinding() {
	DoubleExpression tmp = constantOf(0);

	for (Command command : registeredCommands) {
		final ReadOnlyDoubleProperty progressProperty = command.progressProperty();

		/**
		 * When the progress of a command is "undefined", the progress property has a value of -1.
		 * But in our use case we like to have a value of 0 in this case. 
		 * Therefore we create a custom binding here.
		 */
		final DoubleBinding normalizedProgress = Bindings
				.createDoubleBinding(() -> (progressProperty.get() == -1) ? 0.0 : progressProperty.get(),
						progressProperty);

		tmp = tmp.add(normalizedProgress);
	}
	
	int divisor = registeredCommands.isEmpty() ? 1 : registeredCommands.size();
	progress.bind(Bindings.divide(tmp, divisor));
}
 
开发者ID:cmlanche,项目名称:easyMvvmFx,代码行数:22,代码来源:CompositeCommand.java

示例2: RadialMenuSectionDynamic

import javafx.beans.binding.DoubleExpression; //导入方法依赖的package包/类
public RadialMenuSectionDynamic(Params params, RadialPane radialPane, RadialMenuSectionDynamic parentSection, DoubleExpression streakAngleDeg) {

        this.params = params;
        this.radialPane = radialPane;
        this.parentSection = parentSection;

        this.radialPane.addRadialSection(this);

        if (streakAngleDeg != null) {
            this.streakAngleDeg.bind(streakAngleDeg);
        } else {
            this.streakAngleDeg.bind(params.angleFromDegProperty()
                    .add(params.angleToDegProperty().subtract(params.angleFromDegProperty()).multiply(0.5d)));
        }

        itemsCount = new SimpleListProperty<>(items).sizeProperty();

        final DoubleExpression itemRadiusHalf = params.buttonSizeProperty().multiply(0.5);

        if (parentSection != null) {
            innerRadius.bind(parentSection.outerRadiusProperty().add(itemRadiusHalf.multiply(params.spacingFactorProperty().multiply(2))));
        } else {
            innerRadius.bind(params.minRadiusProperty());
        }

        final DoubleExpression angleDeg = params.angleToDegProperty().subtract(params.angleFromDegProperty());
        final DoubleExpression angleRad = new FunctionDoubleBinding(Math::toRadians, angleDeg);
        final DoubleExpression availablePerimeter = angleRad.multiply(innerRadius.add(itemRadiusHalf));

        final DoubleExpression gapSize = params.buttonSizeProperty().multiply(params.gapFactorProperty());
        final DoubleExpression allItemsSize = params.buttonSizeProperty().multiply(itemsCount.subtract(1));
        final DoubleExpression totalSize = allItemsSize.add(gapSize.multiply(itemsCount.subtract(1)));

        final NumberBinding candidateNominalRadius = new When(availablePerimeter.greaterThan(totalSize))
                .then(innerRadius.add(itemRadiusHalf))
                .otherwise(totalSize.divide(angleRad));

        final DoubleExpression candidateAngularTotalSizeDeg = new FunctionDoubleBinding(Math::toDegrees, totalSize.divide(candidateNominalRadius));
        final DoubleExpression candidateAngularItemSizeDeg = candidateAngularTotalSizeDeg.divide(itemsCount);
        final DoubleExpression angularTotalSizeWithOverlapDeg = candidateAngularTotalSizeDeg.add(candidateAngularItemSizeDeg);

        nominalRadius.bind(candidateNominalRadius.add(new When(angularTotalSizeWithOverlapDeg.greaterThan(TWO_PI))
                .then(totalSize.divide(angularTotalSizeWithOverlapDeg.subtract(TWO_PI)))
                .otherwise(0)));

        angularTotalSizeDeg = new FunctionDoubleBinding(Math::toDegrees, totalSize.divide(nominalRadius));

        // TODO: Make sure, that outerRadius is reasonably small to prevent "large texture" errors
        outerRadius.bind(nominalRadius.add(itemRadiusHalf.add(params.buttonWidthOffsetProperty())));

        params.centerOffsetProperty().add(outerRadius);

        fromAngleDeg.bind(this.streakAngleDeg.subtract(angularTotalSizeDeg.multiply(0.5)));
        toAngleDeg.bind(this.streakAngleDeg.add(angularTotalSizeDeg.multiply(0.5)));


        correctedStreakAngleDeg.bind(this.streakAngleDeg.add(new When(fromAngleDeg.lessThan(params.angleFromDegProperty()))
                .then(params.angleFromDegProperty().subtract(fromAngleDeg))
                .otherwise(new When(toAngleDeg.greaterThan(params.angleToDegProperty()))
                        .then(params.angleToDegProperty().subtract(toAngleDeg))
                        .otherwise(0))));

        toAngleDeg.bind(fromAngleDeg.add(angularTotalSizeDeg));
        angularItemSizeDeg.bind(angularTotalSizeDeg.divide(itemsCount));

        final Circle perimeter = setupPerimeter(params);

        radialPane.getChildren().add(perimeter);

        params.centerOffsetProperty().addListener(observable -> radialPane.layout());
        totalSize.addListener((sender, oldV, newV) -> System.out.println(this + " [" + itemsCount.intValue() + "] totalSize: " + newV));
        nominalRadius.addListener((sender, oldV, newV)-> System.out.println(this + " [" + itemsCount.intValue() + "] nominalRadius: " + newV));
        angularTotalSizeDeg.addListener((sender, oldV, newV)-> System.out.println(this + " [" + itemsCount.intValue() + "] ang. size (deg): " + newV));
    }
 
开发者ID:dejv78,项目名称:jfx.radialmenu,代码行数:75,代码来源:RadialMenuSectionDynamic.java


注:本文中的javafx.beans.binding.DoubleExpression.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。