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.SplitterAdapter;
12 import net.mograsim.preferences.ColorDefinition;
13 import net.mograsim.preferences.ColorManager;
14 import net.mograsim.preferences.Preferences;
16 public class GUISplitter extends GUIComponent
18 private static final double width = 20;
19 private static final double heightPerPin = 10;
21 public final int logicWidth;
23 private ReadEnd inputEnd;
24 private ReadEnd[] outputEnds;
26 public GUISplitter(ViewModelModifiable model, int logicWidth, String name)
29 this.logicWidth = logicWidth;
30 setSize(width, logicWidth * heightPerPin);
31 addPin(new Pin(this, "I", logicWidth, 0, logicWidth * heightPerPin / 2));
32 double outputHeight = 0;
33 for (int i = 0; i < logicWidth; i++, outputHeight += 10)
34 addPin(new Pin(this, "O" + i, 1, width, outputHeight));
38 public void render(GeneralGC gc, Rectangle visibleRegion)
40 double posX = getPosX();
41 double posY = getPosY();
43 ColorDefinition c = BitVectorFormatter.formatAsColor(inputEnd);
45 gc.setForeground(ColorManager.current().toColor(c));
46 gc.drawLine(posX, posY + heightPerPin * logicWidth / 2, posX + width / 2, posY + heightPerPin * logicWidth / 2);
47 gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
48 gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
49 double outputHeight = posY;
50 for (int i = 0; i < logicWidth; i++, outputHeight += 10)
52 c = BitVectorFormatter.formatAsColor(outputEnds[i]);
54 gc.setForeground(ColorManager.current().toColor(c));
55 gc.drawLine(posX + width / 2, outputHeight, posX + width, outputHeight);
59 public void setLogicModelBinding(ReadEnd inputEnd, ReadEnd[] outputEnds)
61 this.inputEnd = inputEnd;
62 this.outputEnds = outputEnds;
67 ViewLogicModelAdapter.addComponentAdapter(new SplitterAdapter());