From: jsimomaa Date: Tue, 17 Oct 2017 20:02:41 +0000 (+0300) Subject: SceneGraph NodeEventHandler should work in headless environments X-Git-Tag: v1.31.0~114 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1ee8004c71eaa9818fe1a49e16d0463adbf559f6;p=simantics%2Fplatform.git SceneGraph NodeEventHandler should work in headless environments refs #7556 Change-Id: I4c217d20cc1b96357276e72c59a228120ec5a607 --- diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java index ec0a4fe5f..1c1ac8a37 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java @@ -12,6 +12,7 @@ package org.simantics.scenegraph.g2d.events; import java.awt.Component; +import java.awt.GraphicsEnvironment; import java.awt.dnd.DnDConstants; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureListener; @@ -35,6 +36,8 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin; import org.simantics.scenegraph.g2d.events.adapter.AWTMouseEventAdapter; import org.simantics.scenegraph.g2d.events.command.CommandEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Delivers events (mouse, key, focus, command, time) to scene graph nodes that @@ -44,6 +47,8 @@ import org.simantics.scenegraph.g2d.events.command.CommandEvent; */ public class NodeEventHandler implements IEventHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(NodeEventHandler.class); + private static final boolean DEBUG_EVENTS = false; private static final boolean DEBUG_HANDLER_SORT = false; @@ -197,12 +202,6 @@ public class NodeEventHandler implements IEventHandler { */ protected G2DSceneGraph sg; - /** - * For proper initiation of native DnD operations within this AWT-based - * scenegraph system. - */ - protected DragSource ds = new DragSource(); - public NodeEventHandler(G2DSceneGraph sg) { this.sg = sg; } @@ -222,6 +221,11 @@ public class NodeEventHandler implements IEventHandler { } public void setRootPane(Component rootPane) { + if (GraphicsEnvironment.isHeadless()) { + LOGGER.info("Disabling DragSource in headless environments"); + return; + } + final DragSource ds = new DragSource(); final DragSourceListener dsl = new DragSourceListener() { @Override public void dropActionChanged(DragSourceDragEvent dsde) {