private void syncOrientationState() { // Apply pseudo classes when orientation changes labelPosition.addListener((observable, oldValue, newValue) -> { if (newValue == HORIZONTAL) { pseudoClassStateChanged(VERTICAL_PSEUDOCLASS_STATE, false); pseudoClassStateChanged(HORIZONTAL_PSEUDOCLASS_STATE, true); } else { pseudoClassStateChanged(HORIZONTAL_PSEUDOCLASS_STATE, false); pseudoClassStateChanged(VERTICAL_PSEUDOCLASS_STATE, true); } }); // Setup listeneres for wrapping wrapWidth.addListener(((observable, oldValue, newValue) -> { ObjectBinding<Orientation> responsiveOrientation = createObjectBinding(() -> getWidth() < newValue ? VERTICAL : HORIZONTAL, widthProperty()); if (labelPositionProperty().isBound()) labelPositionProperty().unbind(); labelPositionProperty().bind(responsiveOrientation); })); }
/** * Constructs one of the selection buttons for the catch selection screen. * Binds the catch type displayed on this button to {@link CatchType#EMPTY} if place is 0, or to one of the top three catches for the trapline if place is between 1 and 3. * @param place The button placement (ranges from 0 to 3) * @return The catch selection button */ private Button makeOptionButton (int place) { ObjectBinding<CatchType> catchType; if (place == 0) { catchType = Bindings.createObjectBinding(() -> CatchType.EMPTY); } else { catchType = Bindings.valueAt(catchTypes, place-1); } Button button = new Button(); button.getStyleClass().add("catch-select-option"); addBackgroundLoader(button, catchType); button.textProperty().bind(Bindings.createStringBinding(() -> catchType.get() == null ? "..." : catchType.get().getName(), catchType)); button.setMaxSize(1000, 1000); //button.getStyleClass().add("large-button"); GridPane.setConstraints(button, place % 2, place > 1 ? 2 : 0); GridPane.setHgrow(button, Priority.ALWAYS); GridPane.setVgrow(button, Priority.ALWAYS); button.setOnAction(evt -> { LOG.log(Level.FINE, "Selected catch: "+catchType.get()); setResult(new Catch(catchType.get())); hide(); }); return button; }
public ItemTile(DisplayableItem item) { Objects.requireNonNull(item); getStyleClass().add(CSS_CLASS_ITEM_TILE); textProperty().bind(item.getLocalizedName()); ImageView iconView = new ImageView(); iconView.imageProperty().bind(item.getIcon()); iconView.fitWidthProperty().bind(iconWidthProperty); iconView.fitHeightProperty().bind(iconHeightProperty); graphicProperty().bind(new ObjectBinding<Node>() { { bind(iconView.imageProperty()); } @Override protected Node computeValue() { if (iconView.imageProperty().get() == null) { return null; } else { return iconView; } } }); }
static PerspectiveTransform computeEnd(ObservableValue<? extends Number> x, ObservableValue<? extends Number> y, ObservableValue<? extends Number> width, ObservableValue<? extends Number> height, ObservableValue<Pos> noEffectPos) { double ratioX = x.getValue().doubleValue() / width.getValue().doubleValue() * 3; double ratioY = y.getValue().doubleValue() / height.getValue().doubleValue() * 3; ObjectBinding<Perspective> perspective = Bindings.createObjectBinding(() -> new Perspective(ratioX, ratioY, width.getValue().doubleValue(), height.getValue().doubleValue(), noEffectPos.getValue()), width, height, noEffectPos); PerspectiveTransform effect = new PerspectiveTransform(); effect.ulxProperty().bind(createPerspectivePropertyBinding(p -> p.ulx, perspective)); effect.ulyProperty().bind(createPerspectivePropertyBinding(p -> p.uly, perspective)); effect.urxProperty().bind(createPerspectivePropertyBinding(p -> p.urx, perspective)); effect.uryProperty().bind(createPerspectivePropertyBinding(p -> p.ury, perspective)); effect.lrxProperty().bind(createPerspectivePropertyBinding(p -> p.lrx, perspective)); effect.lryProperty().bind(createPerspectivePropertyBinding(p -> p.lry, perspective)); effect.llxProperty().bind(createPerspectivePropertyBinding(p -> p.llx, perspective)); effect.llyProperty().bind(createPerspectivePropertyBinding(p -> p.lly, perspective)); return effect; }
public void initialise(final Button buttonUnseen, final Button buttonKnown, final Button buttonUnknown, final SessionModel sessionModel, final ObjectBinding<WordState> wordStateProperty, final Runnable nextWordSelector) { this.sessionModel = sessionModel; this.nextWordSelector = nextWordSelector; SimpleBooleanProperty editableProperty = sessionModel.editableProperty(); BooleanBinding resettableProperty = editableProperty.and(notEqual(WordState.UNSEEN, wordStateProperty)); buttonUnseen.visibleProperty().bind(resettableProperty); buttonKnown.visibleProperty().bind(editableProperty); buttonUnknown.visibleProperty().bind(editableProperty); buttonUnseen.setOnAction(e -> processResponse(WordState.UNSEEN, false)); buttonKnown.setOnAction(e -> processResponse(WordState.KNOWN, true)); buttonUnknown.setOnAction(e -> processResponse(WordState.UNKNOWN, true)); }
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)); }
/** * Perform cycle check and classification. * @throws Exception if anything goes wrong */ public void doClassify() throws Exception { // Make sure in application thread. FxUtils.checkFxUserThread(); // Update UI. rootName.setText(OTFUtility.getConPrefTerm(Taxonomies.SNOMED.getLenient() .getNid())); // Create classifier classifier = new SnomedSnorocketClassifier(); // Do work in background. task = new ClassifyTask(); // Bind cursor to task state. ObjectBinding<Cursor> cursorBinding = Bindings.when(task.runningProperty()).then(Cursor.WAIT) .otherwise(Cursor.DEFAULT); this.getScene().cursorProperty().bind(cursorBinding); taskThread = new Thread(task, "classify"); taskThread.setDaemon(true); taskThread.start(); }
public VentaModel() { subtotal = new ObjectBinding<BigDecimal>() { @Override protected BigDecimal computeValue() { BigDecimal result = BigDecimal.ZERO; for(PartidaModel pm : partidas) result.add(pm.subtotalProperty().get()); return result; } }; montoDescuentos = new SimpleObjectProperty<>(BigDecimal.ZERO); montoImpuestos = new SimpleObjectProperty<>(BigDecimal.ZERO); total = new SimpleObjectProperty<>(BigDecimal.ZERO); cliente = new SimpleObjectProperty<>(); partidas = FXCollections.observableArrayList(); partidas.addListener(new MyListListener()); }
private void init() { setMnemonicParsing(false); tooltipProperty().bind(new ObjectBinding<Tooltip>() { { bind(code); } @Override protected Tooltip computeValue() { return new Tooltip(code.get()); } }); }
public static <T> ObjectBinding<T> toObjectBinding(ObservableValue<T> ov) { return new ObjectBinding<T>() { { bind(ov); } @Override protected T computeValue() { return ov.getValue(); } }; }
public ColorPickerTool(Color startColor) { setMinWidth(USE_PREF_SIZE); setMaxWidth(Double.MAX_VALUE); setAlignment(Pos.BASELINE_LEFT); getStyleClass().add("color-picker"); setTextFill(Color.WHITE); color.set(startColor); textProperty().bind(new StringBinding() { { bind(color); } @Override protected String computeValue() { return getWebColor(getColor()); } }); setOnAction((ActionEvent arg0) -> { if (popover == null) { popover = new ColorPickerPopover(); popover.colorProperty().addListener((ObservableValue<? extends Color> arg1, Color arg2, Color newValue) -> { setColor(newValue); }); } if (popover.isShowing()) { popover.hide(); } else { popover.setColor(getColor()); popover.show(ColorPickerTool.this); } }); Rectangle colorRect = new Rectangle(); colorRect.setWidth(16); colorRect.setHeight(16); colorRect.fillProperty().bind(new ObjectBinding<Paint>() { { bind(color); } @Override protected Paint computeValue() { return getColor(); } }); colorRect.setEffect(new DropShadow(3, 0, 1, Color.rgb(0, 0, 0, 0.8))); setGraphic(colorRect); }
private ObjectBinding<Paint> getColor(AnimatableField field, NodeModel node, KeyValueModel keyValue, KeyFrameModel keyFrame) { ObjectBinding<Paint> currentValue = ModelFunctions.toPaintBinding(keyValue.valueProperty(), Color.TRANSPARENT); KeyFrameModel earlier = getEarlierKeyFrameWithNonNullValue(field, node, keyFrame); KeyFrameModel later = getLaterKeyFrameWithNonNullValue(field, node, keyFrame); if (earlier != null) { DoubleProperty earlierTime = earlier.absoluteTimeProperty(); Color earlierValue = (Color) earlier.getKeyValues().get(node).get(field).getValue(); if (later != null) { DoubleProperty laterTime = later.absoluteTimeProperty(); Color laterValue = (Color) later.getKeyValues().get(node).get(field).getValue(); ObjectBinding<Paint> interpolated = Bindings.createObjectBinding(() -> { double timeFraction = (keyFrame.getAbsoluteTime() - earlierTime.get()) / (laterTime.get() - earlierTime.get()); double interpolatorFactor = later.getKeyValues().get(node).get(field).getInterpolator().curve(timeFraction); return earlierValue.interpolate(laterValue, 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 MainWordHandler(final Label mainWord, final Label useCountLabel, final Pane mainWordPane, final SessionModel sessionModel, final ObjectBinding<WordState> wordStateProperty) { this.mainWord = mainWord; this.useCountLabel = useCountLabel; this.mainWordPane = mainWordPane; this.sessionModel = sessionModel; this.wordStateProperty = wordStateProperty; }
protected ObjectBinding<Paint> getTeamColor() { IntegerBinding teamNum = getTeamNum(); return Bindings.createObjectBinding(() -> { int n = teamNum.get(); switch (n) { case 2: return Color.GREEN; case 3: return Color.RED; default: return Color.GRAY; } }, teamNum); }
protected ObjectBinding<Paint> getPlayerColor() { IntegerBinding playerId = getPlayerId(); return Bindings.createObjectBinding(() -> { int n = playerId.get(); if (n < 0 || n > 9) { return Color.WHITE; } else { return PLAYER_COLORS[n]; } }, playerId); }
public <T> ObjectBinding<T> getPropertyBinding(Class<T> propertyClass, String property, T defaultValue) { FieldPath fp = entity.getDtClass().getFieldPathForName(property); if (fp == null) { return Bindings.createObjectBinding(() -> defaultValue); } else { ObjectBinding<T> ob = getPropertyForFieldPath(fp).rawProperty(); return Bindings.createObjectBinding(() -> ob.get(), ob); } }
void initializeIntervalChartAxes() { final NumberAxis xAxis = (NumberAxis) intervalChart.getXAxis(); xAxis.setForceZeroInRange(false); // Bind X Tick label formatter to choice-box intervalXTickLabel.getItems().addAll(IntervalTickFormatter.values()); intervalXTickLabel.getSelectionModel().select(0); ObjectBinding<StringConverter<Number>> intervalXLabelConverter = Bindings.createObjectBinding( () -> intervalXTickLabel.getSelectionModel().getSelectedItem().getConverter(), intervalXTickLabel.getSelectionModel().selectedItemProperty() ); xAxis.tickLabelFormatterProperty().bind(intervalXLabelConverter); }
public final ObjectBinding<TableProperty> foreignTableProperty() { return createObjectBinding( () -> ForeignKeyColumn.super.findForeignTable() .map(TableProperty.class::cast) .orElse(null), foreignTableNameProperty() ); }
public final ObjectBinding<ColumnProperty> foreignColumnProperty() { return createObjectBinding( () -> ForeignKeyColumn.super.findForeignColumn() .map(ColumnProperty.class::cast) .orElse(null), foreignTableNameProperty(), foreignColumnNameProperty() ); }
/** * Perform an export according the specifed parameters. * * @param exportType the export type * @param pathNid the path nid * @param folderName the file name * @param zipChecked the flag indicating whether to compress output */ public void doExport(ExportType exportType, int pathNid, final String folderName, boolean zipChecked) { Preconditions.checkNotNull(exportType); Preconditions.checkNotNull(folderName); // Make sure in application thread. FxUtils.checkFxUserThread(); // Update UI. exportTypeLabel.setText(exportType.getDisplayName()); pathNameLabel.setText(OTFUtility.getConPrefTerm(pathNid)); folderNameLabel.setText(folderName); File folder = new File(folderName); // Inject into an ExportFileHandler. exportFileHandler = new ExportFileHandler(pathNid, exportType, folder, zipChecked); // Do work in background. task = new ExporterTask(exportFileHandler); // Bind cursor to task state. ObjectBinding<Cursor> cursorBinding = Bindings.when(task.runningProperty()).then(Cursor.WAIT) .otherwise(Cursor.DEFAULT); this.getScene().cursorProperty().bind(cursorBinding); taskThread = new Thread(task, "Exporter_" + exportType); taskThread.setDaemon(true); taskThread.start(); }
private void scheduleTask(InformationModel infoModel, Task<String> task) { // Bind cursor to task state. ObjectBinding<Cursor> cursorBinding = Bindings.when(task.runningProperty()).then(Cursor.WAIT) .otherwise(Cursor.DEFAULT); this.stage.getScene().cursorProperty().bind(cursorBinding); // Bind progress indicator to task state. modelXmlProgress.visibleProperty().bind(task.runningProperty()); Thread t = new Thread(task, "Display_" + infoModel.getName()); t.setDaemon(true); t.start(); }
@Test public void testObjectBinding(){ ObjectBinding<TestPerson> actual = Bindings.createObjectBinding(()-> person); assertThat(actual).hasValue(person); assertThat(actual).hasSameValue(actual); }
/** * Helper method which binds the dynamical computation of a {@link ContextMenu} to a {@link TreeItem} * {@link Property}. * <p> * * @param <T> the type of the item contained in the {@link TreeItem} * @param appCtx the {@link ApplicationContext} of the application * @param ctxMenuProperty the {@link ContextMenu} {@link Property} of the {@link TreeTableCell} or {@link TreeCell} * @param treeItemProperty the {@link TreeItem} {@link Property} */ private static <T> void bindContextMenu(ApplicationContext appCtx, ObjectProperty<ContextMenu> ctxMenuProperty, ReadOnlyObjectProperty<TreeItem<T>> treeItemProperty) { ctxMenuProperty.bind(new ObjectBinding<ContextMenu>() { { // Fire when the encapsulated TreeItem instance changes super.bind(treeItemProperty); } @Override protected ContextMenu computeValue() { // No TreeItemProperty == no ContextMenu if (treeItemProperty == null) { return null; } TreeItem<?> treeItem = treeItemProperty.get(); // No or Empty TreeItem == no ContextMenu, otherwise construct the menu. return (treeItem == null || treeItem.getChildren().size() == 0) ? null : getContextMenu(appCtx, treeItem); } }); }
@Test public void testMap(){ ObjectProperty<Person> selectedPerson = new SimpleObjectProperty<>(); ObjectBinding<String> name = ObjectBindings.map(selectedPerson, Person::getName); assertThat(name).hasNullValue(); selectedPerson.set(obi); assertThat(name).hasValue("Obi-Wan"); selectedPerson.set(luke); assertThat(name).hasValue("Luke"); }
@Test public void testMapWithDefaultValue(){ ObjectProperty<Person> selectedPerson = new SimpleObjectProperty<>(); ObjectBinding<String> name = ObjectBindings.map(selectedPerson, Person::getName, "empty"); assertThat(name).hasValue("empty"); selectedPerson.set(obi); assertThat(name).hasValue("Obi-Wan"); selectedPerson.set(luke); assertThat(name).hasValue("Luke"); }
@Test public void testCastBinding2(){ ObjectProperty<Double> doubleProperty = new SimpleObjectProperty<>(10.0); ObjectBinding<Number> numberBinding = ObjectBindings.cast(doubleProperty); assertThat(numberBinding).hasValue(10.0); doubleProperty.setValue(12.34); assertThat(numberBinding).hasValue(12.34); }
public ObjectBinding<ImageView> selectedRun_resultImageView() { return Bindings.createObjectBinding(new Callable<ImageView>() { @Override public ImageView call() throws Exception { return new ImageView(selectedRun_resultImage().get()); } }, selectedRunProperty()); }
public ObjectBinding<Date> endDateProperty() { return Bindings.createObjectBinding(new Callable<Date>() { @Override public Date call() throws Exception { return getBatch().getEndDate(); } }, isRunningProperty()); }
public ObjectBinding<TestBatchState> stateProperty() { return Bindings.createObjectBinding(new Callable<TestBatchState>() { @Override public TestBatchState call() throws Exception { if (isRunning()) { return TestBatchState.RUNNING; } else if (isSuccessful()) { return TestBatchState.SUCCESS; } else { return TestBatchState.FAILURE; } } }, isRunningProperty(), isSuccessfulProperty()); }
public static ObjectBinding<Paint> toPaintBinding(ObjectProperty<Object> property, Paint fallback) { return Bindings.createObjectBinding(() -> (property.get() instanceof Paint ? (Paint) property.get() : fallback), property); }
public <T> ObjectBinding<T> selectObject(Function<S, ? extends ObservableValue<T>> childPropertyAccessor) { return new ChainBinding<>(rootProperty, childPropertyAccessor); }
public <T> ObjectBinding<T> mapToObject(Function<S, ? extends T> childPropertyAccessor) { return new MappedBinding<>(rootProperty, childPropertyAccessor); }
IntegerBindingAdapter(ObjectBinding<Number> integerObjectBinding, int defaultValue) { this.integerObjectBinding = integerObjectBinding; this.defaultValue = defaultValue; bind(integerObjectBinding); }
LongBindingAdapter(ObjectBinding<Number> longObjectBinding, long defaultValue) { this.longObjectBinding = longObjectBinding; this.defaultValue = defaultValue; bind(longObjectBinding); }
FloatBindingAdapter(ObjectBinding<Number> floatObjectBinding, float defaultValue) { this.floatObjectBinding = floatObjectBinding; this.defaultValue = defaultValue; bind(floatObjectBinding); }
DoubleBindingAdapter(ObjectBinding<Number> doubleObjectBinding, double defaultValue) { this.doubleObjectBinding = doubleObjectBinding; this.defaultValue = defaultValue; bind(doubleObjectBinding); }
BooleanBindingAdapter(ObjectBinding<Boolean> booleanObjectBinding, boolean defaultValue) { this.booleanObjectBinding = booleanObjectBinding; this.defaultValue = defaultValue; bind(booleanObjectBinding); }
StringBindingAdapter(ObjectBinding<String> stringObjectBinding, String defaultValue) { this.stringObjectBinding = stringObjectBinding; this.defaultValue = defaultValue; bind(stringObjectBinding); }
@Override public void start(Stage primaryStage) throws Exception { FilterableTreeItem<String> filterableTreeItem = new FilterableTreeItem<>(""); filterableTreeItem.setExpanded(true); TreeView<String> treeView = new TreeView<>(filterableTreeItem); treeView.setShowRoot(false); treeView.setRoot(filterableTreeItem); BorderPane borderPane = new BorderPane(treeView); TextField value = new TextField(); value.textProperty().addListener((oba, oldval, newval) -> { Callable<TreeItemPredicate<String>> func = () -> { Predicate<String> predicate = str -> str.indexOf(newval) >= 0; return TreeItemPredicate.<String> create(predicate); }; ObjectBinding<TreeItemPredicate<String>> createObjectBinding = Bindings.createObjectBinding(func, hide); filterableTreeItem.predicateProperty().bind(createObjectBinding); }); borderPane.setTop(value); Scene scene = new Scene(borderPane); primaryStage.setScene(scene); primaryStage.show(); FilterableTreeItem<String> e = new FilterableTreeItem<>("ABC"); // e.getChildren().add(new FilterableTreeItem<>("DEF")); // e.getChildren().add(new FilterableTreeItem<>("김aa")); // e.getChildren().add(new FilterableTreeItem<>("김bb")); // e.getChildren().add(new FilterableTreeItem<>("김cc")); // filterableTreeItem.getChildren().add(e); // filterableTreeItem.getChildren().add(new FilterableTreeItem<>("DEF")); // filterableTreeItem.getChildren().add(new FilterableTreeItem<>("김DD")); // e.getSourceChildren().add(new FilterableTreeItem<>("DEF")); e.getSourceChildren().add(new FilterableTreeItem<>("김aa")); e.getSourceChildren().add(new FilterableTreeItem<>("김bb")); e.getSourceChildren().add(new FilterableTreeItem<>("김cc")); filterableTreeItem.getSourceChildren().add(e); filterableTreeItem.getSourceChildren().add(new FilterableTreeItem<>("DEF")); filterableTreeItem.getSourceChildren().add(new FilterableTreeItem<>("김DD")); // filterableTreeItem.predicateProperty() // .bind(Bindings.createObjectBinding(() -> // TreeItemPredicate<String>.create(str -> str.indexOf("김") >= 0), // hide)); }