Commit 23e18a37 authored by Tobias Liese's avatar Tobias Liese

major transition logic update

parent d310738f
Pipeline #96115 failed with stages
in 1 minute and 44 seconds
Mrz 06, 2020 4:10:03 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
Mrz 06, 2020 6:51:12 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
Mrz 09, 2020 10:54:11 VORM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
Mrz 09, 2020 3:04:42 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
Mrz 09, 2020 3:58:24 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
Mrz 01, 2020 12:46:54 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 01, 2020 1:07:10 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 01, 2020 2:51:45 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 01, 2020 5:39:21 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 01, 2020 9:41:20 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
This diff is collapsed.
Mrz 03, 2020 8:05:31 VORM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 03, 2020 2:18:15 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 03, 2020 4:13:29 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
This diff is collapsed.
Mrz 05, 2020 8:17:28 VORM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 05, 2020 10:02:00 VORM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 05, 2020 11:18:57 VORM. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleNotification
WARNUNG: Notification threw an exception: {
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"languageId": "properties",
"version": -1,
"text": "#Gradle properties\n#Tue Feb 11 17:11:23 UTC 2020\nquarkusPluginVersion\u003d999-SNAPSHOT\nquarkusPlatformArtifactId\u003dquarkus-bom\nquarkusPlatformVersion\u003d999-SNAPSHOT\nquarkusPlatformGroupId\u003dio.quarkus\n"
}
}
}
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
at com.redhat.quarkus.ls.commons.ParentProcessWatcher.lambda$apply$0(ParentProcessWatcher.java:140)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
... 12 more
Caused by: java.lang.IllegalArgumentException: Property must not be null: uri
at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29)
at org.eclipse.lsp4j.TextDocumentItem.setUri(TextDocumentItem.java:70)
at com.redhat.quarkus.ls.commons.TextDocument.<init>(TextDocument.java:47)
at com.redhat.quarkus.ls.commons.TextDocument.<init>(TextDocument.java:41)
at com.redhat.quarkus.ls.commons.ModelTextDocument.<init>(ModelTextDocument.java:37)
at com.redhat.quarkus.ls.commons.ModelTextDocuments.createDocument(ModelTextDocuments.java:34)
at com.redhat.quarkus.ls.commons.ModelTextDocuments.createDocument(ModelTextDocuments.java:24)
at com.redhat.quarkus.ls.commons.TextDocuments.onDidOpenTextDocument(TextDocuments.java:93)
at com.redhat.quarkus.ls.QuarkusTextDocumentService.didOpen(QuarkusTextDocumentService.java:107)
... 17 more
Mrz 05, 2020 11:19:15 VORM. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleNotification
WARNUNG: Notification threw an exception: {
"jsonrpc": "2.0",
"method": "textDocument/didClose",
"params": {
"textDocument": {}
}
}
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
at com.redhat.quarkus.ls.commons.ParentProcessWatcher.lambda$apply$0(ParentProcessWatcher.java:140)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
... 12 more
Caused by: java.lang.IllegalArgumentException: Property must not be null: uri
at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29)
at org.eclipse.lsp4j.PublishDiagnosticsParams.<init>(PublishDiagnosticsParams.java:45)
at com.redhat.quarkus.ls.QuarkusTextDocumentService.didClose(QuarkusTextDocumentService.java:122)
... 17 more
Mrz 05, 2020 3:29:34 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 06, 2020 9:37:47 VORM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.5985.32\jbr
Mrz 06, 2020 9:43:44 VORM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
Mrz 06, 2020 11:34:40 VORM. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleNotification
WARNUNG: Notification threw an exception: {
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"languageId": "properties",
"version": -1,
"text": "#Gradle properties\n#Tue Feb 11 17:11:23 UTC 2020\nquarkusPluginVersion\u003d1.2.1.Final\nquarkusPlatformArtifactId\u003dquarkus-bom\nquarkusPlatformVersion\u003d1.2.1.Final\nquarkusPlatformGroupId\u003dio.quarkus\n"
}
}
}
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
at com.redhat.quarkus.ls.commons.ParentProcessWatcher.lambda$apply$0(ParentProcessWatcher.java:140)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
... 12 more
Caused by: java.lang.IllegalArgumentException: Property must not be null: uri
at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29)
at org.eclipse.lsp4j.TextDocumentItem.setUri(TextDocumentItem.java:70)
at com.redhat.quarkus.ls.commons.TextDocument.<init>(TextDocument.java:47)
at com.redhat.quarkus.ls.commons.TextDocument.<init>(TextDocument.java:41)
at com.redhat.quarkus.ls.commons.ModelTextDocument.<init>(ModelTextDocument.java:37)
at com.redhat.quarkus.ls.commons.ModelTextDocuments.createDocument(ModelTextDocuments.java:34)
at com.redhat.quarkus.ls.commons.ModelTextDocuments.createDocument(ModelTextDocuments.java:24)
at com.redhat.quarkus.ls.commons.TextDocuments.onDidOpenTextDocument(TextDocuments.java:93)
at com.redhat.quarkus.ls.QuarkusTextDocumentService.didOpen(QuarkusTextDocumentService.java:107)
... 17 more
Mrz 06, 2020 11:34:59 VORM. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleNotification
WARNUNG: Notification threw an exception: {
"jsonrpc": "2.0",
"method": "textDocument/didClose",
"params": {
"textDocument": {}
}
}
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
at com.redhat.quarkus.ls.commons.ParentProcessWatcher.lambda$apply$0(ParentProcessWatcher.java:140)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
... 12 more
Caused by: java.lang.IllegalArgumentException: Property must not be null: uri
at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29)
at org.eclipse.lsp4j.PublishDiagnosticsParams.<init>(PublishDiagnosticsParams.java:45)
at com.redhat.quarkus.ls.QuarkusTextDocumentService.didClose(QuarkusTextDocumentService.java:122)
... 17 more
Mrz 06, 2020 4:00:13 NACHM. com.redhat.quarkus.ls.QuarkusLanguageServer initialize
INFORMATION: Initializing Quarkus server 0.0.4-20191120-1547 with C:\Users\tobia\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.6073.9\jbr
"use strict";
class Field {
constructor() {
this.canvas = document.getElementById("canvas");
this.context = this.canvas.getContext("2d");
this.states = [];
this.rePaint();
document.getElementById("removeState").addEventListener("mousedown", () => {
this.removeState(selected);
});
document.getElementById("createState").addEventListener("mousedown", (event) => {
let x = event.clientX - field.xOrigin + window.pageXOffset;
let y = event.clientY - field.yOrigin + window.pageYOffset;
this.addState(x, y, "q1");
});
document.getElementById("addTransition").addEventListener("mousedown", () => {
transitionMode = true;
});
document.getElementById("nameForm").oninput = () => {
let elm = this.getStateByIndex(lastSelected);
elm.update(elm.x, elm.y, editName.value);
};
this.xOrigin = this.canvas.getBoundingClientRect().left;
this.yOrigin = this.canvas.getBoundingClientRect().top;
}
addState(x, y, name) {
this.context.font = "40px Dancing Script";
let textSize = this.context.measureText(name);
this.states.push(new State(this, x, y, name, textSize.width * 0.5 + 10, textSize.actualBoundingBoxDescent));
this.states[this.states.length - 1].draw();
states.textContent = states.innerText.replace(/{.*}/gm, "{" + this.states.toString() + "}");
}
removeState(i) {
this.states.splice(i, 1);
this.rePaint();
selected = null;
}
getStateByIndex(i) {
return this.states[i];
}
drawLineTo(origin, x, y, curve) {
this.context.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--main-ac-color');
this.context.beginPath();
this.context.moveTo(origin.x, origin.y);
this.context.lineWidth = 5;
this.context.lineTo(x, y);
this.context.stroke();
}
rePaint() {
this.canvas.height = 1000;
this.canvas.width = document.getElementsByClassName("menu").item(0).clientWidth;
for (let state of this.states) {
state.draw();
}
states.textContent = states.innerText.replace(/{.*}/gm, "{" + this.states.toString() + "}");
}
getStateIndex(x, y) {
let i = 0;
while (i < this.states.length) {
let state = this.getStateByIndex(i);
if (Math.sqrt(Math.pow(x - state.x, 2) + Math.pow(y - state.y, 2)) <= state.radius) {
return i;
}
i++;
}
}
}
class State {
constructor(field, x, y, name, radius, height) {
this.transitions = new Map();
this.field = field;
this.x = x;
this.y = y;
this.name = name;
this.radius = radius;
this.height = height;
this.id = Math.random();
}
update(x, y, name) {
this.x = x;
this.y = y;
if (name != null) {
this.name = name;
let textSize = field.context.measureText(name);
this.radius = textSize.width * 0.5 + 10;
}
this.field.rePaint();
}
addTransition(destination, key, curve) {
let dest = field.getStateByIndex(destination);
if (!this.transitions.has(key)) {
this.transitions.set(key, []);
}
this.transitions.get(key).push(this.field.getStateByIndex(destination));
}
draw() {
this.field.context.fillStyle = "#212121";
this.field.context.beginPath();
this.field.context.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
this.field.context.fill();
this.field.context.font = "40px Dancing Script";
this.field.context.fillStyle = "white";
this.field.context.textAlign = "center";
this.field.context.fillText(this.name, this.x, this.y + this.height);
this.transitions.forEach((states, key) => {
states.forEach((state) => {
this.field.drawLineTo(this, state.x, state.y, null);
});
});
}
toString() {
return this.name;
}
}
onmousemove = (event) => {
let x = event.clientX - field.xOrigin + window.pageXOffset.valueOf();
let y = event.clientY - field.yOrigin + window.pageYOffset.valueOf();
selected = field.getStateIndex(x, y);
if (selected != null) {
if (!transitionMode) {
lastSelected = selected;
editName.value = field.getStateByIndex(selected).name;
editName.removeAttribute("disabled");
}
document.body.style.cursor = "grab";
}
else {
document.body.style.cursor = "default";
}
if (dragMode) {
field.getStateByIndex(lastSelected).update(x, y, null);
}
else if (transitionMode) {
document.body.style.cursor = "default";
if (selected == null || selected != lastSelected) {
field.rePaint();
field.drawLineTo(field.getStateByIndex(lastSelected), x, y, 0.5);
}
}
};
onmousedown = () => {
if (contextMenu != null) {
contextMenu.className = "hide";
contextMenu = null;
menuVisible = false;
}
else if (transitionMode) {
if (selected != null) {
field.getStateByIndex(lastSelected).addTransition(selected, "", 0);
}
transitionMode = false;
}
else if (selected != null) {
dragMode = true;
document.body.style.cursor = "grabbing";
}
else if (transitionMode && selected != null) {
transitionMode = false;
}
};
onmouseup = () => {
dragMode = false;
if (!transitionMode) {
if (selected != null) {
document.body.style.cursor = "grab";
}
else {
document.body.style.cursor = "default";
}
}
};
onresize = () => {
field.rePaint();
};
window.addEventListener("contextmenu", e => {
e.preventDefault();
if (selected != null) {
contextMenu = document.getElementById("state-menu");
}
else {
contextMenu = document.getElementById("field-menu");
}
let x = e.clientX + window.pageXOffset;
let y = e.clientY + window.pageYOffset;
contextMenu.style.left = x + "px";
contextMenu.style.top = y + "px";
contextMenu.className = "show";
menuVisible = true;
return false;
});
let dragMode = false;
let transitionMode = false;
let menuVisible = false;
let editName = document.getElementById("stateName");
let states = document.getElementById("states");
let contextMenu;
let selected;
let lastSelected;
const field = new Field();
// Classes:
class Field {
private canvas: HTMLCanvasElement = <HTMLCanvasElement>document.getElementById("canvas")
private context: CanvasRenderingContext2D = this.canvas.getContext("2d")
private states: State[] = new Array<State>()
readonly context: CanvasRenderingContext2D = this.canvas.getContext("2d")
private states: State[] = []
readonly xOrigin: number
readonly yOrigin: number
......@@ -13,17 +13,17 @@ class Field {
}
);
document.getElementById("createState").addEventListener("mousedown", (event: MouseEvent) => {
let x = event.clientX - field.xOrigin + +window.pageXOffset.valueOf()
let y = event.clientY - field.yOrigin + window.pageYOffset.valueOf()
let x = event.clientX - field.xOrigin + window.pageXOffset
let y = event.clientY - field.yOrigin + window.pageYOffset
this.addState(x, y, "q1")
});
document.getElementById("addTransition").addEventListener("mousedown", () => {
transitionMode = true
// document.body.style.cursor = "crosshair"
});
(<HTMLFormElement>document.getElementById("nameForm")).oninput = (event: Event) => {
(<HTMLFormElement>document.getElementById("nameForm")).oninput = () => {
let elm = this.getStateByIndex(lastSelected)
this.updateState(lastSelected, elm.x, elm.y, editName.value)
elm.update(elm.x, elm.y, editName.value)
}
this.xOrigin = this.canvas.getBoundingClientRect().left
this.yOrigin = this.canvas.getBoundingClientRect().top
......@@ -32,8 +32,8 @@ class Field {
addState(x: number, y: number, name: string) {
this.context.font = "40px Dancing Script"
let textSize: TextMetrics = this.context.measureText(name)
this.states.push(new State(x, y, name, textSize.width * 0.5 + 10, textSize.actualBoundingBoxDescent))
this.drawState(this.states[this.states.length - 1])
this.states.push(new State(this, x, y, name, textSize.width * 0.5 + 10, textSize.actualBoundingBoxDescent))
this.states[this.states.length - 1].draw()
states.textContent = states.innerText.replace(/{.*}/gm, "{" + this.states.toString() + "}")
}
......@@ -47,17 +47,6 @@ class Field {
return this.states[i]
}
updateState(i: number, x, y, name) {
this.states[i].x = x
this.states[i].y = y
if (name != null) {
this.states[i].name = name
let textSize: TextMetrics = this.context.measureText(name)
this.states[i].radius = textSize.width * 0.5 + 10
}
this.rePaint()
}
drawLineTo(origin: State, x: number, y: number, curve: number) {
this.context.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--main-ac-color')
this.context.beginPath()
......@@ -74,32 +63,11 @@ class Field {
this.canvas.height = 1000
this.canvas.width = document.getElementsByClassName("menu").item(0).clientWidth
for (let state of this.states) {
this.drawState(state)
state.draw()
}
states.textContent = states.innerText.replace(/{.*}/gm, "{" + this.states.toString() + "}")
}
private drawState(state: State) {
this.context.fillStyle = "#212121"
this.context.beginPath()
this.context.arc(
state.x,
state.y,
state.radius, 0, 2 * Math.PI)
this.context.fill()
this.context.font = "40px Dancing Script"
this.context.fillStyle = "white"
this.context.textAlign = "center"
this.context.fillText(
state.name,
state.x, state.y + state.height,
)
}
addTransition(origin: number, destination: number, key: String, curve: number) {
let dest = this.getStateByIndex(destination)
this.drawLineTo(this.getStateByIndex(origin), dest.x, dest.y, curve)
}
getStateIndex(x: number, y: number): number {
// let's try every State and check if x and y are inside the state
......@@ -121,8 +89,11 @@ class State {
name: string
radius: number
height: number
field: Field
transitions: Map<String, State[]> = new Map<String, State[]>()
constructor(x, y, name, radius, height) {
constructor(field: Field, x: number, y: number, name: string, radius: number, height: number) {
this.field = field
this.x = x
this.y = y
this.name = name
......@@ -131,6 +102,48 @@ class State {
this.id = Math.random()
}
update(x: number, y: number, name: string) {
this.x = x
this.y = y
if (name != null) {
this.name = name
let textSize: TextMetrics = field.context.measureText(name)
this.radius = textSize.width * 0.5 + 10
}
this.field.rePaint()
}
addTransition(destination: number, key: String, curve: number) {
let dest = field.getStateByIndex(destination)
if (!this.transitions.has(key)) {
this.transitions.set(key, [])
}
this.transitions.get(key).push(this.field.getStateByIndex(destination))
}
draw() {
this.field.context.fillStyle = "#212121"
this.field.context.beginPath()
this.field.context.arc(
this.x,
this.y,
this.radius, 0, 2 * Math.PI)
this.field.context.fill()
this.field.context.font = "40px Dancing Script"
this.field.context.fillStyle = "white"
this.field.context.textAlign = "center"
this.field.context.fillText(
this.name,
this.x, this.y + this.height
)
this.transitions.forEach((states: State[], key: String) => {
states.forEach((state: State) => {
this.field.drawLineTo(this, state.x, state.y, null)
})
}
)
}
public toString(): string {
return this.name
}
......@@ -144,19 +157,15 @@ onmousemove = (event: MouseEvent) => {
if (selected != null) {
if (!transitionMode) {
lastSelected = selected
editName.value = field.getStateByIndex(selected).name
editName.removeAttribute("disabled")
}
document.body.style.cursor = "grab"
} else {
document.body.style.cursor = "default"
}
if (dragMode) {
field.updateState(lastSelected, x, y, null)
} else if (menuVisible) {
if (selected != null) {
editName.value = field.getStateByIndex(selected).name
editName.removeAttribute("disabled")
lastSelected = selected
}
field.getStateByIndex(lastSelected).update(x, y, null)
} else if (transitionMode) {
document.body.style.cursor = "default"
if (selected == null || selected != lastSelected) {
......@@ -165,15 +174,14 @@ onmousemove = (event: MouseEvent) => {
}
}
}
onmousedown = (event: MouseEvent) => {
onmousedown = () => {
if (contextMenu != null) {
contextMenu.className = "hide";
contextMenu = null
menuVisible = false
} else if (transitionMode) {
field.rePaint()