Java Code Examples for javafx.collections.ListChangeListener#Change
The following examples show how to use
javafx.collections.ListChangeListener#Change .
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: UpdateAxisLabels.java From chart-fx with Apache License 2.0 | 6 votes |
private void setupDataSetListeners(Renderer renderer, ObservableList<DataSet> dataSets) { Map<DataSet, EventListener> dataSetListeners; if (renderer == null) { dataSetListeners = chartDataSetsListeners; } else if (rendererDataSetsListeners.containsKey(renderer)) { dataSetListeners = rendererDataSetsListeners.get(renderer); } else { dataSetListeners = new HashMap<>(); rendererDataSetsListeners.put(renderer, dataSetListeners); } ListChangeListener<DataSet> rendererListener = (ListChangeListener.Change<? extends DataSet> change) -> dataSetsChanged(change, renderer); dataSets.addListener(rendererListener); renderersListeners.put(renderer, rendererListener); dataSets.forEach((DataSet dataSet) -> { EventListener dataSetListener = update -> FXUtils.runFX(() -> dataSetChange(update, renderer)); EventRateLimiter rateLimitedDataSetListener = new EventRateLimiter(dataSetListener, UPDATE_RATE_LIMIT); dataSet.addListener(rateLimitedDataSetListener); dataSetListeners.put(dataSet, rateLimitedDataSetListener); dataSetChange(new AxisChangeEvent(dataSet, -1), renderer); }); }
Example 2
Source File: TableViewer.java From chart-fx with Apache License 2.0 | 6 votes |
protected void rendererChanged(final ListChangeListener.Change<? extends Renderer> change) { boolean dataSetChanges = false; while (change.next()) { // handle added renderer change.getAddedSubList().forEach(renderer -> renderer.getDatasets().addListener(datasetChangeListener)); if (!change.getAddedSubList().isEmpty()) { dataSetChanges = true; } // handle removed renderer change.getRemoved().forEach(renderer -> renderer.getDatasets().removeListener(datasetChangeListener)); if (!change.getRemoved().isEmpty()) { dataSetChanges = true; } } if (dataSetChanges) { datasetsChanged(null); } }
Example 3
Source File: PluginReporterPane.java From constellation with Apache License 2.0 | 6 votes |
@Override public void onChanged(ListChangeListener.Change<? extends String> c) { filteredTags.addAll(tagComboBox.getItems()); filteredTags.removeAll(tagComboBox.getCheckModel().getCheckedItems()); // Save the new filtered tags to preferences StringBuilder prefString = new StringBuilder(); String delimiter = ""; for (String filteredTag : filteredTags) { prefString.append(delimiter); delimiter = "\t"; prefString.append(filteredTag); } final Preferences prefs = NbPreferences.forModule(PluginReporterPane.class); prefs.put(FILTERED_TAGS_KEY, prefString.toString()); setGraphReport(graphReport); }
Example 4
Source File: Chart.java From chart-fx with Apache License 2.0 | 6 votes |
protected void rendererChanged(final ListChangeListener.Change<? extends Renderer> change) { FXUtils.assertJavaFxThread(); while (change.next()) { // handle added renderer change.getAddedSubList().forEach(renderer -> { // update legend and recalculateLayout on datasetChange renderer.getDatasets().addListener(datasetChangeListener); // add listeners to all datasets already in the renderer renderer.getDatasets().forEach(set -> set.addListener(dataSetDataListener)); }); // handle removed renderer change.getRemoved().forEach(renderer -> { renderer.getDatasets().removeListener(datasetChangeListener); renderer.getDatasets().forEach(set -> set.removeListener(dataSetDataListener)); }); } // reset change to allow derived classes to add additional listeners to renderer changes change.reset(); requestLayout(); updateLegend(getDatasets(), getRenderers()); }
Example 5
Source File: ListListenerHelperEx.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Infers the elementary changes constituting the change of the * {@link ObservableList}. * * @param <E> * The element type of the {@link ObservableList} that was * changed. * @param change * The (atomic) change to infer elementary changes from. * @return A list of elementary changes. */ protected static <E> List<ElementarySubChange<E>> getElementaryChanges( ListChangeListener.Change<? extends E> change) { List<ElementarySubChange<E>> elementarySubChanges = new ArrayList<>(); while (change.next()) { if (change.wasReplaced()) { elementarySubChanges.add(ElementarySubChange.replaced( change.getRemoved(), change.getAddedSubList(), change.getFrom(), change.getTo())); } else if (change.wasRemoved()) { elementarySubChanges.add(ElementarySubChange.removed( change.getRemoved(), change.getFrom(), change.getTo())); } else if (change.wasAdded()) { elementarySubChanges.add(ElementarySubChange.added( new ArrayList<>(change.getAddedSubList()), change.getFrom(), change.getTo())); } else if (change.wasPermutated()) { // find permutation int[] permutation = CollectionUtils.getPermutation(change); elementarySubChanges.add(ElementarySubChange.<E> permutated( permutation, change.getFrom(), change.getTo())); } } change.reset(); return elementarySubChanges; }
Example 6
Source File: CollectionUtils.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Computes the permutation for the given {@link Change}. * * @param <E> * The element type of the {@link ObservableList} that was * changed. * @param change * The change, for which {@link Change#wasPermutated()} has to * return <code>true</code>. * @return An integer array mapping previous indexes to current ones. */ public static <E> int[] getPermutation( ListChangeListener.Change<? extends E> change) { if (!change.wasPermutated()) { throw new IllegalArgumentException( "Change is no permutation change."); } if (change instanceof AtomicChange) { return ((AtomicChange<?>) change).getPermutation(); } int[] permutation = new int[change.getTo() - change.getFrom()]; for (int oldIndex = change.getFrom(); oldIndex < change .getTo(); oldIndex++) { int newIndex = change.getPermutation(oldIndex); permutation[oldIndex] = newIndex; } return permutation; }
Example 7
Source File: XYChart.java From chart-fx with Apache License 2.0 | 5 votes |
/** * add XYChart specific axis handling (ie. placement around charts, add new DefaultNumericAxis if one is missing, * etc.) * * @param change the new axis change that is being added */ @Override protected void axesChanged(final ListChangeListener.Change<? extends Axis> change) { while (change.next()) { change.getRemoved().forEach(axis -> { AssertUtils.notNull("to be removed axis is null", axis); // check if axis is associated with an existing renderer, if yes // -> throw an exception // remove from axis.side property side listener removeFromAllAxesPanes(axis); axis.sideProperty().removeListener(axisSideChangeListener); }); change.getAddedSubList().forEach(axis -> { // check if axis is associated with an existing renderer, // if yes -> throw an exception AssertUtils.notNull("to be added axis is null", axis); final Side side = axis.getSide(); if (side == null) { throw new InvalidParameterException(new StringBuilder().append("axis '").append(axis.getName()).append("' has 'null' as side being set").toString()); } if (!getAxesPane(axis.getSide()).getChildren().contains((Node) axis)) { getAxesPane(axis.getSide()).getChildren().add((Node) axis); } axis.sideProperty().addListener(axisSideChangeListener); }); } requestLayout(); }
Example 8
Source File: XYChart.java From chart-fx with Apache License 2.0 | 5 votes |
@Override protected void rendererChanged(final ListChangeListener.Change<? extends Renderer> change) { while (change.next()) { // handle added renderer //TODO: check if this function is still necessary (presently commented) // for (final Renderer renderer : change.getAddedSubList()) { // checkRendererForRequiredAxes(renderer); //} } // reset change to allow derived classes to add additional listeners to renderer changes change.reset(); super.rendererChanged(change); }
Example 9
Source File: ContentBehavior.java From gef with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void onChanged( final ListChangeListener.Change<? extends Object> change) { // System.out.println("Content children changed " + change); // XXX: An atomic operation (including setAll()) on the // ObservableList will lead to an atomic change here; we do not have // to iterate through the individual changes but may simply // synchronize with the list as it emerges after the changes have // been applied. IContentPart<? extends Node> parent = (IContentPart<? extends Node>) ((ReadOnlyProperty<?>) change .getList()).getBean(); // while (change.next()) { // if (change.wasRemoved()) { // removeContentPartChildren(parent, // ImmutableList.copyOf(change.getRemoved())); // } else if (change.wasAdded()) { // addContentPartChildren(parent, // ImmutableList.copyOf(change.getAddedSubList()), // change.getFrom()); // } else if (change.wasPermutated()) { // throw new UnsupportedOperationException( // "Reorder not yet implemented"); // } // } synchronizeContentPartChildren(parent, change.getList()); }
Example 10
Source File: Preferences.java From bisq-core with GNU Affero General Public License v3.0 | 5 votes |
private void updateTradeCurrencies(ListChangeListener.Change<? extends TradeCurrency> change) { change.next(); if (change.wasAdded() && change.getAddedSize() == 1 && initialReadDone) tradeCurrenciesAsObservable.add(change.getAddedSubList().get(0)); else if (change.wasRemoved() && change.getRemovedSize() == 1 && initialReadDone) tradeCurrenciesAsObservable.remove(change.getRemoved().get(0)); }
Example 11
Source File: RevealPrimarySelectionBehavior.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void onChanged( ListChangeListener.Change<? extends IContentPart<? extends Node>> c) { // determine primary selection IContentPart<? extends Node> currentPrimarySelection = null; if (c.getList().size() > 0) { currentPrimarySelection = c.getList().get(0); } if (currentPrimarySelection != previousPrimarySelection) { onPrimarySelectionChanged(previousPrimarySelection, currentPrimarySelection); previousPrimarySelection = currentPrimarySelection; } }
Example 12
Source File: SelectionBehavior.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void onChanged( ListChangeListener.Change<? extends IContentPart<? extends Node>> c) { // order of selection should not be relevant for feedback and // handles, as such we ignore permutations List<IContentPart<? extends Node>> newSelection = new ArrayList<>( c.getList()); List<? extends IContentPart<? extends Node>> oldSelection = CollectionUtils .getPreviousContents(c); removeFeedbackAndHandles(oldSelection); addFeedbackAndHandles(newSelection); }
Example 13
Source File: ListExpressionHelperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Fires notifications to all attached * {@link javafx.beans.InvalidationListener InvalidationListeners}, and * {@link ListChangeListener ListChangeListeners}. * * @param change * The change that needs to be propagated. */ @Override public void fireValueChangedEvent( ListChangeListener.Change<? extends E> 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) notifyListChangeListeners( new AtomicChange<>(observableValue, change)); } }
Example 14
Source File: GraphPart.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void onChanged(ListChangeListener.Change<? extends Object> c) { // synchronize children (triggered through content children) refreshContentChildren(); refreshVisual(); }
Example 15
Source File: GraphLayoutBehavior.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void onChanged(ListChangeListener.Change<? extends IVisualPart<? extends Node>> c) { applyLayout(true, null); }
Example 16
Source File: CollectionUtils.java From gef with Eclipse Public License 2.0 | 4 votes |
/** * Computes the previous contents of the source {@link ObservableList} * before the given {@link javafx.collections.ListChangeListener.Change} was * applied. * * @param <E> * The element type of the {@link ObservableList}. * @param change * The {@link javafx.collections.ListChangeListener.Change} for * which to compute the previous contents. * @return A newly created {@link List} that resembles the state of the * source {@link ObservableList} before the change. */ public static <E> List<E> getPreviousContents( ListChangeListener.Change<E> change) { if (change instanceof AtomicChange) { return ((AtomicChange<E>) change).getPreviousContents(); } ObservableList<E> currentList = change.getList(); ObservableList<E> previousList = FXCollections .observableArrayList(currentList); // walk over elementary changes and record them in a list change.reset(); List<ElementarySubChange<E>> changes = ListListenerHelperEx .getElementaryChanges(change); // undo the changes in reverse order for (int i = changes.size() - 1; i >= 0; i--) { ElementarySubChange<E> c = changes.get(i); int from = c.getFrom(); int to = c.getTo(); if (ElementarySubChange.Kind.ADD.equals(c.getKind()) || ElementarySubChange.Kind.REPLACE.equals(c.getKind())) { // remove added elements for (int j = to - 1; j >= from; j--) { previousList.remove(j); } } if (ElementarySubChange.Kind.REMOVE.equals(c.getKind()) || ElementarySubChange.Kind.REPLACE.equals(c.getKind())) { // add removed elements List<E> removed = c.getRemoved(); previousList.addAll(from, removed); } if (ElementarySubChange.Kind.PERMUTATE.equals(c.getKind())) { // create sub list with old permutation int[] permutation = c.getPermutation(); List<E> subList = new ArrayList<>(to - from); for (int j = from; j < to; j++) { int k = permutation[j - from]; subList.add(currentList.get(k)); } // insert sub list at correct position previousList.remove(from, to); previousList.addAll(from, subList); } } return previousList; }
Example 17
Source File: ZestContentViewer.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void onChanged(ListChangeListener.Change<? extends IContentPart<? extends javafx.scene.Node>> c) { fireSelectionChanged(new SelectionChangedEvent(ZestContentViewer.this, getSelection())); }
Example 18
Source File: AbstractFeedbackPart.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void onChanged(ListChangeListener.Change<? extends Point> c) { refreshVisual(); }
Example 19
Source File: FocusFeedbackPart.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void onChanged( ListChangeListener.Change<? extends IContentPart<? extends Node>> c) { refreshVisual(); }
Example 20
Source File: Chart.java From chart-fx with Apache License 2.0 | 2 votes |
/** * add Chart specific axis handling (ie. placement around charts, add new DefaultNumericAxis if one is missing, * etc.) * * @param change the new axis change that is being added */ protected abstract void axesChanged(final ListChangeListener.Change<? extends Axis> change);