-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
520 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/App.java
This file was deleted.
Oops, something went wrong.
209 changes: 209 additions & 0 deletions
209
...nt-app/src/main/java/com/github/hronom/robocraft/assistant/app/RobocraftAssistantApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}*/ | ||
} |
22 changes: 22 additions & 0 deletions
22
.../src/main/java/com/github/hronom/robocraft/assistant/app/controllers/ShootController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
); | ||
} | ||
}); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...tant-app/src/main/java/com/github/hronom/robocraft/assistant/app/models/ShooterModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/AssistantMainView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.