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) {
try (var s = newFiles) {
var l = s.limit(5000).toList();
var l = s.filter(entry -> entry != null).limit(5000).toList();
all.setValue(l);
refreshShown();
}

View file

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