diff --git a/java_console/inifile/src/com/opensr5/ini/IniFileModel.java b/java_console/inifile/src/com/opensr5/ini/IniFileModel.java index 370096d1fc..313258d59e 100644 --- a/java_console/inifile/src/com/opensr5/ini/IniFileModel.java +++ b/java_console/inifile/src/com/opensr5/ini/IniFileModel.java @@ -21,10 +21,14 @@ public class IniFileModel { // this is only used while reading model - TODO extract reader private List fieldsOfCurrentDialog = new ArrayList<>(); + public Map 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 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); } } diff --git a/java_console/inifile/src/com/opensr5/ini/IniFileReader.java b/java_console/inifile/src/com/opensr5/ini/IniFileReader.java index fc74ff070a..00cd71a91b 100644 --- a/java_console/inifile/src/com/opensr5/ini/IniFileReader.java +++ b/java_console/inifile/src/com/opensr5/ini/IniFileReader.java @@ -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 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)); diff --git a/java_console/inifile/src/com/opensr5/ini/RawIniFile.java b/java_console/inifile/src/com/opensr5/ini/RawIniFile.java index 03e60ab87d..c034fd61de 100644 --- a/java_console/inifile/src/com/opensr5/ini/RawIniFile.java +++ b/java_console/inifile/src/com/opensr5/ini/RawIniFile.java @@ -91,5 +91,13 @@ public class RawIniFile { public String getRawText() { return rawText; } + + @Override + public String toString() { + return "Line{" + + "rawText='" + rawText + '\'' + + ", tokens=" + Arrays.toString(tokens) + + '}'; + } } } diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index fbe4f0887a..dfb0c6f0ee 100644 Binary files a/java_tools/ConfigDefinition.jar and b/java_tools/ConfigDefinition.jar differ diff --git a/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java b/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java index 14aa502e53..958f78e0d9 100644 --- a/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java +++ b/java_tools/configuration_definition/src/com/rusefi/output/TSProjectConsumer.java @@ -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()); diff --git a/java_tools/ts_screenshots/screen/src/com/rusefi/ScreenGenerator.java b/java_tools/ts_screenshots/screen/src/com/rusefi/ScreenGenerator.java index 1c2618701f..31109e9caf 100644 --- a/java_tools/ts_screenshots/screen/src/com/rusefi/ScreenGenerator.java +++ b/java_tools/ts_screenshots/screen/src/com/rusefi/ScreenGenerator.java @@ -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 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) { diff --git a/java_tools/ts_screenshots/screen/src/com/rusefi/xml/DialogDescription.java b/java_tools/ts_screenshots/screen/src/com/rusefi/xml/DialogDescription.java index 019d79121f..6be150a835 100644 --- a/java_tools/ts_screenshots/screen/src/com/rusefi/xml/DialogDescription.java +++ b/java_tools/ts_screenshots/screen/src/com/rusefi/xml/DialogDescription.java @@ -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 fields = new ArrayList<>(); + + public DialogDescription(String dialogTitle) { + this.dialogTitle = dialogTitle; + } + + @XmlAttribute + public String getDialogTitle() { + return dialogTitle; + } } diff --git a/java_tools/ts_screenshots/screen/src/com/rusefi/xml/FieldDescription.java b/java_tools/ts_screenshots/screen/src/com/rusefi/xml/FieldDescription.java index 529ee515bf..9e2f2ab0ae 100644 --- a/java_tools/ts_screenshots/screen/src/com/rusefi/xml/FieldDescription.java +++ b/java_tools/ts_screenshots/screen/src/com/rusefi/xml/FieldDescription.java @@ -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; + } } diff --git a/java_tools/ts_screenshots/screen/src/com/rusefi/xml/XmlUtil.java b/java_tools/ts_screenshots/screen/src/com/rusefi/xml/XmlUtil.java index 43c7294340..89bfc07482 100644 --- a/java_tools/ts_screenshots/screen/src/com/rusefi/xml/XmlUtil.java +++ b/java_tools/ts_screenshots/screen/src/com/rusefi/xml/XmlUtil.java @@ -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); } }