From 1ee8004c71eaa9818fe1a49e16d0463adbf559f6 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 17 Oct 2017 23:02:41 +0300 Subject: [PATCH] SceneGraph NodeEventHandler should work in headless environments refs #7556 Change-Id: I4c217d20cc1b96357276e72c59a228120ec5a607 --- .../scenegraph/g2d/events/NodeEventHandler.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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) { -- 2.47.1