@Override public void setParent(IComposition parent) { this.parent = parent; final FilterPropertiesComponent fpc = parent.getComponent(FilterPropertiesComponent.class); // TODO maybe make this more error prone if (fpc != null) { Platform.runLater(() -> { shape.fillProperty().unbind(); shape.fillProperty().bind(new When(fpc.hasColorProperty()).then(fpc.activeColorProperty()).otherwise(colorPicked)); }); } }
public RadialItem addItem(MenuItem item) { final DoubleExpression idx = new SimpleDoubleProperty(items.size()); final NumberExpression itemRange = new When(params.directionProperty().isEqualTo(Direction.CW)) .then(idx.divide(itemsCount.subtract(1))) .otherwise(itemsCount.subtract(idx.add(1)).divide(itemsCount.subtract(1))); final DoubleExpression itemAngleDeg = correctedStreakAngleDeg.add(angularTotalSizeDeg.multiply(itemRange)).subtract(angularTotalSizeDeg.multiply(0.5)); final RadialItem itemButton = new RadialItem(params, item.getGraphic(), item.getText(), this, itemAngleDeg, (parentSection != null) ? parentSection.nominalRadius : new SimpleDoubleProperty(0), (item instanceof Menu)); items.add(itemButton); radialPane.getChildren().add(itemButton); return itemButton; }
private void initButtons() { btnBack.disableProperty().bind(currentStep.lessThanOrEqualTo(0)); btnNext.disableProperty().bind(currentStep.greaterThanOrEqualTo(steps.size() - 1)); btnCancel.textProperty().bind( new When(currentStep.lessThan(steps.size() - 1)) .then("Cancel") .otherwise("Start Over") ); }
private Circle createIndicatorCircle(int i) { Circle circle = new Circle(INDICATOR_RADIUS, Color.WHITE); circle.setStroke(Color.BLACK); circle.fillProperty().bind( new When( currentStep.greaterThanOrEqualTo(i)) .then(Color.DODGERBLUE) .otherwise(Color.WHITE)); return circle; }
/** * A more general version of {@link Bindings#when(ObservableBooleanValue)} * that can accept general boolean properties as conditions. * * @param condition the condition to bind to * * @see Bindings#when(ObservableBooleanValue) */ public static When when(Property<Boolean> condition) { if (condition instanceof ObservableBooleanValue) { return Bindings.when((ObservableBooleanValue) condition); } SimpleBooleanProperty realCondition = new SimpleBooleanProperty(); realCondition.bind(condition); return Bindings.when(realCondition); }
private void initializeProgressIndicator() { // Find the progress indicator final JFXSpinner progressIndicator = (JFXSpinner) lookup("#progressIndicator"); // If the query is running show the indicator, otherwise hide it progressIndicator.visibleProperty().bind(new When(query.queryStateProperty().isEqualTo(QueryState.RUNNING)).then(true).otherwise(false)); }
private void initMenu() { Menu fileMenu = new Menu(EditorConfig.MENU_FILE); MenuItem openFile = new MenuItem(EditorConfig.MENU_FILE_OPEN); FontAwesomeIconView openView = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_OPEN); openFile.setGraphic(openView); MenuItem saveFile = new MenuItem(EditorConfig.MENU_FILE_SAVE); FontAwesomeIconView saveView = new FontAwesomeIconView(FontAwesomeIcon.SAVE); saveFile.setGraphic(saveView); fileMenu.getItems().addAll(openFile, saveFile); Menu toolMenu = new Menu(EditorConfig.MENU_TOOL); MenuItem randomName = new MenuItem(EditorConfig.MENU_TOOL_RANDOM); BooleanBinding when = new When(Bindings.createBooleanBinding(() -> torrentProperty.getValue() == null, torrentProperty)).then(true).otherwise(false); randomName.disableProperty().bind(when); saveFile.disableProperty().bind(when); centerBtn.visibleProperty().bind(when); fileTree.visibleProperty().bind(when.not()); toolMenu.getItems().add(randomName); menuBar.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null))); menuBar.getMenus().addAll(fileMenu, toolMenu); openFile.setOnAction(event -> openFile()); saveFile.setOnAction((event) -> saveFile()); randomName.setOnAction(event -> randomNameAll(itemRoot)); }
@FXML private void initialize() { mControlOffsetX.set(100.0); mControlOffsetY.set(50.0); mControlDirectionX1.bind(new When ( node_link.startXProperty().greaterThan(node_link.endXProperty())) .then(-1.0).otherwise(1.0)); mControlDirectionX2.bind(new When ( node_link.startXProperty().greaterThan(node_link.endXProperty())) .then(1.0).otherwise(-1.0)); node_link.controlX1Property().bind( Bindings.add( node_link.startXProperty(), mControlOffsetX.multiply(mControlDirectionX1) ) ); node_link.controlX2Property().bind( Bindings.add( node_link.endXProperty(), mControlOffsetX.multiply(mControlDirectionX2) ) ); node_link.controlY1Property().bind( Bindings.add( node_link.startYProperty(), mControlOffsetY.multiply(mControlDirectionY1) ) ); node_link.controlY2Property().bind( Bindings.add( node_link.endYProperty(), mControlOffsetY.multiply(mControlDirectionY2) ) ); }
private void initButtons() { btnBack.disableProperty().bind( currentStep.lessThanOrEqualTo(0) ); btnNext.disableProperty().bind( currentStep.greaterThanOrEqualTo(steps.size()-1) ); btnCancel.textProperty().bind( new When( currentStep.lessThan(steps.size()-1) ) .then("Cancel") .otherwise("Start Over") ); }
public RfxTabButton(RfxWindow rfxWindow, View tab) { super(tab.getViewTitle()); this.rfxWindow = rfxWindow; this.tab = tab; setButtonType(ButtonType.FLAT); setMinHeight(HEIGHT); setPadding(new Insets(0, PADDING, 0, PADDING)); setMaxWidth(MAX_WIDTH); When whenTabSelected = Bindings.when(rfxWindow.getSelectedTabProperty().isEqualTo(tab)); ObservableValue<String> styleBinding = createStyleBinding(whenTabSelected); styleProperty().bind(styleBinding); setOnAction(this::onAction); }
private ObservableValue<String> createStyleBinding( When whenTabSelected) { String selectedTabStyle = new RfxStyleProperties().setTextFill(MaterialColorSetCssName.PRIMARY.FOREGROUND1()) .setBorderWidth(0,0,4,0) .setBorderColor(MaterialColorSetCssName.ACCENT.BACKGROUND()) .setFont(MaterialFont.getBody2(DisplayScale.NONE_DENSE)).toString(); String unselectedTabStyle = new RfxStyleProperties().setTextFill(MaterialColorSetCssName.PRIMARY.FOREGROUND2()) .setBorderWidth(0,0,4,0) .setBorderColor(MaterialColorSetCssName.PRIMARY.BACKGROUND()) .setFont(MaterialFont.getBody2(DisplayScale.NONE_DENSE)).toString(); ObservableValue<String> styleBinding=whenTabSelected.then(selectedTabStyle).otherwise(unselectedTabStyle); return styleBinding; }
private void initializeLabel() { final Label label = (Label) lookup("#label"); final JFXTextField textField = (JFXTextField) lookup("#textField"); final Path shape = (Path) lookup("#shape"); final Insets insets = new Insets(0,2,0,2); textField.setPadding(insets); label.setPadding(insets); final int padding = 0; label.layoutBoundsProperty().addListener((obs, oldBounds, newBounds) -> { double newWidth = Math.max(newBounds.getWidth(), 10); final double res = GRID_SIZE * 2 - (newWidth % (GRID_SIZE * 2)); newWidth += res; textField.setMinWidth(newWidth); textField.setMaxWidth(newWidth); l2.setX(newWidth + padding); l3.setX(newWidth + padding); setMinWidth(newWidth + padding); setMaxWidth(newWidth + padding); textField.setMinHeight(TAG_HEIGHT); textField.setMaxHeight(TAG_HEIGHT); textField.focusedProperty().addListener((observable, oldFocused, newFocused) -> { if (newFocused) { shape.setTranslateY(2); textField.setTranslateY(2); } }); if (getWidth() >= 1000) { setWidth(newWidth); setHeight(TAG_HEIGHT); shape.setTranslateY(-1); textField.setTranslateY(-1); } // Fixes the jumping of the shape when the text field is empty if (textField.getText().isEmpty()) { shape.setLayoutX(0); } }); label.textProperty().bind(new When(textField.textProperty().isNotEmpty()).then(textField.textProperty()).otherwise(textField.promptTextProperty())); }
private Label initializeLabel() { final Label label = new Label(); // Add the caption text-size class, and make the text white label.getStyleClass().addAll("caption", "white-text"); DoubleBinding lx = new DoubleBinding() { { super.bind(ax, bx, cx, label.widthProperty()); } @Override protected double computeValue() { return (ax.get() + bx.get() + cx.get()) / 3 - label.widthProperty().get() / 2; } }; DoubleBinding ly = new DoubleBinding() { { super.bind(ay, by, cy, label.heightProperty()); } @Override protected double computeValue() { return (ay.get() + by.get() + cy.get()) / 3 - label.heightProperty().get() / 2; } }; // Bind the label to the centroid of the triangle label.layoutXProperty().bind(lx); label.layoutYProperty().bind(ly); // Display the label U - for urgent label.setText("U"); // Bind the isUrgent stringBinder to hide and show the label label.opacityProperty().bind(new When(isUrgent).then(1d).otherwise(0d)); // Rotate the label back so that it is always displayed as U label.rotateProperty().bind(this.rotateProperty().multiply(-1)); return label; }
public void initialize() { comments.showingProperty().addListener((obs, oldValue, newValue) -> { if (newValue) { AppBar appBar = getApp().getAppBar(); appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> getApp().showLayer(DRAWER_LAYER))); appBar.setTitleText("Comments"); } }); FloatingActionButton floatingActionButton = new FloatingActionButton(); floatingActionButton.textProperty().bind(new When(userProperty().isNotNull()) .then(MaterialDesignIcon.ADD.text) .otherwise(MaterialDesignIcon.CLOUD_DOWNLOAD.text)); floatingActionButton.setOnAction(e -> { if (service.getUser() == null) { service.retrieveComments(); } else { EDITION_VIEW.switchView(); } }); comments.getLayers().add(floatingActionButton.getLayer()); commentsList.setCellFactory(cell -> { final CommentListCell commentListCell = new CommentListCell( service, // left button: delete comment, only author's comment can delete it c -> { if (service.getUser().getNetworkId().equals(c.getNetworkId())) { showDialog(c); } }, // right button: edit comment, everybody can view it, only author can edit it c -> { service.activeCommentProperty().set(c); EDITION_VIEW.switchView(); }); // notify view that cell is sliding sliding.bind(commentListCell.slidingProperty()); return commentListCell; }); final Label label = new Label(SIGN_IN_MESSAGE); label.textProperty().bind(new When(userProperty().isNotNull()) .then(NO_COMMENTS_MESSAGE) .otherwise(SIGN_IN_MESSAGE)); commentsList.setPlaceholder(label); commentsList.disableProperty().bind(service.userProperty().isNull()); commentsList.setItems(service.commentsProperty()); comments.addEventHandler(LifecycleEvent.SHOWN, new EventHandler<LifecycleEvent>() { @Override public void handle(LifecycleEvent event) { comments.removeEventHandler(LifecycleEvent.SHOWN, this); service.retrieveComments(); } }); // block scrolling when sliding comments.addEventFilter(ScrollEvent.ANY, e -> { if (sliding.get() && e.getDeltaY() != 0) { e.consume(); } }); }
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)); }
/** * Constructs a directed line between the source and target cells and binds * properties to handle relocation smoothly * @param source the source (parent) cell * @param target the target (child) cell */ public Edge(Cell source, Cell target) { this.source = source; this.target = target; this.addedMidPoints = false; midLineX = new SimpleDoubleProperty(0); DoubleBinding endX = source.translateXProperty().add(source.widthProperty().divide(2.0)); DoubleBinding endY = source.translateYProperty().add(source.heightProperty()); DoubleBinding startX = target.translateXProperty().add(target.widthProperty().divide(2.0)); DoubleBinding startY = target.translateYProperty().add(0); path = new DirectedPath(startX, startY, endX, endY); checkAndAddMidPoints(startY, endY); path.addPoint(endX, endY.add(TreeLayout.V_SPACING / 4.)); source.translateXProperty().addListener((observable, oldValue, newValue) -> { checkAndAddMidPoints(startY, endY); }); target.translateYProperty().addListener((observable, oldValue, newValue) -> { checkAndAddMidPoints(startY, endY); }); source.translateXProperty().addListener((observable, oldValue, newValue) -> { checkAndAddMidPoints(startY, endY); }); target.translateYProperty().addListener((observable, oldValue, newValue) -> { checkAndAddMidPoints(startY, endY); }); // Change the X of the midpoints depending on whether the target is above, below, or at the same // level as the source midLineX.bind(new When(target.rowLocationProperty.subtract(source.rowLocationProperty).lessThan(0)) .then(new When(target.columnLocationProperty.subtract(source.columnLocationProperty).greaterThan(0)) .then(endX.add(TreeLayout.H_SPACING / 2.)) .otherwise(new When(target.columnLocationProperty.subtract(source.columnLocationProperty).lessThan(0)) .then(startX.add(TreeLayout.H_SPACING / 2.)) .otherwise(startX))) .otherwise(new When(target.columnLocationProperty.subtract(source.columnLocationProperty).greaterThan(0)) .then(endX.add(TreeLayout.H_SPACING / 2.)) .otherwise(new When(target.columnLocationProperty.subtract(source.columnLocationProperty).lessThan(0)) .then(startX.add(TreeLayout.H_SPACING / 2.)) .otherwise(startX)))); if(source.getCellType() != Cell.CellType.BOTH || target.getCellType() != Cell.CellType.BOTH){ path.setDashed(true); } getChildren().add(path); visible = new SimpleBooleanProperty(false); visibleProperty().bind(source.visibleProperty().and(target.visibleProperty()) .and(allVisible.or(visible))); source.edges.add(this); target.edges.add(this); }
public TriangleArea() { initialize(); for(int i = 0; i < 3; i++) { int j = (i == 2) ? 0 : i+1; // Start and end positions of Line is bound by // the vertices(the center position of Circles) l[i].startXProperty().bind(c[i].centerXProperty()); l[i].startYProperty().bind(c[i].centerYProperty()); l[i].endXProperty().bind(c[j].centerXProperty()); l[i].endYProperty().bind(c[j].centerYProperty()); // center position of Circle is bound by // the mouse clicked position c[i].centerXProperty().bind(org_x[i]); c[i].centerYProperty().bind(org_y[i]); // Text of TextField is bound by the string form // presenting the vertices(the center of Circles) tx[i].textProperty().bind(map_x[i].asString("%2.1f")); ty[i].textProperty().bind(map_y[i].asString("%2.1f")); } // the area of triangle is computed by the bound values // by Circle positions NumberBinding tmp_area = map_x[0].multiply(map_y[1]) .add(map_x[1].multiply(map_y[2])) .add(map_x[2].multiply(map_y[0])) .subtract(map_x[0].multiply(map_y[2])) .subtract(map_x[1].multiply(map_y[0])) .subtract(map_x[2].multiply(map_y[1])) .divide(2.0); // the code for computing the absolute value using // Class When and then() and otherwise() methods. area = new When(tmp_area.lessThan(0)) .then(tmp_area.negate()) .otherwise(tmp_area); // Text of Label presenting the area of triangle is // bound by the string form the computing the area area_Label.textProperty().bind( new SimpleStringProperty("Area = ") .concat(area.asString("%2.1f"))); }
public ObjectBinding<Image> selectedRun_resultImage() { return new When(selectedRun_isSuccessful()).then(IMAGE_TEST_SUCCESS).otherwise(IMAGE_TEST_FAILURE); }