screen capture tool now reads .ini and starts to generate .xml

This commit is contained in:
rusefi 2020-04-26 01:28:29 -04:00
parent cd27f0cd81
commit db35cf7fbe
7 changed files with 120 additions and 23 deletions

View File

@ -17,5 +17,15 @@
</library>
</orderEntry>
<orderEntry type="library" name="junit" level="project" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -2,6 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/../../java_console/inifile/inifile.iml" filepath="$PROJECT_DIR$/../../java_console/inifile/inifile.iml" />
<module fileurl="file://$PROJECT_DIR$/screen/screen.iml" filepath="$PROJECT_DIR$/screen/screen.iml" />
</modules>
</component>

View File

@ -10,5 +10,6 @@
<orderEntry type="library" name="TunerStudioMS" level="project" />
<orderEntry type="library" name="serial" level="project" />
<orderEntry type="library" name="3rd_party" level="project" />
<orderEntry type="module" module-name="inifile" />
</component>
</module>

View File

@ -0,0 +1,23 @@
import com.rusefi.ScreenGenerator;
public class ScreenCaptureLauncher {
public static void main(String[] args) throws Exception {
startTunerStudio(args);
ScreenGenerator.main(args);
}
private static void startTunerStudio(String[] args) {
Thread t = new Thread(() -> {
try {
TunerStudio.main(args);
} catch (Exception e) {
e.printStackTrace();
throw new IllegalStateException(e);
}
});
t.setDaemon(false);
t.start();
}
}

View File

@ -0,0 +1,18 @@
package com.rusefi;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;
@XmlRootElement
public class Content {
private List<TopLevelMenu> menus = new ArrayList<>();
@XmlElementWrapper
@XmlElement(name = "keyword")
public List<TopLevelMenu> getTopLevelMenus() {
return menus;
}
}

View File

@ -1,13 +1,18 @@
package com.rusefi;
import com.opensr5.ini.IniFileModel;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RasterFormatException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@ -21,15 +26,14 @@ public class ScreenGenerator {
private static final String DESTINATION = "images" + File.separator;
public static void main(String[] args) throws InterruptedException, InvocationTargetException, IOException, AWTException {
static Content content = new Content();
public static void main(String[] args) throws Exception {
IniFileModel iniFileModel = new IniFileModel();
iniFileModel.readIniFile("../../firmware/tunerstudio");
new File(DESTINATION).mkdirs();
Thread t = new Thread(() -> TunerStudio.main(args));
t.setDaemon(false);
t.start();
Frame mainFrame = findMainFrame();
while (topLevelButtons.isEmpty()) {
@ -48,9 +52,22 @@ public class ScreenGenerator {
System.out.println("Done discovering buttons, " + topLevelButtons.size());
doJob(mainFrame);
handleTopLevelButtons(mainFrame, topLevelButtons);
}
private static void writeXml(Content content) throws JAXBException, IOException {
JAXBContext jaxbContext = JAXBContext.newInstance(Content.class);
Marshaller marshaller = jaxbContext.createMarshaller();
StringWriter xmlWriter = new StringWriter();
marshaller.marshal(content, xmlWriter);
System.out.println(xmlWriter.toString());
marshaller.marshal(content, new FileWriter("output.xml"));
}
private static Frame findMainFrame() throws InterruptedException {
while (true) {
Frame[] all = JFrame.getFrames();
@ -108,19 +125,23 @@ public class ScreenGenerator {
return component instanceof bi.b;
}
private static void doJob(Frame frame) throws InterruptedException, InvocationTargetException, IOException, AWTException {
private static void handleTopLevelButtons(Frame frame, ArrayList<AbstractButton> topLevelButtons) throws Exception {
printAllDialogs("Dialogs before clicking ", JDialog.getWindows());
for (AbstractButton topLevel : topLevelButtons) {
handleTopLevelButton(frame, topLevel);
}
}
private static void handleTopLevelButton(Frame frame, AbstractButton topLevel) throws InterruptedException, InvocationTargetException, IOException {
private static void handleTopLevelButton(Frame frame, AbstractButton topLevel) throws Exception {
SwingUtilities.invokeAndWait(topLevel::doClick);
Thread.sleep(TOP_MENU_CLICK_DELAY);
content.getTopLevelMenus().add(new TopLevelMenu(topLevel.getText()));
writeXml(content);
ImageIO.write(
getScreenShot(frame),
"png",
@ -134,20 +155,13 @@ public class ScreenGenerator {
}
private static void handleMenuItem(JMenuItem menuItem) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
menuItem.doClick();
}
});
SwingUtilities.invokeAndWait(menuItem::doClick);
Thread.sleep(MENU_CLICK_DELAY);
AtomicReference<JDialog> ref = new AtomicReference<>();
SwingUtilities.invokeAndWait(() -> {
ref.set(findDynamicDialog());
});
SwingUtilities.invokeAndWait(() -> ref.set(findDynamicDialog()));
// let's give it time to appear on the screen
Thread.sleep(MENU_CLICK_DELAY);
JDialog dialog = ref.get();

View File

@ -0,0 +1,30 @@
package com.rusefi;
import com.opensr5.ini.DialogModel;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.ArrayList;
import java.util.List;
public class TopLevelMenu {
private final String title;
@XmlElementWrapper
@XmlElement(name = "dialog")
private List<DialogModel> dialogs = new ArrayList<>();
public TopLevelMenu(String title) {
this.title = title;
}
@XmlAttribute
public String getTitle() {
return title;
}
public List<DialogModel> getDialogs() {
return dialogs;
}
}