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.Mux;
9 import era.mi.logic.wires.WireArray;
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 GUIMux extends Mux implements BasicGUIComponent
16 private final double height;
17 private final List<WireArray> connectedWireArrays;
18 private final List<Point> wireArrayConnectionPoints;
20 public GUIMux(int processTime, WireArray out, WireArray select, WireArray... inputs)
22 super(processTime, out, select, inputs);
24 double height = inputs.length * 5;
29 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
30 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
32 connectedWireArraysModifiable.add(out);
33 wireArrayConnectionPointsModifiable.add(new Point(20, 10 + height / 2));
35 connectedWireArraysModifiable.add(select);
36 wireArrayConnectionPointsModifiable.add(new Point(10, 5));
39 connectedWireArraysModifiable.addAll(Arrays.asList(inputs));
40 double inputHeightIncrement = (height + 20) / inputs.length;
41 double inputHeight = inputHeightIncrement / 2;
42 for(int i = 0; i < inputs.length; i ++, inputHeight += inputHeightIncrement)
43 wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight));
46 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
47 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
51 public Rectangle getBounds()
53 return new Rectangle(0, 0, 20, height + 20);
56 public void render(GeneralGC gc)
58 gc.drawPolygon(new double[] {
65 public int getConnectedWireArraysCount()
67 return connectedWireArrays.size();
70 public WireArray getConnectedWireArray(int connectionIndex)
72 return connectedWireArrays.get(connectionIndex);
75 public Point getWireArrayConnectionPoint(int connectionI)
77 return wireArrayConnectionPoints.get(connectionI);