screen generator
This commit is contained in:
parent
da402193e4
commit
f2e7e825be
|
@ -21,10 +21,14 @@ public class IniFileModel {
|
|||
// this is only used while reading model - TODO extract reader
|
||||
private List<DialogModel.Field> fieldsOfCurrentDialog = new ArrayList<>();
|
||||
|
||||
public Map<String, String> tooltips = new TreeMap<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(IniFileModel.getInstance("..").dialogs);
|
||||
}
|
||||
|
||||
static boolean isInSettingContextHelp = false;
|
||||
|
||||
public void readIniFile(String iniFilePath) {
|
||||
String fileName = findMetaInfoFile(iniFilePath);
|
||||
File input = null;
|
||||
|
@ -35,6 +39,7 @@ public class IniFileModel {
|
|||
return;
|
||||
}
|
||||
|
||||
System.out.println("Reading " + fileName);
|
||||
RawIniFile content = IniFileReader.read(input);
|
||||
|
||||
|
||||
|
@ -68,23 +73,42 @@ public class IniFileModel {
|
|||
}
|
||||
|
||||
private void handleLine(RawIniFile.Line line) {
|
||||
|
||||
String rawTest = line.getRawText();
|
||||
try {
|
||||
LinkedList<String> list = new LinkedList<>(Arrays.asList(line.getTokens()));
|
||||
|
||||
// todo: use TSProjectConsumer constant
|
||||
if (isInSettingContextHelp) {
|
||||
// todo: use TSProjectConsumer constant
|
||||
if (rawTest.contains("SettingContextHelpEnd")) {
|
||||
isInSettingContextHelp = false;
|
||||
}
|
||||
if (list.size() == 2)
|
||||
tooltips.put(list.get(0), list.get(1));
|
||||
return;
|
||||
} else if (rawTest.contains("SettingContextHelp")) {
|
||||
isInSettingContextHelp = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (RawIniFile.Line.isCommentLine(rawTest))
|
||||
return;
|
||||
|
||||
trim(list);
|
||||
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
String first = list.getFirst();
|
||||
|
||||
|
||||
if ("dialog".equals(first)) {
|
||||
handleDialog(list);
|
||||
|
||||
} else if ("field".equals(first)) {
|
||||
handleField(list);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalStateException("While [" + line.getRawText() + "]", e);
|
||||
throw new IllegalStateException("While [" + rawTest + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,9 @@ public class IniFileReader {
|
|||
return c == ' ' || c == '\t' || c == '=' || c == ',';
|
||||
}
|
||||
|
||||
/**
|
||||
* Just grabs an collecton of lines, no parsing logic here
|
||||
*/
|
||||
public static RawIniFile read(InputStream in) {
|
||||
List<RawIniFile.Line> lines = new ArrayList<>();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
|
@ -61,8 +64,7 @@ public class IniFileReader {
|
|||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.trim().isEmpty() || RawIniFile.Line.isCommentLine(line)) {
|
||||
// let's skip comments right here
|
||||
if (line.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
lines.add(new RawIniFile.Line(line));
|
||||
|
|
|
@ -91,5 +91,13 @@ public class RawIniFile {
|
|||
public String getRawText() {
|
||||
return rawText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Line{" +
|
||||
"rawText='" + rawText + '\'' +
|
||||
", tokens=" + Arrays.toString(tokens) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -16,6 +16,8 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
private static final String CONFIG_DEFINITION_START = "CONFIG_DEFINITION_START";
|
||||
private static final String CONFIG_DEFINITION_END = "CONFIG_DEFINITION_END";
|
||||
private static final String TS_CONDITION = "@@if_";
|
||||
public static final String SETTING_CONTEXT_HELP_END = "SettingContextHelpEnd";
|
||||
public static final String SETTING_CONTEXT_HELP = "SettingContextHelp";
|
||||
public static String TS_FILE_OUTPUT_NAME = "rusefi.ini";
|
||||
private StringBuilder settingContextHelp = new StringBuilder();
|
||||
|
||||
|
@ -119,8 +121,9 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
tsHeader.write("page = 1" + ConfigDefinition.EOL);
|
||||
tsHeader.write(fieldsSection);
|
||||
if (settingContextHelp.length() > 0) {
|
||||
tsHeader.write("[SettingContextHelp]" + ConfigDefinition.EOL);
|
||||
tsHeader.write("[" + SETTING_CONTEXT_HELP + "]" + ConfigDefinition.EOL);
|
||||
tsHeader.write(settingContextHelp.toString() + ConfigDefinition.EOL + ConfigDefinition.EOL);
|
||||
tsHeader.write("; " + SETTING_CONTEXT_HELP_END + ConfigDefinition.EOL);
|
||||
}
|
||||
tsHeader.write("; " + CONFIG_DEFINITION_END + ConfigDefinition.EOL);
|
||||
tsHeader.write(tsContent.getPostfix());
|
||||
|
|
|
@ -42,12 +42,26 @@ public class ScreenGenerator {
|
|||
byCleanUiName.put(cleanUiName, a.getValue());
|
||||
}
|
||||
|
||||
if (byCleanUiName.isEmpty())
|
||||
throw new IllegalStateException("Something not right with input file. April 29 version is needed");
|
||||
|
||||
|
||||
System.out.println("mkdirs " + DESTINATION);
|
||||
new File(DESTINATION).mkdirs();
|
||||
|
||||
System.out.println("Launching TunerStudioIntegraion");
|
||||
Frame mainFrame = TunerStudioIntegraion.findMainFrame();
|
||||
|
||||
waitForMainFrame(mainFrame);
|
||||
|
||||
System.out.println("Done discovering buttons, " + topLevelButtons.size());
|
||||
|
||||
handleTopLevelButtons(mainFrame, topLevelButtons);
|
||||
|
||||
XmlUtil.writeXml(content);
|
||||
}
|
||||
|
||||
private static void waitForMainFrame(Frame mainFrame) throws InterruptedException {
|
||||
while (topLevelButtons.isEmpty()) {
|
||||
UiUtils.visitComponents(mainFrame, "", (parent, component) -> {
|
||||
if (component instanceof AbstractButton) {
|
||||
|
@ -61,17 +75,12 @@ public class ScreenGenerator {
|
|||
});
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
System.out.println("Done discovering buttons, " + topLevelButtons.size());
|
||||
|
||||
handleTopLevelButtons(mainFrame, topLevelButtons);
|
||||
}
|
||||
|
||||
private static void handleTopLevelButtons(Frame frame, ArrayList<AbstractButton> topLevelButtons) throws Exception {
|
||||
for (AbstractButton topLevel : topLevelButtons) {
|
||||
handleTopLevelButton(frame, topLevel, content);
|
||||
}
|
||||
XmlUtil.writeXml(content);
|
||||
}
|
||||
|
||||
private static void handleTopLevelButton(Frame frame, AbstractButton topLevel, Content content) throws Exception {
|
||||
|
@ -108,7 +117,10 @@ public class ScreenGenerator {
|
|||
return;
|
||||
}
|
||||
|
||||
DialogDescription dialogDescription = new DialogDescription();
|
||||
String dialogTitle = dialog.getTitle();
|
||||
|
||||
|
||||
DialogDescription dialogDescription = new DialogDescription(dialogTitle);
|
||||
topLevelMenu.getDialogs().add(dialogDescription);
|
||||
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
|
@ -129,7 +141,7 @@ public class ScreenGenerator {
|
|||
ImageIO.write(
|
||||
dialogScreenShot,
|
||||
PNG,
|
||||
new File(DESTINATION + cleanName(dialog.getTitle()) + ".png"));
|
||||
new File(DESTINATION + cleanName(dialogTitle) + ".png"));
|
||||
dialog.setVisible(false);
|
||||
dialog.dispose();
|
||||
} catch (Exception e) {
|
||||
|
@ -170,7 +182,10 @@ public class ScreenGenerator {
|
|||
if (f == null)
|
||||
continue;
|
||||
|
||||
dialogDescription.fields.add(new FieldDescription(sectionNameWithSpecialCharacters, f.getKey(), fileName));
|
||||
String fieldName = f.getKey();
|
||||
String tooltip = iniFileModel.tooltips.get(fieldName);
|
||||
|
||||
dialogDescription.fields.add(new FieldDescription(sectionNameWithSpecialCharacters, fieldName, fileName, tooltip));
|
||||
|
||||
File output = new File(DESTINATION + fileName);
|
||||
if (output == null) {
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
package com.rusefi.xml;
|
||||
|
||||
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 DialogDescription {
|
||||
private final String dialogTitle;
|
||||
@XmlElementWrapper
|
||||
@XmlElement(name = "field")
|
||||
public List<FieldDescription> fields = new ArrayList<>();
|
||||
|
||||
public DialogDescription(String dialogTitle) {
|
||||
this.dialogTitle = dialogTitle;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getDialogTitle() {
|
||||
return dialogTitle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ public class FieldDescription {
|
|||
private final String uiName;
|
||||
private final String fieldName;
|
||||
private final String fileName;
|
||||
private final String tooltip;
|
||||
|
||||
public FieldDescription(String uiName, String fieldName, String fileName) {
|
||||
public FieldDescription(String uiName, String fieldName, String fileName, String tooltip) {
|
||||
this.uiName = uiName;
|
||||
this.fieldName = fieldName;
|
||||
this.fileName = fileName;
|
||||
this.tooltip = tooltip == null ? "" : tooltip;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
|
@ -28,4 +30,9 @@ public class FieldDescription {
|
|||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import java.io.IOException;
|
|||
import java.io.StringWriter;
|
||||
|
||||
public class XmlUtil {
|
||||
|
||||
public static final String FILE_NAME = "output.xml";
|
||||
|
||||
public static void writeXml(Content content) throws JAXBException, IOException {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(Content.class);
|
||||
|
||||
|
@ -17,6 +20,8 @@ public class XmlUtil {
|
|||
marshaller.marshal(content, xmlWriter);
|
||||
System.out.println(xmlWriter.toString());
|
||||
|
||||
marshaller.marshal(content, new FileWriter("output.xml"));
|
||||
System.out.println("Writing " + FILE_NAME);
|
||||
marshaller.marshal(content, new FileWriter(FILE_NAME));
|
||||
System.out.println("Done " + FILE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue