albums, synchronous stuff, ya
parent
6bd68a3be7
commit
a143091948
146
src/Item.java
146
src/Item.java
|
|
@ -9,6 +9,7 @@ import java.awt.geom.Rectangle2D;
|
|||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -39,12 +40,14 @@ public class Item {
|
|||
private final BufferedImage thumbnail;
|
||||
|
||||
// the original image, not cropped or anything.
|
||||
private final BufferedImage[] image;
|
||||
private BufferedImage[] image;
|
||||
|
||||
// Absolute path, i think.
|
||||
private final String path;
|
||||
private String name;
|
||||
|
||||
private boolean enterable = true;
|
||||
|
||||
// we need this because im scared.
|
||||
// if literally anything in the creating of an item
|
||||
// goes MODERATELY wrong, you set this to FALSE.
|
||||
|
|
@ -61,16 +64,19 @@ public class Item {
|
|||
BufferedImage[] images = null;
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
final File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
// thumbnail =
|
||||
// ImageCreator.creatImageWithStripes(Viewer.THUMBNAIL_SIZE,
|
||||
// Viewer.THUMBNAIL_SIZE, Color.BLUE);
|
||||
try {
|
||||
//just... like its not hard but its not properly spaced out to be readable
|
||||
//so just trust drunk on life marcus that it tooootally works.
|
||||
//doesn't mess with image yet though so feel free to implement that.
|
||||
//yeah, TODO...
|
||||
//so many locals, had to split it up
|
||||
//TODO methodize this or something
|
||||
{
|
||||
// just... like its not hard but its not properly spaced
|
||||
// out to be readable
|
||||
// so just trust drunk on life marcus that it tooootally
|
||||
// works.
|
||||
// doesn't mess with image yet though so feel free to
|
||||
// implement that.
|
||||
// yeah, TODO...
|
||||
Font font = new Font("Serif", Font.PLAIN, 50);
|
||||
thumbnail = new BufferedImage(Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) thumbnail.getGraphics();
|
||||
|
|
@ -78,7 +84,7 @@ public class Item {
|
|||
g.setFont(font);
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
String string = "" + file.getName();
|
||||
if(string.length() > 8) {
|
||||
if (string.length() > 8) {
|
||||
string = string.substring(0, 9) + "...";
|
||||
}
|
||||
int padding = 5;
|
||||
|
|
@ -89,7 +95,7 @@ public class Item {
|
|||
textGraphics.setFont(font);
|
||||
textGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
textGraphics.setColor(Color.BLACK);
|
||||
textGraphics.drawString(string, 1, (int)bounds.getHeight());
|
||||
textGraphics.drawString(string, 1, (int) bounds.getHeight());
|
||||
text = fitImageScale(text, frameSize, frameSize);
|
||||
g.setColor(new Color(220, 220, 220));
|
||||
g.fillRect(0, 0, Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE);
|
||||
|
|
@ -97,9 +103,16 @@ public class Item {
|
|||
g.drawRect(0, 0, Viewer.THUMBNAIL_SIZE - 1, Viewer.THUMBNAIL_SIZE - 1);
|
||||
g.drawImage(text, padding, padding, null);
|
||||
|
||||
//now try to make a mini album thing showing us what we're missing!
|
||||
//queue collage mode
|
||||
// now try to make a mini album thing showing us what
|
||||
// we're missing!
|
||||
// queue collage mode
|
||||
}
|
||||
|
||||
// the image block for creating a mini album
|
||||
|
||||
new Thread(new Runnable() {public void run() {
|
||||
createAlbum(file);
|
||||
}}).start();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
@ -107,7 +120,8 @@ public class Item {
|
|||
}
|
||||
name = file.getName();
|
||||
|
||||
} else {
|
||||
} else if (file.isFile()) {
|
||||
enterable = false;
|
||||
if (!path.endsWith(".gif")) {
|
||||
// try and do the image thing!
|
||||
images = new BufferedImage[] { ImageIO.read(file) };
|
||||
|
|
@ -118,15 +132,46 @@ public class Item {
|
|||
for (int i = 0; i < imageList.size(); i++)
|
||||
images[i] = imageList.get(i);
|
||||
}
|
||||
thumbnail = (fillImageScale(images[0], 80, 80));
|
||||
thumbnail = (fillImageScale(images[0], Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE));
|
||||
path = file.getAbsolutePath();
|
||||
|
||||
name = "";
|
||||
name = file.getName();
|
||||
} else if (path.equals("\\drives")) {
|
||||
|
||||
name = "Drives";
|
||||
|
||||
// just... like its not hard but its not properly spaced out to
|
||||
// be readable
|
||||
// so just trust drunk on life marcus that it tooootally works.
|
||||
// doesn't mess with image yet though so feel free to implement
|
||||
// that.
|
||||
// yeah, TODO...
|
||||
Font font = new Font("Serif", Font.PLAIN, 50);
|
||||
thumbnail = new BufferedImage(Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) thumbnail.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g.setFont(font);
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
String string = "Drives";
|
||||
int padding = 5;
|
||||
int frameSize = Viewer.THUMBNAIL_SIZE - 2 * padding;
|
||||
Rectangle2D bounds = metrics.getStringBounds(string, g);
|
||||
BufferedImage text = new BufferedImage((int) bounds.getWidth() + 2, (int) bounds.getHeight() + 2 + metrics.getMaxDescent(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D textGraphics = (Graphics2D) text.getGraphics();
|
||||
textGraphics.setFont(font);
|
||||
textGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
textGraphics.setColor(Color.BLACK);
|
||||
textGraphics.drawString(string, 1, (int) bounds.getHeight());
|
||||
text = fitImageScale(text, frameSize, frameSize);
|
||||
g.setColor(new Color(220, 220, 220));
|
||||
g.fillRect(0, 0, Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE);
|
||||
g.setColor(new Color(170, 170, 170));
|
||||
g.drawRect(0, 0, Viewer.THUMBNAIL_SIZE - 1, Viewer.THUMBNAIL_SIZE - 1);
|
||||
g.drawImage(text, padding, padding, null);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
seemsLegit = false;
|
||||
System.out.println("wat: " + e.getMessage());
|
||||
System.out.println("wat was in " + path);
|
||||
}
|
||||
|
||||
this.image = images;
|
||||
|
|
@ -134,6 +179,52 @@ public class Item {
|
|||
this.thumbnail = thumbnail;
|
||||
}
|
||||
|
||||
private void createAlbum(final File file) {
|
||||
|
||||
File[] files = file.listFiles(new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return name.endsWith(".png") || name.endsWith(".jpg");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
BufferedImage image = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);
|
||||
this.image = new BufferedImage[] {image};
|
||||
Graphics2D graphics = (Graphics2D)image.getGraphics();
|
||||
|
||||
//could be derived but imma lazy personnn
|
||||
int currentFileCount = 0; //TODO do dat later
|
||||
|
||||
final int ROWS = 2;
|
||||
final int COLUMNS = 3;
|
||||
|
||||
|
||||
for(int i = 0; i < ROWS; i ++) {
|
||||
|
||||
for(int j = 0; j < COLUMNS; j ++) {
|
||||
|
||||
boolean failed = false;
|
||||
|
||||
try{
|
||||
File currentFile = files[currentFileCount];
|
||||
BufferedImage current = ImageIO.read(currentFile);
|
||||
current = fillImageScale(current, (1000 - (15*(2 + 1))) / 2, (1000 - (15*(2 + 1))) / 2);
|
||||
graphics.drawImage(current, (j * (15 + ((1000 - (15*(2 + 1))) / 2))), (i * (15 + ((1000 - (15*(2 + 1))) / 2))), null);
|
||||
}catch(Exception e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
if(failed) j --;
|
||||
if(currentFileCount == files.length) i = j = 2;
|
||||
currentFileCount ++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean getSeemsLegit() {
|
||||
return seemsLegit;
|
||||
}
|
||||
|
|
@ -171,10 +262,6 @@ public class Item {
|
|||
int newImageWidth = newImage.getWidth(null);
|
||||
int newImageHeight = newImage.getHeight(null);
|
||||
|
||||
Engine.log("original: " + imageWidth + " x " + imageHeight);
|
||||
Engine.log("new: " + width + " x " + height);
|
||||
Engine.log("after: " + newImageWidth + " x " + newImageHeight);
|
||||
|
||||
// do math, shove it on.
|
||||
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||
|
||||
|
|
@ -182,7 +269,6 @@ public class Item {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
private static BufferedImage fitImageScale(BufferedImage image, int width, int height) throws IOException {
|
||||
|
||||
int imageWidth = image.getWidth();
|
||||
|
|
@ -192,7 +278,7 @@ public class Item {
|
|||
double scaleX = (double) width / imageWidth;
|
||||
|
||||
// fill or fit bit
|
||||
//heh, hutch
|
||||
// heh, hutch
|
||||
if (scaleX > scaleY)
|
||||
scaleX = scaleY;
|
||||
else
|
||||
|
|
@ -207,8 +293,6 @@ public class Item {
|
|||
// out new image that we need to crop onto the buffer with the right
|
||||
// dimensions.
|
||||
BufferedImage newImage = bilinearScaleOp.filter(image, new BufferedImage((int) (imageWidth * scaleX), (int) (imageHeight * scaleY), image.getType()));
|
||||
// Image newImage = image.getScaledInstance((int) (imageWidth * scaleX),
|
||||
// (int) (imageWidth * scaleY), Image.SCALE_SMOOTH);
|
||||
|
||||
// make the buffer
|
||||
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
|
|
@ -217,10 +301,6 @@ public class Item {
|
|||
int newImageWidth = newImage.getWidth(null);
|
||||
int newImageHeight = newImage.getHeight(null);
|
||||
|
||||
Engine.log("original: " + imageWidth + " x " + imageHeight);
|
||||
Engine.log("new: " + width + " x " + height);
|
||||
Engine.log("after: " + newImageWidth + " x " + newImageHeight);
|
||||
|
||||
// do math, shove it on.
|
||||
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||
|
||||
|
|
@ -238,8 +318,6 @@ public class Item {
|
|||
lastTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
System.out.println(pointer);
|
||||
|
||||
return image[pointer];
|
||||
}
|
||||
|
||||
|
|
@ -321,4 +399,8 @@ public class Item {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isEnterable() {
|
||||
return enterable;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -61,7 +61,10 @@ public class Viewer implements BasicApp {
|
|||
|
||||
private void setCurrentDir(String path) {
|
||||
currentDirectoryVariable.setValue(path);
|
||||
if (!path.equals("\\drives"))
|
||||
currentDirectoryFile = new File(path);
|
||||
else
|
||||
currentDirectoryFile = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -87,6 +90,7 @@ public class Viewer implements BasicApp {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (currentDirectoryFile != null) {
|
||||
populationThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
|
|
@ -95,6 +99,14 @@ public class Viewer implements BasicApp {
|
|||
}
|
||||
});
|
||||
populationThread.start();
|
||||
} else {
|
||||
for (File f : File.listRoots()) {
|
||||
Item item = new Item(f.getAbsolutePath());
|
||||
if(item.getSeemsLegit()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -102,24 +114,22 @@ public class Viewer implements BasicApp {
|
|||
|
||||
if (currentDirectoryFile.isDirectory()) {
|
||||
|
||||
System.out.println("adding?");
|
||||
// parent?
|
||||
String parent = currentDirectoryFile.getParent();
|
||||
if (parent != null) {
|
||||
System.out.println("adding parent?");
|
||||
Item item = new Item(parent);
|
||||
if (item.getSeemsLegit()) {
|
||||
System.out.println("added.");
|
||||
items.add(item);
|
||||
}
|
||||
} else {
|
||||
Item item = new Item("\\drives");
|
||||
items.add(item);
|
||||
}
|
||||
System.out.println("k?");
|
||||
|
||||
// folderssss
|
||||
for (String path : currentDirectoryFile.list()) {
|
||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||
if (file.isDirectory()) {
|
||||
System.out.println("folder: " + file.getAbsolutePath());
|
||||
Item item = new Item(file.getAbsolutePath());
|
||||
if (item.getSeemsLegit())
|
||||
items.add(item);
|
||||
|
|
@ -130,7 +140,6 @@ public class Viewer implements BasicApp {
|
|||
for (String path : currentDirectoryFile.list()) {
|
||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||
if (!file.isDirectory()) {
|
||||
System.out.println("file: " + file.getAbsolutePath());
|
||||
Item item = new Item(file.getAbsolutePath());
|
||||
if (item.getSeemsLegit())
|
||||
items.add(item);
|
||||
|
|
@ -200,7 +209,6 @@ public class Viewer implements BasicApp {
|
|||
for (int i = 0; i < items.size(); i++)
|
||||
g.drawImage(items.get(i).getThumbnail(), THUMB_MARGIN, -1 + (int) (THUMB_MARGIN + (i * FULL_WIDTH) - (scroll * FULL_WIDTH)), null);
|
||||
|
||||
|
||||
/*
|
||||
* g.setColor(Color.WHITE); g.drawRect(THUMB_MARGIN - 2, Y_OFFSET -
|
||||
* 2, THUMB_WIDTH + 3, THUMB_WIDTH + 3);
|
||||
|
|
@ -222,8 +230,6 @@ public class Viewer implements BasicApp {
|
|||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
||||
Engine.log("" + e.getKeyCode());
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_S) {
|
||||
if (selection == items.size() - 1)
|
||||
selection = 0;
|
||||
|
|
@ -236,11 +242,9 @@ public class Viewer implements BasicApp {
|
|||
selection = items.size() - 1;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
if (new File(items.get(selection).getPath()).isDirectory()) {
|
||||
if (items.get(selection).isEnterable()) {
|
||||
setCurrentDir(items.get(selection).getPath());
|
||||
reload();
|
||||
} else {
|
||||
Engine.switchApps(AppHelper.getIDbyClass("MainMenu"));
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
|
|
@ -261,7 +265,9 @@ public class Viewer implements BasicApp {
|
|||
}
|
||||
|
||||
/**
|
||||
* gets called every tick because of scaling, we dont particularly know the res...
|
||||
* gets called every tick because of scaling, we dont particularly know the
|
||||
* res...
|
||||
*
|
||||
* @param image
|
||||
* @param width
|
||||
* @param height
|
||||
|
|
@ -273,39 +279,38 @@ public class Viewer implements BasicApp {
|
|||
int imageWidth = image.getWidth();
|
||||
int imageHeight = image.getHeight();
|
||||
|
||||
|
||||
double scaleY = (double) height / imageHeight;
|
||||
double scaleX = (double) width / imageWidth ;
|
||||
double scaleX = (double) width / imageWidth;
|
||||
|
||||
//fill or fit bit
|
||||
if(scaleX > scaleY) scaleX = scaleY;
|
||||
else scaleY = scaleX;
|
||||
// fill or fit bit
|
||||
if (scaleX > scaleY)
|
||||
scaleX = scaleY;
|
||||
else
|
||||
scaleY = scaleX;
|
||||
|
||||
//give us the transform object thing
|
||||
// give us the transform object thing
|
||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
|
||||
|
||||
//then make the scaling algorithm thing.
|
||||
// then make the scaling algorithm thing.
|
||||
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
||||
|
||||
//out new image that we need to crop onto the buffer with the right dimensions.
|
||||
// out new image that we need to crop onto the buffer with the right
|
||||
// dimensions.
|
||||
BufferedImage newImage = bilinearScaleOp.filter(image, new BufferedImage((int) (imageWidth * scaleX), (int) (imageHeight * scaleY), image.getType()));
|
||||
//Image newImage = image.getScaledInstance((int) (imageWidth * scaleX), (int) (imageWidth * scaleY), Image.SCALE_SMOOTH);
|
||||
// Image newImage = image.getScaledInstance((int) (imageWidth * scaleX),
|
||||
// (int) (imageWidth * scaleY), Image.SCALE_SMOOTH);
|
||||
|
||||
//make the buffer
|
||||
// make the buffer
|
||||
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics g = buffer.getGraphics();
|
||||
|
||||
int newImageWidth = newImage.getWidth(null);
|
||||
int newImageHeight = newImage.getHeight(null);
|
||||
|
||||
Engine.log("original: " + imageWidth + " x " + imageHeight);
|
||||
Engine.log("new: " + width + " x " + height);
|
||||
Engine.log("after: " + newImageWidth + " x " + newImageHeight);
|
||||
|
||||
//do math, shove it on.
|
||||
// do math, shove it on.
|
||||
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||
|
||||
//return dat
|
||||
// return dat
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue