From: Daniel Kirschten Date: Tue, 13 Oct 2020 22:59:29 +0000 (+0200) Subject: Wrote a utility previewing every component X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=0da6e6a9fca133abc76b3221b15e400f31ef4943;p=Mograsim.git Wrote a utility previewing every component --- 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; + } + }); + } +}