Skip to content

Commit bee715d

Browse files
LinusDietzSiedlerchr
authored andcommitted
Replace Reimplement MappedList.kt (#3032)
* Working version of the MappedList * Typo, naming, attribution * remove jfx dependency
1 parent c553826 commit bee715d

File tree

4 files changed

+118
-14
lines changed

4 files changed

+118
-14
lines changed

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ dependencies {
113113
compile 'de.codecentric.centerdevice:javafxsvg:1.2.1'
114114
compile 'org.controlsfx:controlsfx:8.40.12'
115115
compile 'org.fxmisc.easybind:easybind:1.0.3'
116-
compile('net.corda:jfx:0.12.1') {
117-
transitive = false
118-
}
119-
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3' // required by net.corda:jfxc
116+
117+
120118
compile 'org.fxmisc.flowless:flowless:0.5.2'
121119
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
122120
compile 'org.fxmisc.richtext:richtextfx:0.7-M5'

external-libraries.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ Project: EasyBind
138138
URL: https://github.com/TomasMikula/EasyBind
139139
License: BSD-2-Clause
140140

141-
Id: net.corda:jfx
142-
Project: Corda
143-
URL: https://github.com/corda/corda/tree/master/client/jfx
144-
License: Apache-2.0
145-
146141
Id: org.fxmisc.flowless:flowless
147142
Project: Flowless
148143
URL: https://github.com/TomasMikula/Flowless

src/main/java/org/jabref/gui/util/BindingsHelper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import javafx.css.PseudoClass;
1919
import javafx.scene.Node;
2020

21-
import net.corda.client.jfx.utils.MappedList;
22-
2321

2422
/**
2523
* Helper methods for javafx binding.
@@ -67,8 +65,8 @@ public String getName() {
6765
* the items are converted when the are inserted (and at the initialization) instead of when they are accessed.
6866
* Thus the initial CPU overhead and memory consumption is higher but the access to list items is quicker.
6967
*/
70-
public static <A, B> ObservableList<B> mapBacked(ObservableList<A> source, Function<A, B> mapper) {
71-
return new MappedList<>(source, mapper::apply);
68+
public static <A, B> MappedList mapBacked(ObservableList<A> source, Function<A, B> mapper) {
69+
return new MappedList<>(source, mapper);
7270
}
7371

7472
/**
@@ -154,7 +152,7 @@ public ChangeListener<? super B> getChangeListenerB() {
154152
public void changedA(ObservableValue<? extends A> observable, A oldValue, A newValue) {
155153
updateLocked(updateB, oldValue, newValue);
156154
}
157-
155+
158156
public void changedB(ObservableValue<? extends B> observable, B oldValue, B newValue) {
159157
updateLocked(updateA, oldValue, newValue);
160158
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package org.jabref.gui.util;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.function.Function;
6+
7+
import javafx.collections.ListChangeListener;
8+
import javafx.collections.ObservableList;
9+
import javafx.collections.transformation.TransformationList;
10+
11+
/**
12+
* MappedList implementation based on https://gist.github.com/TomasMikula/8883719
13+
*
14+
* @author https://github.com/TomasMikula
15+
*/
16+
public final class MappedList<A, B> extends TransformationList<A, B> {
17+
18+
private final Function<B, A> mapper;
19+
20+
public MappedList(ObservableList<? extends B> sourceList, Function<B, A> mapper) {
21+
super(sourceList);
22+
this.mapper = mapper;
23+
}
24+
25+
@Override
26+
protected void sourceChanged(ListChangeListener.Change<? extends B> change) {
27+
fireChange(new ListChangeListener.Change<A>(this) {
28+
29+
@Override
30+
public boolean wasAdded() {
31+
return change.wasAdded();
32+
}
33+
34+
@Override
35+
public boolean wasRemoved() {
36+
return change.wasRemoved();
37+
}
38+
39+
@Override
40+
public boolean wasReplaced() {
41+
return change.wasReplaced();
42+
}
43+
44+
@Override
45+
public boolean wasUpdated() {
46+
return change.wasUpdated();
47+
}
48+
49+
@Override
50+
public boolean wasPermutated() {
51+
return change.wasPermutated();
52+
}
53+
54+
@Override
55+
public int getPermutation(int index) {
56+
return change.getPermutation(index);
57+
}
58+
59+
@Override
60+
protected int[] getPermutation() {
61+
// This method is only called by the superclass methods
62+
// wasPermutated() and getPermutation(int), which are
63+
// both overridden by this class. There is no other way
64+
// this method can be called.
65+
throw new AssertionError("Unreachable code");
66+
}
67+
68+
@Override
69+
public List<A> getRemoved() {
70+
List<A> result = new ArrayList<>(change.getRemovedSize());
71+
for (B element : change.getRemoved()) {
72+
result.add(mapper.apply(element));
73+
}
74+
return result;
75+
}
76+
77+
@Override
78+
public int getFrom() {
79+
return change.getFrom();
80+
}
81+
82+
@Override
83+
public int getTo() {
84+
return change.getTo();
85+
}
86+
87+
@Override
88+
public boolean next() {
89+
return change.next();
90+
}
91+
92+
@Override
93+
public void reset() {
94+
change.reset();
95+
}
96+
});
97+
}
98+
99+
@Override
100+
public int getSourceIndex(int index) {
101+
return index;
102+
}
103+
104+
@Override
105+
public A get(int index) {
106+
return mapper.apply(super.getSource().get(index));
107+
}
108+
109+
@Override
110+
public int size() {
111+
return super.getSource().size();
112+
}
113+
}

0 commit comments

Comments
 (0)