albums, synchronous stuff, ya
parent
6bd68a3be7
commit
a143091948
192
src/Item.java
192
src/Item.java
|
|
@ -9,6 +9,7 @@ import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.image.AffineTransformOp;
|
import java.awt.image.AffineTransformOp;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -39,12 +40,14 @@ public class Item {
|
||||||
private final BufferedImage thumbnail;
|
private final BufferedImage thumbnail;
|
||||||
|
|
||||||
// the original image, not cropped or anything.
|
// the original image, not cropped or anything.
|
||||||
private final BufferedImage[] image;
|
private BufferedImage[] image;
|
||||||
|
|
||||||
// Absolute path, i think.
|
// Absolute path, i think.
|
||||||
private final String path;
|
private final String path;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private boolean enterable = true;
|
||||||
|
|
||||||
// we need this because im scared.
|
// we need this because im scared.
|
||||||
// if literally anything in the creating of an item
|
// if literally anything in the creating of an item
|
||||||
// goes MODERATELY wrong, you set this to FALSE.
|
// goes MODERATELY wrong, you set this to FALSE.
|
||||||
|
|
@ -61,53 +64,64 @@ public class Item {
|
||||||
BufferedImage[] images = null;
|
BufferedImage[] images = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File file = new File(path);
|
final File file = new File(path);
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
// thumbnail =
|
|
||||||
// ImageCreator.creatImageWithStripes(Viewer.THUMBNAIL_SIZE,
|
|
||||||
// Viewer.THUMBNAIL_SIZE, Color.BLUE);
|
|
||||||
try {
|
try {
|
||||||
//just... like its not hard but its not properly spaced out to be readable
|
//so many locals, had to split it up
|
||||||
//so just trust drunk on life marcus that it tooootally works.
|
//TODO methodize this or something
|
||||||
//doesn't mess with image yet though so feel free to implement that.
|
{
|
||||||
//yeah, TODO...
|
// just... like its not hard but its not properly spaced
|
||||||
Font font = new Font("Serif", Font.PLAIN, 50);
|
// out to be readable
|
||||||
thumbnail = new BufferedImage(Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE, BufferedImage.TYPE_INT_ARGB);
|
// so just trust drunk on life marcus that it tooootally
|
||||||
Graphics2D g = (Graphics2D) thumbnail.getGraphics();
|
// works.
|
||||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
// doesn't mess with image yet though so feel free to
|
||||||
g.setFont(font);
|
// implement that.
|
||||||
FontMetrics metrics = g.getFontMetrics();
|
// yeah, TODO...
|
||||||
String string = "" + file.getName();
|
Font font = new Font("Serif", Font.PLAIN, 50);
|
||||||
if(string.length() > 8) {
|
thumbnail = new BufferedImage(Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||||
string = string.substring(0, 9) + "...";
|
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 = "" + file.getName();
|
||||||
|
if (string.length() > 8) {
|
||||||
|
string = string.substring(0, 9) + "...";
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
// now try to make a mini album thing showing us what
|
||||||
|
// we're missing!
|
||||||
|
// queue collage mode
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
|
|
||||||
//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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
name = file.getName();
|
name = file.getName();
|
||||||
|
|
||||||
} else {
|
} else if (file.isFile()) {
|
||||||
|
enterable = false;
|
||||||
if (!path.endsWith(".gif")) {
|
if (!path.endsWith(".gif")) {
|
||||||
// try and do the image thing!
|
// try and do the image thing!
|
||||||
images = new BufferedImage[] { ImageIO.read(file) };
|
images = new BufferedImage[] { ImageIO.read(file) };
|
||||||
|
|
@ -118,21 +132,98 @@ public class Item {
|
||||||
for (int i = 0; i < imageList.size(); i++)
|
for (int i = 0; i < imageList.size(); i++)
|
||||||
images[i] = imageList.get(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();
|
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) {
|
} catch (Exception e) {
|
||||||
seemsLegit = false;
|
seemsLegit = false;
|
||||||
System.out.println("wat: " + e.getMessage());
|
|
||||||
System.out.println("wat was in " + path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.image = images;
|
this.image = images;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.thumbnail = thumbnail;
|
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() {
|
public boolean getSeemsLegit() {
|
||||||
return seemsLegit;
|
return seemsLegit;
|
||||||
|
|
@ -171,10 +262,6 @@ public class Item {
|
||||||
int newImageWidth = newImage.getWidth(null);
|
int newImageWidth = newImage.getWidth(null);
|
||||||
int newImageHeight = newImage.getHeight(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);
|
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||||
|
|
||||||
|
|
@ -182,7 +269,6 @@ public class Item {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static BufferedImage fitImageScale(BufferedImage image, int width, int height) throws IOException {
|
private static BufferedImage fitImageScale(BufferedImage image, int width, int height) throws IOException {
|
||||||
|
|
||||||
int imageWidth = image.getWidth();
|
int imageWidth = image.getWidth();
|
||||||
|
|
@ -192,7 +278,7 @@ public class Item {
|
||||||
double scaleX = (double) width / imageWidth;
|
double scaleX = (double) width / imageWidth;
|
||||||
|
|
||||||
// fill or fit bit
|
// fill or fit bit
|
||||||
//heh, hutch
|
// heh, hutch
|
||||||
if (scaleX > scaleY)
|
if (scaleX > scaleY)
|
||||||
scaleX = scaleY;
|
scaleX = scaleY;
|
||||||
else
|
else
|
||||||
|
|
@ -207,8 +293,6 @@ public class Item {
|
||||||
// out new image that we need to crop onto the buffer with the right
|
// out new image that we need to crop onto the buffer with the right
|
||||||
// dimensions.
|
// dimensions.
|
||||||
BufferedImage newImage = bilinearScaleOp.filter(image, new BufferedImage((int) (imageWidth * scaleX), (int) (imageHeight * scaleY), image.getType()));
|
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
|
// make the buffer
|
||||||
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
@ -217,10 +301,6 @@ public class Item {
|
||||||
int newImageWidth = newImage.getWidth(null);
|
int newImageWidth = newImage.getWidth(null);
|
||||||
int newImageHeight = newImage.getHeight(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);
|
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||||
|
|
||||||
|
|
@ -238,8 +318,6 @@ public class Item {
|
||||||
lastTime = System.currentTimeMillis();
|
lastTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(pointer);
|
|
||||||
|
|
||||||
return image[pointer];
|
return image[pointer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -321,4 +399,8 @@ public class Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnterable() {
|
||||||
|
return enterable;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -11,4 +11,4 @@ public class Main {
|
||||||
Engine engine = new Engine(new String[] {"Viewer"}, false);
|
Engine engine = new Engine(new String[] {"Viewer"}, false);
|
||||||
engine.run();
|
engine.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,10 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
private void setCurrentDir(String path) {
|
private void setCurrentDir(String path) {
|
||||||
currentDirectoryVariable.setValue(path);
|
currentDirectoryVariable.setValue(path);
|
||||||
currentDirectoryFile = new File(path);
|
if (!path.equals("\\drives"))
|
||||||
|
currentDirectoryFile = new File(path);
|
||||||
|
else
|
||||||
|
currentDirectoryFile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -87,14 +90,23 @@ public class Viewer implements BasicApp {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
populationThread = new Thread(new Runnable() {
|
if (currentDirectoryFile != null) {
|
||||||
public void run() {
|
populationThread = new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
|
||||||
repopulate();
|
repopulate();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
populationThread.start();
|
||||||
|
} else {
|
||||||
|
for (File f : File.listRoots()) {
|
||||||
|
Item item = new Item(f.getAbsolutePath());
|
||||||
|
if(item.getSeemsLegit()) {
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
populationThread.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,24 +114,22 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
if (currentDirectoryFile.isDirectory()) {
|
if (currentDirectoryFile.isDirectory()) {
|
||||||
|
|
||||||
System.out.println("adding?");
|
|
||||||
// parent?
|
// parent?
|
||||||
String parent = currentDirectoryFile.getParent();
|
String parent = currentDirectoryFile.getParent();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
System.out.println("adding parent?");
|
|
||||||
Item item = new Item(parent);
|
Item item = new Item(parent);
|
||||||
if (item.getSeemsLegit()) {
|
if (item.getSeemsLegit()) {
|
||||||
System.out.println("added.");
|
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Item item = new Item("\\drives");
|
||||||
|
items.add(item);
|
||||||
}
|
}
|
||||||
System.out.println("k?");
|
|
||||||
|
|
||||||
// folderssss
|
// folderssss
|
||||||
for (String path : currentDirectoryFile.list()) {
|
for (String path : currentDirectoryFile.list()) {
|
||||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
System.out.println("folder: " + file.getAbsolutePath());
|
|
||||||
Item item = new Item(file.getAbsolutePath());
|
Item item = new Item(file.getAbsolutePath());
|
||||||
if (item.getSeemsLegit())
|
if (item.getSeemsLegit())
|
||||||
items.add(item);
|
items.add(item);
|
||||||
|
|
@ -130,7 +140,6 @@ public class Viewer implements BasicApp {
|
||||||
for (String path : currentDirectoryFile.list()) {
|
for (String path : currentDirectoryFile.list()) {
|
||||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||||
if (!file.isDirectory()) {
|
if (!file.isDirectory()) {
|
||||||
System.out.println("file: " + file.getAbsolutePath());
|
|
||||||
Item item = new Item(file.getAbsolutePath());
|
Item item = new Item(file.getAbsolutePath());
|
||||||
if (item.getSeemsLegit())
|
if (item.getSeemsLegit())
|
||||||
items.add(item);
|
items.add(item);
|
||||||
|
|
@ -200,7 +209,6 @@ public class Viewer implements BasicApp {
|
||||||
for (int i = 0; i < items.size(); i++)
|
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.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 -
|
* g.setColor(Color.WHITE); g.drawRect(THUMB_MARGIN - 2, Y_OFFSET -
|
||||||
* 2, THUMB_WIDTH + 3, THUMB_WIDTH + 3);
|
* 2, THUMB_WIDTH + 3, THUMB_WIDTH + 3);
|
||||||
|
|
@ -222,8 +230,6 @@ public class Viewer implements BasicApp {
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
|
|
||||||
Engine.log("" + e.getKeyCode());
|
|
||||||
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_S) {
|
if (e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_S) {
|
||||||
if (selection == items.size() - 1)
|
if (selection == items.size() - 1)
|
||||||
selection = 0;
|
selection = 0;
|
||||||
|
|
@ -236,11 +242,9 @@ public class Viewer implements BasicApp {
|
||||||
selection = items.size() - 1;
|
selection = items.size() - 1;
|
||||||
}
|
}
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||||
if (new File(items.get(selection).getPath()).isDirectory()) {
|
if (items.get(selection).isEnterable()) {
|
||||||
setCurrentDir(items.get(selection).getPath());
|
setCurrentDir(items.get(selection).getPath());
|
||||||
reload();
|
reload();
|
||||||
} else {
|
|
||||||
Engine.switchApps(AppHelper.getIDbyClass("MainMenu"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
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 image
|
||||||
* @param width
|
* @param width
|
||||||
* @param height
|
* @param height
|
||||||
|
|
@ -269,43 +275,42 @@ public class Viewer implements BasicApp {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException {
|
private static BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException {
|
||||||
|
|
||||||
int imageWidth = image.getWidth();
|
int imageWidth = image.getWidth();
|
||||||
int imageHeight = image.getHeight();
|
int imageHeight = image.getHeight();
|
||||||
|
|
||||||
|
|
||||||
double scaleY = (double) height / imageHeight;
|
double scaleY = (double) height / imageHeight;
|
||||||
double scaleX = (double) width / imageWidth ;
|
double scaleX = (double) width / imageWidth;
|
||||||
|
|
||||||
//fill or fit bit
|
// fill or fit bit
|
||||||
if(scaleX > scaleY) scaleX = scaleY;
|
if (scaleX > scaleY)
|
||||||
else scaleY = scaleX;
|
scaleX = scaleY;
|
||||||
|
else
|
||||||
//give us the transform object thing
|
scaleY = scaleX;
|
||||||
|
|
||||||
|
// give us the transform object thing
|
||||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
|
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);
|
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()));
|
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);
|
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics g = buffer.getGraphics();
|
Graphics g = buffer.getGraphics();
|
||||||
|
|
||||||
int newImageWidth = newImage.getWidth(null);
|
int newImageWidth = newImage.getWidth(null);
|
||||||
int newImageHeight = newImage.getHeight(null);
|
int newImageHeight = newImage.getHeight(null);
|
||||||
|
|
||||||
Engine.log("original: " + imageWidth + " x " + imageHeight);
|
// do math, shove it on.
|
||||||
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);
|
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||||
|
|
||||||
//return dat
|
// return dat
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,7 +349,7 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
WIDTH = width;
|
WIDTH = width;
|
||||||
HEIGHT = height;
|
HEIGHT = height;
|
||||||
|
|
||||||
THUMB_MARGIN = 30;
|
THUMB_MARGIN = 30;
|
||||||
FULL_WIDTH = THUMBNAIL_SIZE + THUMB_MARGIN;
|
FULL_WIDTH = THUMBNAIL_SIZE + THUMB_MARGIN;
|
||||||
Y_OFFSET = 470;
|
Y_OFFSET = 470;
|
||||||
|
|
@ -361,7 +366,7 @@ public class Viewer implements BasicApp {
|
||||||
@Override
|
@Override
|
||||||
public void click() {
|
public void click() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue