本文整理汇总了Java中javafx.collections.ListChangeListener.Change方法的典型用法代码示例。如果您正苦于以下问题:Java ListChangeListener.Change方法的具体用法?Java ListChangeListener.Change怎么用?Java ListChangeListener.Change使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.collections.ListChangeListener
的用法示例。
在下文中一共展示了ListChangeListener.Change方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOutputToScreenLogger
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
private ListChangeListener<String> getOutputToScreenLogger() {
outputListener = new ListChangeListener<String>() {
boolean first = true;
@Override
public void onChanged(ListChangeListener.Change<? extends String> change) {
change.next();
Platform.runLater(() -> {
List<? extends String> changedList = change.getList();
for (int index = first ? 0 : change.getFrom(); index < change.getTo(); index++) {
String added = changedList.get(index);
if (added != null) {
outputTextArea.appendText(added);
}
}
first = false;
});
}
};
return new WeakListChangeListener<>(outputListener);
}
示例2: onChanged
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Override
public void onChanged(ListChangeListener.Change<? extends U> listChange) {
List<T> boundList = boundListWeakRef.get();
if (boundList == null) {
listChange.getList().removeListener(this);
return;
}
while (listChange.next()) {
if (listChange.wasRemoved()) {
boundList.subList(listChange.getFrom(), listChange.getFrom() + listChange.getRemovedSize()).clear();
}
if (listChange.wasAdded()) {
boundList.addAll(listChange.getFrom(), map(listChange.getAddedSubList(), mapper));
}
}
}
示例3: onHybridRowChanged
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
private void onHybridRowChanged(ListChangeListener.Change<? extends HybridRow> change) {
while (change.next()) {
if (change.wasAdded()) {
List<SpecificationRow<ConstraintCell>> rowsToBeAdded = new ArrayList<>();
List<ConstraintDuration> durationsToBeAdded = new ArrayList<>();
for (HybridRow row : change.getAddedSubList()) {
SpecificationRow<ConstraintCell> rowToBeAdded = row.getSourceRow();
rowToBeAdded.commentProperty().bindBidirectional(row.commentProperty());
rowsToBeAdded.add(rowToBeAdded);
durationsToBeAdded.add(row.getDuration().getCell());
}
getRows().addAll(change.getFrom(), rowsToBeAdded);
getDurations().addAll(change.getFrom(), durationsToBeAdded);
}
if (change.wasRemoved()) {
getRows().remove(change.getFrom(), change.getFrom() + change.getRemovedSize());
getDurations().remove(change.getFrom(), change.getFrom() + change.getRemovedSize());
}
}
}
示例4: unbindTest
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Test
public void unbindTest()
{
final ObservableList<Model> collection1 = FXCollections.observableArrayList(new Model("value1"),
new Model("value2"),
new Model("value3"),
new Model("value4"));
final ObservableList<String> collection2 = FXCollections.observableArrayList();
IFXContentBinding.bind(collection2, collection1, Model::getText);
final AtomicReference<ListChangeListener.Change<? extends String>> change = new AtomicReference<>(null);
collection2.addListener((ListChangeListener<String>) c -> {
change.set(c);
});
IFXContentBinding.unbind(FXCollections.observableArrayList(), collection1);
collection1.add(new Model("value5"));
assertNotNull("Change event", change.get());
assertEquals(Arrays.asList("value1", "value2", "value3", "value4", "value5"), collection2);
change.set(null);
IFXContentBinding.unbind(collection2, FXCollections.observableArrayList());
collection1.add(new Model("value6"));
assertNotNull("Change event", change.get());
assertEquals(Arrays.asList("value1", "value2", "value3", "value4", "value5", "value6"), collection2);
change.set(null);
IFXContentBinding.unbind(collection2, collection1);
collection1.add(new Model("value7"));
assertNull("Change event", change.get());
assertEquals(Arrays.asList("value1", "value2", "value3", "value4", "value5", "value6"), collection2);
}
示例5: selectItemAction
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
private void selectItemAction(ListChangeListener.Change<? extends TreeItem<FileComponent>> c) {
if (c.next() && c.wasAdded()) {
TreeItem<FileComponent> node = c.getList().get(c.getFrom());
if (node != null && node.getParent() != null) {
FileComponent cc = node.getValue();
Log.info("Select " + cc);
statusLabel.setText(cc.toString());
if (cc.getLength() > 0) {
hexPane.select(cc);
bytesBar.select(cc);
}
}
}
}
示例6: onChanged
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Override
public void onChanged(ListChangeListener.Change<? extends OHLC> c) {
while(c.next()) {
if (c.wasAdded()) {
draw();
}
}
}
示例7: processUpdateEvent
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
/**
* Maps an update event of the model list to new elements of the {@link #viewModelList}.
*
* @param listEvent
* to process
*/
private void processUpdateEvent(ListChangeListener.Change<? extends SourceType> listEvent) {
for (int i = listEvent.getFrom(); i < listEvent.getTo(); i++) {
SourceType item = listEvent.getList().get(i);
viewModelList.set(i, ListTransformation.this.function.apply(item));
}
}
示例8: processReplaceEvent
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
/**
* Maps an replace event of the model list to new elements of the {@link #viewModelList}.
*
* @param listEvent
* to process
*/
private void processReplaceEvent(
ListChangeListener.Change<? extends SourceType> listEvent, List<TargetType> deletedStaging) {
processRemoveEvent(listEvent, deletedStaging);
processStagingLists(deletedStaging);
processAddEvent(listEvent);
}
示例9: processAddEvent
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
/**
* Maps an add event of the model list to new elements of the {@link #viewModelList}.
*
* @param listEvent
* to analyze
*/
private void processAddEvent(
ListChangeListener.Change<? extends SourceType> listEvent) {
final List<TargetType> toAdd = new ArrayList<>();
for (int index = listEvent.getFrom(); index < listEvent.getTo(); index++) {
final SourceType item = listEvent.getList().get(index);
toAdd.add(function.apply(item));
}
viewModelList.addAll(listEvent.getFrom(), toAdd);
}
示例10: onRowChange
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
/**
* Invoked when the list of row changes.
* @param change The {@link javafx.collections.ListChangeListener.Change} object corresponding
* to the list change
*/
protected void onRowChange(ListChangeListener.Change<? extends SpecificationRow<C>> change) {
while (change.next()) {
if (change.wasPermutated()) {
onRowOrderChanged();
}
if (change.wasAdded()) {
onRowAdded(change.getAddedSubList());
}
if (change.wasRemoved()) {
onRowRemoved(change.getRemoved());
}
}
}
示例11: onKeyFramesChanged
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
private void onKeyFramesChanged(ListChangeListener.Change<? extends KeyFrameModel> change) {
while (change.next()) {
if (change.wasAdded()) {
change.getAddedSubList().forEach(k -> k.timeProperty().addListener(listener));
}
if (change.wasRemoved()) {
change.getRemoved().forEach(k -> k.timeProperty().removeListener(listener));
}
}
calculateTimelineDuration();
}
示例12: addElementsTest
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Test
public void addElementsTest()
{
final ObservableList<Model> collection1 = FXCollections.observableArrayList(new Model("value1"),
new Model("value2"),
new Model("value3"),
new Model("value4"));
final ObservableList<String> collection2 = FXCollections.observableArrayList();
IFXContentBinding.bind(collection2, collection1, Model::getText);
final AtomicReference<ListChangeListener.Change<? extends String>> change = new AtomicReference<>(null);
collection2.addListener((ListChangeListener<String>) c -> {
change.set(c);
});
collection1.addAll(2, Arrays.asList(new Model("value2bis"), new Model("value2ter")));
assertNotNull("Change event", change.get());
assertTrue("Has change", change.get().next());
assertTrue("Was added", change.get().wasAdded());
assertFalse("Was removed", change.get().wasRemoved());
assertFalse("Was update", change.get().wasUpdated());
assertFalse("Was permuted", change.get().wasPermutated());
assertEquals("from", 2, change.get().getFrom());
assertEquals("to", 4, change.get().getTo());
assertEquals("Added sub-list", Arrays.asList("value2bis", "value2ter"), change.get().getAddedSubList());
assertFalse("Has more change", change.get().next());
assertEquals(Arrays.asList("value1", "value2", "value2bis", "value2ter", "value3", "value4"), collection2);
}
示例13: replaceElementsTest
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Test
public void replaceElementsTest()
{
final ObservableList<Model> collection1 = FXCollections.observableArrayList(new Model("value1"),
new Model("value2"),
new Model("value3"),
new Model("value4"));
final ObservableList<String> collection2 = FXCollections.observableArrayList();
IFXContentBinding.bind(collection2, collection1, Model::getText);
final AtomicReference<ListChangeListener.Change<? extends String>> change = new AtomicReference<>(null);
collection2.addListener((ListChangeListener<String>) c -> {
change.set(c);
});
collection1.set(1, new Model("value2bis"));
assertNotNull("Change event", change.get());
assertTrue("Has change", change.get().next());
assertTrue("Was added", change.get().wasAdded());
assertTrue("Was removed", change.get().wasRemoved());
assertFalse("Was update", change.get().wasUpdated());
assertFalse("Was permuted", change.get().wasPermutated());
assertEquals("from", 1, change.get().getFrom());
assertEquals("to", 2, change.get().getTo());
assertEquals("Added sub-list", Arrays.asList("value2bis"), change.get().getAddedSubList());
assertEquals("Removed", Arrays.asList("value2"), change.get().getRemoved());
assertFalse("Has more change", change.get().next());
assertEquals(Arrays.asList("value1", "value2bis", "value3", "value4"), collection2);
}
示例14: updateElementsTest
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Test
public void updateElementsTest()
{
final ObservableList<Model> collection1 = FXCollections.observableArrayList(m -> new ObservableValue[] {
m.textProperty() });
collection1.setAll(new Model("value1"), new Model("value2"), new Model("value3"), new Model("value4"));
final ObservableList<String> collection2 = FXCollections.observableArrayList();
IFXContentBinding.bind(collection2, collection1, Model::getText);
final AtomicReference<ListChangeListener.Change<? extends String>> change = new AtomicReference<>(null);
collection2.addListener((ListChangeListener<String>) c -> {
change.set(c);
});
collection1.get(1).setText("value2bis");
assertNotNull("Change event", change.get());
assertTrue("Has change", change.get().next());
assertTrue("Was added", change.get().wasAdded());
assertTrue("Was removed", change.get().wasRemoved());
assertFalse("Was update", change.get().wasUpdated());
assertFalse("Was permuted", change.get().wasPermutated());
assertEquals("from", 1, change.get().getFrom());
assertEquals("to", 2, change.get().getTo());
assertEquals("Added sub-list", Arrays.asList("value2bis"), change.get().getAddedSubList());
assertEquals("Removed", Arrays.asList("value2"), change.get().getRemoved());
assertFalse("Has more change", change.get().next());
assertEquals(Arrays.asList("value1", "value2bis", "value3", "value4"), collection2);
}
示例15: permuteElementsTest
import javafx.collections.ListChangeListener; //导入方法依赖的package包/类
@Test
public void permuteElementsTest()
{
final ObservableList<Model> collection1 = FXCollections.observableArrayList(new Model("value2"),
new Model("value4"),
new Model("value1"),
new Model("value3"));
final ObservableList<String> collection2 = FXCollections.observableArrayList();
IFXContentBinding.bind(collection2, collection1, Model::getText);
// Permutation can be generated only by calling sort, so IFXContentBinding generate a remove then an add
final List<ListChangeListener.Change<? extends String>> change = new ArrayList<>(2);
collection2.addListener((ListChangeListener<String>) c -> {
if (change.isEmpty())
{
assertEquals(Collections.emptyList(), collection2);
}
change.add(c);
});
collection1.sort(Comparator.comparing(Model::getText));
assertEquals("Change event", 2, change.size());
assertTrue("Has change", change.get(0).next());
assertFalse("Was added", change.get(0).wasAdded());
assertTrue("Was removed", change.get(0).wasRemoved());
assertFalse("Was update", change.get(0).wasUpdated());
assertFalse("Was permuted", change.get(0).wasPermutated());
assertEquals("from", 0, change.get(0).getFrom());
assertEquals("to", 0, change.get(0).getTo());
assertEquals("Removed", Arrays.asList("value2", "value4", "value1", "value3"), change.get(0).getRemoved());
assertFalse("Has more change", change.get(0).next());
assertTrue("Has change", change.get(1).next());
assertTrue("Was added", change.get(1).wasAdded());
assertFalse("Was removed", change.get(1).wasRemoved());
assertFalse("Was update", change.get(1).wasUpdated());
assertFalse("Was permuted", change.get(1).wasPermutated());
assertEquals("from", 0, change.get(1).getFrom());
assertEquals("to", 4, change.get(1).getTo());
assertEquals("Added sub-list", Arrays.asList("value1", "value2", "value3", "value4"),
change.get(1).getAddedSubList());
assertFalse("Has more change", change.get(1).next());
assertEquals(Arrays.asList("value1", "value2", "value3", "value4"), collection2);
}