Restructured packages
[Mograsim.git] / LogicUI / src / era / mi / gui / components / GUIOrGate.java
1 package era.mi.gui.components;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
6 import java.util.List;
7
8 import era.mi.logic.components.gates.OrGate;
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;
14
15 public class GUIOrGate extends OrGate implements BasicGUIComponent
16 {
17         private static final String LABEL = "\u22651";//>=1
18
19         private final int                               inputCount;
20         private final double                    height;
21         private final List<WireArray>   connectedWireArrays;
22         private final List<Point>               wireArrayConnectionPoints;
23
24         public GUIOrGate(int processTime, WireArray out, WireArray... in)
25         {
26                 super(processTime, out, in);
27
28                 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
29                 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
30
31                 this.inputCount = in.length;
32                 this.height = inputCount * 10;
33
34                 {
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));
39                 }
40
41                 connectedWireArraysModifiable.add(out);
42                 wireArrayConnectionPointsModifiable.add(new Point(20, height / 2));
43
44                 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
45                 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
46         }
47
48         @Override
49         public Rectangle getBounds()
50         {
51                 return new Rectangle(0, 0, 20, height);
52         }
53         @Override
54         public void render(GeneralGC gc)
55         {
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);
62                 gc.setFont(oldFont);
63                 gc.drawOval(17, height / 2 - 1.5, 3, 3);
64         }
65
66         @Override
67         public int getConnectedWireArraysCount()
68         {
69                 return connectedWireArrays.size();
70         }
71         @Override
72         public WireArray getConnectedWireArray(int connectionIndex)
73         {
74                 return connectedWireArrays.get(connectionIndex);
75         }
76         @Override
77         public Point getWireArrayConnectionPoint(int connectionI)
78         {
79                 return wireArrayConnectionPoints.get(connectionI);
80         }
81 }