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


Java DoubleBinding.addListener方法代码示例

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


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

示例1: StraightEdgeView

import javafx.beans.binding.DoubleBinding; //导入方法依赖的package包/类
public StraightEdgeView(DoubleProperty sX, DoubleProperty sY, DoubleProperty eX, DoubleProperty eY) {
	super(sX, sY, eX, eY);
	
	aX = new DoubleBinding() {

		{
			super.bind(sX, eX);
		}

		@Override
		protected double computeValue() {
			return (sX.get() + eX.get()) * .5;
		}
	};

	aY = new DoubleBinding() {

		{
			super.bind(sY, eY);
		}

		@Override
		protected double computeValue() {
			return (sY.get() + eY.get()) * .5;
		}
	};
	
	Line line = new Line();
	line.setStrokeWidth(1.5);
	line.setStroke(Color.BLUE);
	line.startXProperty().bind(sX);
	line.startYProperty().bind(sY);
	line.endXProperty().bind(eX);
	line.endYProperty().bind(eY);
	
	Polygon arrow = new Polygon();
	arrow.setFill(Color.BLUE);
	final ChangeListener<Number> listener = (_0, _1, _2) -> {
		final double angle = a.get() + Math.PI;
		final double x = aX.get();
		final double y = aY.get();
		final double x0 = x + 5 * Math.cos(angle);
		final double x1 = x + 5 * Math.cos(angle + 2 * Math.PI / 3);
		final double x2 = x + 5 * Math.cos(angle - 2 * Math.PI / 3);
		final double y0 = y + 5 * Math.sin(angle);
		final double y1 = y + 5 * Math.sin(angle + 2 * Math.PI / 3);
		final double y2 = y + 5 * Math.sin(angle - 2 * Math.PI / 3);
		arrow.getPoints().clear();
		arrow.getPoints().addAll(x0, y0, x1, y1, x2, y2);
	};

	aX.addListener(listener);
	aY.addListener(listener);
	
	getChildren().addAll(line, arrow);
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:57,代码来源:StraightEdgeView.java

示例2: BidirectionalDoubleOffsetBinding

import javafx.beans.binding.DoubleBinding; //导入方法依赖的package包/类
private BidirectionalDoubleOffsetBinding(DoubleProperty property1, DoubleProperty property2, DoubleBinding offset) {


            this.offset = offset;
            this.lhs = property1;
            this.rhs = property2;

            lhs.set(rhs.get() + offset.get());

            rhs.addListener(this);
            lhs.addListener(this);
            offset.addListener(this);
        }
 
开发者ID:truffle-hog,项目名称:truffle-hog,代码行数:14,代码来源:MyBindings.java


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