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.MergerAdapter;
\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 GUIMerger 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[] inputEnds;
\r
24 private ReadEnd outputEnd;
\r
26 public GUIMerger(ViewModelModifiable model, int logicWidth, String name)
\r
29 this.logicWidth = logicWidth;
\r
30 setSize(width, logicWidth * heightPerPin);
\r
31 double inputHeight = 0;
\r
32 for (int i = 0; i < logicWidth; i++, inputHeight += 10)
\r
33 addPin(new Pin(this, "I" + i, 1, 0, inputHeight));
\r
34 addPin(new Pin(this, "O", logicWidth, width, logicWidth * heightPerPin / 2));
\r
38 public void render(GeneralGC gc, Rectangle visibleRegion)
\r
40 double posX = getPosX();
\r
41 double posY = getPosY();
\r
43 double inputHeight = posY;
\r
44 for (int i = 0; i < logicWidth; i++, inputHeight += 10)
\r
46 ColorDefinition c = BitVectorFormatter.formatAsColor(inputEnds[i]);
\r
48 gc.setForeground(ColorManager.current().toColor(c));
\r
49 gc.drawLine(posX, inputHeight, posX + width / 2, inputHeight);
\r
51 gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
\r
52 gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
\r
53 ColorDefinition c = BitVectorFormatter.formatAsColor(outputEnd);
\r
55 gc.setForeground(ColorManager.current().toColor(c));
\r
56 gc.drawLine(posX + width / 2, posY + heightPerPin * logicWidth / 2, posX + width, posY + heightPerPin * logicWidth / 2);
\r
59 public void setLogicModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
\r
61 this.inputEnds = inputEnds;
\r
62 this.outputEnd = outputEnd;
\r
67 ViewLogicModelAdapter.addComponentAdapter(new MergerAdapter());
\r