Base project structure

This commit is contained in:
Thibaud Gasser 2018-09-27 13:40:45 +02:00
parent dccbc52c0a
commit 15f7b2f2e9
5 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,4 @@
package fr.uha.gabalier.controller;
public interface Controller {
}

View File

@ -0,0 +1,70 @@
package fr.uha.gabalier.core;
import fr.uha.gabalier.util.ImageLib;
import fr.uha.gabalier.view.Preview;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
public class ImageLoader extends SwingWorker<List<Image>, Integer> {
private final File root;
private Preview app;
private List<Image> images;
private final int iconWidth;
public ImageLoader(File root, Preview app, int iconWidth) {
this.root = root;
this.app = app;
this.iconWidth = iconWidth;
this.images = new ArrayList<>();
}
private void loadImages(File current) throws NullPointerException {
if (current.isFile()) {
final Image icon = ImageLib.createScaledImage(current, this.iconWidth, -1);
if (icon != null) {
images.add(icon);
publish(images.size());
}
return;
}
final File[] files = current.listFiles();
if (files == null) throw new NullPointerException();
for (File f : files) {
loadImages(f);
}
}
@Override
protected List<Image> doInBackground() throws Exception {
loadImages(root);
return images;
}
@Override
protected void process(List<Integer> data) {
if (this.isCancelled()) return;
app.setStatus(String.valueOf(data.get(data.size() - 1)));
}
@Override
protected void done() {
try {
app.setModel(this.get());
app.setStatus(app.getModel().size() + "images loaded");
} catch (CancellationException e) {
app.setStatus("Cancelled");
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} finally {
app.postLoad();
}
}
}

View File

@ -0,0 +1,13 @@
package fr.uha.gabalier.util;
import java.awt.*;
import java.io.File;
public final class ImageLib {
public static Image createScaledImage(File file, int iconWidth, int i) {
return null;
}
private ImageLib() {}
}

View File

@ -0,0 +1,25 @@
package fr.uha.gabalier.view;
import java.awt.*;
import java.util.List;
public class Preview {
private List<Image> model;
private String status;
public void setModel(List<Image> images) {
this.model = images;
}
public List<Image> getModel() {
return model;
}
public void setStatus(String status) {
this.status = status;
}
public void postLoad() {
}
}

View File

@ -0,0 +1,4 @@
package fr.uha.gabalier.view;
public interface View {
}