1 package net.mograsim.logic.model.model.components.atomic;
3 import java.util.Objects;
5 import org.eclipse.swt.graphics.Color;
7 import net.haspamelodica.swt.helper.gcs.GeneralGC;
8 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
9 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
10 import net.mograsim.logic.core.types.BitVector;
11 import net.mograsim.logic.core.types.BitVectorFormatter;
12 import net.mograsim.logic.model.model.LogicModelModifiable;
13 import net.mograsim.logic.model.model.components.ModelComponent;
14 import net.mograsim.logic.model.model.wires.Pin;
15 import net.mograsim.logic.model.model.wires.PinUsage;
16 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
17 import net.mograsim.logic.model.modeladapter.componentadapters.FixedOutputAdapter;
18 import net.mograsim.logic.model.serializing.IdentifyParams;
19 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
20 import net.mograsim.logic.model.util.JsonHandler;
21 import net.mograsim.logic.model.util.TextRenderingHelper;
22 import net.mograsim.preferences.Preferences;
24 public class ModelFixedOutput extends ModelComponent
26 private static final double width = 20;
27 private static final double height = 20;
28 private static final double fontHeight = 5;
29 private static final double textMargin = 0.5;
31 public final BitVector bits;
33 public ModelFixedOutput(LogicModelModifiable model, BitVector bits, String name)
35 super(model, name, false);
37 setSize(width, height);
38 addPin(new Pin(model, this, "out", bits.length(), PinUsage.OUTPUT, width, height / 2));
44 public String getIDForSerializing(IdentifyParams idParams)
50 public Object getParamsForSerializing(IdentifyParams idParams)
56 public void render(GeneralGC gc, Rectangle visibleRegion)
58 Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
59 if (foreground != null)
60 gc.setForeground(foreground);
61 gc.drawRectangle(getBounds());
62 String label = BitVectorFormatter.formatAsString(bits, false);
63 Font oldFont = gc.getFont();
64 Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
65 gc.setFont(labelFont);
66 Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
67 if (textColor != null)
68 gc.setForeground(textColor);
69 TextRenderingHelper.drawTextFitting(gc, label, getBounds(), textMargin, true);
75 LogicCoreAdapter.addComponentAdapter(new FixedOutputAdapter());
76 IndirectModelComponentCreator.setComponentSupplier(ModelFixedOutput.class.getCanonicalName(),
77 (m, p, n) -> new ModelFixedOutput(m, Objects.requireNonNull(JsonHandler.fromJsonTree(p, BitVector.class)), n));