1 package net.mograsim.logic.model.model.components.atomic;
3 import net.haspamelodica.swt.helper.gcs.GeneralGC;
4 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
5 import net.mograsim.logic.core.types.BitVectorFormatter;
6 import net.mograsim.logic.core.wires.Wire.ReadEnd;
7 import net.mograsim.logic.model.model.ViewModelModifiable;
8 import net.mograsim.logic.model.model.components.GUIComponent;
9 import net.mograsim.logic.model.model.wires.Pin;
10 import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
11 import net.mograsim.logic.model.modeladapter.componentadapters.MergerAdapter;
12 import net.mograsim.preferences.ColorDefinition;
13 import net.mograsim.preferences.ColorManager;
14 import net.mograsim.preferences.Preferences;
16 public class GUIMerger extends GUIComponent
18 private static final double width = 20;
19 private static final double heightPerPin = 10;
21 public final int logicWidth;
23 private ReadEnd[] inputEnds;
24 private ReadEnd outputEnd;
26 public GUIMerger(ViewModelModifiable model, int logicWidth, String name)
29 this.logicWidth = logicWidth;
30 setSize(width, logicWidth * heightPerPin);
31 double inputHeight = 0;
32 for (int i = 0; i < logicWidth; i++, inputHeight += 10)
33 addPin(new Pin(this, "I" + i, 1, 0, inputHeight));
34 addPin(new Pin(this, "O", logicWidth, width, logicWidth * heightPerPin / 2));
38 public void render(GeneralGC gc, Rectangle visibleRegion)
40 double posX = getPosX();
41 double posY = getPosY();
43 double inputHeight = posY;
44 for (int i = 0; i < logicWidth; i++, inputHeight += 10)
46 ColorDefinition c = BitVectorFormatter.formatAsColor(inputEnds[i]);
48 gc.setForeground(ColorManager.current().toColor(c));
49 gc.drawLine(posX, inputHeight, posX + width / 2, inputHeight);
51 gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
52 gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
53 ColorDefinition c = BitVectorFormatter.formatAsColor(outputEnd);
55 gc.setForeground(ColorManager.current().toColor(c));
56 gc.drawLine(posX + width / 2, posY + heightPerPin * logicWidth / 2, posX + width, posY + heightPerPin * logicWidth / 2);
59 public void setLogicModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
61 this.inputEnds = inputEnds;
62 this.outputEnd = outputEnd;
67 ViewLogicModelAdapter.addComponentAdapter(new MergerAdapter());