import org.eclipse.swt.widgets.Shell;\r
\r
import era.mi.components.gui.BasicGUIComponent;\r
+import era.mi.components.gui.GUIAndGate;\r
import era.mi.components.gui.GUIMerger;\r
import era.mi.components.gui.GUIMux;\r
import era.mi.components.gui.GUINotGate;\r
import era.mi.components.gui.GUISplitter;\r
import era.mi.logic.Simulation;\r
-import era.mi.logic.components.gates.AndGate;\r
import era.mi.logic.wires.WireArray;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
import net.haspamelodica.swt.helper.gcs.TranslatedGC;\r
Simulation.TIMELINE.reset();\r
WireArray a = new WireArray(1, 1), b = new WireArray(1, 1), c = new WireArray(1, 10), d = new WireArray(2, 1), e = new WireArray(1, 1),\r
f = new WireArray(1, 1), g = new WireArray(1, 1), h = new WireArray(2, 1), i = new WireArray(2, 1), j = new WireArray(1, 1), k = new WireArray(1, 1);\r
- new AndGate(1, f, a, b);\r
+ addComponent(new GUIAndGate(1, f, a, b), 130, 10);\r
addComponent(new GUINotGate(1, f, g), 100, 10);\r
addComponent(new GUIMerger(h, c, g), 70, 10);\r
addComponent(new GUIMux(1, i, e, h, d), 10, 10);\r
--- /dev/null
+package era.mi.components.gui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import era.mi.logic.components.gates.AndGate;\r
+import era.mi.logic.wires.WireArray;\r
+import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Font;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
+\r
+public class GUIAndGate extends AndGate implements BasicGUIComponent\r
+{\r
+ private static final String LABEL = "&";\r
+\r
+ private final int inputCount;\r
+ private final double height;\r
+ private final List<WireArray> connectedWireArrays;\r
+ private final List<Point> wireArrayConnectionPoints;\r
+\r
+ public GUIAndGate(int processTime, WireArray out, WireArray... in)\r
+ {\r
+ super(processTime, out, in);\r
+\r
+ List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
+ List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
+\r
+ this.inputCount = in.length;\r
+ this.height = inputCount * 10;\r
+\r
+ {\r
+ connectedWireArraysModifiable.addAll(Arrays.asList(in));\r
+ double inputHeight = 5;\r
+ for(int i = 0; i < inputCount; i ++, inputHeight += 10)\r
+ wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight));\r
+ }\r
+\r
+ connectedWireArraysModifiable.add(out);\r
+ wireArrayConnectionPointsModifiable.add(new Point(20, height / 2));\r
+\r
+ this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);\r
+ this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);\r
+ }\r
+\r
+ @Override\r
+ public void render(GeneralGC gc)\r
+ {\r
+ gc.drawRectangle(0, 0, 17, height);\r
+ Font oldFont = gc.getFont();\r
+ Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());\r
+ gc.setFont(labelFont);\r
+ Point textExtent = gc.textExtent(LABEL);\r
+ gc.drawText(LABEL, 8.5 - textExtent.x / 2, (height - textExtent.y) / 2, true);\r
+ gc.setFont(oldFont);\r
+ gc.drawOval(17, height / 2 - 1.5, 3, 3);\r
+ }\r
+\r
+ @Override\r
+ public int getConnectedWireArraysCount()\r
+ {\r
+ return connectedWireArrays.size();\r
+ }\r
+ @Override\r
+ public WireArray getConnectedWireArray(int connectionIndex)\r
+ {\r
+ return connectedWireArrays.get(connectionIndex);\r
+ }\r
+ @Override\r
+ public Point getWireArrayConnectionPoint(int connectionI)\r
+ {\r
+ return wireArrayConnectionPoints.get(connectionI);\r
+ }\r
+}
\ No newline at end of file