本文整理匯總了Java中javafx.collections.ObservableMap.addListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ObservableMap.addListener方法的具體用法?Java ObservableMap.addListener怎麽用?Java ObservableMap.addListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.collections.ObservableMap
的用法示例。
在下文中一共展示了ObservableMap.addListener方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addItemConfiguration
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
/**
* General mechanism for adding {@link ColorPicker}s.
* @param row the row to add the items on.
* @param label the {@link Label} describing the {@link ColorPicker}.
* @param picker the {@link ColorPicker}.
* @param shortcut the {@link Button} providing the shortcut.
* @param map the {@link ObservableMap} providing the {@link Color}.
*/
private void addItemConfiguration( int row, Label label, ColorPicker picker, Button shortcut, ObservableMap< BuildResultStatus, Color > map ) {
add( label, 0, row );
styling.configureColorPicker( picker, map.get( status ) );
map.addListener(
new StatusFilterPropertyUpdater( map, status, picker.valueProperty() )
);
picker.valueProperty().addListener( ( s, o, n ) -> map.put( status, n ) );
add( picker, 1, row );
shortcut.setMaxWidth( Double.MAX_VALUE );
shortcut.setOnAction( e -> picker.setValue( shortcuts.shortcutColorProperty().get() ) );
add( shortcut, 2, row );
}
示例2: bindToMapBidirectionally
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
/**
* Binds a property to a specific key in a map. If there is no entry for that key, the property's
* value will be set to null.
*
* @param property the property to bind
* @param map the map to bind to
* @param key the key for the entry to bind to
* @param v2t a conversion function for converting objects of type <i>V</i> to type <i>T</i>
* @param <K> the types of the keys in the map
* @param <V> the types of the values in the map
* @param <T> the type of data in the property
*/
public static <K, V, T extends V> void bindToMapBidirectionally(Property<T> property,
ObservableMap<K, V> map,
K key,
Function<V, T> v2t) {
property.addListener((__, oldValue, newValue) -> map.put(key, newValue));
map.addListener((MapChangeListener<K, V>) change -> {
if (change.getKey().equals(key)) {
if (change.wasRemoved() && !map.containsKey(key)) {
property.setValue(null);
} else if (change.wasAdded()) {
property.setValue(v2t.apply(change.getValueAdded()));
}
}
});
}
示例3: mergeMap
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
@SafeVarargs
public static <K, V> void mergeMap(ObservableMap<K, V> into,
ObservableMap<K, V>... maps) {
final ObservableMap<K, V> map = into;
for (ObservableMap<K, V> m : maps) {
map.putAll(m);
m.addListener((MapChangeListener<K, V>) c -> {
if (c.wasAdded()) {
map.put(c.getKey(), c.getValueAdded());
}
if (c.wasRemoved()) {
map.remove(c.getKey());
}
});
}
}
示例4: GeneralGameDataBar
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
public GeneralGameDataBar(ObservableMap<String, String> data) {
this.setSpacing(SPACING);
data.addListener(new MapChangeListener<String, String>() {
@Override
public void onChanged(@SuppressWarnings("rawtypes") MapChangeListener.Change change) {
redraw(data);
}
});
redraw(data);
}
示例5: onDebug
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
@FXML
public void onDebug(ActionEvent actionEvent) {
final ObservableMap<String, String> rmbStyleMap = FXCollections.observableHashMap();
rmbStyleMap.addListener((InvalidationListener)(observable) ->
rmb.setStyle(rmbStyleMap.entrySet().stream()
.map((entry) -> entry.getKey() + ": " + entry.getValue() + ";")
.reduce((s1, s2) -> s1 + s2).orElse("")));
final Button bSize = new Button("Size");
bSize.setOnAction((event) -> rmbStyleMap.put("-fx-size", "35"));
final Button bGraphic = new Button("Graphic");
bGraphic.setOnAction((event) -> rmbStyleMap.put("-fx-graphic","url(\"http://icons.iconarchive.com/icons/hopstarter/button/16/Button-Add-icon.png\")"));
final HBox menuButtonRow = new HBox();
menuButtonRow.setAlignment(Pos.CENTER_LEFT);
menuButtonRow.getChildren().addAll(new Label("RadialMenuButton:"), bSize, bGraphic);
final VBox vbox = new VBox();
vbox.getChildren().addAll(menuButtonRow);
final Dialog dialog = new Dialog();
dialog.initModality(Modality.NONE);
dialog.initOwner(pane.getScene().getWindow());
dialog.setTitle("Debugging actions");
dialog.setHeaderText("Select an action to perform below:");
dialog.getDialogPane().setContent(vbox);
dialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
dialog.show();
}
示例6: ObservableMapValues
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
public ObservableMapValues(ObservableList<T> internalStore, ObservableMap<?, T> referencedMap) {
this.internalStore = internalStore;
this.referencedMap = referencedMap;
referencedMap.addListener((MapChangeListener<Object, T>) change -> {
if (change.wasAdded()) {
internalStore.add(change.getValueAdded());
}
if (change.wasRemoved()) {
internalStore.remove(change.getValueRemoved());
}
});
}
示例7: bindContentBidirectional
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
public static <A, V, B> void bindContentBidirectional(ObservableMap<A, V> propertyA, ObservableValue<B> propertyB, Consumer<B> updateA, Consumer<Map<A, V>> updateB) {
final BidirectionalMapBinding<A, V, B> binding = new BidirectionalMapBinding<>(propertyA, propertyB, updateA, updateB);
// use list as initial source
updateB.accept(propertyA);
propertyA.addListener(binding);
propertyB.addListener(binding);
}
示例8: changesOf
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
public static <K, V> EventStream<MapChangeListener.Change<? extends K, ? extends V>> changesOf(ObservableMap<K, V> map) {
return new EventStreamBase<MapChangeListener.Change<? extends K, ? extends V>>() {
@Override
protected Subscription observeInputs() {
MapChangeListener<K, V> listener = c -> emit(c);
map.addListener(listener);
return () -> map.removeListener(listener);
}
};
}
示例9: addRemoveCollectionListener
import javafx.collections.ObservableMap; //導入方法依賴的package包/類
/**
* Adds/Removes the {@link FieldProperty} as a collection listener
*
* @param observable
* the {@link Observable} collection/map to listen for
* changes on
* @param add
* true to add, false to remove
*/
protected void addRemoveCollectionListener(final Observable observable,
final boolean add) {
final boolean isCol = getCollectionObservable() == observable;
if (isCol
&& ((this.isCollectionListening && add) || (this.isCollectionListening && !add))) {
return;
}
Boolean change = null;
if (observable instanceof ObservableList) {
final ObservableList<?> ol = (ObservableList<?>) observable;
if (add) {
ol.addListener(this);
change = true;
} else {
ol.removeListener(this);
change = false;
}
} else if (observable instanceof ObservableSet) {
final ObservableSet<?> os = (ObservableSet<?>) observable;
if (add) {
os.addListener(this);
change = true;
} else {
os.removeListener(this);
change = false;
}
} else if (observable instanceof ObservableMap) {
final ObservableMap<?, ?> om = (ObservableMap<?, ?>) observable;
if (add) {
om.addListener(this);
change = true;
} else {
om.removeListener(this);
change = false;
}
} else if (observable == null) {
throw new IllegalStateException(String.format(
"Observable collection/map bound to %1$s (item path: %2$s) "
+ "has been garbage collected",
this.fieldHandle.getFieldName(),
this.collectionItemPath, observable,
this.getFieldType()));
} else {
throw new UnsupportedOperationException(String.format(
"%1$s (item path: %2$s) of type \"%4$s\" "
+ "must be bound to a supported "
+ "observable collection/map type... "
+ "Found observable: %3$s",
this.fieldHandle.getFieldName(),
this.collectionItemPath, observable,
this.getFieldType()));
}
if (isCol && change != null) {
this.isCollectionListening = change;
}
}