it mostly works!

This commit is contained in:
rusefi 2020-05-01 14:14:41 -04:00
parent 4e115c12c1
commit 2fbecab905
7 changed files with 156 additions and 8 deletions

View File

@ -0,0 +1,60 @@
package com.rusefi;
import com.rusefi.xml.*;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
public class MdGenerator {
static String FOLDER;
private static final String EOL = "\r\n";
public static void main(String[] args) throws Exception {
// FOLDER = "images/";
FOLDER = "overview/TS_generated/";
ContentModel contentModel = XmlUtil.readModel();
FileWriter md = new FileWriter("rusEFI_project.md");
for (TopLevelMenuModel topLevelMenuModel : contentModel.getTopLevelMenus()) {
md.append("# " + topLevelMenuModel.getTitle() + EOL);
md.append(getImageTag(topLevelMenuModel.getImageName()));
md.append(EOL);
}
for (TopLevelMenuModel topLevelMenuModel : contentModel.getTopLevelMenus()) {
md.append("# " + topLevelMenuModel.getTitle() + EOL);
for (DialogModel dialogModel : topLevelMenuModel.getDialogs()) {
appendDialog(md, dialogModel);
}
}
md.write(EOL);
md.write("generated by " + MdGenerator.class + " on " + new Date());
md.write(EOL);
md.close();
}
private static void appendDialog(FileWriter md, DialogModel dialogModel) throws IOException {
md.append(getImageTag(dialogModel.getImageName()));
for (FieldModel fieldModel : dialogModel.fields) {
String tooltip = fieldModel.getTooltip();
if (tooltip.length() > 0) {
md.append(fieldModel.getUiName() + ": " + tooltip + EOL + EOL);
}
}
}
private static String getImageTag(String imageName) {
String IMG_SUFFIX = ")" + EOL;
String IMG_PREFIX = "![x](";
return IMG_PREFIX + FOLDER + imageName + IMG_SUFFIX;
}
}

View File

@ -57,6 +57,8 @@ public class ScreenGenerator {
System.out.println("Done discovering buttons, " + topLevelButtons.size());
Thread.sleep(2 * WAITING_FOR_FRAME_PERIOD); // we have this sleep to avoid an artifact on first screenshot
handleTopLevelButtons(mainFrame, topLevelButtons);
XmlUtil.writeXml(contentModel);

View File

@ -24,4 +24,11 @@ public class ContentModel {
public String getVersion() {
return "Generated by " + ScreenGenerator.class + " on " + new Date();
}
@Override
public String toString() {
return "ContentModel{" +
"menus=" + menus +
'}';
}
}

View File

@ -7,12 +7,15 @@ import java.util.ArrayList;
import java.util.List;
public class DialogModel {
private final String dialogTitle;
private final String imageName;
private String dialogTitle;
private String imageName;
@XmlElementWrapper
@XmlElement(name = "field")
public List<FieldModel> fields = new ArrayList<>();
public DialogModel() {
}
public DialogModel(String dialogTitle, String imageName) {
this.dialogTitle = dialogTitle;
this.imageName = imageName;
@ -23,8 +26,25 @@ public class DialogModel {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
@XmlAttribute
public String getDialogTitle() {
return dialogTitle;
}
public void setDialogTitle(String dialogTitle) {
this.dialogTitle = dialogTitle;
}
@Override
public String toString() {
return "DialogModel{" +
"dialogTitle='" + dialogTitle + '\'' +
", imageName='" + imageName + '\'' +
", fields=" + fields +
'}';
}
}

View File

@ -4,10 +4,13 @@ import javax.xml.bind.annotation.XmlAttribute;
public class FieldModel {
private final String uiName;
private final String fieldName;
private final String imageName;
private final String tooltip;
private String uiName;
private String fieldName;
private String imageName;
private String tooltip;
public FieldModel() {
}
public FieldModel(String uiName, String fieldName, String fileName, String tooltip) {
this.uiName = uiName;
@ -21,18 +24,44 @@ public class FieldModel {
return uiName;
}
public void setUiName(String uiName) {
this.uiName = uiName;
}
@XmlAttribute
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
@XmlAttribute
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
@XmlAttribute
public String getTooltip() {
return tooltip;
}
public void setTooltip(String tooltip) {
this.tooltip = tooltip;
}
@Override
public String toString() {
return "FieldModel{" +
"uiName='" + uiName + '\'' +
", fieldName='" + fieldName + '\'' +
", imageName='" + imageName + '\'' +
", tooltip='" + tooltip + '\'' +
'}';
}
}

View File

@ -7,13 +7,16 @@ import java.util.ArrayList;
import java.util.List;
public class TopLevelMenuModel {
private final String title;
private final String imageName;
private String title;
private String imageName;
@XmlElementWrapper
@XmlElement(name = "dialog")
private List<DialogModel> dialogs = new ArrayList<>();
public TopLevelMenuModel() {
}
public TopLevelMenuModel(String title, String imageName) {
this.title = title;
this.imageName = imageName;
@ -24,12 +27,29 @@ public class TopLevelMenuModel {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@XmlAttribute
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
public List<DialogModel> getDialogs() {
return dialogs;
}
@Override
public String toString() {
return "TopLevelMenuModel{" +
"title='" + title + '\'' +
", imageName='" + imageName + '\'' +
", dialogs=" + dialogs +
'}';
}
}

View File

@ -3,6 +3,8 @@ package com.rusefi.xml;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
@ -24,4 +26,12 @@ public class XmlUtil {
marshaller.marshal(contentModel, new FileWriter(FILE_NAME));
System.out.println("Done " + FILE_NAME);
}
public static ContentModel readModel() throws Exception {
File xmlFile = new File(FILE_NAME);
JAXBContext jaxbContext;
jaxbContext = JAXBContext.newInstance(ContentModel.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return (ContentModel) jaxbUnmarshaller.unmarshal(xmlFile);
}
}