From 0da6e6a9fca133abc76b3221b15e400f31ef4943 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 14 Oct 2020 00:59:29 +0200 Subject: [PATCH] Wrote a utility previewing every component --- .../examples/OpenPreviewOfEveryComponent.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/OpenPreviewOfEveryComponent.java 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 index 00000000..7c47a3ee --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/OpenPreviewOfEveryComponent.java @@ -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 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; + } + }); + } +} -- 2.17.1