本文整理汇总了Java中javafx.beans.property.ObjectProperty.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectProperty.addListener方法的具体用法?Java ObjectProperty.addListener怎么用?Java ObjectProperty.addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.beans.property.ObjectProperty
的用法示例。
在下文中一共展示了ObjectProperty.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
@Override
public void initialize(final URL location, final ResourceBundle resources) {
final ObjectProperty<GfaNode> selectedNodeProperty = graphVisualizer.getSelectedSegmentProperty();
selectedNodeProperty.addListener((observable, oldValue, newValue) ->
nodePosition.setText(newValue == null ? "" : String.valueOf(newValue.getSegmentIds())));
radius.textProperty().bind(graphDimensionsCalculator.getRadiusProperty().asString());
baseOffset.setTextFormatter(new TextFormatter<>(new IntegerStringConverter()));
baseOffset.setText(String.valueOf(sequenceVisualizer.getOffsetProperty().get()));
baseOffset.textProperty().addListener((observable, oldValue, newValue) -> updateBaseOffset(newValue));
sequenceVisualizer.getOffsetProperty().addListener((observable, oldValue, newValue) ->
baseOffset.setText(String.valueOf(newValue)));
saveButton.disableProperty().bind(selectedNodeProperty.isNull());
}
示例2: bind
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void bind(final ObjectProperty<?> property, final String propertyName, Class<?> type) {
String value = props.getProperty(propertyName);
if (value != null) {
if (type.getName().equals(Color.class.getName())) {
((ObjectProperty<Color>) property).set(Color.valueOf(value));
} else if (type.getName().equals(String.class.getName())) {
((ObjectProperty<String>) property).set(value);
} else {
((ObjectProperty<Object>) property).set(value);
}
}
property.addListener(new InvalidationListener() {
@Override
public void invalidated(Observable o) {
props.setProperty(propertyName, property.getValue().toString());
}
});
}
示例3: bindToColor
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public void bindToColor(final ObjectProperty<Color> color, final ObjectProperty<Color.Intensity> intensity, final boolean doColorBackground) {
final BiConsumer<Color, Color.Intensity> recolor = (newColor, newIntensity) -> {
final JFXTextField textField = (JFXTextField) lookup("#textField");
textField.setUnFocusColor(TRANSPARENT);
textField.setFocusColor(newColor.getColor(newIntensity));
if (doColorBackground) {
final Path shape = (Path) lookup("#shape");
shape.setFill(newColor.getColor(newIntensity.next(-1)));
shape.setStroke(newColor.getColor(newIntensity.next(-1).next(2)));
textField.setStyle("-fx-prompt-text-fill: rgba(255, 255, 255, 0.6); -fx-text-fill: " + newColor.getTextColorRgbaString(newIntensity) + ";");
textField.setFocusColor(newColor.getTextColor(newIntensity));
} else {
textField.setStyle("-fx-prompt-text-fill: rgba(0, 0, 0, 0.6);");
}
};
color.addListener(observable -> recolor.accept(color.get(), intensity.get()));
intensity.addListener(observable -> recolor.accept(color.get(), intensity.get()));
recolor.accept(color.get(), intensity.get());
}
示例4: bind
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public static <T> void bind(TextField textField, ObjectProperty<T> value, StringConverter<T> stringConverter, Runnable onCommit) {
executeOnFocusLostOrEnter(textField, () -> {
T oldValue = value.get();
value.set(stringConverter.fromString(textField.getText()));
textField.setText(stringConverter.toString(stringConverter.fromString(textField.getText())));
textField.positionCaret(textField.getLength());
if (onCommit != null && !Objects.equals(oldValue, value.get())) {
onCommit.run();
}
});
value.addListener((v, o, n) -> textField.setText(stringConverter.toString(n)));
textField.setText(stringConverter.toString(value.get()));
}
示例5: setHero
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
@Override
public void setHero(ObjectProperty<Hero> hero) {
hero.addListener((observable, oldValue, newValue) -> {
lblHeroName.textProperty().bind(newValue.nameProperty());
lblHeroRaceAndProfession.textProperty()
.bind(StringConvertors.forRaceAndProfessionConverter(translator, newValue));
lblLive.setMaxActValue(newValue.getLive());
lblMag.setMaxActValue(newValue.getMag());
defaultStaffLeftController.bindWithHero(newValue);
defaultStaffRightController.bindWithHero(newValue);
lblMoney.forMoney(newValue.getMoney());
});
}
示例6: ArmorEntry
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
/**
* Vytvoří novou nákupní položku obsahující zbroj
*
* @param armor Zbroj
* @param height Velikost bytosti, která zbroj kupuje
*/
public ArmorEntry(Armor armor, ObjectProperty<Height> height) {
super(armor);
this.defenceNumber.bind(armor.defenceNumberProperty());
this.minimumStrength.bind(armor.minimumStrengthProperty());
height.addListener((observable, oldValue, newValue) -> armor.forHeight(newValue));
}
示例7: main
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public static void main(String[] args) {
ObjectProperty<LocalDateTime> dp = new SimpleObjectProperty<>(LocalDateTime.now());
ObjectProperty<Instant> ip = new SimpleObjectProperty<>();
Binding<Instant> ib = Bindings.createObjectBinding(
() -> dp.get().toInstant(OffsetDateTime.now().getOffset()),
dp);
ip.bind(ib);
// Binding<LocalDateTime> db = Bindings.createObjectBinding(
// () -> ip.get().atZone(ZoneId.systemDefault()).toLocalDateTime(),
// ip);
// dp.bind(db);
dp.addListener((obs, ov, nv) -> System.out.println(dp.get()));
ip.addListener((obs, ov, nv) -> System.out.println(ip.get()));
dp.setValue(LocalDateTime.of(2000, 9, 22, 9, 16, 0));
dp.setValue(LocalDateTime.of(1968, 12, 25, 8, 0, 0));
dp.setValue(LocalDateTime.of(2002, 7, 27, 3, 30, 0));
//
// ip.setValue(Instant.EPOCH);
// ip.setValue(Instant.MAX);
// ip.setValue(Instant.MIN);
}
示例8: ConstraintSpecificationValidator
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
/**
* <p>
* Creates a validator with given observable models as context information.
* </p>
*
* <p>
* The validator observes changes in any of the given context models. It automatically updates the
* validated specification (see {@link #validSpecificationProperty()}) and/or the problems with
* the constraint specification (see {@link #problemsProperty()}).
* </p>
*
* @param typeContext the extracted types (esp. enums) from the code area
* @param codeIoVariables the extracted {@link CodeIoVariable}s from the code area
* @param validFreeVariables the most latest validated free variables from the
* {@link FreeVariableList}.
* @param specification the specification to be validated
*/
public ConstraintSpecificationValidator(ObjectProperty<List<Type>> typeContext,
ObjectProperty<List<CodeIoVariable>> codeIoVariables,
ReadOnlyObjectProperty<List<ValidFreeVariable>> validFreeVariables,
ConstraintSpecification specification) {
this.typeContext = typeContext;
this.codeIoVariables = codeIoVariables;
this.validFreeVariables = validFreeVariables;
this.specification = specification;
this.problems = new SimpleObjectProperty<>(new ArrayList<>());
this.validSpecification = new NullableProperty<>();
this.valid = new SimpleBooleanProperty(false);
// All these ObservableLists invoke the InvalidationListeners on deep updates
// So if only a cell in the Specification changes, the change listener on the ObservableList
// two layers above gets notified.
specification.getRows().addListener(listenToSpecUpdate);
specification.getDurations().addListener(listenToSpecUpdate);
specification.getColumnHeaders().addListener(listenToSpecUpdate);
typeContext.addListener(listenToSpecUpdate);
codeIoVariables.addListener(listenToSpecUpdate);
validFreeVariables.addListener(listenToSpecUpdate);
recalculateSpecProblems();
}
示例9: bind
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public static <T> void bind(SelectionModel<T> selectionModel, ObjectProperty<T> selectedItem) {
selectionModel.selectedItemProperty().addListener((v, o, n) -> {
selectedItem.set(n);
});
selectedItem.addListener((v, o, n) -> {
selectionModel.select(n);
});
selectionModel.select(selectedItem.get());
}
示例10: initialize
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
@Override
@SuppressWarnings("squid:MaximumInheritanceDepth") // We need to overwrite the behaviour of table cells
public void initialize(final URL location, final ResourceBundle resources) {
nodeId.setCellValueFactory(cell -> cell.getValue().getNodeIdProperty());
baseOffset.setCellValueFactory(cell -> cell.getValue().getBaseOffsetProperty());
description.setCellValueFactory(cell -> cell.getValue().getDescriptionProperty());
radius.setCellValueFactory(cell -> cell.getValue().getRadiusProperty());
description.setCellFactory(param -> new TableCell<SimpleBookmark, String>() {
@Override
protected void updateItem(final String item, final boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
return;
}
final Text text = new Text(item);
text.setWrappingWidth(param.getWidth() - DESCRIPTION_TEXT_PADDING);
setPrefHeight(text.getLayoutBounds().getHeight());
setGraphic(text);
}
});
bookmarksTable.setRowFactory(tableView -> {
final TableRow<SimpleBookmark> simpleBookmarkTableRow = new TableRow<>();
simpleBookmarkTableRow.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && !simpleBookmarkTableRow.isEmpty()) {
simpleBookmarkTableRow.getItem().getOnClick().run();
}
});
return simpleBookmarkTableRow;
});
bookmarksTable.setItems(bookmarkStore.getSimpleBookmarks());
final ObjectProperty<GfaNode> selectedNodeProperty = graphVisualizer.getSelectedSegmentProperty();
createBookmarkButton.disableProperty().bind(selectedNodeProperty.isNull());
selectedNodeProperty.addListener((observable, oldValue, newValue) -> {
if (newValue == null) {
createBookmarkButton.setText("Create Bookmark (Select node first)");
} else {
createBookmarkButton.setText("Create Bookmark for Node " + newValue.getSegmentIds());
}
});
}
示例11: initialize
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
@Override
public void initialize(final URL location, final ResourceBundle resources) {
final ObjectProperty<GfaNode> selectedNodeProperty = graphVisualizer.getSelectedSegmentProperty();
nameAnnotation.setCellValueFactory(cell -> {
final String[] name = cell.getValue().getAttributes().get("Name");
return new SimpleStringProperty(name == null ? "" : name[0]);
});
nameAnnotation.setCellFactory(this::wrappableTableCell);
typeAnnotation.setCellValueFactory(cell -> {
final String type = cell.getValue().getType();
return new SimpleStringProperty(type == null ? "" : type);
});
typeAnnotation.setCellFactory(this::wrappableTableCell);
colorAnnotation.setCellValueFactory(cell -> new SimpleObjectProperty<>(cell.getValue().getColor()));
colorAnnotation.setCellFactory(column -> new TableCell<Annotation, Color>() {
@Override
protected void updateItem(final Color color, final boolean empty) {
super.updateItem(color, empty);
if (color == null || empty) {
setBackground(Background.EMPTY);
} else {
setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
}
}
});
annotationTable.setRowFactory(tableView -> {
final TableRow<Annotation> annotationTableRow = new TableRow<>();
annotationTableRow.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
final int startNodeId = annotationTableRow.getItem().getStartNodeId();
final int endNodeId = annotationTableRow.getItem().getEndNodeId();
final int radius = (int) Math.round(((double) endNodeId - startNodeId) / 2);
final int middleNodeId = (int) Math.round(startNodeId + (double) radius / 2);
final Graph graph = graphStore.getGfaFileProperty().get().getGraph();
final int viewPointX = (int) Math.round(
((double) graph.getRealStartXPosition(middleNodeId)
+ graph.getRealEndXPosition(middleNodeId)) / 2
);
graphDimensionsCalculator.getViewPointProperty().set(viewPointX);
graphDimensionsCalculator.getViewRadiusProperty().set(radius * 2000);
}
});
return annotationTableRow;
});
selectedNodeProperty.addListener((observable, oldNode, newNode) -> updateFields(newNode));
}
示例12: displayPlayer
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public static void displayPlayer(Pane parent, ObjectProperty<PlayerInterface> currentPlayerProperty, PlayerInterface player, int playerIndex, ResourceBundle i18nMessages) {
// Layout of each player frame
StackPane playerContainer = new StackPane();
playerContainer.getStyleClass().add("player");
HBox innerHBox = new HBox();
innerHBox.getStyleClass().add("inner-player");
// Texts in each player frame
Text playerNumber = new Text(Integer.toString(playerIndex + 1));
playerNumber.getStyleClass().add("player-number");
HBox.setHgrow(playerNumber, Priority.NEVER);
// Spinner indicating that player is "thinking" (only for non-local and non-human players)
ProgressIndicator progressIndicator = new ProgressIndicator();
progressIndicator.getStyleClass().add("player-progress-indicator");
HBox.setHgrow(progressIndicator, Priority.NEVER);
VBox innerVBox = new VBox();
innerVBox.getStyleClass().add("player-information");
HBox.setHgrow(innerVBox, Priority.ALWAYS);
Text playerName = new Text(player.getName());
playerName.getStyleClass().add("player-name");
// Bound number of points
TextFlow playerPoints = new TextFlow();
playerPoints.getStyleClass().add("player-points");
Text boundPlayerPoints = new Text();
boundPlayerPoints.textProperty().bind(player.scoreProperty().asString());
Text playerPointsLegend = new Text(" " + i18nMessages.getString("points"));
playerPoints.getChildren().addAll(boundPlayerPoints, playerPointsLegend);
TextFlow playerStatusInformation = new TextFlow();
if (player instanceof HumanPlayerInterface) {
Text boundPlayerAvailableHelps = new Text();
boundPlayerAvailableHelps.textProperty().bind(((HumanPlayerInterface) player).availableHelpsProperty().asString());
Text playerAvailableHelpsLegend = new Text(" " + i18nMessages.getString("availableHelps"));
playerStatusInformation.getChildren().addAll(boundPlayerAvailableHelps, playerAvailableHelpsLegend);
} else if (player instanceof ArtificialIntelligencePlayerInterface) {
Text artificalIntelligenceLevelInformation = new Text(i18nMessages.getString("computer") + " - " + i18nMessages.getString("artificialIntelligenceLevels." + ((ArtificialIntelligencePlayerInterface) player).getLevel()));
playerStatusInformation.getChildren().add(artificalIntelligenceLevelInformation);
}
// Assembling all elements of the player frame and adding it to the list of players
innerVBox.getChildren().addAll(playerName, playerPoints, playerStatusInformation);
innerHBox.getChildren().addAll(playerNumber, innerVBox);
playerContainer.getChildren().add(innerHBox);
// Make player active if he is the current player
if (player.equals(currentPlayerProperty.getValue())) {
playerContainer.getStyleClass().add("active");
}
// Create the event to listen if the user is a current player
currentPlayerProperty.addListener((ObservableValue<? extends PlayerInterface> observable, PlayerInterface oldValue, PlayerInterface newValue) -> {
if (player.equals(newValue)) {
playerContainer.getStyleClass().add("active");
if (player instanceof ArtificialIntelligencePlayerInterface) {
innerHBox.getChildren().set(innerHBox.getChildren().indexOf(playerNumber), progressIndicator);
}
} else {
playerContainer.getStyleClass().remove("active");
int indexOfProgressIndicator = innerHBox.getChildren().indexOf(progressIndicator);
if (-1 != indexOfProgressIndicator && player instanceof ArtificialIntelligencePlayerInterface) {
innerHBox.getChildren().set(indexOfProgressIndicator, playerNumber);
}
}
});
parent.getChildren().add(playerContainer);
}
示例13: bindDoubleBidirectional
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public static void bindDoubleBidirectional(ObjectProperty<Object> keyValueProperty, ObjectProperty<Double> doubleProperty) {
doubleProperty.addListener((v, o, n) -> keyValueProperty.set(n));
keyValueProperty.addListener((v, o, n) -> doubleProperty.set(n instanceof Double ? (Double) n : null));
doubleProperty.set(keyValueProperty.get() instanceof Double ? (Double) keyValueProperty.get() : null);
}
示例14: bindColorBidirectional
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
public static void bindColorBidirectional(ObjectProperty<Object> keyValueProperty, ObjectProperty<Color> colorProperty) {
colorProperty.addListener((v, o, n) -> keyValueProperty.set(n));
keyValueProperty.addListener((v, o, n) -> colorProperty.set(n instanceof Color ? (Color) n : null));
keyValueProperty.set(colorProperty.get());
}
示例15: NeighbourVisualizer
import javafx.beans.property.ObjectProperty; //导入方法依赖的package包/类
/**
* Create a neighbour visualiser which gives a visualisation of the neighbours of a node.
*
* @param edgeColorProperty property which determines the color of edges to neighbours
* @param nodeProperty property which determines what node should actually be visualised
*/
NeighbourVisualizer(final ObjectProperty<Color> edgeColorProperty, final ObjectProperty<GfaNode> nodeProperty) {
edgeColorProperty.addListener((observable, oldColor, newColor) -> draw(nodeProperty.get(), newColor));
nodeProperty.addListener((observable, oldNode, newNode) -> draw(newNode, edgeColorProperty.get()));
}