made things make more sense and such
parent
ad0483829b
commit
3eb0962a59
104
src/Item.java
104
src/Item.java
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.AffineTransformOp;
|
import java.awt.image.AffineTransformOp;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
@ -11,13 +9,19 @@ import java.io.IOException;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import MAndEngine.ImageCreator;
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
|
||||||
private static int scaleToHeight;
|
private static int scaleToHeight;
|
||||||
|
|
||||||
|
//cropped to a thumb nail, of size 80*80
|
||||||
private final BufferedImage thumbnail;
|
private final BufferedImage thumbnail;
|
||||||
|
|
||||||
|
//the original image, not cropped or anything.
|
||||||
private final BufferedImage image;
|
private final BufferedImage image;
|
||||||
private final int yRange;
|
|
||||||
private final boolean isDir;
|
//Absolute path, i think.
|
||||||
private final String path;
|
private final String path;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -27,35 +31,24 @@ public class Item {
|
||||||
// then we don't try and render something that
|
// then we don't try and render something that
|
||||||
// makes no sense.
|
// makes no sense.
|
||||||
// set this to false by the end of the constructor
|
// set this to false by the end of the constructor
|
||||||
// and when it comes back to being added to the list,
|
// and when it comes back to be added to the list,
|
||||||
// it'll be thrown out.
|
// it'll get thrown out.
|
||||||
private boolean seemsLegit = true;
|
private boolean seemsLegit = true;
|
||||||
|
|
||||||
public Item(String path) {
|
public Item(String path) {
|
||||||
|
|
||||||
|
|
||||||
BufferedImage thumbnail = null;
|
BufferedImage thumbnail = null;
|
||||||
BufferedImage image = null;
|
BufferedImage image = null;
|
||||||
int yRange = 0;
|
|
||||||
boolean isDir = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
// then lets do the directory thing!
|
thumbnail = ImageCreator.creatImageWithStripes(Viewer.THUMBNAIL_SIZE, Viewer.THUMBNAIL_SIZE, Color.BLUE);
|
||||||
yRange = 0;
|
image = ImageCreator.creatImageWithStripes(800, 600, Color.BLUE);
|
||||||
|
Graphics g = image.getGraphics();
|
||||||
thumbnail = new BufferedImage(80, 80, BufferedImage.TYPE_INT_ARGB);
|
g.setColor(Color.WHITE);
|
||||||
Graphics thumbnailGraphics = thumbnail.getGraphics();
|
g.setFont(new Font("Courier", Font.BOLD, 15));
|
||||||
thumbnailGraphics.setColor(new Color(0, 0, 255));
|
g.drawString("" + path, 100, 100);
|
||||||
thumbnailGraphics.fillRect(0, 0, 80, 80);
|
|
||||||
|
|
||||||
image = new BufferedImage((int)((scaleToHeight/3d)*4d), scaleToHeight, BufferedImage.TYPE_INT_ARGB);
|
|
||||||
Graphics imageGraphics = image.getGraphics();
|
|
||||||
imageGraphics.fillRect(0, 0, (int)((scaleToHeight/3d)*4d), scaleToHeight);
|
|
||||||
|
|
||||||
imageGraphics.setColor(Color.black);
|
|
||||||
imageGraphics.drawString("" + path, 100, 100);
|
|
||||||
|
|
||||||
name = file.getName();
|
name = file.getName();
|
||||||
|
|
||||||
|
|
@ -63,55 +56,57 @@ public class Item {
|
||||||
|
|
||||||
// try and do the image thing!
|
// try and do the image thing!
|
||||||
image = ImageIO.read(file);
|
image = ImageIO.read(file);
|
||||||
image = getScaledImage(image, scaleToHeight);
|
image = getScaledImage(image, 800, 600);
|
||||||
thumbnail = (getScaledImageFill(image, 80, 80));
|
thumbnail = (getScaledImage(image, 80, 80));
|
||||||
path = file.getAbsolutePath();
|
path = file.getAbsolutePath();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
name = "";
|
name = "";
|
||||||
|
|
||||||
yRange = image.getHeight() - 600;
|
|
||||||
}
|
}
|
||||||
} 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 = image;
|
this.image = image;
|
||||||
this.isDir = isDir;
|
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.thumbnail = thumbnail;
|
this.thumbnail = thumbnail;
|
||||||
this.yRange = yRange;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSeemsLegit() {
|
public boolean getSeemsLegit() {
|
||||||
return seemsLegit;
|
return seemsLegit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BufferedImage getScaledImage(BufferedImage image, 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 scale = (double) height / imageHeight;
|
|
||||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scale, scale);
|
|
||||||
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
|
||||||
return bilinearScaleOp.filter(image, new BufferedImage((int) (imageWidth * scale), height, image.getType()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BufferedImage getScaledImageFill(BufferedImage image, int width, int height) throws IOException {
|
|
||||||
int imageWidth = image.getWidth();
|
|
||||||
int imageHeight = image.getHeight();
|
|
||||||
double scaleX = (double) width / imageWidth;
|
|
||||||
double scaleY = (double) height / imageHeight;
|
double scaleY = (double) height / imageHeight;
|
||||||
double scale = scaleX > scaleY ? scaleX : scaleY;
|
double scaleX = (double) width / imageWidth ;
|
||||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scale, scale);
|
|
||||||
|
//fill or fit bit
|
||||||
|
if(scaleX > scaleY) scaleX = scaleY;
|
||||||
|
else scaleY = scaleX;
|
||||||
|
|
||||||
|
//give us the transform object thing
|
||||||
|
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
|
||||||
|
|
||||||
|
//then make the scaling algorithm thing.
|
||||||
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
||||||
return bilinearScaleOp.filter(image, new BufferedImage(width, height, image.getType()));
|
|
||||||
}
|
//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) (imageWidth * scaleY), image.getType()));
|
||||||
public double getYRange() {
|
|
||||||
return yRange;
|
//make the buffer
|
||||||
|
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics g = buffer.getGraphics();
|
||||||
|
|
||||||
|
//do math, shove it on.
|
||||||
|
g.drawImage(newImage, (width / 2) + ((width - imageWidth) / 2), (height / 2) + ((height - imageHeight) / 2), null);
|
||||||
|
|
||||||
|
//return dat
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage getImage() {
|
public BufferedImage getImage() {
|
||||||
|
|
@ -126,12 +121,7 @@ public class Item {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setImageHeight(int i) {
|
|
||||||
scaleToHeight = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
import static MAndEngine.Engine.ANIMATION_CONSTANT;
|
import static MAndEngine.Engine.ANIMATION_CONSTANT;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
@ -17,41 +17,39 @@ import MAndEngine.Variable;
|
||||||
|
|
||||||
public class Viewer implements BasicApp {
|
public class Viewer implements BasicApp {
|
||||||
|
|
||||||
private static final int WIDTH = 800, HEIGHT = 600;
|
public static final int THUMBNAIL_SIZE = 80;
|
||||||
|
|
||||||
|
private static int WIDTH = 800, HEIGHT = 600;
|
||||||
|
|
||||||
// we need to have a home in case all else fails.
|
// we need to have a home in case all else fails.
|
||||||
private static final String defaultSearchDirectory = System.getenv("APPDATA") + "\\MAndWorks\\MAndApps\\Backgrounds\\";
|
private static final String defaultSearchDirectory = System.getenv("APPDATA") + "\\MAndWorks\\MAndApps\\Backgrounds\\";
|
||||||
|
|
||||||
// current selection
|
// current selection
|
||||||
private int selection = 0;
|
private static int selection = 0;
|
||||||
|
|
||||||
// rendering animation number thing that
|
// rendering animation number thing that
|
||||||
// looks like selection but is rendered
|
// looks like selection but is rendered
|
||||||
// horizontally and stuff. in pixels. BC ANIMATION
|
// horizontally and stuff. in pixels. BC ANIMATION
|
||||||
private double scroll;
|
private static double scroll;
|
||||||
|
|
||||||
// TIME. pretty self explanitory.
|
|
||||||
private static double time = 0;
|
|
||||||
|
|
||||||
// items list
|
// items list
|
||||||
private ArrayList<Item> items;
|
private ArrayList<Item> items;
|
||||||
|
|
||||||
private File currentDirectoryFile;
|
private static File currentDirectoryFile;
|
||||||
private Variable currentDirectoryVariable;
|
private static Variable currentDirectoryVariable;
|
||||||
|
|
||||||
final int THUMB_WIDTH = 80;
|
public static final int THUMB_MARGIN = 30;
|
||||||
final int THUMB_MARGIN = 30;
|
public static final int FULL_WIDTH = THUMBNAIL_SIZE + THUMB_MARGIN;
|
||||||
final int FULL_WIDTH = THUMB_WIDTH + THUMB_MARGIN;
|
public static final int Y_OFFSET = 470;
|
||||||
final int Y_OFFSET = 470;
|
|
||||||
|
|
||||||
final int X_OFFSET_SELECTION = (int)(THUMB_MARGIN + (selection * FULL_WIDTH) - (scroll * FULL_WIDTH));
|
public static final int X_OFFSET_SELECTION = (int)(THUMB_MARGIN + (selection * FULL_WIDTH) - (scroll * FULL_WIDTH));
|
||||||
|
|
||||||
final int LEFT_BAR_WIDTH = FULL_WIDTH + THUMB_MARGIN;
|
public static final int LEFT_BAR_WIDTH = FULL_WIDTH + THUMB_MARGIN;
|
||||||
final int INNER_FRAME_HEIGHT = (int)(((WIDTH - LEFT_BAR_WIDTH) / 4d) * 3d);
|
public static final int INNER_FRAME_HEIGHT = (int)(((WIDTH - LEFT_BAR_WIDTH) / 4d) * 3d);
|
||||||
final int TOP_BAR_HEIGHT = HEIGHT - INNER_FRAME_HEIGHT;
|
public static final int TOP_BAR_HEIGHT = HEIGHT - INNER_FRAME_HEIGHT;
|
||||||
final int INNER_FRAME_WIDTH = WIDTH - LEFT_BAR_WIDTH;
|
public static final int INNER_FRAME_WIDTH = WIDTH - LEFT_BAR_WIDTH;
|
||||||
|
|
||||||
//YES IT WORKED
|
private static Thread populationThread;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getResolution() {
|
public Dimension getResolution() {
|
||||||
|
|
@ -65,11 +63,10 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
Item.setImageHeight(INNER_FRAME_HEIGHT); //NOW WITH MODULAR GOODIES
|
|
||||||
// make sure we have our variable and file
|
// make sure we have our variable and file
|
||||||
// we can explicitly set them as we are trying to pick up where we left
|
// we can explicitly set them as we are trying to pick up where we left
|
||||||
// off
|
// off
|
||||||
currentDirectoryVariable = new Variable("MAndWorks\\MAndApps\\Settings", "WallpaperSearchDirectory", defaultSearchDirectory, false);
|
currentDirectoryVariable = new Variable("MAndWorks\\MAndApps\\Settings", "WallpaperSearchDirectory", defaultSearchDirectory, true);
|
||||||
currentDirectoryFile = new File(currentDirectoryVariable.getValue());
|
currentDirectoryFile = new File(currentDirectoryVariable.getValue());
|
||||||
|
|
||||||
// which we use, be it variable or file, is completely arbitrary here.
|
// which we use, be it variable or file, is completely arbitrary here.
|
||||||
|
|
@ -82,29 +79,42 @@ public class Viewer implements BasicApp {
|
||||||
items = new ArrayList<Item>();
|
items = new ArrayList<Item>();
|
||||||
selection = 0;
|
selection = 0;
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
try {
|
||||||
|
populationThread.stop();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
populationThread = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
repopulate();
|
repopulate();
|
||||||
|
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
|
populationThread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repopulate() {
|
private void repopulate() {
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("k?");
|
||||||
|
|
||||||
// folderssss
|
// folderssss
|
||||||
for (String path : currentDirectoryFile.list()) {
|
for (String path : currentDirectoryFile.list()) {
|
||||||
|
System.out.println("folders...");
|
||||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
Item item = new Item(file.getAbsolutePath());
|
Item item = new Item(file.getAbsolutePath());
|
||||||
|
|
@ -115,6 +125,7 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
// filezzzz
|
// filezzzz
|
||||||
for (String path : currentDirectoryFile.list()) {
|
for (String path : currentDirectoryFile.list()) {
|
||||||
|
System.out.println("files...");
|
||||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||||
if (!file.isDirectory()) {
|
if (!file.isDirectory()) {
|
||||||
Item item = new Item(file.getAbsolutePath());
|
Item item = new Item(file.getAbsolutePath());
|
||||||
|
|
@ -151,8 +162,6 @@ public class Viewer implements BasicApp {
|
||||||
scroll -= (scroll - desiredScroll) / (ANIMATION_CONSTANT);
|
scroll -= (scroll - desiredScroll) / (ANIMATION_CONSTANT);
|
||||||
|
|
||||||
|
|
||||||
time += 1 / 60d;
|
|
||||||
time = Math.PI + 1; // PI IS TOP, 0/2PI is bottom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -185,7 +194,6 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
g.setColor(new Color(35, 35, 35));
|
g.setColor(new Color(35, 35, 35));
|
||||||
//g.setFont(Main.largerFont);
|
//g.setFont(Main.largerFont);
|
||||||
int dirWidth = g.getFontMetrics().stringWidth(currentDirectoryVariable.getValue());
|
|
||||||
|
|
||||||
g.drawString(currentDirectoryVariable.getValue(), LEFT_BAR_WIDTH + THUMB_MARGIN, TOP_BAR_HEIGHT / 2 + 5);
|
g.drawString(currentDirectoryVariable.getValue(), LEFT_BAR_WIDTH + THUMB_MARGIN, TOP_BAR_HEIGHT / 2 + 5);
|
||||||
|
|
||||||
|
|
@ -241,7 +249,8 @@ public class Viewer implements BasicApp {
|
||||||
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||||
|
|
||||||
if(selection == 0) {
|
if(selection == 0) {
|
||||||
Engine.switchApps(AppHelper.getIDbyClass("MainMenu"));
|
setCurrentDir(items.get(selection).getPath());
|
||||||
|
reload();
|
||||||
} else {
|
} else {
|
||||||
selection = 0;
|
selection = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +280,7 @@ public class Viewer implements BasicApp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getResizable() {
|
public boolean getResizable() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue