Wrote a utility previewing every component
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 13 Oct 2020 22:59:29 +0000 (00:59 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 13 Oct 2020 22:59:29 +0000 (00:59 +0200)
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/OpenPreviewOfEveryComponent.java [new file with mode: 0644]

diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/OpenPreviewOfEveryComponent.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/OpenPreviewOfEveryComponent.java
new file mode 100644 (file)
index 0000000..7c47a3e
--- /dev/null
@@ -0,0 +1,56 @@
+package net.mograsim.logic.model.examples;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.gson.JsonObject;
+
+import net.mograsim.logic.model.SimpleLogicUIStandalone;
+import net.mograsim.logic.model.am2900.Am2900Loader;
+import net.mograsim.logic.model.model.components.ModelComponent;
+import net.mograsim.logic.model.model.components.atomic.ModelTextComponent;
+import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.util.JsonHandler;
+
+public class OpenPreviewOfEveryComponent
+{
+       public static void main(String[] args) throws IOException
+       {
+               Am2900Loader.setup();
+
+               List<String> allComponents = new ArrayList<>();
+
+               // TODO this is ugly. Is there a better way?
+               try (InputStream resourceAsStream = Am2900Loader.class.getResourceAsStream("standardComponentIDMapping.json"))
+               {
+                       allComponents.addAll(JsonHandler.readJson(resourceAsStream, JsonObject.class).keySet());
+               }
+               try (InputStream resourceAsStream = IndirectModelComponentCreator.class.getResourceAsStream("standardComponentIDMapping.json"))
+               {
+                       allComponents.addAll(JsonHandler.readJson(resourceAsStream, JsonObject.class).keySet());
+               }
+
+               Collections.sort(allComponents, String::compareToIgnoreCase);
+
+               SimpleLogicUIStandalone.executeVisualisation(model ->
+               {
+                       int y = 0;
+                       for (String componentID : allComponents)
+                               try
+                               {
+                                       ModelComponent createComponent = IndirectModelComponentCreator.createComponent(model, componentID);
+                                       createComponent.moveTo(0, y);
+                                       new ModelTextComponent(model, componentID).moveTo(createComponent.getWidth() + 10, y);
+                                       y += createComponent.getHeight() + 10;
+                               }
+                               catch (RuntimeException e)
+                               {
+                                       new ModelTextComponent(model, "Error creating " + componentID + ": " + e).moveTo(0, y);
+                                       y += 20;
+                               }
+               });
+       }
+}