+ return getHint(DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS);
+ }
+
+ private ScheduledFuture<?> hoverUpdateSchedule;
+ private static final Object COMPLETE = new Object();
+
+ public void hoverNode(Resource runtimeDiagram, Resource mapElement, INode hoveredNode, int zoomLevel) {
+ IThreadWorkQueue thread = getThread();
+ Simantics.getSession().asyncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ DynamicVisualisation visualisation = graph.syncRequest(new RuntimeDynamicVisualisationsRequest(runtimeDiagram));
+ if (visualisation == null)
+ return;
+ cancelCurrentHoverUpdate();
+ hoverUpdateSchedule = ThreadUtils.getNonBlockingWorkExecutor().scheduleWithFixedDelay(
+ () -> updateHoverInfo(runtimeDiagram, mapElement, hoveredNode, zoomLevel, visualisation, thread),
+ 0,
+ visualisation.getInterval(),
+ TimeUnit.MILLISECONDS);
+ }
+ });
+ }
+
+ private void updateHoverInfo(Resource runtimeDiagram, Resource mapElement, INode hoveredNode, int zoomLevel, DynamicVisualisation visualisation, IThreadWorkQueue thread) {
+ CompletableFuture<Object> future = new CompletableFuture<>();
+ try {
+ Simantics.getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ Set<Resource> mapElementTypes = graph.getTypes(mapElement);
+ if (mapElementTypes.isEmpty()) {
+ future.complete(COMPLETE);
+ return;
+ }
+
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+
+ boolean doHover =
+ (mapElementTypes.contains(DN.Vertex) && visualisation.isKeyVariablesVertexHover())
+ || (mapElementTypes.contains(DN.Edge) && visualisation.isKeyVariablesEdgesHover());
+
+ StyleResult results = DistrictNetworkHoverInfoStyle.doCalculateStyleResult(graph, runtimeDiagram, mapElement);
+ if (results != null) {
+ Point2D location = DistrictNetworkHoverInfoStyle.calculatePoint(hoveredNode, zoomLevel, null);
+ thread.asyncExec(() -> {
+ if (isRemoved())
+ return;
+ if (doHover) {
+ hoverInfoNode.setLabels(results.getLabels());
+ hoverInfoNode.setOrigin(results.getOrigin());
+ hoverInfoNode.setMousePosition(location);
+ hoverInfoNode.setHoveredNode(hoveredNode);
+ } else {
+ hoverInfoNode.setHoveredNode(null);
+ }
+ future.complete(COMPLETE);
+ });
+ } else {
+ future.complete(COMPLETE);
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ future.completeExceptionally(e);
+ }
+ // this waits until everything is done
+ try {
+ future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOGGER.debug("Interrupted hovering", e);
+ }
+ }
+
+ public boolean doHover(boolean hover, boolean isConnectionTool) {
+ if (!hover)
+ cancelCurrentHoverUpdate();
+ return hoverInfoNode.hover(hover, isConnectionTool);