當前位置: 首頁>>代碼示例>>Java>>正文


Java ObservableMap.addListener方法代碼示例

本文整理匯總了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 );
}
 
開發者ID:DanGrew,項目名稱:JttDesktop,代碼行數:24,代碼來源:StatusConfigurationPane.java

示例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()));
      }
    }
  });
}
 
開發者ID:wpilibsuite,項目名稱:shuffleboard,代碼行數:28,代碼來源:PropertyUtils.java

示例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());
            }
        });
    }
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:17,代碼來源:ObservableMergers.java

示例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);
}
 
開發者ID:LtubSalad,項目名稱:voogasalad-ltub,代碼行數:11,代碼來源:GeneralGameDataBar.java

示例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();
}
 
開發者ID:dejv78,項目名稱:j.commons,代碼行數:31,代碼來源:DemoFXMLController.java

示例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());
        }
    });
}
 
開發者ID:narrowtux,項目名稱:SmartModInserter,代碼行數:14,代碼來源:ObservableMapValues.java

示例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);
}
 
開發者ID:JabRef,項目名稱:jabref,代碼行數:10,代碼來源:BindingsHelper.java

示例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);
        }
    };
}
 
開發者ID:TomasMikula,項目名稱:ReactFX,代碼行數:11,代碼來源:EventStreams.java

示例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;
	}
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:66,代碼來源:BeanPathAdapter.java


注:本文中的javafx.collections.ObservableMap.addListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。