X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FGUIMemoryWA.java;h=bd5eba8937977ead556426cb19a936ef3fa193cd;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=079c7e5b50893d915f485affed4ce62ac59346d8;hpb=976f7f2be00457b5cda2489545635ccd076c9afd;p=Mograsim.git diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java index 079c7e5b..bd5eba89 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java @@ -1,42 +1,47 @@ package net.mograsim.machine.standard.memory; -import org.eclipse.swt.graphics.Color; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - import net.haspamelodica.swt.helper.gcs.GeneralGC; -import net.haspamelodica.swt.helper.swtobjectwrappers.Font; -import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.components.atomic.GUIAndGate; import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.model.wires.PinUsage; import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter; -import net.mograsim.logic.model.serializing.IdentifierGetter; +import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; +import net.mograsim.logic.model.snippets.Renderer; +import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer; +import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer; +import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer.CenteredTextParams; +import net.mograsim.logic.model.util.JsonHandler; import net.mograsim.machine.MainMemoryDefinition; -import net.mograsim.machine.standard.memory.WordAddressableMemoryComponent; -import net.mograsim.preferences.Preferences; public class GUIMemoryWA extends GUIComponent { - private final MainMemoryDefinition definition; - private final Pin addrPin, dataPin, rWPin; - private WordAddressableMemoryComponent memory; - private final static int width = 100, height = 300; - - private final static String addrKey = "addrBits", cellWidthKey = "cellWidth", minAddrKey = "minAddr", maxAddrKey = "maxAddr"; + private final MainMemoryDefinition definition; + private final Pin addrPin, dataPin, rWPin; + private WordAddressableMemoryComponent memory; + private final static int width = 100, height = 300; + private Renderer symbolRenderer; + private Renderer outlineRenderer; public GUIMemoryWA(ViewModelModifiable model, MainMemoryDefinition definition, String name) { super(model, name); this.definition = definition; + + CenteredTextParams renderer1Params = new CenteredTextParams(); + renderer1Params.text = "RAM"; + renderer1Params.fontHeight = 24; + this.symbolRenderer = new CenteredTextSymbolRenderer(this, renderer1Params); + this.outlineRenderer = new DefaultOutlineRenderer(this); + setSize(width, height); - addPin(addrPin = new Pin(this, "A", definition.getMemoryAddressBits(), 0, 10)); - addPin(dataPin = new Pin(this, "D", definition.getCellWidth(), 0, 30)); - addPin(rWPin = new Pin(this, "RW", 1, 0, 50)); + //TODO check the usages + addPin(addrPin = new Pin(this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10)); + addPin(dataPin = new Pin(this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30)); + addPin(rWPin = new Pin(this, "RW", 1, PinUsage.INPUT, 0, 50)); } public Pin getAddressPin() @@ -53,17 +58,17 @@ public class GUIMemoryWA extends GUIComponent { return rWPin; } - + public void setLogicModelBinding(WordAddressableMemoryComponent memory) { this.memory = memory; } - + public MainMemoryDefinition getDefinition() { return definition; } - + public WordAddressableMemoryComponent getMemory() { return memory; @@ -72,32 +77,25 @@ public class GUIMemoryWA extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - // TODO This is copied from SimpleRectangularGUIGate; do this via delegation instead - Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground"); - if (foreground != null) - gc.setForeground(foreground); - gc.drawRectangle(getPosX(), getPosY(), width, height); - Font oldFont = gc.getFont(); - Font labelFont = new Font(oldFont.getName(), 24, oldFont.getStyle()); - gc.setFont(labelFont); - String label = "RAM"; - Point textExtent = gc.textExtent(label); - Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); - if (textColor != null) - gc.setForeground(textColor); - gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); - gc.setFont(oldFont); + symbolRenderer.render(gc, visibleRegion); + outlineRenderer.render(gc, visibleRegion); } @Override - public JsonElement getParamsForSerializing(IdentifierGetter idGetter) + public String getIDForSerializing(IdentifyParams idParams) { - JsonObject o = new JsonObject(); - o.addProperty(addrKey, definition.getMemoryAddressBits()); - o.addProperty(cellWidthKey, definition.getCellWidth()); - o.addProperty(maxAddrKey, definition.getMaximalAddress()); - o.addProperty(minAddrKey, definition.getMinimalAddress()); - return o; + return "GUIMemoryWA";//TODO + } + + @Override + public GUIMemoryWAParams getParamsForSerializing(IdentifyParams idParams) + { + GUIMemoryWAParams params = new GUIMemoryWAParams(); + params.addrBits = definition.getMemoryAddressBits(); + params.cellWidth = definition.getCellWidth(); + params.minAddr = definition.getMinimalAddress(); + params.maxAddr = definition.getMaximalAddress(); + return params; } static @@ -105,12 +103,16 @@ public class GUIMemoryWA extends GUIComponent ViewLogicModelAdapter.addComponentAdapter(new WordAddressableMemoryAdapter()); IndirectGUIComponentCreator.setComponentSupplier(GUIAndGate.class.getCanonicalName(), (m, p, n) -> { - JsonObject o = (JsonObject) p; - int addressBits = o.get(addrKey).getAsInt(); - int cellWidth = o.get(cellWidthKey).getAsInt(); - long maxAddr = o.get(maxAddrKey).getAsLong(); - long minAddr = o.get(minAddrKey).getAsLong(); - return new GUIMemoryWA(m, MainMemoryDefinition.create(addressBits, cellWidth, minAddr, maxAddr), n); + GUIMemoryWAParams params = JsonHandler.fromJsonTree(p, GUIMemoryWAParams.class); + return new GUIMemoryWA(m, MainMemoryDefinition.create(params.addrBits, params.cellWidth, params.minAddr, params.maxAddr), n); }); } + + public static class GUIMemoryWAParams + { + public int addrBits; + public int cellWidth; + public long minAddr; + public long maxAddr; + } }