+++ /dev/null
-mograsim version: 0.1.2
-{
- "GUIAm2901": "file:components/am2901/GUIAm2901.json",
- "GUIAm2901ALUFuncDecode": "file:components/am2901/GUIAm2901ALUFuncDecode.json",
- "GUIAm2901ALUInclDecode": "file:components/am2901/GUIAm2901ALUInclDecode.json",
- "GUIAm2901ALUInclSourceDecodeInclFunctionDecode": "file:components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json",
- "GUIAm2901ALUOneBit": "file:components/am2901/GUIAm2901ALUOneBit.json",
- "GUIAm2901DestDecode": "file:components/am2901/GUIAm2901DestDecode.json",
- "GUIAm2901QReg": "file:components/am2901/GUIAm2901QReg.json",
- "GUIAm2901SourceDecode": "file:components/am2901/GUIAm2901SourceDecode.json",
- "GUIAndGate": "class:net.mograsim.logic.ui.model.components.GUIAndGate",
- "GUINandGate": "class:net.mograsim.logic.ui.model.components.GUINandGate",
- "GUIOrGate": "class:net.mograsim.logic.ui.model.components.GUIOrGate",
- "GUI_rsLatch": "file:components/GUI_rsLatch.json",
- "GUIand": "file:components/GUIand.json",
- "GUIand41": "file:components/GUIand41.json",
- "GUIandor414": "file:components/GUIandor414.json",
- "GUIdemux2": "file:components/GUIdemux2.json",
- "GUIdff": "file:components/GUIdff.json",
- "GUIdlatch": "file:components/GUIdlatch.json",
- "GUIdlatch4": "file:components/GUIdlatch4.json",
- "GUIfulladder": "file:components/GUIfulladder.json",
- "GUIhalfadder": "file:components/GUIhalfadder.json",
- "GUImux1": "file:components/GUImux1.json",
- "GUImux1_4": "file:components/GUImux1_4.json",
- "GUInand3": "file:components/GUInand3.json",
- "GUInot4": "file:components/GUInot4.json",
- "GUIor4": "file:components/GUIor4.json",
- "GUIor_4": "file:components/GUIor_4.json",
- "GUIram2": "file:components/GUIram2.json",
- "GUIram4": "file:components/GUIram4.json",
- "GUIsel2_4": "file:components/GUIsel2_4.json",
- "GUIsel3_4": "file:components/GUIsel3_4.json",
- "GUIxor": "file:components/GUIxor.json",
- "WireCrossPoint": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint"
-}
\ No newline at end of file
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;
public class GUIComponentCreator
{
private final static Map<String, String> componentMapping;
- private final static String componentMappingPath = "../net.mograsim.logic.ui.am2900/components/mapping.json"; // TODO: manage this
- // somewhere else
static
{
Map<String, String> tmp;
- try
+ try (InputStream s = GUIComponentCreator.class.getResourceAsStream("./mapping.json"))
{
- tmp = JsonHandler.readJson(componentMappingPath, Map.class);
+ tmp = JsonHandler.readJson(s, Map.class);
}
catch (IOException e)
{
--- /dev/null
+mograsim version: 0.1.2
+{
+ "GUIAm2901": "file:components/am2901/GUIAm2901.json",
+ "GUIAm2901ALUFuncDecode": "file:components/am2901/GUIAm2901ALUFuncDecode.json",
+ "GUIAm2901ALUInclDecode": "file:components/am2901/GUIAm2901ALUInclDecode.json",
+ "GUIAm2901ALUInclSourceDecodeInclFunctionDecode": "file:components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json",
+ "GUIAm2901ALUOneBit": "file:components/am2901/GUIAm2901ALUOneBit.json",
+ "GUIAm2901DestDecode": "file:components/am2901/GUIAm2901DestDecode.json",
+ "GUIAm2901QReg": "file:components/am2901/GUIAm2901QReg.json",
+ "GUIAm2901SourceDecode": "file:components/am2901/GUIAm2901SourceDecode.json",
+ "GUIAndGate": "class:net.mograsim.logic.ui.model.components.GUIAndGate",
+ "GUINandGate": "class:net.mograsim.logic.ui.model.components.GUINandGate",
+ "GUIOrGate": "class:net.mograsim.logic.ui.model.components.GUIOrGate",
+ "GUI_rsLatch": "file:components/GUI_rsLatch.json",
+ "GUIand": "file:components/GUIand.json",
+ "GUIand41": "file:components/GUIand41.json",
+ "GUIandor414": "file:components/GUIandor414.json",
+ "GUIdemux2": "file:components/GUIdemux2.json",
+ "GUIdff": "file:components/GUIdff.json",
+ "GUIdlatch": "file:components/GUIdlatch.json",
+ "GUIdlatch4": "file:components/GUIdlatch4.json",
+ "GUIfulladder": "file:components/GUIfulladder.json",
+ "GUIhalfadder": "file:components/GUIhalfadder.json",
+ "GUImux1": "file:components/GUImux1.json",
+ "GUImux1_4": "file:components/GUImux1_4.json",
+ "GUInand3": "file:components/GUInand3.json",
+ "GUInot4": "file:components/GUInot4.json",
+ "GUIor4": "file:components/GUIor4.json",
+ "GUIor_4": "file:components/GUIor_4.json",
+ "GUIram2": "file:components/GUIram2.json",
+ "GUIram4": "file:components/GUIram4.json",
+ "GUIsel2_4": "file:components/GUIsel2_4.json",
+ "GUIsel3_4": "file:components/GUIsel3_4.json",
+ "GUIxor": "file:components/GUIxor.json",
+ "WireCrossPoint": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint"
+}
\ No newline at end of file
package net.mograsim.logic.ui.util;
import java.io.BufferedReader;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public static <T> T readJson(String path, Class<T> type) throws IOException
{
- try (FileReader reader = new FileReader(path); BufferedReader bf = new BufferedReader(reader))
+ try (FileInputStream jsonStream = new FileInputStream(path))
+ {
+ return readJson(jsonStream, type);
+ }
+ }
+
+ /**
+ * @param input The Stream is closed after being read
+ */
+ public static <T> T readJson(InputStream input, Class<T> type) throws IOException
+ {
+ try (InputStreamReader reader = new InputStreamReader(input); BufferedReader bf = new BufferedReader(reader))
{
String json = bf.lines().dropWhile(s -> s.length() == 0 || s.charAt(0) != '{').reduce("", (x, y) -> x.concat(y));
T params = parser.fromJson(json, type);