@@ -318,34 +318,49 @@ private double feltStrongMultiplier(double pga){
318
318
319
319
private void drawAlertsBox (Graphics2D g ) {
320
320
Earthquake quake = null ;
321
- double maxPGA = 0 ;
322
- double quakeDist = 1000 ;
321
+ double maxPGA = 0.0 ;
322
+ double distGC = 0 ;
323
+
324
+ int secondsP = 0 ;
325
+ int secondsS = 0 ;
326
+
327
+ // Select quake to be displayed
323
328
324
329
for (Earthquake earthquake : GlobalQuake .instance .getEarthquakeAnalysis ().getEarthquakes ()){
325
- double dist = GeoUtils .geologicalDistance (earthquake .getLat (), earthquake .getLon (), -earthquake .getDepth (), Settings .homeLat , Settings .homeLon , 0 );
326
- double pga = GeoUtils .pgaFunction (earthquake .getMag (), dist , earthquake .getDepth ());
330
+ double _dist = GeoUtils .geologicalDistance (earthquake .getLat (), earthquake .getLon (), -earthquake .getDepth (), Settings .homeLat , Settings .homeLon , 0 );
331
+ double pga = GeoUtils .pgaFunction (earthquake .getMag (), _dist , earthquake .getDepth ());
327
332
if (pga > maxPGA ){
328
333
maxPGA = pga ;
329
334
330
- double distGC = GeoUtils .greatCircleDistance (earthquake .getLat (), earthquake .getLon (), Settings .homeLat , Settings .homeLon );
335
+ double _distGC = GeoUtils .greatCircleDistance (earthquake .getLat (), earthquake .getLon (), Settings .homeLat , Settings .homeLon );
336
+ double age = (System .currentTimeMillis () - earthquake .getOrigin ()) / 1000.0 ;
337
+
338
+ double pTravel = (long ) (TauPTravelTimeCalculator .getPWaveTravelTime (earthquake .getDepth (),
339
+ TauPTravelTimeCalculator .toAngle (_distGC )));
340
+ double sTravel = (long ) (TauPTravelTimeCalculator .getSWaveTravelTime (earthquake .getDepth (),
341
+ TauPTravelTimeCalculator .toAngle (_distGC )));
342
+
343
+ int _secondsP = (int ) Math .ceil (pTravel - age );
344
+ int _secondsS = (int ) Math .ceil (sTravel - age );
345
+
346
+ if (_secondsS < - 60 * 5 ) {
347
+ continue ; // S wave already passed
348
+ }
331
349
332
350
if (pga > IntensityScales .INTENSITY_SCALES [Settings .shakingLevelScale ].getLevels ().get (Settings .shakingLevelIndex ).getPga ()
333
- || AlertManager .meetsConditions (earthquake , true )) {
351
+ || AlertManager .meetsConditions (earthquake , false )) {
334
352
quake = earthquake ;
335
- quakeDist = dist ;
353
+ distGC = _distGC ;
354
+ secondsS = Math .max (0 , _secondsS );
355
+ secondsP = Math .max (0 , _secondsP );
336
356
}
337
357
}
338
358
}
339
359
340
- if (DEBUG ) {
341
- quake = createDebugQuake ();
342
-
343
- double dist = GeoUtils .geologicalDistance (quake .getLat (), quake .getLon (), -quake .getDepth (), Settings .homeLat , Settings .homeLon , 0 );
344
- maxPGA = GeoUtils .pgaFunction (quake .getMag (), dist , quake .getDepth ());
345
- quakeDist = dist ;
360
+ if (quake == null ){
361
+ return ;
346
362
}
347
363
348
-
349
364
int width = 240 ;
350
365
int x = getWidth () / 2 - width / 2 ;
351
366
int height = 22 ;
@@ -356,13 +371,11 @@ private void drawAlertsBox(Graphics2D g) {
356
371
357
372
g .setFont (new Font ("Calibri" , Font .BOLD , 16 ));
358
373
359
- if (quake != null ) {
360
- height = 136 ;
361
- color = new Color (0 , 90 , 192 );
362
- g .setFont (new Font ("Calibri" , Font .BOLD , 22 ));
363
- str = quakeDist <= 200 ? "Earthquake detected nearby!" : "Earthquake detected!" ;
364
- width = 400 ;
365
- }
374
+ height = 136 ;
375
+ color = new Color (0 , 90 , 192 );
376
+ g .setFont (new Font ("Calibri" , Font .BOLD , 22 ));
377
+ str = distGC <= 200 ? "Earthquake detected nearby!" : "Earthquake detected!" ;
378
+ width = 400 ;
366
379
367
380
if (maxPGA >= IntensityScales .INTENSITY_SCALES [Settings .shakingLevelScale ].getLevels ().get (Settings .shakingLevelIndex ).getPga ()){
368
381
color = new Color (255 ,200 ,0 );
@@ -391,7 +404,6 @@ private void drawAlertsBox(Graphics2D g) {
391
404
return ;
392
405
}
393
406
394
- double distGC = GeoUtils .greatCircleDistance (quake .getLat (), quake .getLon (), Settings .homeLat , Settings .homeLon );
395
407
Level level = IntensityScales .getIntensityScale ().getLevel (maxPGA );
396
408
397
409
drawIntensityBox (g , level , x + 4 ,y + 30 ,height - 34 );
@@ -409,16 +421,6 @@ private void drawAlertsBox(Graphics2D g) {
409
421
str = "Depth: %s" .formatted (Settings .getSelectedDistanceUnit ().format (quake .getDepth (), 1 ));
410
422
g .drawString (str , _x , y + 72 );
411
423
412
- double age = (System .currentTimeMillis () - quake .getOrigin ()) / 1000.0 ;
413
-
414
- double pTravel = (long ) (TauPTravelTimeCalculator .getPWaveTravelTime (quake .getDepth (),
415
- TauPTravelTimeCalculator .toAngle (distGC )));
416
- double sTravel = (long ) (TauPTravelTimeCalculator .getSWaveTravelTime (quake .getDepth (),
417
- TauPTravelTimeCalculator .toAngle (distGC )));
418
-
419
- int secondsP = (int ) Math .max (0 , Math .ceil (pTravel - age ));
420
- int secondsS = (int ) Math .max (0 , Math .ceil (sTravel - age ));
421
-
422
424
drawAccuracyBox (g , false , "P Wave arrival: " ,x + intW + 15 ,y + 96 , "%ds" .formatted (secondsP ), secondsP == 0 ? Color .gray : new Color (0 ,100 ,220 ));
423
425
drawAccuracyBox (g , false , "S Wave arrival: " ,x + intW + 15 ,y + 122 , "%ds" .formatted (secondsS ), secondsS == 0 ? Color .gray : new Color (255 ,50 ,0 ));
424
426
@@ -774,7 +776,7 @@ private void drawLocationAcc(Graphics2D g, Earthquake quake, int y, int x, int w
774
776
drawAccuracyBox (g , true , "Err. Origin " , (int ) (x + width * 0.55 ), y + 80 ,
775
777
"%.1fs" .formatted (quality .getQualityOrigin ().getValue ()), quality .getQualityOrigin ().getQualityClass ().getColor ());
776
778
drawAccuracyBox (g , true , "No. Stations " , (int ) (x + width * 0.55 ), y + 104 ,
777
- "%d " .formatted (( int ) quality .getQualityStations ().getValue ()), quality .getQualityStations ().getQualityClass ().getColor ());
779
+ "%.0f " .formatted (quality .getQualityStations ().getValue ()), quality .getQualityStations ().getQualityClass ().getColor ());
778
780
drawAccuracyBox (g , true , "Err. N-S " , x + width , y + 56 ,
779
781
units .format (quality .getQualityNS ().getValue (), 1 ), quality .getQualityNS ().getQualityClass ().getColor ());
780
782
drawAccuracyBox (g , true , "Err. E-W " , x + width , y + 80 ,
0 commit comments