Base project structure
This commit is contained in:
parent
dccbc52c0a
commit
15f7b2f2e9
4
src/main/java/fr/uha/gabalier/controller/Controller.java
Normal file
4
src/main/java/fr/uha/gabalier/controller/Controller.java
Normal file
@ -0,0 +1,4 @@
|
||||
package fr.uha.gabalier.controller;
|
||||
|
||||
public interface Controller {
|
||||
}
|
70
src/main/java/fr/uha/gabalier/core/ImageLoader.java
Normal file
70
src/main/java/fr/uha/gabalier/core/ImageLoader.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
13
src/main/java/fr/uha/gabalier/util/ImageLib.java
Normal file
13
src/main/java/fr/uha/gabalier/util/ImageLib.java
Normal 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() {}
|
||||
}
|
25
src/main/java/fr/uha/gabalier/view/Preview.java
Normal file
25
src/main/java/fr/uha/gabalier/view/Preview.java
Normal 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() {
|
||||
|
||||
}
|
||||
}
|
4
src/main/java/fr/uha/gabalier/view/View.java
Normal file
4
src/main/java/fr/uha/gabalier/view/View.java
Normal file
@ -0,0 +1,4 @@
|
||||
package fr.uha.gabalier.view;
|
||||
|
||||
public interface View {
|
||||
}
|
Loading…
Reference in New Issue
Block a user