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.Mux;
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 GUIMux extends Mux implements BasicGUIComponent
16 private final double height;
17 private final List<WireEnd> connectedWireEnds;
18 private final List<Point> WireEndConnectionPoints;
20 public GUIMux(int processTime, WireEnd out, WireEnd select, WireEnd... inputs)
22 super(processTime, out, select, inputs);
24 double height = inputs.length * 5;
29 List<WireEnd> connectedWireEndsModifiable = new ArrayList<>();
30 List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();
32 connectedWireEndsModifiable.add(out);
33 WireEndConnectionPointsModifiable.add(new Point(20, 10 + height / 2));
35 connectedWireEndsModifiable.add(select);
36 WireEndConnectionPointsModifiable.add(new Point(10, 5));
39 connectedWireEndsModifiable.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 WireEndConnectionPointsModifiable.add(new Point(0, inputHeight));
46 this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);
47 this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable);
51 public Rectangle getBounds()
53 return new Rectangle(0, 0, 20, height + 20);
57 public void render(GeneralGC gc)
59 gc.drawPolygon(new double[] { 0, 0, 20, 10, 20, height + 10, 0, height + 20 });
63 public int getConnectedWireEndsCount()
65 return connectedWireEnds.size();
69 public WireEnd getConnectedWireEnd(int connectionIndex)
71 return connectedWireEnds.get(connectionIndex);
75 public Point getWireEndConnectionPoint(int connectionI)
77 return WireEndConnectionPoints.get(connectionI);