X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fserializing%2FIndirectGUIComponentCreator.java;h=f97b9019dcd596a9d4da4476d0c88dce8db67031;hb=a25f554756e1bc9a1f842293aefe60a220d8b950;hp=874a8a8b377912a1e6f4561a3d1de6fc0cd66ecf;hpb=1ddc8ecf420fd4ccbe351c0cbd58cc9f5792f0c7;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java index 874a8a8b..f97b9019 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java @@ -2,19 +2,24 @@ package net.mograsim.logic.model.serializing; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import com.google.gson.JsonElement; import com.google.gson.JsonNull; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; +import net.mograsim.logic.model.snippets.CodeSnippetSupplier; import net.mograsim.logic.model.util.JsonHandler; public class IndirectGUIComponentCreator { private static final Map standardComponentIDs = new HashMap<>(); + private static final Set standardComponentIDSetUnmodifiable = Collections.unmodifiableSet(standardComponentIDs.keySet()); private static final Map componentSuppliers = new HashMap<>(); @@ -51,6 +56,11 @@ public class IndirectGUIComponentCreator standardComponentIDs.put(standardComponentID, associatedComponentID); } + public static Set getStandardComponentIDs() + { + return standardComponentIDSetUnmodifiable; + } + public static void setComponentSupplier(String className, ComponentSupplier componentSupplier) { componentSuppliers.put(className, componentSupplier); @@ -88,9 +98,18 @@ public class IndirectGUIComponentCreator if (componentSupplier != null) return componentSupplier.create(model, params, name); } else - // we know id has to start with "file:" here - // because standardComponentIDs only contains strings starting with "class:" or "file:" - return SubmodelComponentDeserializer.create(model, resolvedID.substring(5), name); + // we know id has to start with "file:" here + // because standardComponentIDs only contains strings starting with "class:" or "file:" + if (params != null && !JsonNull.INSTANCE.equals(params)) + throw new IllegalArgumentException("Can't give params to a component deserialized from a JSON file"); + try + { + return SubmodelComponentSerializer.deserialize(model, resolvedID.substring(5), name, id, null); + } + catch (IOException e) + { + throw new UncheckedIOException(e); + } } throw new RuntimeException("Could not get component supplier for ID " + id); }