Skip to content

Commit

Permalink
🔖 Version 21.2.0
Browse files Browse the repository at this point in the history
🚚 Renamed classes to be shorter while still avoiding potential "import conflicts"

Signed-off-by: palexdev <alessandro.parisi406@gmail.com>
  • Loading branch information
palexdev committed Dec 29, 2023
1 parent 0149334 commit 1626d8f
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 297 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## General

- [ ] Review names
- [x] Review names
- [ ] Review APIs (classes, simplify as much as possible/re-organize at least)
- [ ] Maybe define a common Interface for Virtualized containers

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#--------------------------------------#
GROUP=io.github.palexdev
POM_ARTIFACT_ID=virtualizedfx
VERSION_NAME=21.1.1
VERSION_NAME=21.2.0
POM_NAME=virtualizedfx
POM_DESCRIPTION=Alternative VirtualFlows for JavaFX
POM_INCEPTION_YEAR=2021
Expand All @@ -19,7 +19,7 @@ POM_PACKAGING=jar
#--------------------------------------#
# Versions #
#--------------------------------------#
vfx=21.1.1
vfx=21.2.0
jdk=21
# Plugins
jfxPlugin=0.1.0
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@
import java.util.function.Function;

/**
* Simple cache implementation for the {@link VirtualizedList} container. Cells are stored in a {@link CellsQueue},
* Simple cache implementation for the {@link VFXList} container. Cells are stored in a {@link CellsQueue},
* a special extension of {@link LinkedList}. The cache can be limited in the maximum number of cells to keep by setting its
* capacity, see {@link VirtualizedList#cacheCapacityProperty()}. Cells won't be added if the capacity is reached and will
* capacity, see {@link VFXList#cacheCapacityProperty()}. Cells won't be added if the capacity is reached and will
* be disposed immediately instead.
* <p>
* Aside from the typical functions of a cache (take/store), you are also allowed to 'populate' it at will, see {@link #populate()}.
* Since we know how to generate the cache items (cells), because they are created by the {@link VirtualizedList#cellFactoryProperty()},
* Since we know how to generate the cache items (cells), because they are created by the {@link VFXList#cellFactoryProperty()},
* you are allowed to fill the cache whenever you want. This is most useful to 'pre-populate' it, fill the cache before
* the container is even laid out so that at init cells are already built and just need to be updated.
* <b>Beware</b>, in order for this to work, the cells you are using must allow {@code null} items!
*/
public class VirtualizedListCache<T, C extends Cell<T>> {
public class VFXListCache<T, C extends Cell<T>> {
//================================================================================
// Properties
//================================================================================
private final VirtualizedList<T, C> list;
private final VFXList<T, C> list;
private final CellsQueue<T, C> queue = new CellsQueue<>(0);

//================================================================================
// Constructors
//================================================================================
public VirtualizedListCache(VirtualizedList<T, C> list) {this.list = list;}
public VFXListCache(VFXList<T, C> list) {this.list = list;}

public VirtualizedListCache(VirtualizedList<T, C> list, int capacity) {
public VFXListCache(VFXList<T, C> list, int capacity) {
this.list = list;
queue.setCapacity(capacity);
}
Expand All @@ -45,9 +45,9 @@ public VirtualizedListCache(VirtualizedList<T, C> list, int capacity) {
* Fills the cache to its limit. Can be useful to 'pre-populate' the cache before init time, making cells already
* available and just in need of an update ({@link Cell#updateIndex(int)}, {@link Cell#updateItem(Object)}).
*
* @throws NullPointerException if {@link VirtualizedList#getCellFactory()} returns {@code null}
* @throws NullPointerException if {@link VFXList#getCellFactory()} returns {@code null}
*/
public VirtualizedListCache<T, C> populate() {
public VFXListCache<T, C> populate() {
Function<T, C> f = list.getCellFactory();
if (queue.size() == queue.getCapacity()) return this; // Already at capacity
if (f == null) throw new NullPointerException("Cannot populate cache as the cell factory is null");
Expand All @@ -63,7 +63,7 @@ public VirtualizedListCache<T, C> populate() {
* Adds the given cells to the queue. For successfully cached cells, {@link Cell#onCache()} will automatically be invoked.
*/
@SafeVarargs
public final VirtualizedListCache<T, C> cache(C... cells) {
public final VFXListCache<T, C> cache(C... cells) {
for (C c : cells) {
if (queue.add(c)) c.onCache();
}
Expand All @@ -73,7 +73,7 @@ public final VirtualizedListCache<T, C> cache(C... cells) {
/**
* Adds the given cells to the queue. For successfully cached cells, {@link Cell#onCache()} will automatically be invoked.
*/
public VirtualizedListCache<T, C> cache(Collection<C> cells) {
public VFXListCache<T, C> cache(Collection<C> cells) {
for (C c : cells) {
if (queue.add(c)) c.onCache();
}
Expand All @@ -100,7 +100,7 @@ public Optional<C> tryTake() {
/**
* Removed the specified cell from the cache's queue. The removed cell is also disposed.
*/
public VirtualizedListCache<T, C> remove(C cell) {
public VFXListCache<T, C> remove(C cell) {
boolean removed = queue.remove(cell);
if (removed) cell.dispose();
return this;
Expand All @@ -109,7 +109,7 @@ public VirtualizedListCache<T, C> remove(C cell) {
/**
* Disposes and removes all the cells from the cache.
*/
public VirtualizedListCache<T, C> clear() {
public VFXListCache<T, C> clear() {
queue.forEach(Cell::dispose);
queue.clear();
return this;
Expand All @@ -121,9 +121,9 @@ public int size() {

/**
* Sets the cache's capacity. Visibility is restricted because capacity is meant to be set through the
* {@link VirtualizedList#cacheCapacityProperty()}.
* {@link VFXList#cacheCapacityProperty()}.
*/
protected VirtualizedListCache<T, C> setCapacity(int capacity) {
protected VFXListCache<T, C> setCapacity(int capacity) {
queue.setCapacity(capacity);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import java.util.Optional;

/**
* This interface is a utility API for {@link VirtualizedList} which helps to avoid if checks that depend on the container's
* orientation, {@link VirtualizedList#orientationProperty()}. There are two concrete implementations: {@link VerticalHelper}
* This interface is a utility API for {@link VFXList} which helps to avoid if checks that depend on the container's
* orientation, {@link VFXList#orientationProperty()}. There are two concrete implementations: {@link VerticalHelper}
* and {@link HorizontalHelper}
*/
public interface VirtualizedListHelper<T, C extends Cell<T>> {
public interface VFXListHelper<T, C extends Cell<T>> {

/**
* @return the index of the first visible item
Expand Down Expand Up @@ -110,18 +110,18 @@ public interface VirtualizedListHelper<T, C extends Cell<T>> {
void scrollToIndex(int index);

/**
* @return the {@link VirtualizedList} instance associated to this helper
* @return the {@link VFXList} instance associated to this helper
*/
VirtualizedList<T, C> getList();
VFXList<T, C> getList();

/**
* Forces the {@link VirtualizedList#vPosProperty()} and {@link VirtualizedList#hPosProperty()} to be invalidated.
* Forces the {@link VFXList#vPosProperty()} and {@link VFXList#hPosProperty()} to be invalidated.
* This is simply done by calling the respective setters with their current respective values. Those two properties
* will automatically call {@link #maxVScroll()} and {@link #maxHScroll()} to ensure the values are correct. This is
* automatically invoked by the {@link VirtualizedListManager} when needed.
* automatically invoked by the {@link VFXListManager} when needed.
*/
default void invalidatePos() {
VirtualizedList<T, C> list = getList();
VFXList<T, C> list = getList();
list.setVPos(list.getVPos());
list.setHPos(list.getHPos());
}
Expand All @@ -135,11 +135,11 @@ default C indexToCell(int index) {
}

/**
* Converts the given item to a cell. The result is either on of the cells cached in {@link VirtualizedListCache} that
* is updated with the given item, or a totally new one created by the {@link VirtualizedList#cellFactoryProperty()}.
* Converts the given item to a cell. The result is either on of the cells cached in {@link VFXListCache} that
* is updated with the given item, or a totally new one created by the {@link VFXList#cellFactoryProperty()}.
*/
default C itemToCell(T item) {
VirtualizedListCache<T, C> cache = getList().getCache();
VFXListCache<T, C> cache = getList().getCache();
Optional<C> opt = cache.tryTake();
opt.ifPresent(c -> c.updateItem(item));
return opt.orElseGet(() -> getList().getCellFactory().apply(item));
Expand All @@ -153,8 +153,8 @@ default T indexToItem(int index) {
}

/**
* Implementing the {@link VirtualizedList#spacingProperty()} has been incredibly easy. It is enough to think at the
* spacing as an extension of the {@link VirtualizedList#cellSizeProperty()}. In other words, for the helper to still
* Implementing the {@link VFXList#spacingProperty()} has been incredibly easy. It is enough to think at the
* spacing as an extension of the {@link VFXList#cellSizeProperty()}. In other words, for the helper to still
* produce valid ranges, it is enough to sum the spacing to the cell size when the latter is needed.
* This is a shortcut for {@code getList().getCellSize() + getList().getSpacing()}.
*/
Expand All @@ -163,13 +163,13 @@ default double getTotalCellSize() {
}

/**
* Automatically called by {@link VirtualizedList} when a helper is not needed anymore (changed).
* Automatically called by {@link VFXList} when a helper is not needed anymore (changed).
* If the helper uses listeners/bindings that may lead to memory leaks, this is the right place to remove them.
*/
default void dispose() {}

/**
* Abstract implementation of {@link VirtualizedListHelper}, contains common members for the two concrete implementations
* Abstract implementation of {@link VFXListHelper}, contains common members for the two concrete implementations
* {@link VerticalHelper} and {@link HorizontalHelper}, such as:
* <p> - the range of items to display as a {@link IntegerRangeProperty}
* <p> - the estimated length, which doesn't depend on the orientation but only on the number of items in the list
Expand All @@ -178,14 +178,14 @@ default void dispose() {}
* <p> - the maximum breadth, {@link #maxBreadthProperty()}
* <p> - the viewport's position, {@link #viewportPositionProperty()} as a {@link PositionProperty}
*/
abstract class AbstractHelper<T, C extends Cell<T>> implements VirtualizedListHelper<T, C> {
protected final VirtualizedList<T, C> list;
abstract class AbstractHelper<T, C extends Cell<T>> implements VFXListHelper<T, C> {
protected final VFXList<T, C> list;
protected final IntegerRangeProperty range = new IntegerRangeProperty();
protected final ReadOnlyDoubleWrapper estimatedLength = new ReadOnlyDoubleWrapper();
protected final ReadOnlyDoubleWrapper maxBreadth = new ReadOnlyDoubleWrapper();
protected final PositionProperty viewportPosition = new PositionProperty();

public AbstractHelper(VirtualizedList<T, C> list) {
public AbstractHelper(VFXList<T, C> list) {
this.list = list;
estimatedLength.bind(DoubleBindingBuilder.build()
.setMapper(() -> (list.size() * getTotalCellSize() - list.getSpacing()))
Expand Down Expand Up @@ -221,15 +221,15 @@ public ReadOnlyObjectProperty<Position> viewportPositionProperty() {
}

@Override
public VirtualizedList<T, C> getList() {
public VFXList<T, C> getList() {
return list;
}
}

/**
* Concrete implementation of {@link AbstractHelper} for {@link Orientation#VERTICAL}. Here the range of items to
* display and the viewport position are defined as follows:
* <p> - the range is given by the {@link #firstVisible()} element minus the buffer size ({@link VirtualizedList#bufferSizeProperty()}),
* <p> - the range is given by the {@link #firstVisible()} element minus the buffer size ({@link VFXList#bufferSizeProperty()}),
* cannot be negative; and the sum between this start index and the total number of needed cells given by {@link #totalNum()}, cannot
* exceed the number of items - 1. It may happen the number of indexes given by the range {@code end - start + 1} is lesser
* than the total number of cells we need, in such cases, the range start is corrected to be {@code end - needed + 1}.
Expand All @@ -238,7 +238,7 @@ public VirtualizedList<T, C> getList() {
* the vertical position.
* <p> - the viewport position. This computation is at the core of virtual scrolling. The viewport, which contains the cell,
* is not supposed to scroll by insane numbers of pixels both for performance reasons and because it is not necessary.
* The horizontal position is just the current {@link VirtualizedList#hPosProperty()} but negative. The vertical
* The horizontal position is just the current {@link VFXList#hPosProperty()} but negative. The vertical
* position is the one virtualized.
* First we get the range of items to display and the total cell size given by {@link #getTotalCellSize()}, yes, the
* spacing also affects the position. Then we compute the range to the first visible cell, which is given by
Expand All @@ -256,7 +256,7 @@ public VirtualizedList<T, C> getList() {
*/
class VerticalHelper<T, C extends Cell<T>> extends AbstractHelper<T, C> {

public VerticalHelper(VirtualizedList<T, C> list) {
public VerticalHelper(VFXList<T, C> list) {
super(list);
range.bind(ObjectBindingBuilder.<IntegerRange>build()
.setMapper(() -> {
Expand Down Expand Up @@ -355,7 +355,7 @@ public double maxHScroll() {
/**
* {@inheritDoc}
* <p></p>
* If {@link VirtualizedList#fitToBreadthProperty()} is true, then the computation will always return the
* If {@link VFXList#fitToBreadthProperty()} is true, then the computation will always return the
* list's width, otherwise the node width is computed by {@link LayoutUtils#boundWidth(Node)}.
* Also, in the latter case, if the found width is greater than the current max breadth, then the property
* {@link #maxBreadthProperty()} is updated with the new value.
Expand All @@ -377,7 +377,7 @@ public double computeBreadth(Node node) {
* {@inheritDoc}
* <p></p>
* The x position is 0. The y position is the total cell size multiplied bu the given index. The width is
* computed by {@link #computeBreadth(Node)}, and the height is given by the {@link VirtualizedList#cellSizeProperty()}.
* computed by {@link #computeBreadth(Node)}, and the height is given by the {@link VFXList#cellSizeProperty()}.
*/
@Override
public void layout(int index, Node node) {
Expand Down Expand Up @@ -406,7 +406,7 @@ public void scrollToIndex(int index) {
/**
* Concrete implementation of {@link AbstractHelper} for {@link Orientation#HORIZONTAL}. Here the range of items to
* display and the viewport position are defined as follows:
* <p> - the range is given by the {@link #firstVisible()} element minus the buffer size ({@link VirtualizedList#bufferSizeProperty()}),
* <p> - the range is given by the {@link #firstVisible()} element minus the buffer size ({@link VFXList#bufferSizeProperty()}),
* cannot be negative; and the sum between this start index and the total number of needed cells given by {@link #totalNum()}, cannot
* exceed the number of items - 1. It may happen the number of indexes given by the range {@code end - start + 1} is lesser
* than the total number of cells we need, in such cases, the range start is corrected to be {@code end - needed + 1}.
Expand All @@ -415,7 +415,7 @@ public void scrollToIndex(int index) {
* the horizontal position.
* <p> - the viewport position. This computation is at the core of virtual scrolling. The viewport, which contains the cell,
* is not supposed to scroll by insane numbers of pixels both for performance reasons and because it is not necessary.
* The vertical position is just the current {@link VirtualizedList#vPosProperty()} but negative. The horizontal
* The vertical position is just the current {@link VFXList#vPosProperty()} but negative. The horizontal
* position is the one virtualized.
* First we get the range of items to display and the total cell size given by {@link #getTotalCellSize()}, yes, the
* spacing also affects the position. Then we compute the range to the first visible cell, which is given by
Expand All @@ -433,7 +433,7 @@ public void scrollToIndex(int index) {
*/
class HorizontalHelper<T, C extends Cell<T>> extends AbstractHelper<T, C> {

public HorizontalHelper(VirtualizedList<T, C> list) {
public HorizontalHelper(VFXList<T, C> list) {
super(list);
range.bind(ObjectBindingBuilder.<IntegerRange>build()
.setMapper(() -> {
Expand Down Expand Up @@ -532,7 +532,7 @@ public double maxHScroll() {
/**
* {@inheritDoc}
* <p></p>
* If {@link VirtualizedList#fitToBreadthProperty()} is true, then the computation will always return the
* If {@link VFXList#fitToBreadthProperty()} is true, then the computation will always return the
* list's height, otherwise the node width is computed by {@link LayoutUtils#boundHeight(Node)}.
* Also, in the latter case, if the found height is greater than the current max breadth, then the property
* {@link #maxBreadthProperty()} is updated with the new value.
Expand All @@ -554,7 +554,7 @@ public double computeBreadth(Node node) {
* {@inheritDoc}
* <p></p>
* The y position is 0. The x position is the total cell size multiplied bu the given index. The height is
* computed by {@link #computeBreadth(Node)}, and the width is given by the {@link VirtualizedList#cellSizeProperty()}.
* computed by {@link #computeBreadth(Node)}, and the width is given by the {@link VFXList#cellSizeProperty()}.
*/
@Override
public void layout(int index, Node node) {
Expand Down

0 comments on commit 1626d8f

Please sign in to comment.