1 package era.mi.gui.components;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
8 import era.mi.logic.components.Merger;
9 import era.mi.logic.wires.Wire.WireEnd;
10 import net.haspamelodica.swt.helper.gcs.GeneralGC;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
12 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
14 public class GUIMerger extends Merger implements BasicGUIComponent
16 private final int inputCount;
17 private final double height;
18 private final List<WireEnd> connectedWireEnds;
19 private final List<Point> WireEndConnectionPoints;
21 public GUIMerger(WireEnd union, WireEnd... inputs)
25 List<WireEnd> connectedWireEndsModifiable = new ArrayList<>();
26 List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();
28 this.inputCount = inputs.length;
29 this.height = (inputCount - 1) * 10;
32 connectedWireEndsModifiable.addAll(Arrays.asList(inputs));
33 double inputHeight = 0;
34 for (int i = 0; i < inputCount; i++, inputHeight += 10)
35 WireEndConnectionPointsModifiable.add(new Point(0, inputHeight));
38 connectedWireEndsModifiable.add(union);
39 WireEndConnectionPointsModifiable.add(new Point(20, height / 2));
41 this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);
42 this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable);
46 public Rectangle getBounds()
48 return new Rectangle(0, 0, 20, height);
52 public void render(GeneralGC gc)
54 double inputHeight = 0;
55 for (int i = 0; i < inputCount; i++, inputHeight += 10)
56 gc.drawLine(0, inputHeight, 10, inputHeight);
57 gc.drawLine(10, 0, 10, height);
58 gc.drawLine(10, height / 2, 20, height / 2);
62 public int getConnectedWireEndsCount()
64 return connectedWireEnds.size();
68 public WireEnd getConnectedWireEnd(int connectionIndex)
70 return connectedWireEnds.get(connectionIndex);
74 public Point getWireEndConnectionPoint(int connectionI)
76 return WireEndConnectionPoints.get(connectionI);