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