1 package era.mi.components.gui;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
8 import era.mi.logic.components.gates.AndGate;
9 import era.mi.logic.wires.WireArray;
10 import net.haspamelodica.swt.helper.gcs.GeneralGC;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
12 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
13 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
15 public class GUIAndGate extends AndGate implements BasicGUIComponent
17 private static final String LABEL = "&";
19 private final int inputCount;
20 private final double height;
21 private final List<WireArray> connectedWireArrays;
22 private final List<Point> wireArrayConnectionPoints;
24 public GUIAndGate(int processTime, WireArray out, WireArray... in)
26 super(processTime, out, in);
28 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
29 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
31 this.inputCount = in.length;
32 this.height = inputCount * 10;
35 connectedWireArraysModifiable.addAll(Arrays.asList(in));
36 double inputHeight = 5;
37 for(int i = 0; i < inputCount; i ++, inputHeight += 10)
38 wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight));
41 connectedWireArraysModifiable.add(out);
42 wireArrayConnectionPointsModifiable.add(new Point(20, height / 2));
44 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
45 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
49 public Rectangle getBounds()
51 return new Rectangle(0, 0, 20, height);
54 public void render(GeneralGC gc)
56 gc.drawRectangle(0, 0, 17, height);
57 Font oldFont = gc.getFont();
58 Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());
59 gc.setFont(labelFont);
60 Point textExtent = gc.textExtent(LABEL);
61 gc.drawText(LABEL, 8.5 - textExtent.x / 2, (height - textExtent.y) / 2, true);
63 gc.drawOval(17, height / 2 - 1.5, 3, 3);
67 public int getConnectedWireArraysCount()
69 return connectedWireArrays.size();
72 public WireArray getConnectedWireArray(int connectionIndex)
74 return connectedWireArrays.get(connectionIndex);
77 public Point getWireArrayConnectionPoint(int connectionI)
79 return wireArrayConnectionPoints.get(connectionI);