当前位置: 首页>>代码示例>>Java>>正文


Java ObservableList.addListener方法代码示例

本文整理汇总了Java中javafx.collections.ObservableList.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java ObservableList.addListener方法的具体用法?Java ObservableList.addListener怎么用?Java ObservableList.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.collections.ObservableList的用法示例。


在下文中一共展示了ObservableList.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addColection

import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
 * Pridá kolekci do registru
 *
 * @param items Kolekce, která se má přidat
 */
public void addColection(ObservableList<? extends DatabaseItem> items) {
    items.addListener((ListChangeListener<DatabaseItem>) c -> {
        while (c.next()) {
            if (c.wasAdded()) {
                this.registry.addAll(c.getAddedSubList());
            }
            if (c.wasRemoved()) {
                this.registry.removeAll(c.getRemoved());
            }
        }
    });
    for (DatabaseItem item : items) {
        this.registry.add(item);
    }
}
 
开发者ID:stechy1,项目名称:drd,代码行数:21,代码来源:ItemRegistry.java

示例2: main

import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
 *
 * @param args
 */
public static void main(String[] args) {
    Logger log = LoggerFactory.getLogger(AppDemo.class);
    Initializer.getToolBox()
            .getEventBus()
            .toObserverable()
            .subscribe(e -> log.debug(e.toString()));
    App.main(args);

    ObservableList<Annotation> annotations = Initializer.getToolBox()
            .getData()
            .getAnnotations();

    annotations.addListener((InvalidationListener) observable ->
            log.debug("Annotation count: " + annotations.size()));
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:20,代码来源:AppDemo.java

示例3: FXThreadedObservableListWrapper

import javafx.collections.ObservableList; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public FXThreadedObservableListWrapper(ObservableList<T> sourceList) {
	this.sourceList = sourceList;
	this.delegatedList = FXCollections.synchronizedObservableList(FXCollections.observableArrayList());
	Platform.runLater(() -> delegatedList.addAll(sourceList.toArray((T[])new Object[sourceList.size()])));
	sourceListListener = i -> Platform.runLater(() ->
		delegatedList.setAll(sourceList.toArray((T[])new Object[sourceList.size()])));
	sourceList.addListener(sourceListListener);
}
 
开发者ID:Gurgy,项目名称:Cypher,代码行数:10,代码来源:FXThreadedObservableListWrapper.java

示例4: mergeList

import javafx.collections.ObservableList; //导入方法依赖的package包/类
@SafeVarargs
public static <T> void mergeList(ObservableList<T> into, ObservableList<T>... lists) {
    final ObservableList<T> list = into;
    for (ObservableList<T> l : lists) {
        list.addAll(l);
        l.addListener((ListChangeListener<T>) c -> {
            while (c.next()) {
                if (c.wasAdded()) {
                    list.addAll(c.getAddedSubList());
                }
                if (c.wasRemoved()) {
                    list.removeAll(c.getRemoved());
                }
            }
        });
    }
}
 
开发者ID:stechy1,项目名称:drd,代码行数:18,代码来源:ObservableMergers.java

示例5: bind

import javafx.collections.ObservableList; //导入方法依赖的package包/类
public static <T, U> void bind(List<T> boundList, ObservableList<U> sourceList, Function<U, T> mapper) {
    ListSynchronizer<T, U> listener = new ListSynchronizer<>(boundList, mapper);
    sourceList.removeListener(listener);
    sourceList.addListener(listener);
    boundList.clear();
    boundList.addAll(map(sourceList, mapper));
}
 
开发者ID:rmfisher,项目名称:fx-animation-editor,代码行数:8,代码来源:BindingFunctions.java

示例6: premain

import javafx.collections.ObservableList; //导入方法依赖的package包/类
public static void premain(final String args, Instrumentation instrumentation) throws Exception {
    instrumentation.addTransformer(new MenuItemTransformer());
    instrumentation.addTransformer(new FileChooserTransformer());
    logger.info("JavaVersion: " + System.getProperty("java.version"));
    final int port;
    if (args != null && args.trim().length() > 0) {
        port = Integer.parseInt(args.trim());
    } else {
        throw new Exception("Port number not specified");
    }
    windowTitle = System.getProperty("start.window.title", "");
    ObservableList<Stage> stages = StageHelper.getStages();
    stages.addListener(new ListChangeListener<Stage>() {
        boolean done = false;

        @Override public void onChanged(javafx.collections.ListChangeListener.Change<? extends Stage> c) {
            if (done) {
                return;
            }
            if (!"".equals(windowTitle)) {
                logger.warning("WindowTitle is not supported yet... Ignoring it.");
            }
            c.next();
            if (c.wasAdded()) {
                AccessController.doPrivileged(new PrivilegedAction<Object>() {
                    @Override public Object run() {
                        return new JavaFxRecorderHook(port);
                    }
                });
                done = true;
            }
        }
    });
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:35,代码来源:JavaFxRecorderHook.java

示例7: map

import javafx.collections.ObservableList; //导入方法依赖的package包/类
public static <F, T> ObservableList<T> map(ObservableList<F> list, Function<F, T> forward, Function<T, F> backward) {
  ObservableList<T> newList = FXCollections.observableArrayList();
  newList.setAll(Lists.transform(list, forward::apply));

  MapToTargetListener<F, T> forwardListener = new MapToTargetListener<>(list, newList, forward);
  MapToTargetListener<T, F> backwardListener = new MapToTargetListener<>(newList, list, backward);
  forwardListener.updating.bindBidirectional(backwardListener.updating);

  list.addListener(forwardListener);
  newList.addListener(backwardListener);
  return newList;
}
 
开发者ID:XDean,项目名称:JavaFX-EX,代码行数:13,代码来源:CollectionUtil.java

示例8: testNestedRows

import javafx.collections.ObservableList; //导入方法依赖的package包/类
@Test
public void testNestedRows() {
  ObservableList<SpecificationRow<StringProperty>> rows =
      FXCollections.observableList(
          Collections.singletonList(specRow),
          identityExtractor()
      );
  rows.addListener((Observable obs) -> listenerCalls++);

  assertEquals("listener calls before change", 0, listenerCalls);
  toBeChanged.set("XXX");
  assertEquals("listener calls after change", 1, listenerCalls);

  StringProperty toBeAddedChangedRemoved = new SimpleStringProperty("");

  rows.get(0).getCells().put("toBeAddedChangedRemoved", toBeAddedChangedRemoved);
  assertEquals("listener calls after adding", 2, listenerCalls);

  toBeAddedChangedRemoved.set("ASDF");
  assertEquals("listener calls after changing added", 3, listenerCalls);

  rows.get(0).getCells().remove("toBeAddedChangedRemoved");
  assertEquals("listener calls after removing", 4, listenerCalls);

  toBeAddedChangedRemoved.set("SHOULD NOT FIRE EVENT");
  assertEquals("listener calls after changing cell that was removed", 4, listenerCalls);
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:28,代码来源:SpecificationRowTest.java

示例9: setHiddenFieldChildren

import javafx.collections.ObservableList; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // Yes, I know the cast below is unchecked
protected void setHiddenFieldChildren(ObservableList<TreeItem<T>> list) {
    try {
        Field childrenField = TreeItem.class.getDeclaredField("children"); //$NON-NLS-1$
        childrenField.setAccessible(true);
        childrenField.set(this, list);

        Field declaredField = TreeItem.class.getDeclaredField("childrenListener"); //$NON-NLS-1$
        declaredField.setAccessible(true);
        list.addListener((ListChangeListener<? super TreeItem<T>>) declaredField.get(this));
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException("Could not set TreeItem.children", e); //$NON-NLS-1$
    }
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:15,代码来源:FilterableTreeItem.java

示例10: addElementsTest

import javafx.collections.ObservableList; //导入方法依赖的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);
}
 
开发者ID:ben12,项目名称:infxnity,代码行数:32,代码来源:IFXContentBindingTest.java

示例11: removeElementsTest

import javafx.collections.ObservableList; //导入方法依赖的package包/类
@Test
public void removeElementsTest()
{
    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.subList(1, 3).clear();

    assertNotNull("Change event", change.get());
    assertTrue("Has change", change.get().next());
    assertFalse("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", 1, change.get().getTo());
    assertEquals("Removed", Arrays.asList("value2", "value3"), change.get().getRemoved());
    assertFalse("Has more change", change.get().next());

    assertEquals(Arrays.asList("value1", "value4"), collection2);
}
 
开发者ID:ben12,项目名称:infxnity,代码行数:32,代码来源:IFXContentBindingTest.java

示例12: replaceElementsTest

import javafx.collections.ObservableList; //导入方法依赖的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);
}
 
开发者ID:ben12,项目名称:infxnity,代码行数:33,代码来源:IFXContentBindingTest.java

示例13: TimingDiagramView

import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
 * Instantiates a new Timing diagram view.
 *
 * @param xaxis the x axis
 * @param yaxis the y axis
 */
public TimingDiagramView(NumberAxis xaxis, Axis<A> yaxis) {
  super(xaxis, yaxis);
  this.xaxis = xaxis;
  this.yaxis = yaxis;

  setPrefHeight(80);

  getPlotChildren().addAll(cycleSelectionPane, durationLinesPane, dataPane);
  ViewUtils.setupView(this);

  ObservableList<Series<Number, A>> seriesObservableList = FXCollections.observableArrayList();
  setData(seriesObservableList);
  seriesObservableList.addListener((InvalidationListener) change -> {
    Platform.runLater(TimingDiagramView.this::requestRelayout);
  });
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:23,代码来源:TimingDiagramView.java

示例14: updateElementsTest

import javafx.collections.ObservableList; //导入方法依赖的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);
}
 
开发者ID:ben12,项目名称:infxnity,代码行数:32,代码来源:IFXContentBindingTest.java

示例15: bindModified

import javafx.collections.ObservableList; //导入方法依赖的package包/类
public <T> void bindModified(ObservableList<T> list) {
  list.addListener((ListChangeListener<T>) c -> modified());
}
 
开发者ID:XDean,项目名称:JavaFX-EX,代码行数:4,代码来源:ModifiableObject.java


注:本文中的javafx.collections.ObservableList.addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。