Small file browser fixes [release] [noannounce]

This commit is contained in:
crschnick 2023-05-01 14:42:02 +00:00
parent db6ba6439e
commit bc74938a60
2 changed files with 55 additions and 18 deletions

View file

@ -61,7 +61,7 @@ final class FileListModel {
public void setAll(Stream<FileSystem.FileEntry> newFiles) { public void setAll(Stream<FileSystem.FileEntry> newFiles) {
try (var s = newFiles) { try (var s = newFiles) {
var l = s.limit(5000).toList(); var l = s.filter(entry -> entry != null).limit(5000).toList();
all.setValue(l); all.setValue(l);
refreshShown(); refreshShown();
} }

View file

@ -45,46 +45,83 @@ public class SvgCacheComp extends SimpleComp {
front.setImage(newValue); front.setImage(newValue);
}); });
var active = new SimpleObjectProperty<AnimationTimer>();
var webViewContent = new SimpleStringProperty(); var webViewContent = new SimpleStringProperty();
var back = SvgView.create(webViewContent).createWebview(); var back = SvgView.create(webViewContent).createWebview();
back.prefWidthProperty().bind(width); back.prefWidthProperty().bind(width);
back.prefHeightProperty().bind(height); back.prefHeightProperty().bind(height);
svgFile.addListener((observable, oldValue, newValue) -> { svgFile.addListener((observable, oldValue, newValue) -> {
var cached = cache.getCached(newValue); if (newValue == null) {
webViewContent.setValue(newValue != null || cached.isEmpty() ? AppImages.svgImage(newValue) : null); back.setVisible(false);
frontContent.setValue(cached.orElse(null)); front.setVisible(false);
back.setVisible(cached.isEmpty());
front.setVisible(cached.isPresent());
if (cached.isPresent()) {
return; return;
} }
Platform.runLater(() -> new AnimationTimer() { var cached = cache.getCached(newValue);
if (cached.isPresent()) {
frontContent.setValue(cached.get());
back.setVisible(false);
front.setVisible(true);
return;
}
webViewContent.setValue(AppImages.svgImage(newValue));
back.setVisible(true);
front.setVisible(false);
AnimationTimer timer = new AnimationTimer() {
int frames = 0; int frames = 0;
final AnimationTimer instance = this;
@Override @Override
public void handle(long l) { public void handle(long l) {
if (++frames == 2) { if (++frames == 30) {
stop();
SnapshotParameters parameters = new SnapshotParameters(); SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT); parameters.setFill(Color.TRANSPARENT);
back.snapshot(snapshotResult -> { if (!instance.equals(active.get())) {
WritableImage image = snapshotResult.getImage(); active.set(null);
return;
}
active.set(null);
WritableImage image = back.snapshot(parameters, null);
if (image.getWidth() < 10) { if (image.getWidth() < 10) {
return null; return;
} }
if (cache.getCached(newValue).isPresent()) { if (cache.getCached(newValue).isPresent()) {
return null; return;
} }
if (!newValue.equals(svgFile.getValue())) {
return;
}
var found = false;
out:
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
if (image.getPixelReader().getArgb(x, y) != 0x00000000) {
found = true;
break out;
}
}
}
if (!found) {
return;
}
System.out.println("cache " + newValue);
cache.put(newValue, image); cache.put(newValue, image);
return null; return;
}, parameters, null);
stop();
} }
} }
}.start()); };
Platform.runLater(() -> {
// timer.start();
// active.set(timer);
});
}); });
var stack = new StackPane(back, front); var stack = new StackPane(back, front);