use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class HelperFunctions method printFields.
public static void printFields(Object o, Class c) {
try {
Field[] fields = c.getDeclaredFields();
if (fields.length > 0) {
System.out.println("*HTML*Fields from class <b>" + c.getSimpleName() + "</b>:");
System.out.println("<ul>");
for (Field field : fields) {
field.setAccessible(true);
System.out.println("<li>" + field.getName() + " : " + field.get(o) + "</li>");
}
System.out.println("</ul>");
System.out.println("");
}
if (c.getSuperclass() != null) {
printFields(o, c.getSuperclass());
}
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Couldn't get value of field");
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class HelperFunctions method callMethod.
public static Object callMethod(Object o, String method, boolean runLater) {
robotLog("INFO", "Calling method " + method + " of object " + o);
Class c = o.getClass();
try {
Method m = c.getMethod(method, null);
try {
if (!runLater) {
return m.invoke(o, null);
} else {
Platform.runLater(() -> {
try {
m.invoke(o, null);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
}
});
}
} catch (InvocationTargetException | IllegalAccessException e) {
throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
}
} catch (NoSuchMethodException e) {
throw new JavaFXLibraryNonFatalException(c + " has no method \"" + method + "()\"");
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
}
return null;
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class HelperFunctions method callMethod.
public static Object callMethod(Object o, String method, List<Object> arguments, List<Object> argumentTypes, boolean runLater) {
robotLog("INFO", "Calling method \"" + method + "\" of object \"" + o + "\" with arguments \"" + Arrays.toString(arguments.toArray()) + "\"");
Class c = o.getClass();
List<Class> aTypes = new ArrayList<>();
for (Object className : argumentTypes) aTypes.add(parseClass((String) className));
try {
Method m = c.getMethod(method, aTypes.toArray(new Class[aTypes.size()]));
if (!runLater) {
try {
return m.invoke(o, arguments.toArray());
} catch (IllegalAccessException | InvocationTargetException e) {
throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
}
} else {
Platform.runLater(() -> {
try {
m.invoke(o, arguments.toArray());
} catch (IllegalAccessException | InvocationTargetException e) {
throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
}
});
}
} catch (NoSuchMethodException e) {
throw new JavaFXLibraryNonFatalException(c + " has no method \"" + method + "\" with arguments " + Arrays.toString(aTypes.toArray()));
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage(), e);
}
return null;
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class HelperFunctions method objectToBounds.
public static Bounds objectToBounds(Object object) {
if (object instanceof Window) {
return new BoundingBox(((Window) object).getX(), ((Window) object).getY(), ((Window) object).getWidth(), ((Window) object).getHeight());
} else if (object instanceof Scene) {
return new BoundingBox(((Scene) object).getX() + ((Scene) object).getWindow().getX(), ((Scene) object).getY() + ((Scene) object).getWindow().getY(), ((Scene) object).getWidth(), ((Scene) object).getHeight());
} else if (object instanceof Point2D) {
return robot.bounds((Point2D) object).query();
} else if (object instanceof Node) {
return robot.bounds((Node) object).query();
} else if (object instanceof String) {
waitUntilExists((String) object, waitUntilTimeout, "SECONDS");
Node node = robot.lookup((String) object).query();
return robot.bounds(node).query();
} else if (object instanceof Bounds) {
return (Bounds) object;
} else if (object instanceof PointQuery) {
return robot.bounds(((PointQuery) object).query()).query();
} else if (object instanceof Rectangle2D) {
Rectangle2D r2 = (Rectangle2D) object;
return new BoundingBox(r2.getMinX(), r2.getMinY(), r2.getWidth(), r2.getHeight());
} else
throw new JavaFXLibraryNonFatalException("Unsupported parameter type: " + object.toString());
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class HelperFunctions method waitUntilExists.
public static Node waitUntilExists(String target, int timeout, String timeUnit) {
robotLog("TRACE", "Waiting until target \"" + target.toString() + "\" becomes existent, timeout=" + Integer.toString(timeout) + ", timeUnit=" + timeUnit);
try {
Awaitility.setDefaultTimeout(timeout, getTimeUnit(timeUnit));
AtomicReference<Node> node = new AtomicReference<>();
Awaitility.await().until(() -> {
node.set(robot.lookup(target).query());
return node.get() != null;
});
robotLog("TRACE", "Node located: \"" + node.get().toString() + "\"");
return node.get();
} catch (ConditionTimeoutException e) {
throw new JavaFXLibraryNonFatalException("Given element \"" + target.toString() + "\" was not found within given timeout of " + Integer.toString(timeout) + " " + timeUnit);
}
}
Aggregations