[#2150] Don't let illegal file format be a silent warning
This commit is contained in:
parent
75408cd48c
commit
5e99746e71
@ -94,7 +94,8 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
// desig diam len delays prop.w tot.w manufacturer
|
// desig diam len delays prop.w tot.w manufacturer
|
||||||
pieces = split(line);
|
pieces = split(line);
|
||||||
if (pieces.length != 7) {
|
if (pieces.length != 7) {
|
||||||
throw new IOException("Illegal file format.");
|
throw new IOException("Illegal file format. Motor header line must contain 7 fields:<br>" +
|
||||||
|
"  designation diameter length delays propellantWeight totalWeight manufacturer");
|
||||||
}
|
}
|
||||||
|
|
||||||
designation = pieces[0];
|
designation = pieces[0];
|
||||||
@ -140,7 +141,8 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
thrust.add(Double.parseDouble(buf[1]));
|
thrust.add(Double.parseDouble(buf[1]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Illegal file format.");
|
throw new IOException("Illegal file format.<br>" +
|
||||||
|
"Data should only have 2 entries: a time and thrust value.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +160,8 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
|
||||||
throw new IOException("Illegal file format.");
|
throw new IOException("Illegal file format. Could not convert value to a number.<br" +
|
||||||
|
">Verify that each number is correctly formatted.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import net.sf.openrocket.util.Pair;
|
|||||||
|
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An asynchronous database loader that loads the internal thrust curves
|
* An asynchronous database loader that loads the internal thrust curves
|
||||||
@ -140,22 +141,27 @@ public class MotorDatabaseLoader extends AsynchronousDatabaseLoader {
|
|||||||
*/
|
*/
|
||||||
private void loadFile(GeneralMotorLoader loader, Pair<File, InputStream> f) {
|
private void loadFile(GeneralMotorLoader loader, Pair<File, InputStream> f) {
|
||||||
try {
|
try {
|
||||||
List<ThrustCurveMotor.Builder> motors = loader.load(f.getV(), f.getU().getName());
|
|
||||||
try {
|
try {
|
||||||
|
List<ThrustCurveMotor.Builder> motors = loader.load(f.getV(), f.getU().getName());
|
||||||
addMotorsFromBuilders(motors);
|
addMotorsFromBuilders(motors);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException | IOException e) {
|
||||||
Translator trans = Application.getTranslator();
|
Translator trans = Application.getTranslator();
|
||||||
String fullPath = f.getU().getPath();
|
String fullPath = f.getU().getPath();
|
||||||
String message = "<html><body><p style='width: 400px;'><i>" + e.getMessage() +
|
String message = "<html><body><p style='width: 400px;'><i>" + e.getMessage() +
|
||||||
"</i>.<br><br>" + MessageFormat.format( trans.get("MotorDbLoaderDlg.message1"), fullPath) +
|
"</i>.<br><br>" + MessageFormat.format( trans.get("MotorDbLoaderDlg.message1"), fullPath) +
|
||||||
"<br>" + trans.get("MotorDbLoaderDlg.message2") + "</p></body></html>";
|
"<br>" + trans.get("MotorDbLoaderDlg.message2") + "</p></body></html>";
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
JOptionPane pane = new JOptionPane(message, JOptionPane.WARNING_MESSAGE);
|
JOptionPane pane = new JOptionPane(message, JOptionPane.WARNING_MESSAGE);
|
||||||
JDialog dialog = pane.createDialog(null, trans.get("MotorDbLoaderDlg.title"));
|
JDialog dialog = pane.createDialog(null, trans.get("MotorDbLoaderDlg.title"));
|
||||||
dialog.setModalityType(Dialog.ModalityType.MODELESS);
|
dialog.setModalityType(Dialog.ModalityType.MODELESS);
|
||||||
dialog.setAlwaysOnTop(true);
|
dialog.setAlwaysOnTop(true);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
f.getV().close();
|
f.getV().close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Exception while loading file " + f.getU() + ": " + e, e);
|
log.warn("Exception while loading file " + f.getU() + ": " + e, e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user