Add timestamp screenshot for MacOS on debugging UI
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bef4913447
commit
8ef9ea9288
@ -1,8 +1,6 @@
|
|||||||
# autosqueal
|
# autosqueal
|
||||||
[![Build Status](https://drone.beatrice.wtf/api/badges/Tools/autosqeal/status.svg?ref=refs/heads/main)](https://drone.beatrice.wtf/Tools/autosqeal)
|
[![Build Status](https://drone.beatrice.wtf/api/badges/Tools/autosqeal/status.svg?ref=refs/heads/main)](https://drone.beatrice.wtf/Tools/autosqeal)
|
||||||
[![Quality Gate Status](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=alert_status&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
[![Quality Gate Status](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=alert_status&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
|
||||||
**Statistics**
|
|
||||||
[![Reliability Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=reliability_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
[![Reliability Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=reliability_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
[![Security Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=security_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
[![Security Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=security_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
[![Maintainability Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=sqale_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
[![Maintainability Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=sqale_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
@ -16,7 +16,6 @@ public class Main {
|
|||||||
LOGGER.info("Hello world!");
|
LOGGER.info("Hello world!");
|
||||||
|
|
||||||
registerJNativeHook();
|
registerJNativeHook();
|
||||||
|
|
||||||
mainWindow.init();
|
mainWindow.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import wtf.beatrice.autosqueal.controls.CursorMover;
|
import wtf.beatrice.autosqueal.controls.CursorMover;
|
||||||
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
|
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
|
||||||
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
||||||
|
import wtf.beatrice.autosqueal.util.SystemUtil;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -16,7 +17,7 @@ public class MainWindow
|
|||||||
{
|
{
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
|
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
|
||||||
|
|
||||||
private static final int WINDOW_HEIGHT = 600;
|
private static final int WINDOW_HEIGHT = 700;
|
||||||
private static final int WINDOW_WIDTH = 800;
|
private static final int WINDOW_WIDTH = 800;
|
||||||
|
|
||||||
private Timer timerRunner = new Timer();
|
private Timer timerRunner = new Timer();
|
||||||
@ -40,25 +41,43 @@ public class MainWindow
|
|||||||
int rescaleRateo = ((WINDOW_WIDTH - (2 * bordersPx)) * 100) / RunnerUtil.SCREEN_WIDTH;
|
int rescaleRateo = ((WINDOW_WIDTH - (2 * bordersPx)) * 100) / RunnerUtil.SCREEN_WIDTH;
|
||||||
int rescaleWidth = RunnerUtil.SCREEN_WIDTH * rescaleRateo / 100;
|
int rescaleWidth = RunnerUtil.SCREEN_WIDTH * rescaleRateo / 100;
|
||||||
int rescaleHeight = RunnerUtil.SCREEN_HEIGHT * rescaleRateo / 100;
|
int rescaleHeight = RunnerUtil.SCREEN_HEIGHT * rescaleRateo / 100;
|
||||||
JLabel imageLabel = new JLabel(getScreenCapture(rescaleWidth, rescaleHeight));
|
JLabel imageLabel = new JLabel(new ImageIcon(getScreenCapture(rescaleWidth, rescaleHeight)));
|
||||||
imageLabel.setBounds(new Rectangle(bordersPx, bordersPx, rescaleWidth, rescaleHeight));
|
imageLabel.setBounds(new Rectangle(bordersPx, bordersPx, rescaleWidth, rescaleHeight));
|
||||||
frame.add(imageLabel);
|
frame.add(imageLabel);
|
||||||
|
|
||||||
|
JLabel timestampLabel = new JLabel(new ImageIcon(getPreciseScreenshot()));
|
||||||
|
timestampLabel.setBounds(new Rectangle(bordersPx, bordersPx + rescaleHeight + bordersPx, 100, 30));
|
||||||
|
frame.add(timestampLabel);
|
||||||
|
|
||||||
frame.setLayout(null);
|
frame.setLayout(null);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageIcon getScreenCapture(int rescaleWidth, int rescaleHeight) {
|
private Image getScreenCapture(int rescaleWidth, int rescaleHeight) {
|
||||||
|
|
||||||
|
Image fullImage = getScreenCapture();
|
||||||
|
return fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image getPreciseScreenshot() {
|
||||||
|
|
||||||
|
if(SystemUtil.getHostSystem().equals(SystemUtil.OperatingSystem.MAC_OS)) {
|
||||||
|
BufferedImage screenshot = getScreenCapture();
|
||||||
|
return screenshot.getSubimage(RunnerUtil.SCREEN_WIDTH - 100,0, 100, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getScreenCapture() {
|
||||||
try {
|
try {
|
||||||
Robot robot = new Robot();
|
Robot robot = new Robot();
|
||||||
BufferedImage fullImage = robot.createScreenCapture(new Rectangle(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT));
|
return robot.createScreenCapture(new Rectangle(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT));
|
||||||
Image image = fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
|
|
||||||
return new ImageIcon(image);
|
|
||||||
} catch (AWTException e) {
|
} catch (AWTException e) {
|
||||||
LOGGER.error("Robot initialization error", e);
|
LOGGER.error("Robot initialization error", e);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleRunning() {
|
public void toggleRunning() {
|
||||||
@ -95,4 +114,5 @@ public class MainWindow
|
|||||||
toggleButton.setLabel(label);
|
toggleButton.setLabel(label);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
24
src/main/java/wtf/beatrice/autosqueal/util/SystemUtil.java
Normal file
24
src/main/java/wtf/beatrice/autosqueal/util/SystemUtil.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package wtf.beatrice.autosqueal.util;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class SystemUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
public static OperatingSystem getHostSystem() {
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
|
||||||
|
if (osName.contains("win")) {
|
||||||
|
return OperatingSystem.WINDOWS;
|
||||||
|
} else if (osName.contains("nix") || osName.contains("nux")) {
|
||||||
|
return OperatingSystem.LINUX;
|
||||||
|
} else if (osName.contains("mac")) {
|
||||||
|
return OperatingSystem.MAC_OS;
|
||||||
|
} else {
|
||||||
|
return OperatingSystem.UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum OperatingSystem {
|
||||||
|
WINDOWS, LINUX, MAC_OS, UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user