1 import java.util.HashMap;
2 import java.util.HashSet;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.layout.FillLayout;
8 import org.eclipse.swt.widgets.Display;
9 import org.eclipse.swt.widgets.Shell;
11 import era.mi.components.gui.BasicGUIComponent;
12 import era.mi.components.gui.GUIAndGate;
13 import era.mi.components.gui.GUIMerger;
14 import era.mi.components.gui.GUIMux;
15 import era.mi.components.gui.GUINotGate;
16 import era.mi.components.gui.GUISplitter;
17 import era.mi.logic.Simulation;
18 import era.mi.logic.wires.WireArray;
19 import net.haspamelodica.swt.helper.gcs.GeneralGC;
20 import net.haspamelodica.swt.helper.gcs.TranslatedGC;
21 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
22 import net.haspamelodica.swt.helper.zoomablecanvas.ZoomableCanvas;
23 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
24 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
28 private final Display display;
29 private final Shell shell;
30 private final Set<BasicGUIComponent> components;
31 private final Map<BasicGUIComponent, Point> componentPositions;
35 display = new Display();
36 shell = new Shell(display);
37 shell.setLayout(new FillLayout());
38 ZoomableCanvas canvas = new ZoomableCanvas(shell, SWT.NONE);
40 components = new HashSet<>();
41 componentPositions = new HashMap<>();
44 canvas.addZoomedRenderer(gc -> components.forEach(component -> drawComponent(gc, component)));
45 new ZoomableCanvasUserInput(canvas).enableUserInput();
46 new ZoomableCanvasOverlay(canvas, null).enableScale();
48 private void initComponents()
50 Simulation.TIMELINE.reset();
51 WireArray a = new WireArray(1, 1), b = new WireArray(1, 1), c = new WireArray(1, 10), d = new WireArray(2, 1), e = new WireArray(1, 1),
52 f = new WireArray(1, 1), g = new WireArray(1, 1), h = new WireArray(2, 1), i = new WireArray(2, 1), j = new WireArray(1, 1), k = new WireArray(1, 1);
53 addComponent(new GUIAndGate(1, f, a, b), 130, 10);
54 addComponent(new GUINotGate(1, f, g), 100, 10);
55 addComponent(new GUIMerger(h, c, g), 70, 10);
56 addComponent(new GUIMux(1, i, e, h, d), 10, 10);
57 addComponent(new GUISplitter(i, k, j), 40, 10);
59 private void addComponent(BasicGUIComponent component, double x, double y)
61 components.add(component);
62 componentPositions.put(component, new Point(x, y));
64 private void drawComponent(GeneralGC gc, BasicGUIComponent component)
66 TranslatedGC tgc = new TranslatedGC(gc, componentPositions.get(component));
67 component.render(tgc);
68 tgc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
69 for(int i = 0; i < component.getConnectedWireArraysCount(); i ++)
71 Point connectionPoint = component.getWireArrayConnectionPoint(i);
72 if(connectionPoint != null)
73 tgc.fillOval(connectionPoint.x - 1, connectionPoint.y - 1, 2, 2);
79 while(!shell.isDisposed())
80 if(!display.readAndDispatch())
84 public static void main(String[] args)