Skip to content

Commit

Permalink
Add GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Hronom committed Apr 24, 2016
1 parent 41caad0 commit 7bef78a
Show file tree
Hide file tree
Showing 10 changed files with 520 additions and 74 deletions.
16 changes: 13 additions & 3 deletions robocraft-assistant-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@
<packaging>jar</packaging>

<name>robocraft-assistant-app</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
<groupId>com.github.hronom</groupId>
<artifactId>robocraft-assistant-core</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -55,7 +65,7 @@
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
<classpathLayoutType>simple</classpathLayoutType>
<mainClass>com.github.hronom.robocraft.assistant.app.App</mainClass>
<mainClass>com.github.hronom.robocraft.assistant.app.RobocraftAssistantApp</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
Expand Down Expand Up @@ -190,7 +200,7 @@
<errTitle>TODO</errTitle>
<icon>src/main/icons/1461509409_robot_64.ico</icon>
<classPath>
<mainClass>com.github.hronom.robocraft.assistant.app.App</mainClass>
<mainClass>com.github.hronom.robocraft.assistant.app.RobocraftAssistantApp</mainClass>
<addDependencies>true</addDependencies>
<preCp>anything</preCp>
</classPath>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
package com.github.hronom.robocraft.assistant.app;

import com.github.hronom.robocraft.assistant.app.controllers.ShootController;
import com.github.hronom.robocraft.assistant.app.models.ShooterModel;
import com.github.hronom.robocraft.assistant.app.views.AssistantMainView;
import com.github.hronom.robocraft.assistant.app.views.ShootView;
import com.github.hronom.robocraft.assistant.core.Shooter;
import com.tulskiy.keymaster.common.HotKey;
import com.tulskiy.keymaster.common.HotKeyListener;
import com.tulskiy.keymaster.common.Provider;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.concurrent.TimeUnit;

import javax.swing.*;

