first
parent
4271cba066
commit
e4d8e3982b
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/ImgurLibrary"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/MAndEngine"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
*.class
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ImgurDownloader2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class ArrayListHelper {
|
||||
public static String[] toArray(ArrayList<String> list) {
|
||||
String[] array = new String[list.size()];
|
||||
for(int i = 0; i < array.length; i ++) {
|
||||
array[i] = list.get(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class GraphicalImgurRequest extends ImgurRequest{
|
||||
private Point point = new Point(0, 0);
|
||||
private Point desiredPoint = new Point(0, 0);
|
||||
private double progress = 0;
|
||||
|
||||
public GraphicalImgurRequest(double x1, double y1, double x2, double y2) {
|
||||
point.x = x1;
|
||||
point.y = y1;
|
||||
desiredPoint.x = x2;
|
||||
desiredPoint.y = y2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setDestination(double x, double y) {
|
||||
desiredPoint.x = x;
|
||||
desiredPoint.y = y;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
double x = point.x;
|
||||
double y = point.y;
|
||||
|
||||
double x2 = desiredPoint.x;
|
||||
double y2 = desiredPoint.y;
|
||||
|
||||
y -= (y - y2) / 8d;
|
||||
x -= (x - x2) / 8d;
|
||||
|
||||
point.x = x;
|
||||
point.y = y;
|
||||
|
||||
double newProgress = getProgress();
|
||||
if(newProgress == newProgress)
|
||||
progress -= (progress - newProgress) / 8d;
|
||||
|
||||
}
|
||||
|
||||
private class Point {
|
||||
public double x, y;
|
||||
public Point(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
g.drawRect(XOFF, YOFF + 13, WIDTH, 20);
|
||||
|
||||
//total images
|
||||
String str = "" + getImagesDiscovered();
|
||||
g.drawString(str, XOFF + WIDTH - (metrics.charsWidth(str.toCharArray(), 0, str.length())) / 2, YOFF + 45);
|
||||
|
||||
//downloaded
|
||||
str = "" + getImagesDownloaded();
|
||||
g.drawString(str, XOFF + (int) (WIDTH * progress) - (metrics.charsWidth(str.toCharArray(), 0, str.length())) / 2, YOFF + 10);
|
||||
|
||||
// name of the thing
|
||||
str = getTitle();
|
||||
g.drawString(str, XOFF + (WIDTH / 2) - (metrics.charsWidth(str.toCharArray(), 0, str.length())) / 2, YOFF);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import MAndEngine.BasicApp;
|
||||
import MAndEngine.Engine;
|
||||
|
||||
public class ImgurDownloader implements BasicApp {
|
||||
|
||||
private ArrayList<GraphicalImgurRequest> requests;
|
||||
private String textBox = "";
|
||||
|
||||
@Override
|
||||
public Dimension getResolution() {
|
||||
return new Dimension(800, 600);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
requests = new ArrayList<GraphicalImgurRequest>();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeApp() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseApp() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
int GAP = 70;
|
||||
int MARGIN_TOP = 30;
|
||||
|
||||
for (int i = 0; i < requests.size(); i++) {
|
||||
requests.get(i).setDestination(450, MARGIN_TOP + (GAP * i));
|
||||
requests.get(i).tick();
|
||||
}
|
||||
|
||||
Iterator<GraphicalImgurRequest> iterator = requests.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
GraphicalImgurRequest req = iterator.next();
|
||||
if(!req.isBusy()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
textBox = "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, 800, 600);
|
||||
for (int i = 0; i < requests.size(); i++) {
|
||||
requests.get(i).draw(g);
|
||||
}
|
||||
g.drawString(textBox, 100, 100);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
char c = ("" + e.getKeyChar()).toLowerCase().charAt(0);
|
||||
if (c >= 97 && c < 123) {
|
||||
|
||||
textBox += c;
|
||||
|
||||
}
|
||||
|
||||
else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
|
||||
textBox = textBox.substring(0, textBox.length() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Imgur Downloader";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramerate() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResizable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visibleInMenu() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resized(int width, int height) {
|
||||
// not resizable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class ListHelper {
|
||||
public static final String listFilePath = System.getenv("APPDATA") + "\\MAndWorks\\Imgur\\settings\\list.txt";
|
||||
|
||||
public static String[] getList() {
|
||||
|
||||
System.out.println(listFilePath);
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
|
||||
|
||||
File file = new File(listFilePath);
|
||||
|
||||
Scanner s = new Scanner(file);
|
||||
|
||||
while (s.hasNextLine()) {
|
||||
|
||||
String line = s.nextLine();
|
||||
|
||||
list.add(line);
|
||||
}
|
||||
s.close();
|
||||
} catch (Exception e) {
|
||||
//hopefully this never happens
|
||||
JFrame frame = new JFrame("Error");
|
||||
frame.add(new JLabel(e.getMessage()));
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
frame.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
System.out.print("Opened List:\n");
|
||||
for(String listItem : list)
|
||||
System.out.print(" - " + listItem + "\n");
|
||||
System.out.print("\n");
|
||||
|
||||
return ArrayListHelper.toArray(list);
|
||||
}
|
||||
|
||||
public static void save(String[] contents) {
|
||||
File file = new File(listFilePath);
|
||||
file.delete();
|
||||
try{
|
||||
file.createNewFile();
|
||||
FileWriter f = new FileWriter(file);
|
||||
String newLine = System.getProperty("line.separator");
|
||||
for(int i = 0; i < contents.length; i ++) {
|
||||
f.write(contents[i] + newLine);
|
||||
}
|
||||
f.close();
|
||||
}catch(Exception e) {
|
||||
JFrame frame = new JFrame("Error");
|
||||
frame.add(new JLabel(e.getMessage()));
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
frame.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
testSave(contents);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* this will test to make sure these contents are in the save.
|
||||
* if they aren't, then resave and check
|
||||
*
|
||||
* indirect recursion.
|
||||
* @param contents
|
||||
* @return
|
||||
*/
|
||||
private static void testSave(String[] contents) {
|
||||
String[] savedContents = getList();
|
||||
|
||||
if(contents.length != savedContents.length) save(contents);
|
||||
for(int i = 0; i < contents.length; i ++) {
|
||||
if(!contents[i].equals(savedContents[i])) save(contents);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static String arrayToString(Object[] array) {
|
||||
String _return = "{";
|
||||
|
||||
for(Object item : array) {
|
||||
_return += item.toString() + ", ";
|
||||
}
|
||||
|
||||
return _return.substring(0, _return.length() - 2) + "}";
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import MAndEngine.Engine;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Engine engine = new Engine(new String[] {"ImgurDownloader"}, false);
|
||||
engine.run();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue