javafx.collections.MapChangeListener Java Examples
The following examples show how to use
javafx.collections.MapChangeListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactfxUtil.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
public static <K, V> Val<Map<K, V>> observableMapVal(ObservableMap<K, V> map) { return new ValBase<Map<K, V>>() { @Override protected Subscription connect() { MapChangeListener<K, V> listener = ch -> notifyObservers(new HashMap<>(map)); map.addListener(listener); return () -> map.removeListener(listener); } @Override protected Map<K, V> computeValue() { return new HashMap<>(map); } }; }
Example #2
Source File: WorkbenchPresenter.java From WorkbenchFX with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public final void setupValueChangedListeners() { overlays.addListener((MapChangeListener<Region, WorkbenchOverlay>) c -> { LOGGER.trace("Listener overlays fired"); if (c.wasAdded()) { LOGGER.trace("Overlay added"); addOverlay(c.getValueAdded()); } else if (c.wasRemoved()) { LOGGER.trace("Overlay removed"); removeOverlay(c.getValueRemoved()); } }); WorkbenchUtils.addListListener( overlaysShown, change -> showOverlay(change, false), this::hideOverlay ); WorkbenchUtils.addListListener( blockingOverlaysShown, change -> showOverlay(change, true), this::hideOverlay ); }
Example #3
Source File: Listeners.java From SynchronizeFX with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onChanged(final MapChangeListener.Change<? extends Object, ? extends Object> change) { final ObservableMap<?, ?> map = change.getMap(); if (disabledFor.containsKey(map)) { return; } try { final UUID mapId = objectRegistry.getIdOrFail(map); final Object key = change.getKey(); if (change.wasAdded()) { final Object value = change.getValueAdded(); final List<Command> commands = creator.putToMap(mapId, key, value); registerListenersOnEverything(key); if (value != null) { registerListenersOnEverything(value); } distributeCommands(commands); } else { distributeCommands(creator.removeFromMap(mapId, key)); } } catch (final SynchronizeFXException e) { topology.onError(e); } }
Example #4
Source File: NewBadge.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
public NewBadge(Node control, String key, Preferences preferences) { super(control); this.key = key; setText(Res.get("shared.new")); getStyleClass().add("new"); setEnabled(!preferences.getDontShowAgainMap().containsKey(key)); refreshBadge(); preferences.getDontShowAgainMapAsObservable().addListener((MapChangeListener<? super String, ? super Boolean>) change -> { if (change.getKey().equals(key)) { setEnabled(!change.wasAdded()); refreshBadge(); } }); }
Example #5
Source File: World.java From charts with Apache License 2.0 | 6 votes |
private void registerListeners() { widthProperty().addListener(o -> resize()); heightProperty().addListener(o -> resize()); sceneProperty().addListener(o -> { if (!locations.isEmpty()) { addShapesToScene(locations.values()); } if (isZoomEnabled()) { getScene().addEventFilter( ScrollEvent.ANY, new WeakEventHandler<>(_scrollEventHandler)); } locations.addListener((MapChangeListener<Location, Shape>) CHANGE -> { if (CHANGE.wasAdded()) { addShapesToScene(CHANGE.getValueAdded()); } else if(CHANGE.wasRemoved()) { Platform.runLater(() -> pane.getChildren().remove(CHANGE.getValueRemoved())); } }); }); }
Example #6
Source File: World.java From worldfx with Apache License 2.0 | 6 votes |
private void registerListeners() { widthProperty().addListener(o -> resize()); heightProperty().addListener(o -> resize()); sceneProperty().addListener(o -> { if (!locations.isEmpty()) { addShapesToScene(locations.values()); } if (isZoomEnabled()) { getScene().addEventFilter( ScrollEvent.ANY, new WeakEventHandler<>(_scrollEventHandler)); } locations.addListener((MapChangeListener<Location, Shape>) CHANGE -> { if (CHANGE.wasAdded()) { addShapesToScene(CHANGE.getValueAdded()); } else if(CHANGE.wasRemoved()) { Platform.runLater(() -> pane.getChildren().remove(CHANGE.getValueRemoved())); } }); }); }
Example #7
Source File: DaoPresentation.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
@Inject public DaoPresentation(Preferences preferences, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, DaoStateService daoStateService, DaoFacade daoFacade) { this.preferences = preferences; this.btcWalletService = btcWalletService; this.bsqWalletService = bsqWalletService; this.daoFacade = daoFacade; this.daoStateService = daoStateService; preferences.getDontShowAgainMapAsObservable().addListener((MapChangeListener<? super String, ? super Boolean>) change -> { if (change.getKey().equals(DAO_NEWS) && DevEnv.isDaoActivated()) { showNotification.set(!change.wasAdded()); } }); if (!DevEnv.isDaoActivated()) { bsqInfo.set(""); bsqSyncProgress.set(0); } walletChainHeightListener = (observable, oldValue, newValue) -> onUpdateAnyChainHeight(); }
Example #8
Source File: Connection.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Creates a position change listener (PCL) which {@link #refresh() * refreshes} this {@link Connection} upon anchor position changes * corresponding to the given {@link AnchorKey}. * * @param anchorKey * The {@link AnchorKey} for which a position change will trigger * a {@link #refresh()} with the returned PCL. * @return A position change listener to {@link #refresh() refresh} this * {@link Connection} when the position for the given * {@link AnchorKey} changes. */ protected MapChangeListener<? super AnchorKey, ? super Point> createPCL( final AnchorKey anchorKey) { return new MapChangeListener<AnchorKey, Point>() { @Override public void onChanged( MapChangeListener.Change<? extends AnchorKey, ? extends Point> change) { // if (inRefresh) { // return; // } if (change.getKey().equals(anchorKey)) { if (change.wasAdded() && change.wasRemoved()) { Point newPoint = FX2Geometry .toPoint(getCurve().localToParent(Geometry2FX .toFXPoint(change.getValueAdded()))); if (!points.get(getAnchorIndex(anchorKey)) .equals(newPoint)) { points.set(getAnchorIndex(anchorKey), newPoint); refresh(); } } } } }; }
Example #9
Source File: MapListenerHelperEx.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Notifies the attached {@link MapChangeListener}s about the related * change. * * @param change * The applied change. */ protected void notifyMapChangeListeners( Change<? extends K, ? extends V> change) { if (mapChangeListeners != null && !mapChangeListeners.isEmpty()) { // if (lockMapChangeListeners) { // throw new IllegalStateException("Re-entrant map change!"); // } try { lockMapChangeListeners = true; for (MapChangeListener<? super K, ? super V> l : mapChangeListeners) { try { l.onChanged(change); } catch (Exception e) { // System.out.println("Exception in listener: " + // e.getMessage() + ", cause=" + e.getCause()); Thread.currentThread().getUncaughtExceptionHandler() .uncaughtException(Thread.currentThread(), e); } } } finally { lockMapChangeListeners = false; } } }
Example #10
Source File: ObservableMapValues.java From SmartModInserter with GNU Lesser General Public License v3.0 | 5 votes |
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()); } }); }
Example #11
Source File: MapListenerHelperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Adds a new {@link MapChangeListener} to this {@link MapListenerHelperEx}. * If the same listener is added more than once, it will be registered more * than once and will receive multiple change events. * * @param listener * The listener to add. */ public void addListener(MapChangeListener<? super K, ? super V> listener) { if (mapChangeListeners == null) { mapChangeListeners = new ArrayList<>(); } // XXX: Prevent ConcurrentModificationExceptions (in case listeners are // added during notifications); as we only create a new multi-set in the // locked case, memory should not be waisted. if (lockMapChangeListeners) { mapChangeListeners = new ArrayList<>(mapChangeListeners); } mapChangeListeners.add(listener); }
Example #12
Source File: MapListenerHelperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Notifies all attached {@link InvalidationListener}s and * {@link MapChangeListener}s about the change. * * @param change * The change to notify listeners about. */ public void fireValueChangedEvent( MapChangeListener.Change<? extends K, ? extends V> change) { notifyInvalidationListeners(); if (change != null) { notifyMapChangeListeners(change); } }
Example #13
Source File: MapListenerHelperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Removes the given {@link MapChangeListener} from this * {@link MapListenerHelperEx}. If its was registered more than once, * removes one occurrence. * * @param listener * The listener to remove. */ public void removeListener( MapChangeListener<? super K, ? super V> listener) { if (mapChangeListeners == null) { return; } // XXX: Prevent ConcurrentModificationExceptions (in case listeners are // added during notifications); as we only create a new multi-set in the // locked case, memory should not be waisted. if (lockMapChangeListeners) { mapChangeListeners = new ArrayList<>(mapChangeListeners); } // XXX: We have to ignore the hash code when removing listeners, as // otherwise unbinding will be broken (JavaFX bindings violate the // contract between equals() and hashCode(): JI-9028554); remove() may // thus not be used. for (Iterator<MapChangeListener<? super K, ? super V>> iterator = mapChangeListeners .iterator(); iterator.hasNext();) { if (iterator.next().equals(listener)) { iterator.remove(); break; } } if (mapChangeListeners.isEmpty()) { mapChangeListeners = null; } }
Example #14
Source File: EdgePart.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void onChanged(MapChangeListener.Change<? extends String, ? extends Object> change) { if (ZestProperties.ROUTER__E.equals(change.getKey())) { // if the router changed, re-attach the visual (so we attach to // a different anchor) for (Entry<IVisualPart<? extends Node>, String> anchoragesByRole : getAnchoragesUnmodifiable() .entries()) { doDetachFromAnchorageVisual(anchoragesByRole.getKey(), anchoragesByRole.getValue()); doAttachToAnchorageVisual(anchoragesByRole.getKey(), anchoragesByRole.getValue()); } } refreshVisual(); }
Example #15
Source File: SelectionModel.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void onChanged( javafx.collections.MapChangeListener.Change<? extends Node, ? extends IVisualPart<? extends Node>> change) { // keep model in sync with part hierarchy if (change.wasRemoved()) { IVisualPart<? extends Node> valueRemoved = change .getValueRemoved(); if (selection.contains(valueRemoved)) { selection.remove(valueRemoved); } } }
Example #16
Source File: HoverModel.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void onChanged( javafx.collections.MapChangeListener.Change<? extends Node, ? extends IVisualPart<? extends Node>> change) { // keep model in sync with part hierarchy if (change.wasRemoved()) { IVisualPart<? extends Node> valueRemoved = change .getValueRemoved(); if (hoverProperty.get() == valueRemoved) { clearHover(); } if (hoverIntentProperty.get() == valueRemoved) { clearHoverIntent(); } } }
Example #17
Source File: FocusModel.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void onChanged( javafx.collections.MapChangeListener.Change<? extends Node, ? extends IVisualPart<? extends Node>> change) { // keep model in sync with part hierarchy if (change.wasRemoved()) { if (focusedProperty.get() == change.getValueRemoved()) { setFocus(null); } } }
Example #18
Source File: MapExpressionHelperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Fires notifications to all attached {@link InvalidationListener * InvalidationListeners}, and {@link MapChangeListener MapChangeListeners}. * * @param change * The change that needs to be propagated. */ @Override public void fireValueChangedEvent( MapChangeListener.Change<? extends K, ? extends V> change) { if (change != null) { notifyInvalidationListeners(); // XXX: We do not notify change listeners here, as the identity of // the observed value did not change (see // https://bugs.openjdk.java.net/browse/JDK-8089169) notifyMapChangeListeners( new AtomicChange<>(observableValue, change)); } }
Example #19
Source File: AccountPresentation.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@Inject public AccountPresentation(Preferences preferences) { this.preferences = preferences; preferences.getDontShowAgainMapAsObservable().addListener((MapChangeListener<? super String, ? super Boolean>) change -> { if (change.getKey().equals(ACCOUNT_NEWS)) { showNotification.set(!change.wasAdded()); } }); }
Example #20
Source File: EventStreams.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
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); } }; }
Example #21
Source File: SimpleMapPropertyEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void removeListener( MapChangeListener<? super K, ? super V> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #22
Source File: SimpleMapPropertyEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void addListener(MapChangeListener<? super K, ? super V> listener) { if (helper == null) { helper = new MapExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #23
Source File: ReadOnlyMapPropertyBaseEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void removeListener( MapChangeListener<? super K, ? super V> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #24
Source File: ReadOnlyMapPropertyBaseEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override protected void fireValueChangedEvent( MapChangeListener.Change<? extends K, ? extends V> change) { if (helper != null) { helper.fireValueChangedEvent(change); } }
Example #25
Source File: ReadOnlyMapPropertyBaseEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void addListener(MapChangeListener<? super K, ? super V> listener) { if (helper == null) { helper = new MapExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #26
Source File: ReadOnlyMapWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void removeListener( MapChangeListener<? super K, ? super V> listener) { // don't delegate to read-only property (fix for // https://bugs.openjdk.java.net/browse/JDK-8089557) if (helper != null) { helper.removeListener(listener); } }
Example #27
Source File: ReadOnlyMapWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void addListener(MapChangeListener<? super K, ? super V> listener) { // don't delegate to read-only property (fix for // https://bugs.openjdk.java.net/browse/JDK-8089557) if (helper == null) { helper = new MapExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #28
Source File: ReadOnlyMapWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void removeListener( MapChangeListener<? super K, ? super V> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #29
Source File: ReadOnlyMapWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void addListener( MapChangeListener<? super K, ? super V> listener) { if (helper == null) { helper = new MapExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #30
Source File: Connection.java From gef with Eclipse Public License 2.0 | 5 votes |
private void registerPCL(AnchorKey anchorKey, IAnchor anchor) { if (!anchorsPCL.containsKey(anchorKey)) { MapChangeListener<? super AnchorKey, ? super Point> pcl = createPCL( anchorKey); anchorsPCL.put(anchorKey, pcl); anchor.positionsUnmodifiableProperty().addListener(pcl); } }