--- /dev/null
+package net.mograsim.logic.model.model.components.atomic;
+
+import java.util.Objects;
+
+import org.eclipse.swt.graphics.Color;
+
+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.core.types.BitVector;
+import net.mograsim.logic.core.types.BitVectorFormatter;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.GUIComponent;
+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.modeladapter.componentadapters.FixedOutputAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.model.util.JsonHandler;
+import net.mograsim.preferences.Preferences;
+
+public class GUIFixedOutput extends GUIComponent
+{
+ private static final double width = 20;
+ private static final double height = 20;
+ private static final double fontHeight = 5;
+
+ public final BitVector bits;
+
+ public GUIFixedOutput(ViewModelModifiable model, BitVector bits, String name)
+ {
+ super(model, name);
+ this.bits = bits;
+ setSize(width, height);
+ addPin(new Pin(this, "out", bits.length(), PinUsage.OUTPUT, width, height / 2));
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return "GUIFixedOutput";
+ }
+
+ @Override
+ public Object getParamsForSerializing(IdentifyParams idParams)
+ {
+ return bits;
+ }
+
+ @Override
+ public void render(GeneralGC gc, Rectangle visibleRegion)
+ {
+ Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
+ if (foreground != null)
+ gc.setForeground(foreground);
+ gc.drawRectangle(getBounds());
+ String label = BitVectorFormatter.formatAsString(bits);
+ Font oldFont = gc.getFont();
+ Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
+ gc.setFont(labelFont);
+ 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);
+ }
+
+ static
+ {
+ ViewLogicModelAdapter.addComponentAdapter(new FixedOutputAdapter());
+ IndirectGUIComponentCreator.setComponentSupplier(GUIFixedOutput.class.getCanonicalName(),
+ (m, p, n) -> new GUIFixedOutput(m, Objects.requireNonNull(JsonHandler.fromJsonTree(p, BitVector.class)), n));
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.mograsim.logic.model.modeladapter.componentadapters;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.wires.Wire;
+import net.mograsim.logic.model.model.components.atomic.GUIFixedOutput;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.LogicModelParameters;
+
+public class FixedOutputAdapter implements ComponentAdapter<GUIFixedOutput>
+{
+ @Override
+ public Class<GUIFixedOutput> getSupportedClass()
+ {
+ return GUIFixedOutput.class;
+ }
+
+ @Override
+ public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, GUIFixedOutput guiComponent,
+ Map<Pin, Wire> logicWiresPerPin)
+ {
+ logicWiresPerPin.get(guiComponent.getPin("out")).createReadWriteEnd().feedSignals(guiComponent.bits);
+ }
+}
\ No newline at end of file
mograsim version: 0.1.3
{
- "GUIManualSwitch": "class:net.mograsim.logic.model.model.components.atomic.GUIManualSwitch",
- "GUIBitDisplay": "class:net.mograsim.logic.model.model.components.atomic.GUIBitDisplay",
"GUIAndGate": "class:net.mograsim.logic.model.model.components.atomic.GUIAndGate",
+ "GUIBitDisplay": "class:net.mograsim.logic.model.model.components.atomic.GUIBitDisplay",
+ "GUIClock": "class:net.mograsim.logic.model.model.components.atomic.GUIClock",
+ "GUIFixedOutput": "class:net.mograsim.logic.model.model.components.atomic.GUIFixedOutput",
+ "GUIManualSwitch": "class:net.mograsim.logic.model.model.components.atomic.GUIManualSwitch",
"GUIMerger": "class:net.mograsim.logic.model.model.components.atomic.GUIMerger",
"GUINandGate": "class:net.mograsim.logic.model.model.components.atomic.GUINandGate",
"GUIOrGate": "class:net.mograsim.logic.model.model.components.atomic.GUIOrGate",
"GUISplitter": "class:net.mograsim.logic.model.model.components.atomic.GUISplitter",
"GUITriStateBuffer": "class:net.mograsim.logic.model.model.components.atomic.GUITriStateBuffer",
- "GUIClock": "class:net.mograsim.logic.model.model.components.atomic.GUIClock",
"TextComponent": "class:net.mograsim.logic.model.model.components.atomic.TextComponent",
"WireCrossPoint": "class:net.mograsim.logic.model.model.wires.WireCrossPoint"
}
\ No newline at end of file