Suppressed warnings where the thing warned about is intentional
[Mograsim.git] / era.mi / src / era / mi / logic / tests / GUITest.java
index 9db2df6..0581812 100644 (file)
@@ -15,12 +15,12 @@ import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.WindowConstants;
 
-import era.mi.logic.Simulation;
 import era.mi.logic.components.ManualSwitch;
 import era.mi.logic.components.gates.NotGate;
 import era.mi.logic.components.gates.OrGate;
+import era.mi.logic.timeline.Timeline;
 import era.mi.logic.timeline.Timeline.ExecutionResult;
-import era.mi.logic.wires.WireArray;
+import era.mi.logic.wires.Wire;
 
 public class GUITest extends JPanel
 {
@@ -31,20 +31,22 @@ public class GUITest extends JPanel
        private static final int OR_DELAY = 100;
        private static final int NOT_DELAY = 100;
 
-       WireArray r = new WireArray(1, WIRE_DELAY);
-       WireArray s = new WireArray(1, WIRE_DELAY);
-       WireArray t1 = new WireArray(1, WIRE_DELAY);
-       WireArray t2 = new WireArray(1, WIRE_DELAY);
-       WireArray q = new WireArray(1, WIRE_DELAY);
-       WireArray nq = new WireArray(1, WIRE_DELAY);
+       private Timeline t = new Timeline(11);
 
-       ManualSwitch rIn = new ManualSwitch(r);
-       ManualSwitch sIn = new ManualSwitch(s);
+       Wire r = new Wire(t, 1, WIRE_DELAY);
+       Wire s = new Wire(t, 1, WIRE_DELAY);
+       Wire t1 = new Wire(t, 1, WIRE_DELAY);
+       Wire t2 = new Wire(t, 1, WIRE_DELAY);
+       Wire q = new Wire(t, 1, WIRE_DELAY);
+       Wire nq = new Wire(t, 1, WIRE_DELAY);
 
-       OrGate or1 = new OrGate(OR_DELAY, t2, r, nq);
-       OrGate or2 = new OrGate(OR_DELAY, t1, s, q);
-       NotGate not1 = new NotGate(NOT_DELAY, t2, q);
-       NotGate not2 = new NotGate(NOT_DELAY, t1, nq);
+       ManualSwitch rIn = new ManualSwitch(t, r.createReadWriteEnd());
+       ManualSwitch sIn = new ManualSwitch(t, s.createReadWriteEnd());
+
+       OrGate or1 = new OrGate(t, OR_DELAY, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());
+       OrGate or2 = new OrGate(t, OR_DELAY, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());
+       NotGate not1 = new NotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), q.createReadWriteEnd());
+       NotGate not2 = new NotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), nq.createReadWriteEnd());
 
        Map<ManualSwitch, Rectangle> switchMap = new HashMap<>();
 
@@ -109,6 +111,11 @@ public class GUITest extends JPanel
                });
        }
 
+       public Timeline getTimeline()
+       {
+               return t;
+       };
+
        @Override
        public void paint(Graphics some_g)
        {
@@ -177,7 +184,7 @@ public class GUITest extends JPanel
                g.drawString(s, x - (int) (w * anchorX), y + (int) (h * anchorY));
        }
 
-       private void drawWire(Graphics g, WireArray wa, String name, double x1, double y1, double x2, double y2)
+       private void drawWire(Graphics g, Wire wa, String name, double x1, double y1, double x2, double y2)
        {
                setTo(g, wa);
                g.drawLine(gX(x1), gY(y1), gX(x2), gY(y2));
@@ -224,7 +231,7 @@ public class GUITest extends JPanel
                g.setColor(Color.BLACK);
        }
 
-       private static void setTo(Graphics g, WireArray wa)
+       private static void setTo(Graphics g, Wire wa)
        {
                switch (wa.getValue())
                {
@@ -275,9 +282,9 @@ public class GUITest extends JPanel
 
                while (f.isVisible())
                {
-                       ExecutionResult er = Simulation.TIMELINE.executeUpTo((lastFrame - begin) * 3, lastFrame + 14);
-//                             if (Simulation.TIMELINE.hasNext()) 
-//                             Simulation.TIMELINE.executeNext();
+                       ExecutionResult er = gt.getTimeline().executeUntil(gt.getTimeline().laterThan((lastFrame - begin) * 3), lastFrame + 14);
+//                             if (t.hasNext()) 
+//                             t.executeNext();
                        if (er != ExecutionResult.NOTHING_DONE)
                                gt.repaint(12);
                        try