X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=LogicUI%2Fsrc%2Fera%2Fmi%2Fgui%2Fcomponents%2FGUIManualSwitch.java;h=c3100ffb94ef257e3cb43db8aafcd20584d0b170;hb=fb169b120e97337093a8707c62bbc4bb06098a9c;hp=9d58cac9f23f57b4453f7d564ada00b4a2f9c84c;hpb=d3a382377768fdb1434d5baebf73c9413e61e46f;p=Mograsim.git diff --git a/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java b/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java index 9d58cac9..c3100ffb 100644 --- a/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java +++ b/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java @@ -2,8 +2,11 @@ package era.mi.gui.components; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import era.mi.logic.Bit; import era.mi.logic.components.ManualSwitch; import era.mi.logic.wires.WireArray; import net.haspamelodica.swt.helper.gcs.GeneralGC; @@ -13,13 +16,28 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent { - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private static final Map bitNames; + static + { + Map bitNamesModifiable = new HashMap<>(); + bitNamesModifiable.put(Bit.ONE, "1"); + bitNamesModifiable.put(Bit.ZERO, "0"); + bitNamesModifiable.put(Bit.Z, "Z"); + bitNamesModifiable.put(Bit.U, "U"); + bitNamesModifiable.put(Bit.X, "X"); + bitNames = Collections.unmodifiableMap(bitNamesModifiable); + } + + private final WireArray wa; + private final List connectedWireArrays; + private final List wireArrayConnectionPoints; public GUIManualSwitch(WireArray output) { super(output); + this.wa = output; + List connectedWireArraysModifiable = new ArrayList<>(); List wireArrayConnectionPointsModifiable = new ArrayList<>(); @@ -35,11 +53,12 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent { return new Rectangle(0, 0, 20, 15); } + @Override public void render(GeneralGC gc) { gc.drawRectangle(0, 0, 20, 15); - String label = isOn() ? "ON" : "OFF"; + String label = bitNames.get(wa.getValue()); Font oldFont = gc.getFont(); Font labelFont = new Font(oldFont.getName(), 6, oldFont.getStyle()); gc.setFont(labelFont); @@ -47,6 +66,7 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent gc.drawText(label, 10 - textExtent.x / 2, 7.5 - textExtent.y / 2, true); gc.setFont(oldFont); } + @Override public boolean clicked(double x, double y) { @@ -59,11 +79,13 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent { return connectedWireArrays.size(); } + @Override public WireArray getConnectedWireArray(int connectionIndex) { return connectedWireArrays.get(connectionIndex); } + @Override public Point getWireArrayConnectionPoint(int connectionI) {