it mostly works!
This commit is contained in:
parent
e4093d7d62
commit
1911d07d1a
|
@ -11,9 +11,9 @@ import java.util.ArrayList;
|
||||||
public class ScreenGenerator {
|
public class ScreenGenerator {
|
||||||
public static final String TS_DIALOG = "com.efiAnalytics.ui.dg";
|
public static final String TS_DIALOG = "com.efiAnalytics.ui.dg";
|
||||||
public static final String PNG = "png";
|
public static final String PNG = "png";
|
||||||
|
private static final int MENU_CLICK_DELAY = 200;
|
||||||
private static ArrayList<AbstractButton> topLevelButtons = new ArrayList<>();
|
private static ArrayList<AbstractButton> topLevelButtons = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
private static final String DESTINATION = "images" + File.separator;
|
private static final String DESTINATION = "images" + File.separator;
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException, InvocationTargetException, IOException, AWTException {
|
public static void main(String[] args) throws InterruptedException, InvocationTargetException, IOException, AWTException {
|
||||||
|
@ -94,7 +94,7 @@ public class ScreenGenerator {
|
||||||
ImageIO.write(
|
ImageIO.write(
|
||||||
getScreenShot(frame),
|
getScreenShot(frame),
|
||||||
"png",
|
"png",
|
||||||
new File(DESTINATION + topLevel.getText() + ".png"));
|
new File(DESTINATION + cleanName(topLevel.getText()) + ".png"));
|
||||||
|
|
||||||
printAllDialogs("dialogs after clicking ", JDialog.getWindows());
|
printAllDialogs("dialogs after clicking ", JDialog.getWindows());
|
||||||
java.util.List<JMenuItem> menuItems = new ArrayList<>();
|
java.util.List<JMenuItem> menuItems = new ArrayList<>();
|
||||||
|
@ -117,23 +117,26 @@ public class ScreenGenerator {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
m.doClick();
|
m.doClick();
|
||||||
Thread.sleep(500);
|
Thread.sleep(MENU_CLICK_DELAY);
|
||||||
|
|
||||||
JDialog d = findDialog();
|
JDialog d = findDialog();
|
||||||
|
if (d == null) {
|
||||||
|
// this happens for example for disabled menu items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Robot robot = new Robot();
|
// Robot robot = new Robot();
|
||||||
Rectangle captureRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
// Rectangle captureRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||||
BufferedImage screenFullImage = robot.createScreenCapture(captureRect);
|
// BufferedImage screenFullImage = robot.createScreenCapture(captureRect);
|
||||||
ImageIO.write(screenFullImage, PNG, new File(DESTINATION + "full_" + d.getTitle() + ".png"));
|
// ImageIO.write(screenFullImage, PNG, new File(DESTINATION + "full_" + d.getTitle() + ".png"));
|
||||||
|
|
||||||
ImageIO.write(
|
ImageIO.write(
|
||||||
getScreenShot(d),
|
getScreenShot(d),
|
||||||
PNG,
|
PNG,
|
||||||
new File(DESTINATION + d.getTitle() + ".png"));
|
new File(DESTINATION + cleanName(d.getTitle()) + ".png"));
|
||||||
Thread.sleep(100);
|
|
||||||
d.setVisible(false);
|
d.setVisible(false);
|
||||||
d.dispose();
|
d.dispose();
|
||||||
} catch (IOException | InterruptedException | AWTException e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,13 +150,23 @@ public class ScreenGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String cleanName(String title) {
|
||||||
|
title = title.replace(' ', '_');
|
||||||
|
title = title.replace(")", "");
|
||||||
|
title = title.replace("(", "");
|
||||||
|
title = title.replace('/', '_');
|
||||||
|
title = title.replace('\\', '_');
|
||||||
|
title = title.replace(" ", " ");
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
private static JDialog findDialog() {
|
private static JDialog findDialog() {
|
||||||
for (Window d : Dialog.getWindows()) {
|
for (Window d : Dialog.getWindows()) {
|
||||||
if (d.getClass().getName().equals(TS_DIALOG) && d.isVisible()) {
|
if (d.getClass().getName().equals(TS_DIALOG) && d.isVisible()) {
|
||||||
return (JDialog) d;
|
return (JDialog) d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Not found");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printAllDialogs(String message, Window[] windows) {
|
private static void printAllDialogs(String message, Window[] windows) {
|
||||||
|
|
Loading…
Reference in New Issue