fa18e2d3e292c0dc52089d578411ef15bc56d6a4
[Mograsim.git] / SampleERCP / src / sampleercp / parts / LogicUIPart.java
1 package sampleercp.parts;
2
3 import javax.annotation.PostConstruct;
4 import javax.inject.Inject;
5
6 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.widgets.Composite;
9
10 import era.mi.gui.LogicUICanvas;
11 import era.mi.gui.model.ViewModel;
12 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
13
14 public class LogicUIPart
15 {
16         @Inject
17         private MPart part;
18
19         @PostConstruct
20         public void create(Composite parent)
21         {
22                 ViewModel model = new ViewModel();
23                 LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE, model);
24 //              RSLatchGUIExample.addComponentsAndWires(ui, timeline);
25                 ui.addTransformListener((x, y, z) -> part.setDirty(z < 1));
26                 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
27                 userInput.buttonDrag = 3;
28                 userInput.buttonZoom = 2;
29                 userInput.enableUserInput();
30 //              Thread simulationThread = new Thread(() ->
31 //              {
32 //                      // TODO find a better condition
33 //                      while (!ui.isDisposed())
34 //                      {
35 //                              // always execute to keep timeline from "hanging behind" for too long
36 //                              timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
37 //                              long sleepTime;
38 //                              if (timeline.hasNext())
39 //                                      sleepTime = timeline.nextEventTime() - System.currentTimeMillis();
40 //                              else
41 //                                      sleepTime = 10;
42 //                              try
43 //                              {
44 //                                      if (sleepTime > 0)
45 //                                              Thread.sleep(sleepTime);
46 //                              }
47 //                              catch (InterruptedException e)
48 //                              {
49 //                              } // it is normal execution flow to be interrupted
50 //                      }
51 //              });
52 //              simulationThread.start();
53 //              timeline.addEventAddedListener(event ->
54 //              {
55 //                      if (event.getTiming() <= System.currentTimeMillis())
56 //                              simulationThread.interrupt();
57 //              });
58         }
59 }