From 23a0c840dd86a507a3b2757978bdfe413ed9ecd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Karlstr=C3=B6m?= Date: Tue, 15 Feb 2022 08:54:58 +0100 Subject: [PATCH] me-worldwind: Add workaround for https://github.com/NASAWorldWind/WorldWindJava/issues/240 --- .../org/mapton/worldwind/api/LayerBundle.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/me-worldwind/src/main/java/org/mapton/worldwind/api/LayerBundle.java b/modules/me-worldwind/src/main/java/org/mapton/worldwind/api/LayerBundle.java index 37febae35..9391c4cb9 100644 --- a/modules/me-worldwind/src/main/java/org/mapton/worldwind/api/LayerBundle.java +++ b/modules/me-worldwind/src/main/java/org/mapton/worldwind/api/LayerBundle.java @@ -22,6 +22,7 @@ import gov.nasa.worldwind.layers.Layer; import gov.nasa.worldwind.layers.RenderableLayer; import gov.nasa.worldwind.render.Renderable; +import gov.nasa.worldwind.render.airspaces.AbstractAirspace; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -34,6 +35,7 @@ import javafx.collections.ObservableList; import javafx.scene.Node; import org.mapton.api.MKey; +import org.openide.util.Exceptions; import se.trixon.almond.util.Dict; /** @@ -224,7 +226,11 @@ public void setDragEnabled(boolean enabled, RenderableLayer... layers) { for (var layer : layers) { for (var renderable : layer.getRenderables()) { if (renderable instanceof Draggable) { - ((Draggable) renderable).setDragEnabled(enabled); + if (renderable instanceof AbstractAirspace) { + setDragEnabled((AbstractAirspace) renderable, enabled); + } else { + ((Draggable) renderable).setDragEnabled(enabled); + } } } } @@ -282,4 +288,17 @@ private boolean getChildVisibility(Layer layer) { return visible; } + + private void setDragEnabled(AbstractAirspace abstractAirspace, boolean enabled) { + //TODO Remove this method once resolved: https://github.com/NASAWorldWind/WorldWindJava/issues/240 + try { + var dragEnabledField = AbstractAirspace.class.getDeclaredField("dragEnabled"); + boolean accessible = dragEnabledField.canAccess(abstractAirspace); + dragEnabledField.setAccessible(true); + dragEnabledField.set(abstractAirspace, enabled); + dragEnabledField.setAccessible(accessible); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { + Exceptions.printStackTrace(ex); + } + } }