Skip to content

Commit

Permalink
me-worldwind: Add workaround for NASAWorldWind/WorldWindJava#240
Browse files Browse the repository at this point in the history
  • Loading branch information
trixon committed Feb 15, 2022
1 parent a42d73f commit 23a0c84
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 23a0c84

Please sign in to comment.