public class RobocraftAssistantApp {
private static final Logger logger = LogManager.getLogger();

public static void main(String[] args) throws InterruptedException, AWTException {
logger.info(RobocraftAssistantApp.class.getSimpleName());
printSystemInfo();

ShooterModel shooterModel = new ShooterModel();

ShootView shootView = new ShootView();
new ShootController(shooterModel, shootView);
new AssistantMainView(shootView);
}

/*private static final Logger logger = LogManager.getLogger();
public static void main(String[] args) {
logger.info(ScrapeDatRoomsViewApp.class.getSimpleName());
printSystemInfo();
ScrapeView scrapeView = new ScrapeView();
new ScrapeButtonController(scrapeView);
new WebsiteUrlTypingController(scrapeView);
new GrabberSelectionController(scrapeView);
new ScrapeMainView(scrapeView);
// testMotel6();
// testRedRoof();
// testRedLion();
}*/

private static void printSystemInfo() {
logger.info("Java version: " + System.getProperty("java.version"));
logger.info("Java vendor: " + System.getProperty("java.vendor"));
logger.info("Java vendor url: " + System.getProperty("java.vendor.url"));
logger.info("Java home: " + System.getProperty("java.home"));
logger.info("Java vm specification version: " +
System.getProperty("java.vm.specification.version"));
logger.info(
"Java vm specification vendor: " + System.getProperty("java.vm.specification.vendor"));
logger.info(
"Java vm specification name: " + System.getProperty("java.vm.specification.name"));
logger.info("Java vm version: " + System.getProperty("java.vm.version"));
logger.info("Java vm vendor: " + System.getProperty("java.vm.vendor"));
logger.info("Java vm name: " + System.getProperty("java.vm.name"));
logger.info(
"Java specification version: " + System.getProperty("java.specification.version"));
logger
.info("Java specification vendor: " + System.getProperty("java.specification.vendor"));
logger.info("Java specification name: " + System.getProperty("java.specification.name"));
logger.info("Java class.version: " + System.getProperty("java.class.version"));
logger.info("Java class.path: " + System.getProperty("java.class.path"));
logger.info("Java library.path: " + System.getProperty("java.library.path"));
logger.info("Java io.tmpdir: " + System.getProperty("java.io.tmpdir"));
logger.info("Java compiler: " + System.getProperty("java.compiler"));
logger.info("Java ext.dirs: " + System.getProperty("java.ext.dirs"));
logger.info("OS name: " + System.getProperty("os.name"));
logger.info("OS arch: " + System.getProperty("os.arch"));
logger.info("OS version: " + System.getProperty("os.version"));

// Total number of processors or cores available to the JVM.
logger.info("Available processors (cores): " + Runtime.getRuntime().availableProcessors());
// Total amount of free memory available to the JVM.
logger.info("Free memory (bytes): " + Runtime.getRuntime().freeMemory());
// This will return Long.MAX_VALUE if there is no preset limit.
long maxMemory = Runtime.getRuntime().maxMemory();
// Maximum amount of memory the JVM will attempt to use.
logger.info(
"Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
// Total memory currently in use by the JVM.
logger.info("Total memory (bytes): " + Runtime.getRuntime().totalMemory());
// Get a list of all filesystem roots on this system.
File[] roots = File.listRoots();
// For each filesystem root, print some info.
for (File root : roots) {
logger.info("File system root: " + root.getAbsolutePath());
logger.info("Total space (bytes): " + root.getTotalSpace());
logger.info("Free space (bytes): " + root.getFreeSpace());
logger.info("Usable space (bytes): " + root.getUsableSpace());
}
}

/*private static void testMotel6() {
final Path resultsDir = Paths.get("motel6");
final Path resultsPhotosDir = resultsDir.resolve("photos");
try {
PathsUtils.deletePathIfExists(resultsDir);
PathsUtils.createDirectoryIfNotExists(resultsDir);
PathsUtils.createDirectoryIfNotExists(resultsPhotosDir);
} catch (IOException e) {
logger.fatal(e);
}
JxBrowserGrabber jxBrowserGrabber = new JxBrowserGrabber();
String html = jxBrowserGrabber.grabContent(
"https://www.motel6.com/en/motels.nv.las-vegas.8612.html#?propertyId=8612&numGuests=1&checkinDate=2015-11-26&numNights=1&corporatePlusNumber=CP555996&travelAgentNumber=7724054");
Motel6HtmlParser dataProvider = new Motel6HtmlParser();
ArrayList<RoomInfo> roomInfos = dataProvider.parse(html, new RoomPhotoDownloader() {
@Override
public Path download(String url) {
try {
return NetworkUtils.downloadImage(url, resultsPhotosDir).toAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
});
save(roomInfos, resultsDir);
}
private static void testRedRoof() {
final Path resultsDir = Paths.get("redroof");
final Path resultsPhotosDir = resultsDir.resolve("photos");
try {
PathsUtils.deletePathIfExists(resultsDir);
PathsUtils.createDirectoryIfNotExists(resultsDir);
PathsUtils.createDirectoryIfNotExists(resultsPhotosDir);
} catch (IOException e) {
logger.fatal(e);
}
JxBrowserGrabber jxBrowserGrabber = new JxBrowserGrabber();
String html = jxBrowserGrabber.grabContent(
"https://www.redroof.com/search/index.cfm?children=0&adults=1&SearchTerm=RRI570&checkin=11/30/15&checkout=12/31/15&rooms=1");
RedRoofHtmlParser parser = new RedRoofHtmlParser();
ArrayList<RoomInfo> roomInfos = parser.parse(html, new RoomPhotoDownloader() {
@Override
public Path download(String url) {
try {
return NetworkUtils.downloadImage(url, resultsPhotosDir);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
});
save(roomInfos, resultsDir);
}
private static void testRedLion() {
final Path resultsDir = Paths.get("redlion");
final Path resultsPhotosDir = resultsDir.resolve("photos");
try {
PathsUtils.deletePathIfExists(resultsDir);
PathsUtils.createDirectoryIfNotExists(resultsDir);
PathsUtils.createDirectoryIfNotExists(resultsPhotosDir);
} catch (IOException e) {
logger.fatal(e);
}
JxBrowserGrabber jxBrowserGrabber = new JxBrowserGrabber();
String html = jxBrowserGrabber.grabContent(
"https://reservations.redlion.com/ibe/index.aspx?dt1=5367&hgID=280&hotelID=2072&langID=1&checkin=11%2F22%2F2015&checkout=11%2F23%2F2015&adults=1&children=0&destination=Settle%20Inn%20%26%20Suites%20Harlan#ws-rsftr-0");
RedLionHtmlParser parser = new RedLionHtmlParser();
ArrayList<RoomInfo> roomInfos = parser.parse(html, new RoomPhotoDownloader() {
@Override
public Path download(String url) {
try {
return NetworkUtils.downloadImage(url, resultsPhotosDir).toAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
});
save(roomInfos, resultsDir);
}
private static void save(ArrayList<RoomInfo> roomInfos, Path resultsPath) {
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
CsvSchema schema = mapper.schemaFor(RoomInfo.class).withColumnSeparator(',').withHeader();
try (BufferedWriter bw = Files.newBufferedWriter(resultsPath.resolve("results.csv"))) {
mapper.writer(schema).writeValues(bw).writeAll(roomInfos);
} catch (IOException e) {
e.printStackTrace();
}
}*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.hronom.robocraft.assistant.app.controllers;

import com.github.hronom.robocraft.assistant.app.models.ShooterModel;
import com.github.hronom.robocraft.assistant.app.views.ShootView;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ShootController {
public ShootController(ShooterModel shooterModel, ShootView shootViewArg) {
shootViewArg.addApplySettingsButtonActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
shooterModel.set(
shootViewArg.key().toUpperCase().charAt(0),
Integer.valueOf(shootViewArg.shootDelay()),
Integer.valueOf(shootViewArg.shootCount())
);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.hronom.robocraft.assistant.app.models;

import com.github.hronom.robocraft.assistant.core.Shooter;
import com.tulskiy.keymaster.common.HotKey;
import com.tulskiy.keymaster.common.HotKeyListener;
import com.tulskiy.keymaster.common.Provider;

import java.awt.*;

import javax.swing.*;

public class ShooterModel {
private final Provider provider = Provider.getCurrentProvider(true);
private Shooter shooter;

public ShooterModel() throws AWTException, InterruptedException {
shooter = new Shooter();
}

public void set(Character keyChar, int shootDelay, int shootCount) {
provider.reset();
provider.register(KeyStroke.getKeyStroke(String.valueOf(keyChar)), new HotKeyListener() {
public void onHotKey(HotKey hotKey) {
shooter.toggle();
}
});
shooter.resetAndStart(shootDelay, shootCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.hronom.robocraft.assistant.app.views;

import java.awt.*;
import java.net.URL;
import java.util.ArrayList;

import javax.swing.*;

public class AssistantMainView {
public AssistantMainView(ShootView shootView) {
JPanel mainPanel = new JPanel();
mainPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));

GridBagLayout layout = new GridBagLayout();
mainPanel.setLayout(layout);

GridBagConstraints constraint = new GridBagConstraints();
constraint.insets = new Insets(3, 3, 3, 3);
constraint.weightx = 1;
constraint.weighty = 1;
constraint.gridx = 0;
constraint.gridy = 0;
constraint.gridwidth = 1;
constraint.gridheight = 1;
constraint.fill = GridBagConstraints.BOTH;
mainPanel.add(shootView, constraint);

ArrayList<Image> images = new ArrayList<>();
images.add(getImage("1461511403_robot_64.png"));

JFrame frame = new JFrame("Robocraft assistant");
frame.setIconImages(images);
frame.setContentPane(mainPanel);
frame.setPreferredSize(new Dimension(500, 150));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

private Image getImage(String fileName) {
URL url = this.getClass().getResource(fileName);
ImageIcon imageIcon = new ImageIcon(url);
return imageIcon.getImage();
}
}
Loading

0 comments on commit 7bef78a

Please sign in to comment.