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.Point;
10 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
11 import net.mograsim.logic.core.types.BitVector;
12 import net.mograsim.logic.core.types.BitVectorFormatter;
13 import net.mograsim.logic.model.model.LogicModelModifiable;
14 import net.mograsim.logic.model.model.components.ModelComponent;
15 import net.mograsim.logic.model.model.wires.Pin;
16 import net.mograsim.logic.model.model.wires.PinUsage;
17 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
18 import net.mograsim.logic.model.modeladapter.componentadapters.FixedOutputAdapter;
19 import net.mograsim.logic.model.serializing.IdentifyParams;
20 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
21 import net.mograsim.logic.model.util.JsonHandler;
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;
30 public final BitVector bits;
32 public ModelFixedOutput(LogicModelModifiable model, BitVector bits, String name)
34 super(model, name, false);
36 setSize(width, height);
37 addPin(new Pin(model, this, "out", bits.length(), PinUsage.OUTPUT, width, height / 2));
43 public String getIDForSerializing(IdentifyParams idParams)
49 public Object getParamsForSerializing(IdentifyParams idParams)
55 public void render(GeneralGC gc, Rectangle visibleRegion)
57 Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
58 if (foreground != null)
59 gc.setForeground(foreground);
60 gc.drawRectangle(getBounds());
61 String label = BitVectorFormatter.formatAsString(bits, false);
62 Font oldFont = gc.getFont();
63 Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
64 gc.setFont(labelFont);
65 Point textExtent = gc.textExtent(label);
66 Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
67 if (textColor != null)
68 gc.setForeground(textColor);
69 gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, 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));