X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fserializing%2FIndirectGUIComponentCreator.java;h=365fe9abb7c04b8bef557cbe7396f73bbba387c3;hb=5ece0acf049bf9af2933f513fe0206565681f622;hp=ba713bd563178d6e2087a26f19b0e6f1af3c949e;hpb=5897a6d81c418d27ca5bb402e5f1038e10a191fb;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java index ba713bd5..365fe9ab 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.Map; import com.google.gson.JsonElement; +import com.google.gson.JsonNull; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUIComponent; @@ -15,7 +16,7 @@ public class IndirectGUIComponentCreator { private static final Map standardComponentIDs = new HashMap<>(); - private static final Map componentProviders = new HashMap<>(); + private static final Map componentSuppliers = new HashMap<>(); static { @@ -50,12 +51,27 @@ public class IndirectGUIComponentCreator standardComponentIDs.put(standardComponentID, associatedComponentID); } - public static void setComponentProvider(String className, ComponentProvider componentProvider) + public static void setComponentSupplier(String className, ComponentSupplier componentSupplier) { - componentProviders.put(className, componentProvider); + componentSuppliers.put(className, componentSupplier); + } + + public static GUIComponent createComponent(ViewModelModifiable model, String id) + { + return createComponent(model, id, (String) null); + } + + public static GUIComponent createComponent(ViewModelModifiable model, String id, String name) + { + return createComponent(model, id, JsonNull.INSTANCE, name); } public static GUIComponent createComponent(ViewModelModifiable model, String id, JsonElement params) + { + return createComponent(model, id, params, null); + } + + public static GUIComponent createComponent(ViewModelModifiable model, String id, JsonElement params, String name) { if (id != null) { @@ -68,24 +84,24 @@ public class IndirectGUIComponentCreator { String className = resolvedID.substring(6); tryLoadComponentClass(className); - ComponentProvider componentProvider = componentProviders.get(className); - if (componentProvider != null) - return componentProvider.create(model, params); + ComponentSupplier componentSupplier = componentSuppliers.get(className); + 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)); + return SubmodelComponentDeserializer.create(model, resolvedID.substring(5), name); } - throw new RuntimeException("Could not get component provider for ID " + id); + throw new RuntimeException("Could not get component supplier for ID " + id); } private static void tryLoadComponentClass(String componentClassName) { - CodeSnippetSupplier.tryLoadClass(componentClassName, "Error loading component class %s\n"); + CodeSnippetSupplier.tryInvokeStaticInitializer(componentClassName, "Error loading component class %s: %s\n"); } - public static interface ComponentProvider + public static interface ComponentSupplier { - public GUIComponent create(ViewModelModifiable model, JsonElement params); + public GUIComponent create(ViewModelModifiable model, JsonElement params, String name); } } \ No newline at end of file