X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FGUIComponentCreator.java;fp=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FGUIComponentCreator.java;h=0000000000000000000000000000000000000000;hb=01c5d7035474a5eb58f216b6831b2c0d8c174efa;hp=76b89190165bffb5ea081859f1814810085127f0;hpb=4ac977cb31feb34f24e05e9d5e7976951dccf557;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponentCreator.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponentCreator.java deleted file mode 100644 index 76b89190..00000000 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponentCreator.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.mograsim.logic.ui.model.components; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; - -import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.wires.WireCrossPoint; -import net.mograsim.logic.ui.util.JsonHandler; - -public class GUIComponentCreator -{ - private final static Map componentMapping; - - static - { - Map tmp; - try (InputStream s = GUIComponentCreator.class.getResourceAsStream("./mapping.json")) - { - tmp = JsonHandler.readJson(s, Map.class); - } - catch (IOException e) - { - System.err.println("Failed to initialize component mapping; Components cannot be created from file."); - e.printStackTrace(); - tmp = new HashMap<>(); - } - componentMapping = tmp; - } - - public static GUIComponent create(ViewModelModifiable model, String name, Map params) - { - try - { - String path = componentMapping.get(name); - if (path.startsWith("class:")) - { - path = path.substring(6); - return createComponentFromClass(model, path, params); - } else if (path.startsWith("file:")) - { - path = path.substring(5); - return GUICustomComponentCreator.create(model, path); - } else - throw new IllegalArgumentException("Invalid submodel type! Type was neither prefixed by 'class:' nor by 'file:'"); - } - catch (NullPointerException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException - | SecurityException | ClassNotFoundException | IllegalArgumentException e) - { - System.err.println("Failed to create requested component!"); - e.printStackTrace(); - return new SimpleRectangularSubmodelComponent(model, 1, "ERROR"); - } - } - - private static GUIComponent createComponentFromClass(ViewModelModifiable model, String classname, Map params) - throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException, - ClassNotFoundException - { - Class c = Class.forName(classname); - Object comp; - if (SimpleRectangularGUIGate.class.isAssignableFrom(c) || WireCrossPoint.class.equals(c)) - { - Constructor constructor = c.getConstructor(ViewModelModifiable.class, int.class); - comp = constructor.newInstance(model, ((Number) params.get(SimpleRectangularGUIGate.kLogicWidth)).intValue()); - } else - { - Constructor constructor = c.getConstructor(ViewModelModifiable.class); - comp = constructor.newInstance(model); - } - return (GUIComponent) comp; - } -}