added page progress
parent
2d37b71e5b
commit
cde75c9365
|
|
@ -6,14 +6,16 @@ public class GraphicalImgurRequest extends ImgurRequest{
|
|||
private Point point = new Point(0, 0);
|
||||
private Point desiredPoint = new Point(0, 0);
|
||||
private double progress = 0;
|
||||
private double scanProgress = 0;
|
||||
private ImageListener listener;
|
||||
|
||||
public GraphicalImgurRequest(double x1, double y1, double x2, double y2) {
|
||||
public GraphicalImgurRequest(double x1, double y1, double x2, double y2, ImageListener listener) {
|
||||
super(listener);
|
||||
point.x = x1;
|
||||
point.y = y1;
|
||||
desiredPoint.x = x2;
|
||||
desiredPoint.y = y2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setDestination(double x, double y) {
|
||||
|
|
@ -33,11 +35,15 @@ public class GraphicalImgurRequest extends ImgurRequest{
|
|||
|
||||
point.x = x;
|
||||
point.y = y;
|
||||
|
||||
|
||||
double newProgress = getProgress();
|
||||
if(newProgress == newProgress)
|
||||
progress -= (progress - newProgress) / 8d;
|
||||
|
||||
double newScanProgress = getScanProgress();
|
||||
if(newScanProgress == newScanProgress)
|
||||
scanProgress -= (scanProgress - newScanProgress) / 8d;
|
||||
|
||||
}
|
||||
|
||||
private class Point {
|
||||
|
|
@ -47,17 +53,21 @@ public class GraphicalImgurRequest extends ImgurRequest{
|
|||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
public final static int WIDTH = 100;
|
||||
public void draw(Graphics2D g) {
|
||||
final int WIDTH = 300;
|
||||
|
||||
|
||||
int XOFF = (int)(point.x);
|
||||
int YOFF = (int)(point.y);
|
||||
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect(XOFF, YOFF + 13, (int) (WIDTH * progress), 20);
|
||||
//the bar
|
||||
g.setColor(new Color(150, 150, 150));
|
||||
g.fillRect(XOFF, YOFF + 13, (int) (WIDTH * scanProgress) + 1, 20);
|
||||
g.drawRect(XOFF, YOFF + 13, WIDTH, 20);
|
||||
g.setColor(new Color(70, 70, 70));
|
||||
g.fillRect(XOFF, YOFF + 13, (int) (WIDTH * progress) + 1, 20);
|
||||
g.drawRect(XOFF, YOFF + 13, WIDTH, 20);
|
||||
|
||||
//total images
|
||||
|
|
|
|||
|
|
@ -1,18 +1,29 @@
|
|||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.Savepoint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import MAndEngine.BasicApp;
|
||||
import MAndEngine.Engine;
|
||||
|
||||
public class ImgurDownloader implements BasicApp {
|
||||
public class ImgurDownloader implements BasicApp, ImageListener{
|
||||
|
||||
private ArrayList<GraphicalImgurRequest> requests;
|
||||
private String textBox = "";
|
||||
private BufferedImage image;
|
||||
|
||||
@Override
|
||||
public Dimension getResolution() {
|
||||
|
|
@ -23,7 +34,13 @@ public class ImgurDownloader implements BasicApp {
|
|||
public void initialize() {
|
||||
|
||||
requests = new ArrayList<GraphicalImgurRequest>();
|
||||
|
||||
try {
|
||||
image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("start.png"));
|
||||
} catch (Exception e) {
|
||||
image = null;
|
||||
System.out.println("eakljrfgskldhfg");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -38,13 +55,14 @@ public class ImgurDownloader implements BasicApp {
|
|||
|
||||
}
|
||||
|
||||
final int LEFT_MARGIN = 20;
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
int GAP = 70;
|
||||
int MARGIN_TOP = 30;
|
||||
|
||||
int GAP = GraphicalImgurRequest.WIDTH + LEFT_MARGIN;
|
||||
|
||||
for (int i = 0; i < requests.size(); i++) {
|
||||
requests.get(i).setDestination(450, MARGIN_TOP + (GAP * i));
|
||||
requests.get(i).setDestination(LEFT_MARGIN + (GAP * i), INNER_FRAME_HEIGHT + 25);
|
||||
requests.get(i).tick();
|
||||
}
|
||||
|
||||
|
|
@ -57,28 +75,92 @@ public class ImgurDownloader implements BasicApp {
|
|||
}
|
||||
|
||||
if (Engine.keys[KeyEvent.VK_ENTER] && textBox != "") {
|
||||
GraphicalImgurRequest request = new GraphicalImgurRequest(800, MARGIN_TOP + (GAP * (requests.size())), 450, MARGIN_TOP + (GAP * (requests.size())));
|
||||
request.saveSubreddit(textBox, 10, "time");
|
||||
requests.add(request);
|
||||
execute(textBox);
|
||||
textBox = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void execute(String str) {
|
||||
String[] parts = str.split(" ");
|
||||
if(parts[0].equalsIgnoreCase("load")) {
|
||||
loadScript(parts[1]);
|
||||
}else{
|
||||
//assume subreddit
|
||||
GraphicalImgurRequest request = new GraphicalImgurRequest(0, 0, 0, 0, this);
|
||||
int pages = 0;
|
||||
try{
|
||||
pages = Integer.parseInt(parts[1]);
|
||||
}catch (Exception e) {}
|
||||
request.saveSubreddit(parts[0], pages == 0 ? 10 : pages, "time");
|
||||
requests.add(request);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadScript(String script) {
|
||||
File file = new File(System.getenv("APPDATA") + "\\MAndWorks\\ImgurDownloader\\scripts\\" + script + ".lst");
|
||||
try {
|
||||
Scanner scan = new Scanner(file);
|
||||
while(scan.hasNextLine()) {
|
||||
String line = scan.nextLine();
|
||||
|
||||
execute(line);
|
||||
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO NAME THESE RIGHT
|
||||
final int INNER_FRAME_WIDTH = 800;
|
||||
final int INNER_FRAME_HEIGHT = 520;
|
||||
|
||||
//yeah, image scaling!
|
||||
final int IMAGE_WIDTH = 800;
|
||||
final int IMAGE_HEIGHT = 520 - 35;
|
||||
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, 800, 600);
|
||||
|
||||
|
||||
g.setColor(new Color(230, 230, 230));
|
||||
g.fillRect(0, 0, 800, 600);
|
||||
|
||||
|
||||
g.setColor(new Color(210, 210, 210));
|
||||
g.fillRect(0, 0, INNER_FRAME_WIDTH, INNER_FRAME_HEIGHT);
|
||||
|
||||
g.setColor(new Color(230, 230, 230));
|
||||
g.fillRect(0, 0, 800, 35);
|
||||
|
||||
for (int i = 0; i < requests.size(); i++) {
|
||||
requests.get(i).draw(g);
|
||||
}
|
||||
g.drawString(textBox, 100, 100);
|
||||
g.setColor(new Color(70, 70, 70));
|
||||
g.drawString("save: " + textBox, 100, 20);
|
||||
|
||||
g.drawImage(image, 0, 35, null);
|
||||
g.setColor(rgb(255,154,0));
|
||||
g.drawLine(0, INNER_FRAME_HEIGHT, 800, INNER_FRAME_HEIGHT);
|
||||
g.setColor(rgb(255,154,0));
|
||||
g.drawLine(0, 35, 800, 35);
|
||||
|
||||
g.setColor(new Color(50, 50, 50));
|
||||
g.drawString("Requests: " + requests.size(), 0, 600);
|
||||
}
|
||||
|
||||
private Color rgb (int r, int g, int b) {
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
char c = ("" + e.getKeyChar()).toLowerCase().charAt(0);
|
||||
if (c >= 97 && c < 123) {
|
||||
if ((c >= 97 && c < 123) || c == ' ') {
|
||||
|
||||
textBox += c;
|
||||
|
||||
|
|
@ -131,4 +213,55 @@ public class ImgurDownloader implements BasicApp {
|
|||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newImage(BufferedImage image) {
|
||||
|
||||
try {
|
||||
image = fitImageScale(image, IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
this.image = image;
|
||||
} catch (IOException e) {
|
||||
//eh, whatevs
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static BufferedImage fitImageScale(BufferedImage image, int width, int height) throws IOException {
|
||||
|
||||
int imageWidth = image.getWidth();
|
||||
int imageHeight = image.getHeight();
|
||||
|
||||
double scaleY = (double) height / imageHeight;
|
||||
double scaleX = (double) width / imageWidth;
|
||||
|
||||
// fill or fit bit
|
||||
// heh, hutch
|
||||
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);
|
||||
|
||||
// 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()));
|
||||
|
||||
// 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);
|
||||
|
||||
// do math, shove it on.
|
||||
g.drawImage(newImage, (width - newImageWidth) / 2, (height - newImageHeight) / 2, null);
|
||||
|
||||
// return dat
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue