From 9704cfa108f083dd26df0b4c223c3b6cd40b5f69 Mon Sep 17 00:00:00 2001 From: Joonas Vali Date: Sun, 28 Apr 2019 11:39:45 +0300 Subject: [PATCH] prep 2.0.1 and polish SystemDiagnosis class a bit --- pom.xml | 2 +- .../naturalmouse/tools/SystemDiagnosis.java | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9abb343..2bbabe1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.joonasvali.naturalmouse naturalmouse - 2.0.1-SNAPSHOT + 2.0.1 Natural Mouse Motion https://github.com/JoonasVali/NaturalMouseMotion This library provides a way to move cursor to specified coordinates on screen reliably, diff --git a/src/main/java/com/github/joonasvali/naturalmouse/tools/SystemDiagnosis.java b/src/main/java/com/github/joonasvali/naturalmouse/tools/SystemDiagnosis.java index 01c357d..9919a31 100644 --- a/src/main/java/com/github/joonasvali/naturalmouse/tools/SystemDiagnosis.java +++ b/src/main/java/com/github/joonasvali/naturalmouse/tools/SystemDiagnosis.java @@ -9,11 +9,14 @@ public class SystemDiagnosis { - public static void main(String[] args) { - new SystemDiagnosis().validateMouseMovement(); - } - - public void validateMouseMovement() { + /** + * Runs a diagnosis with default configuration, by setting mouse all over your screen and expecting to receive + * correct coordinates back. + * If java.awt.Robot cannot be constructed, then new RuntimeException is thrown. + * If no issues are found, then this method completes without throwing an error, otherwise IllegalStateException is + * thrown. + */ + public static void validateMouseMovement() { try { Robot robot = new Robot(); validateMouseMovement(new DefaultSystemCalls(robot), new DefaultMouseInfoAccessor()); @@ -22,7 +25,14 @@ public void validateMouseMovement() { } } - public void validateMouseMovement(SystemCalls system, MouseInfoAccessor accessor) { + /** + * Runs a diagnosis, by setting mouse all over your screen and expecting to receive correct coordinates back. + * If no issues are found, then this method completes without throwing an error, otherwise IllegalStateException is + * thrown. + * @param system a SystemCalls class which is used for setting the mouse position + * @param accessor a MouseInfoAccessor which is used for querying mouse position + */ + public static void validateMouseMovement(SystemCalls system, MouseInfoAccessor accessor) { Dimension dimension = system.getScreenSize(); for (int y = 0; y < dimension.height; y += 50) { for (int x = 0; x < dimension.width; x += 50) { @@ -36,7 +46,7 @@ public void validateMouseMovement(SystemCalls system, MouseInfoAccessor accessor Point p = accessor.getMousePosition(); if (x != p.x || y != p.y) { - throw new IllegalArgumentException( + throw new IllegalStateException( "Tried to move mouse to (" + x + ", " + y + "). Actually moved to (" + p.x + ", " + p.y + ")" + "This means NaturalMouseMotion is not able to work optimally on this system as the cursor move " + "calls may miss the target pixels on the screen."