Skip to content

Commit

Permalink
Add cli option to take a screenshot every measurement (usibility conf…
Browse files Browse the repository at this point in the history
…irmed)
  • Loading branch information
pskowronek committed Dec 9, 2018
1 parent c81fa86 commit a3f0c46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 9 additions & 3 deletions desktop/src/main/java/pmstation/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pmstation.configuration.Constants;
import pmstation.observers.CSVObserver;
import pmstation.observers.ConsoleObserver;
import pmstation.observers.UIScreenShotObserver;
import pmstation.plantower.PlanTowerSensor;

public class Start {
Expand Down Expand Up @@ -61,7 +62,12 @@ public static void main(String[] args) {
setLookAndFeel();
PlanTowerSensor planTowerSensor = new PlanTowerSensor();
Station station = new Station(planTowerSensor);
SwingUtilities.invokeLater(() -> { station.showUI(); });
SwingUtilities.invokeLater(() -> {
station.showUI();
if (line.hasOption("screenshot")) {
planTowerSensor.addObserver(new UIScreenShotObserver(station.getJFrame(), line.getOptionValue("screenshot")));
}
});
}
} catch (ParseException e) {
logger.error("Ooops", e);
Expand Down Expand Up @@ -89,10 +95,10 @@ private static void setLookAndFeel() {

private static Options getOptions() {
Options options = new Options();
//options.addOption("noui", false, "no UI, console only");
options.addOption("h", "help", false, "print this message and exit");
options.addOption("c", "headless", false, "headless mode (cli mode) - autostarts measurements based on config");
options.addOption("v", "version", false, "print the version information and exit");
options.addOption("s", "screenshot", true, "takes a screenshot of main window every measurment, the argument is filename where png will be (re)written");
options.addOption("v", "version", false, "print version information and exit");
return options;
}
}
4 changes: 4 additions & 0 deletions desktop/src/main/java/pmstation/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ public void setVisible(boolean visible) {
}
});
}

public JFrame getJFrame() {
return frame;
}

private void handleAutostart(JLabel labelStatus, JButton connectionBtn) {
boolean autostart = Config.instance().to().getBoolean(Config.Entry.AUTOSTART.key(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ public void screenshot(JFrame jFrame) {
BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
component.paint(image.getGraphics());
try {
ImageIO.write(image, "png", new File(screenShotPath));
File destFile = new File(screenShotPath);
File tmpFile = File.createTempFile("pm-station-screenshot", "png", destFile.getParentFile());

ImageIO.write(image, "png", tmpFile);
destFile.delete();
if (!tmpFile.renameTo(destFile)) {
logger.error("There was a problem renaming temp screenshot file to target name");
}
logger.info("Screenshot written to: {}", screenShotPath);
} catch (Exception e) {
logger.error("Error writing screenshot to {}", screenShotPath, e);
Expand Down

0 comments on commit a3f0c46

Please sign in to comment.