diff --git a/plugins-dev/alert-intrusion/src/java/pt/lsts/neptus/plugins/alertintrusion/AlertIntrusion.java b/plugins-dev/alert-intrusion/src/java/pt/lsts/neptus/plugins/alertintrusion/AlertIntrusion.java index 1eb567a0eb..f6265aab6a 100644 --- a/plugins-dev/alert-intrusion/src/java/pt/lsts/neptus/plugins/alertintrusion/AlertIntrusion.java +++ b/plugins-dev/alert-intrusion/src/java/pt/lsts/neptus/plugins/alertintrusion/AlertIntrusion.java @@ -333,38 +333,42 @@ public void paint(Graphics2D g, StateRenderer2D renderer) { AtomicReference shipClosest = new AtomicReference<>(null); AtomicDouble distanceClosest = new AtomicDouble(Double.MAX_VALUE); AtomicReference timeClosest = new AtomicReference<>(null); - collisionsTree.get(lastMainVehicle).forEach((time, pair) -> { - String sysName = pair.first(); - double distance = pair.second(); - if (distance < distanceClosest.get()) { - shipClosest.set(sysName); - distanceClosest.set(distance); - timeClosest.set(time); - - LocationType loc = null; - ImcSystem sys = ImcSystemsHolder.lookupSystemByName(sysName); - if (sys != null) { - loc = sys.getLocation().getNewAbsoluteLatLonDepth(); - } else { - ExternalSystem esys = ExternalSystemsHolder.lookupSystem(sysName); - if (esys != null) { - loc = esys.getLocation().getNewAbsoluteLatLonDepth(); + Map> ctlast = collisionsTree.get(lastMainVehicle); + if (ctlast != null) { + ctlast.forEach((time, pair) -> { + String sysName = pair.first(); + double distance = pair.second(); + if (distance < distanceClosest.get()) { + shipClosest.set(sysName); + distanceClosest.set(distance); + timeClosest.set(time); + + LocationType loc = null; + ImcSystem sys = ImcSystemsHolder.lookupSystemByName(sysName); + if (sys != null) { + loc = sys.getLocation().getNewAbsoluteLatLonDepth(); } - } - if (loc != null) { - Graphics2D gg = (Graphics2D) g2.create(); - Point2D spos = renderer.getScreenPosition(loc); - gg.translate(spos.getX() - 20 - 8, spos.getY()); - boolean res = !gg.drawImage(colregImageSmall, null, null); - if (res) { - askForLaterRepaint.compareAndSet(false, true); + else { + ExternalSystem esys = ExternalSystemsHolder.lookupSystem(sysName); + if (esys != null) { + loc = esys.getLocation().getNewAbsoluteLatLonDepth(); + } + } + if (loc != null) { + Graphics2D gg = (Graphics2D) g2.create(); + Point2D spos = renderer.getScreenPosition(loc); + gg.translate(spos.getX() - 20 - 8, spos.getY()); + boolean res = !gg.drawImage(colregImageSmall, null, null); + if (res) { + askForLaterRepaint.compareAndSet(false, true); + } + gg.dispose(); } - gg.dispose(); - } - } - //Point2D pt = renderer.getScreenPosition(loc); - }); + } + //Point2D pt = renderer.getScreenPosition(loc); + }); + } if (shipClosest.get() != null) { String line1 = shipClosest.get(); String line2 = Math.round(distanceClosest.get()) + "m at " + sdf.format(timeClosest.get()); @@ -385,39 +389,46 @@ public void paint(Graphics2D g, StateRenderer2D renderer) { Point2D indicatorPoint = new Point2D.Double(20 + 25, 100 + 25); AtomicReference mainlookAngle = new AtomicReference<>((short) 0); boolean[] lookAngle = {false, false, false, false}; - collisionsTree.get(lastMainVehicle).forEach((time, pair) -> { - String sysName = pair.first(); - LocationType loc = null; - ImcSystem sys = ImcSystemsHolder.lookupSystemByName(sysName); - if (sys != null) { - loc = sys.getLocation().getNewAbsoluteLatLonDepth(); - } else { - ExternalSystem esys = ExternalSystemsHolder.lookupSystem(sysName); - if (esys != null) { - loc = esys.getLocation().getNewAbsoluteLatLonDepth(); + ctlast = collisionsTree.get(lastMainVehicle); + if (ctlast != null) { + ctlast.forEach((time, pair) -> { + String sysName = pair.first(); + LocationType loc = null; + ImcSystem sys = ImcSystemsHolder.lookupSystemByName(sysName); + if (sys != null) { + loc = sys.getLocation().getNewAbsoluteLatLonDepth(); } - } - if (loc != null) { - Point2D pointShipClosest = renderer.getScreenPosition(loc); - Pair angleRadAndQuadrant = calculateAngleToRotate(indicatorPoint, pointShipClosest); - if (angleRadAndQuadrant.second() == 0) { - lookAngle[0] = true; - } else if (angleRadAndQuadrant.second() == 1) { - lookAngle[1] = true; - } else if (angleRadAndQuadrant.second() == 2) { - lookAngle[2] = true; - } else if (angleRadAndQuadrant.second() == 3) { - lookAngle[3] = true; + else { + ExternalSystem esys = ExternalSystemsHolder.lookupSystem(sysName); + if (esys != null) { + loc = esys.getLocation().getNewAbsoluteLatLonDepth(); + } } + if (loc != null) { + Point2D pointShipClosest = renderer.getScreenPosition(loc); + Pair angleRadAndQuadrant = calculateAngleToRotate(indicatorPoint, pointShipClosest); + if (angleRadAndQuadrant.second() == 0) { + lookAngle[0] = true; + } + else if (angleRadAndQuadrant.second() == 1) { + lookAngle[1] = true; + } + else if (angleRadAndQuadrant.second() == 2) { + lookAngle[2] = true; + } + else if (angleRadAndQuadrant.second() == 3) { + lookAngle[3] = true; + } - if (shipClosest.get() != null) { - String closestSysName = shipClosest.get(); - if (closestSysName.equals(sysName)) { - mainlookAngle.set(angleRadAndQuadrant.second()); + if (shipClosest.get() != null) { + String closestSysName = shipClosest.get(); + if (closestSysName.equals(sysName)) { + mainlookAngle.set(angleRadAndQuadrant.second()); + } } } - } - }); + }); + } for (int i = 0; i < lookAngle.length; i++) { if (lookAngle[i]) { Graphics2D gg = (Graphics2D) g2.create();