-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathCell.java
More file actions
125 lines (105 loc) · 3.54 KB
/
Cell.java
File metadata and controls
125 lines (105 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package org.fxmisc.flowless;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import javafx.scene.Node;
/**
* Provides efficient memory usage by wrapping a {@link Node} within this object and reusing it when
* {@link #isReusable()} is true.
*/
@FunctionalInterface
public interface Cell<T, N extends Node> {
static <T, N extends Node> Cell<T, N> wrapNode(N node) {
return new Cell<T, N>() {
@Override
public N getNode() { return node; }
@Override
public String toString() { return node.toString(); }
};
}
N getNode();
/**
* Indicates whether this cell can be reused to display different items.
*
* <p>Default implementation returns {@code false}.
*/
default boolean isReusable() {
return false;
}
/**
* If this cell is reusable (as indicated by {@link #isReusable()}),
* this method is called to display a different item. {@link #reset()}
* will have been called before a call to this method.
*
* <p>The default implementation calls {@link #updateItem(Object)}
*
* @param index the item's position in the VirtualFlow list
* @param item the new item to display
*/
default void update(Integer index, T item) {
updateItem(item);
}
/**
* If this cell is reusable (as indicated by {@link #isReusable()}),
* this method is called to display a different item. {@link #reset()}
* will have been called before a call to this method.
*
* <p>The default implementation throws
* {@link UnsupportedOperationException}.
*
* @param item the new item to display
*/
default void updateItem(T item) {
throw new UnsupportedOperationException();
}
/**
* Called to update index of a visible cell.
*
* <p>Default implementation does nothing.
*/
default void updateIndex(int index) {
// do nothing by default
}
/**
* Called when this cell is no longer used to display its item.
* If this cell is reusable, it may later be asked to display a different
* item by a call to {@link #updateItem(Object)}.
*
* <p>Default implementation does nothing.
*/
default void reset() {
// do nothing by default
}
/**
* Called when this cell is no longer going to be used at all.
* {@link #reset()} will have been called before this method is invoked.
*
* <p>Default implementation does nothing.
*/
default void dispose() {
// do nothing by default
}
default Cell<T, N> beforeDispose(Runnable action) {
return CellWrapper.beforeDispose(this, action);
}
default Cell<T, N> afterDispose(Runnable action) {
return CellWrapper.afterDispose(this, action);
}
default Cell<T, N> beforeReset(Runnable action) {
return CellWrapper.beforeReset(this, action);
}
default Cell<T, N> afterReset(Runnable action) {
return CellWrapper.afterReset(this, action);
}
default Cell<T, N> beforeUpdateItem(Consumer<? super T> action) {
return CellWrapper.beforeUpdateItem(this, action);
}
default Cell<T, N> afterUpdateItem(Consumer<? super T> action) {
return CellWrapper.afterUpdateItem(this, action);
}
default Cell<T, N> beforeUpdateIndex(IntConsumer action) {
return CellWrapper.beforeUpdateIndex(this, action);
}
default Cell<T, N> afterUpdateIndex(IntConsumer action) {
return CellWrapper.afterUpdateIndex(this, action);
}
}