JFXTras to JavaFX 8 migration
Tom Eugelink
tbee at tbee.org
Sat Apr 6 13:34:29 PDT 2013
I'm in the process of migrating my controls in JFXtras to JFX8. One of the issues I run in to is that my ListSpinner control gets stuck in a very long loop when it is used to spin over the years, where it does not on JFX2.2. The reason seems to be that the ObservableListWrapper, used to turn a regular List into a observable one (which is returned by FXCollections.observableList) is somehow by-passing the optimized indexOf that is implemented in my ListSpinnerIntegerList.
ListSpinnerIntegerList extends AbstractList and overrides get() and size() to get an unmodifiable list as per JavaDoc.
http://docs.oracle.com/javase/7/docs/api/java/util/AbstractList.html
ListSpinnerIntegerList also overrides indexOf, because it has a very large range and instead of iterating, the index can easily be calculated from the value.
https://github.com/JFXtras/jfxtras-labs/blob/8.0/src/main/java/jfxtras/labs/scene/control/ListSpinnerIntegerList.java
In JFX 2.2 this works correctly, in JFX 8.0 the optimized indexOf is 'never' reached, but the JavaFX thread is busy in the iteration based implementation of indexOf in AbstractList.
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/AbstractList.java#AbstractList.indexOf%28java.lang.Object%29
However, I cannot explain how it gets there and not in my optimized indexOf. The implementation of indexOf in ObservableListWrapper seems to forward it to the backing list.
https://bitbucket.org/openjfxmirrors/openjfx-8-graphics-rt/src/c5937c934c188b70a51ad98cad4d24b91450105f/javafx-beans/src/com/sun/javafx/collections/ObservableListWrapper.java
So I'm expecting
call list.index() -> ObservableListWrapper.indexOf() -> backingList.indexOf() which is ListSpinnerIntegerList.indexOf()
But that does not happen. The current workaround basically by overriding indexOf re-enforces the behavior of calling the backing list.
See line 118 in https://github.com/JFXtras/jfxtras-labs/blob/8.0/src/main/java/jfxtras/labs/scene/control/ListSpinner.java
I'm suspecting I'm not seeing the correct implementation of indexOf in ObservableListWrapper.
How is indexOf implemented in ObservableListWrapper in 8.0?
Tom
More information about the openjfx-dev
mailing list