Map file errors

Trap errors in corrupt map files and deal with a null array error in
analogue sensors readout.
This commit is contained in:
Douglas Gillespie 2023-05-23 15:45:44 +01:00
parent db037c6d29
commit c17208d315
10 changed files with 48 additions and 13 deletions

View File

@ -4,7 +4,7 @@
<groupId>org.pamguard</groupId>
<artifactId>Pamguard</artifactId>
<name>Pamguard Java12+</name>
<version>2.02.07ab</version>
<version>2.02.08</version>
<description>Pamguard for Java 12+, using Maven to control dependcies</description>
<url>www.pamguard.org</url>
<organization>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.pamguard</groupId>
<artifactId>Pamguard</artifactId>
<version>2.02.07ab</version>
<version>2.02.08</version>
<name>Pamguard Java12+</name>
<description>Pamguard for Java 12+, using Maven to control dependcies</description>
<url>www.pamguard.org</url>

View File

@ -11,8 +11,10 @@ import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import PamController.PamController;
import PamUtils.LatLong;
import PamUtils.PamFileChooser;
import PamView.dialog.warn.WarnOnce;
public class GebcoMapFile implements MapFileManager {
@ -109,10 +111,19 @@ public class GebcoMapFile implements MapFileManager {
int pointCount;
int depth;
MapContour mapContour;
boolean error = false;
try {
int iLine = 0;
while((line = reader.readLine())!=null){
iLine++;
line = line.trim();
spaceIndex = line.indexOf(' ');
if (spaceIndex < 0) {
String msg = String.format("Error in map file at line %d \"%s\"", iLine, line);
WarnOnce.showNamedWarning("Gebco Map File Warning", PamController.getMainFrame(), gebcoFile.getName(), msg, WarnOnce.WARNING_MESSAGE);
error = true;
break;
}
num1 = line.substring(0,spaceIndex).trim();
num2 = line.substring(spaceIndex).trim();
depth = Integer.valueOf(num1);
@ -143,11 +154,22 @@ public class GebcoMapFile implements MapFileManager {
}
catch (NumberFormatException nex) {
nex.printStackTrace();
return false;
error = true;
}
catch (IndexOutOfBoundsException iex) {
iex.printStackTrace();
error = true;
}
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Collections.sort(mapContours);
Collections.sort(availableContours);
return true;
return !error;
}

View File

@ -519,9 +519,15 @@ public class PamSettingManager {
if (initializationComplete == false) {
// if PAMGAURD hasn't finished loading, then don't save the settings
// or the file will get wrecked (bug tracker 2269579)
System.out.println("Settings have not yet loaded. Don't save file");
return false;
// or the file will get wrecked (bug tracker 2269579)
String msg = "There was an error loading settings from this configuration, so the configuration"
+ " may be incomplete. <p>Do you want to save anyway ? <p>"
+ " If you have added new modules, the answer is probably \"Yes\"";
int ans = WarnOnce.showWarning("Confuguration file warning", msg, WarnOnce.YES_NO_OPTION);
if (ans == WarnOnce.CANCEL_OPTION) {
System.out.println("Settings have not yet loaded. Don't save file");
return false;
}
}
saveGlobalSettings();

View File

@ -31,12 +31,12 @@ public class PamguardVersionInfo {
* Version number, major version.minorversion.sub-release.
* Note: can't go higher than sub-release 'f'
*/
static public final String version = "2.02.07f";
static public final String version = "2.02.08";
/**
* Release date
*/
static public final String date = "4 April 2023";
static public final String date = "9 May 2023";
// /**
// * Release type - Beta or Core

View File

@ -24,6 +24,7 @@ import javafx.scene.control.Alert.AlertType;
public class WarnOnce implements PamSettings {
public static final int OK_CANCEL_OPTION = JOptionPane.OK_CANCEL_OPTION;
public static final int YES_NO_OPTION = JOptionPane.YES_NO_OPTION;
public static final int WARNING_MESSAGE = JOptionPane.DEFAULT_OPTION;
public static final int OK_OPTION = JOptionPane.OK_OPTION;
public static final int CANCEL_OPTION = JOptionPane.CANCEL_OPTION;

View File

@ -92,12 +92,17 @@ public class WarnOnceDialog extends PamDialog {
}
// if the message type is OK_OPTION, hide the cancel button
if (messageType == WarnOnce.OK_OPTION) {
if (messageType == WarnOnce.YES_NO_OPTION) {
getOkButton().setText("Yes");
getCancelButton().setText("No");
}
else if (messageType == WarnOnce.OK_OPTION) {
getCancelButton().setVisible(false);
} else {
getCancelButton().setVisible(true);
}
// change the button text to custom text, if needed
if (okButtonText!=null) {
getOkButton().setText(okButtonText);

View File

@ -60,7 +60,7 @@ public class AnalogArraySensorDataUnit extends PamDataUnit implements Array.sens
}
private Double getFieldVal(int iVal) {
if (sensorData == null || sensorData.length <= iVal) {
if (sensorData == null || sensorData.length <= iVal || iVal < 0) {
return null;
}
AnalogSensorData sensDat = sensorData[iVal];

View File

@ -225,7 +225,8 @@ public class AnalogDiagnosticsDisplay extends UserDisplayComponentAdapter implem
}
break;
case 4:
if (allItemData[rowIndex] != null) {
ItemAllData data = allItemData[rowIndex];
if (data != null) {
return allItemData[rowIndex].getIntValue();
}
break;

View File

@ -140,7 +140,7 @@ public class BBED549 {
public static double hexToEngineering(int range, int data) {
/**
* convert integer data to engineering units.
* @param range range on device, asumed the same for all channels.
* @param range range on device, assumed the same for all channels.
* @param data data array
* @return
*/