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)); }
public EdgeView(final DoubleProperty sX, final DoubleProperty sY, final DoubleProperty eX, final DoubleProperty eY) { a = new DoubleBinding() { private final DoubleBinding dX = sX.subtract(eX); private final DoubleBinding dY = sY.subtract(eY); { super.bind(dX, dY); } @Override protected double computeValue() { return Math.atan2(dY.get(), dX.get()); } }; }
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 NumberBinding getDouble(AnimatableField field, NodeModel node, KeyValueModel keyValue, KeyFrameModel keyFrame) { DoubleBinding currentValue = ModelFunctions.toDoubleBinding(keyValue.valueProperty()); KeyFrameModel earlier = getEarlierKeyFrameWithNonNullValue(field, node, keyFrame); KeyFrameModel later = getLaterKeyFrameWithNonNullValue(field, node, keyFrame); if (earlier != null) { DoubleProperty earlierTime = earlier.absoluteTimeProperty(); double earlierValue = (Double) earlier.getKeyValues().get(node).get(field).getValue(); if (later != null) { DoubleProperty laterTime = later.absoluteTimeProperty(); double laterValue = (Double) later.getKeyValues().get(node).get(field).getValue(); DoubleBinding interpolated = Bindings.createDoubleBinding(() -> { double timeFraction = (keyFrame.getAbsoluteTime() - earlierTime.get()) / (laterTime.get() - earlierTime.get()); double interpolatorFactor = later.getKeyValues().get(node).get(field).getInterpolator().curve(timeFraction); return (double) Math.round(earlierValue + (laterValue - earlierValue) * interpolatorFactor); }, earlierTime, laterTime, keyFrame.absoluteTimeProperty()); return Bindings.when(keyValue.valueProperty().isNotNull()).then(currentValue).otherwise(interpolated); } else { return Bindings.when(keyValue.valueProperty().isNotNull()).then(currentValue).otherwise(earlierValue); } } else { return currentValue; } }
public Board() { super(GAP, GAP); getStyleClass().add("board"); build(); sceneProperty().addListener((o, os, ns) -> { DoubleBinding tileSize = getScene().widthProperty().subtract(GAP * 4).divide(SIZE); prefTileHeightProperty().bind(tileSize); prefTileWidthProperty().bind(tileSize); }); setTileAlignment(Pos.CENTER); setPrefColumns(Board.SIZE); setAlignment(Pos.CENTER); }
@Override public Collection<Shape> createSymbol(BoardCell cell) { final DoubleBinding padding = cell.widthProperty().multiply(.15); Line l1 = new Line(20, 20, cell.getWidth() - 20, cell.getHeight() - 20); l1.setMouseTransparent(true); l1.getStyleClass().add("board-symbol"); l1.endXProperty().bind(cell.widthProperty().subtract(padding)); l1.endYProperty().bind(cell.heightProperty().subtract(padding)); Line l2 = new Line(20, cell.getHeight() - 20, cell.getWidth() - 20, 20); l2.setMouseTransparent(true); l2.getStyleClass().add("board-symbol"); l2.endXProperty().bind(cell.widthProperty().subtract(padding)); l2.startYProperty().bind(cell.heightProperty().subtract(padding)); return Arrays.asList(l1,l2); }
/** * Constructs a new {@link InternalNode}. * @param children The children nodes of this InternalNode. */ public InternalNode(List<AbstractNode> children) { this.children = children; List<Edge> outgoingEdges = new ArrayList<>(); bindMargins(); bindLeafCount(); // Position the children. DoubleBinding rangeBegin = marginProperty().divide(2).negate(); for (AbstractNode child : children) { child.translateYProperty().bind(rangeBegin.add(child.marginProperty().divide(2))); child.translateXProperty().set(LEVELWIDTH); rangeBegin = rangeBegin.add(child.marginProperty()); Edge e = new Edge(child); outgoingEdges.add(e); } this.getChildren().addAll(0, outgoingEdges); // Add the nodes after the edges, so that they're on top. this.getChildren().addAll(children); }
public PointingHeroIcon(ObservableEntity oe) { super(oe); shape = new Polygon( 0, -200, -120, 200, 120, 200 ); shape.fillProperty().bind(getPlayerColor()); ObjectBinding<Vector> angRotVector = oe.getPropertyBinding(Vector.class, "CBodyComponent.m_angRotation", null); DoubleBinding angRot = Bindings.createDoubleBinding(() -> (double) angRotVector.get().getElement(1), angRotVector); IntegerBinding angDiff = Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "m_anglediff", 0)); shape.translateXProperty().bind(getMapX()); shape.translateYProperty().bind(getMapY()); shape.rotateProperty().bind(getBaseAngle().add(angRot).add(angDiff)); }
/** * Constructs and binds the appropriate properties for the line and * the arrow */ public DirectedPath(DoubleBinding startX, DoubleBinding startY, DoubleBinding endX,DoubleBinding endY){ this.path = new Path(); MoveTo start = new MoveTo(); start.xProperty().bind(startX); start.yProperty().bind(startY); LineTo end = new LineTo(); end.xProperty().bind(endX); end.yProperty().bind(endY); path.getElements().add(start); path.getElements().add(end); this.arrow = getArrow(); this.getChildren().add(path); this.getChildren().add(arrow); this.path.getStyleClass().setAll("edge"); }
/** * Checks the start and endpoints to see if any midpoints are necessary for drawing the line * between them correctly. If the endpoints are more than 1 column apart and, the midpoints * are added at the calculated x value * @param startY the starting y coordinate of this edge * @param endY the ending y coordinate of this edge */ private void checkAndAddMidPoints(DoubleBinding startY, DoubleBinding endY){ if(target.rowLocationProperty.get() - source.rowLocationProperty.get() > 1 || target.rowLocationProperty.get() - source.rowLocationProperty.get() < 0){ if(!addedMidPoints){ path.addPoint(midLineX.add(0), startY.subtract(TreeLayout.V_SPACING/3.), 1); path.addPoint(midLineX.add(0), endY.add(TreeLayout.V_SPACING/2.), 2); this.addedMidPoints = true; } }else{ if(addedMidPoints){ path.removePoint(2); path.removePoint(1); this.addedMidPoints = false; } } }
private void bindNode() { final View v = View.getInstance(); node.translateXProperty().bind(new DoubleBinding() { { super.bind(v.xProperty()); } @Override protected double computeValue() { double offset = v.getX() % View.WIDTH.get(); if (offset < 0) { offset += View.WIDTH.get(); } return -offset; } }); node.translateYProperty().bind(new SimpleDoubleProperty(32).add(v.yProperty())); }
/** * Bind our logarithmic bounds with the super class bounds, consider the base 10 logarithmic scale. */ private void bindLogBoundsToDefaultBounds() { logLowerBound.bind(new DoubleBinding() { { super.bind(lowerBoundProperty()); } @Override protected double computeValue() { return Math.log10(lowerBoundProperty().get()); } }); logUpperBound.bind(new DoubleBinding() { { super.bind(upperBoundProperty()); } @Override protected double computeValue() { return Math.log10(upperBoundProperty().get()); } }); }
private Node getRightPane() { StackPane rightPane = new StackPane(); rightPane.setStyle("-fx-background-color:#F0F0F0;"); rightPane.setPadding(new Insets(0,10,10,10)); rightPane.setPrefWidth(300); rightPane.getChildren().add( getBox() ); final double translateVal = 55.0D; rightPane.setTranslateY(-1 * translateVal); rightPane.minHeightProperty().bind(new DoubleBinding() { { bind(leftPane.heightProperty()); } @Override protected double computeValue() { return (leftPane.getHeight()+translateVal); } }); return rightPane; }
private DoubleBinding constantOf(double defaultValue) { return new DoubleBinding() { @Override protected double computeValue() { return defaultValue; } }; }
public static DoubleBinding toDoubleBinding(ObservableValue<? extends Number> ov) { return new DoubleBinding() { { bind(ov); } @Override protected double computeValue() { return ov.getValue() == null ? 0 : ov.getValue().doubleValue(); } }; }
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); }
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); } }; }
/** * Instantiates a new Texture layer cell. * @param prefWidth the pref width * @param maxWidth the max width */ public TextureLayerCell(final DoubleBinding prefWidth, final DoubleBinding maxWidth) { settingContainer = new GridPane(); settingContainer.prefWidthProperty().bind(prefWidth); settingContainer.maxWidthProperty().bind(maxWidth); layerField = new Label(); layerField.prefWidthProperty().bind(settingContainer.widthProperty()); diffuseTextureControl = new NamedChooseTextureControl("Diffuse"); diffuseTextureControl.setChangeHandler(this::updateDiffuse); diffuseTextureControl.setControlWidthPercent(PropertyControl.CONTROL_WIDTH_PERCENT_2); normalTextureControl = new NamedChooseTextureControl("Normal"); normalTextureControl.setChangeHandler(this::updateNormal); normalTextureControl.setControlWidthPercent(PropertyControl.CONTROL_WIDTH_PERCENT_2); final Label scaleLabel = new Label(Messages.EDITING_COMPONENT_SCALE + ":"); scaleLabel.prefWidthProperty().bind(settingContainer.widthProperty().multiply(LABEL_PERCENT)); scaleField = new FloatTextField(); scaleField.setMinMax(0.0001F, Integer.MAX_VALUE); scaleField.setScrollPower(3F); scaleField.addChangeListener((observable, oldValue, newValue) -> updateScale(newValue)); scaleField.prefWidthProperty().bind(settingContainer.widthProperty().multiply(FIELD_PERCENT)); settingContainer.add(layerField, 0, 0, 2, 1); settingContainer.add(diffuseTextureControl, 0, 1, 2, 1); settingContainer.add(normalTextureControl, 0, 2, 2, 1); settingContainer.add(scaleLabel, 0, 3); settingContainer.add(scaleField, 1, 3); FXUtils.addClassTo(settingContainer, CSSClasses.DEF_GRID_PANE); FXUtils.addClassTo(layerField, CSSClasses.ABSTRACT_PARAM_CONTROL_PARAM_NAME); FXUtils.addClassTo(scaleLabel, CSSClasses.ABSTRACT_PARAM_CONTROL_PARAM_NAME_SINGLE_ROW); FXUtils.addClassTo(scaleField, CSSClasses.ABSTRACT_PARAM_CONTROL_COMBO_BOX); FXUtils.addClassTo(this, CSSClasses.PROCESSING_COMPONENT_TERRAIN_EDITOR_TEXTURE_LAYER); }
private DoubleBinding createXPositionBinding(StackPane track, ScrollBar scrollBar) { Callable<Double> getX = () -> { double width = track.getLayoutBounds().getWidth(); return scalePosition(position.get(), width, scrollBar); }; return Bindings.createDoubleBinding(getX, position, alignment, thickness, track.layoutBoundsProperty(), scrollBar.minProperty(), scrollBar.maxProperty()); }
private DoubleBinding createYPositionBinding(StackPane track, ScrollBar scrollBar) { Callable<Double> getY = () -> { double height = track.getLayoutBounds().getHeight(); return scalePosition(position.get(), height, scrollBar); }; return Bindings.createDoubleBinding(getY, position, alignment, thickness, track.layoutBoundsProperty(), scrollBar.minProperty(), scrollBar.maxProperty()); }
public TextButton(String name, final Runnable action, final Color color) { this.name = name; this.textAction = action; this.setId(name); Rectangle bg = new Rectangle(100, 20, color); bg.setArcHeight(5); bg.setArcHeight(5); getChildren().add(bg); final Text txt = new Text(name); getChildren().add(txt); bg.widthProperty().bind(new DoubleBinding() { { bind(txt.boundsInLocalProperty()); } @Override protected double computeValue() { return txt.getBoundsInLocal().getWidth() + 10; } }); EventHandler<MouseEvent> handler = new EventHandler<MouseEvent>() { public void handle(MouseEvent t) { if (null != textAction) { textAction.run(); } } }; this.setOnMousePressed(handler); }
@Override public Binding<Number> createMeasurement(PathObject pathObject) { return new DoubleBinding() { @Override protected double computeValue() { return getCentroid(pathObject.getROI()); } }; }
@Override public Binding<Number> createMeasurement(final PathObject pathObject) { return new DoubleBinding() { @Override protected double computeValue() { ROI roi = pathObject.getROI(); if (!(roi instanceof PathArea)) return Double.NaN; if (hasPixelSizeMicrons()) return ((PathArea)roi).getScaledArea(pixelWidthMicrons(), pixelHeightMicrons()); return ((PathArea)roi).getArea(); } }; }
@Override public Binding<Number> createMeasurement(final PathObject pathObject) { return new DoubleBinding() { @Override protected double computeValue() { ROI roi = pathObject.getROI(); if (!(roi instanceof PathArea)) return Double.NaN; if (hasPixelSizeMicrons()) return ((PathArea)roi).getScaledPerimeter(pixelWidthMicrons(), pixelHeightMicrons()); return ((PathArea)roi).getPerimeter(); } }; }
@Override public Binding<Number> createMeasurement(final PathObject pathObject) { return new DoubleBinding() { @Override protected double computeValue() { ROI roi = pathObject.getROI(); List<Point2> points; if (roi instanceof PolygonROI) points = ((PolygonROI)roi).getPolygonPoints(); else if (roi instanceof AreaROI) points = ((AreaROI)roi).getPolygonPoints(); else return Double.NaN; double xScale = hasPixelSizeMicrons() ? pixelWidthMicrons() : 1; double yScale = hasPixelSizeMicrons() ? pixelHeightMicrons() : 1; double maxLengthSq = 0; for (int i = 0; i < points.size(); i++) { Point2 pi = points.get(i); for (int j = i+1; j < points.size(); j++) { Point2 pj = points.get(j); double dx = (pi.getX() - pj.getX()) * xScale; double dy = (pi.getY() - pj.getY()) * yScale; maxLengthSq = Math.max(maxLengthSq, dx*dx + dy*dy); } } return Math.sqrt(maxLengthSq); } }; }
@Override public Binding<Number> createMeasurement(final PathObject pathObject) { return new DoubleBinding() { @Override protected double computeValue() { ROI roi = pathObject.getROI(); if (!(roi instanceof PathLine)) return Double.NaN; if (hasPixelSizeMicrons()) return ((PathLine)roi).getScaledLength(pixelWidthMicrons(), pixelHeightMicrons()); return ((PathLine)roi).getLength(); } }; }
@Override public Binding<Number> createMeasurement(final PathObject pathObject) { return new DoubleBinding() { @Override protected double computeValue() { ROI roi = pathObject.getROI(); if (!(roi instanceof PathPoints)) return Double.NaN; return ((PathPoints)roi).getNPoints(); } }; }
@Override public void start(Stage s) throws Exception { VBox root = new VBox(); root.setBackground(Background.EMPTY); Scene scene = new Scene(root, 1024, 768, Color.TRANSPARENT); ObservableList<Node> rootNode = root.getChildren(); MenuForm menuView = new MenuForm(); rootNode.add(menuView); DoubleBinding db = scene.heightProperty().subtract(menuView.heightProperty()).subtract(-0.1); SplitPane sp = new SplitPane(); sp.setBackground(Background.EMPTY); sp.minHeightProperty().bind(db); sp.maxHeightProperty().bind(db); // sp.setDividerPositions(0, 0.3); rootNode.add(sp); VBox left = new VBox(); left.setStyle("-fx-background-color:#c0c0c0;"); left.getChildren().add(new Label("this is Left")); SplitPane rightPane = new SplitPane(); rightPane.setBackground(Background.EMPTY); rightPane.setOrientation(Orientation.VERTICAL); sp.getItems().addAll(left, rightPane); VBox editPane = new VBox(); editPane.setBackground(Background.EMPTY); TextArea consolePane = new TextArea(); consolePane.setPrefRowCount(10); rightPane.getItems().addAll(editPane, consolePane); s.setScene(scene); s.show(); }
@Override public Collection<Shape> createSymbol(BoardCell cell) { Circle c = new Circle(); c.setMouseTransparent(true); c.getStyleClass().add("board-symbol"); final DoubleBinding padding = cell.widthProperty().multiply(.15); c.radiusProperty().bind(cell.widthProperty().divide(2).subtract(padding)); return Arrays.asList(c); }
@Test public void createWithValidParams() { final DoubleBinding cut = new ReductionDoubleBinding(REDUCTION, DE1, DE2); assertEquals("Binding value 1", REDUCTION.apply(DE1.get(), DE2.get()), cut.get(), Precision.EPSILON); DE1.set(30); assertEquals("Binding value 2", REDUCTION.apply(DE1.get(), DE2.get()), cut.get(), Precision.EPSILON); DE2.set(50); assertEquals("Binding value 3", REDUCTION.apply(DE1.get(), DE2.get()), cut.get(), Precision.EPSILON); }
private void createEditorNode() { EventHandler<KeyEvent> keyEventsHandler = t -> { if (t.getCode() == KeyCode.ENTER) { commitHelper(false); } else if (t.getCode() == KeyCode.ESCAPE) { cancelEdit(); } else if (t.getCode() == KeyCode.TAB) { commitHelper(false); TreeTableColumn nextColumn = getNextColumn(!t.isShiftDown()); if (nextColumn != null) { getTreeTableView().edit(getIndex(), nextColumn); } } }; ChangeListener<Boolean> focusChangeListener = (observable, oldValue, newValue) -> { //This focus listener fires at the end of cell editing when focus is lost //and when enter is pressed (because that causes the text field to lose focus). //The problem is that if enter is pressed then cancelEdit is called before this //listener runs and therefore the text field has been cleaned up. If the //text field is null we don't commit the edit. This has the useful side effect //of stopping the double commit. if (!newValue && editorNode != null) { commitHelper(true); } }; DoubleBinding minWidthBinding = Bindings.createDoubleBinding(() -> { return this.getWidth() - this.getGraphicTextGap() * 2 - this.getBaselineOffset(); }, this.widthProperty(), this.graphicTextGapProperty()); editorNode = builder.createNode(getValue(), minWidthBinding, keyEventsHandler, focusChangeListener); }
@Override public Region createNode(Double value, DoubleBinding minWidthBinding, EventHandler<KeyEvent> keyEventsHandler, ChangeListener<Boolean> focusChangeListener) { StackPane pane = new StackPane(); pane.setStyle("-fx-padding:-10 0 -10 0"); textField = new JFXTextField(value + ""); textField.minWidthProperty().bind(minWidthBinding); textField.setOnKeyPressed(keyEventsHandler); textField.focusedProperty().addListener(focusChangeListener); DoubleValidator validator = new DoubleValidator(); validator.setMessage("Value must be a rational number"); textField.getValidators().add(validator); pane.getChildren().add(textField); return pane; }
@Override public Region createNode(String value, DoubleBinding minWidthBinding, EventHandler<KeyEvent> keyEventsHandler, ChangeListener<Boolean> focusChangeListener) { StackPane pane = new StackPane(); pane.setStyle("-fx-padding:-10 0 -10 0"); textField = new JFXTextField(value); textField.setStyle("-fx-background-color:TRANSPARENT;"); textField.minWidthProperty().bind(minWidthBinding); textField.setOnKeyPressed(keyEventsHandler); textField.focusedProperty().addListener(focusChangeListener); pane.getChildren().add(textField); return pane; }