]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
SceneGraph NodeEventHandler should work in headless environments 19/1119/3
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 17 Oct 2017 20:02:41 +0000 (23:02 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 17 Oct 2017 20:21:26 +0000 (23:21 +0300)
refs #7556

Change-Id: I4c217d20cc1b96357276e72c59a228120ec5a607

bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java

index ec0a4fe5f1a35182901cdb311c9fe7186356b83f..1c1ac8a37a7b523ace66705188f148c1972ed763 100644 (file)
@@ -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) {