Clean up application startup
This commit is contained in:
parent
730f7b2697
commit
d63dc601c0
@ -54,11 +54,6 @@ public class ApplicationStartup {
|
||||
log.info("Checking for graphics head");
|
||||
checkHead();
|
||||
|
||||
// Check that we're running a good version of a JRE
|
||||
log.info("Checking JRE compatibility");
|
||||
VersionHelper.checkVersion();
|
||||
VersionHelper.checkOpenJDK();
|
||||
|
||||
// If running on a MAC set up OSX UI Elements.
|
||||
if (SystemInfo.getPlatform() == Platform.MAC_OS) {
|
||||
OSXStartup.setupOSX();
|
||||
@ -88,24 +83,6 @@ public class ApplicationStartup {
|
||||
log.info("Initializing the splash screen");
|
||||
Splash.init();
|
||||
|
||||
// Must be done after localization is initialized
|
||||
ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase(true) {
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
ConcurrentComponentPresetDatabaseLoader presetLoader = new ConcurrentComponentPresetDatabaseLoader(this);
|
||||
presetLoader.load();
|
||||
try {
|
||||
presetLoader.await();
|
||||
} catch (InterruptedException iex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Application.setComponentPresetDao(componentPresetDao);
|
||||
|
||||
componentPresetDao.startLoading();
|
||||
|
||||
// Setup the uncaught exception handler
|
||||
log.info("Registering exception handler");
|
||||
@ -134,9 +111,11 @@ public class ApplicationStartup {
|
||||
// Load defaults
|
||||
((SwingPreferences) Application.getPreferences()).loadDefaultUnits();
|
||||
|
||||
|
||||
|
||||
// Load motors etc.
|
||||
log.info("Loading databases");
|
||||
|
||||
loadPresetComponents();
|
||||
loadMotor();
|
||||
|
||||
Databases.fakeMethod();
|
||||
@ -147,8 +126,7 @@ public class ApplicationStartup {
|
||||
if (!handleCommandLine(args)) {
|
||||
if (!Application.getPreferences().isAutoOpenLastDesignOnStartupEnabled()) {
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
String lastFile = MRUDesignFile.getInstance().getLastEditedDesignFile();
|
||||
if (lastFile != null) {
|
||||
if (!BasicFrame.open(new File(lastFile), null)) {
|
||||
@ -171,8 +149,33 @@ public class ApplicationStartup {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this method is useful for the python bindings.
|
||||
* Start loading preset components in background thread.
|
||||
*
|
||||
* Public for Python bindings.
|
||||
*/
|
||||
public void loadPresetComponents() {
|
||||
ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase(true) {
|
||||
@Override
|
||||
protected void load() {
|
||||
ConcurrentComponentPresetDatabaseLoader presetLoader = new ConcurrentComponentPresetDatabaseLoader(this);
|
||||
presetLoader.load();
|
||||
try {
|
||||
presetLoader.await();
|
||||
} catch (InterruptedException iex) {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
Application.setComponentPresetDao(componentPresetDao);
|
||||
componentPresetDao.startLoading();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start loading motors in background thread.
|
||||
*
|
||||
* Public for Python bindings.
|
||||
*/
|
||||
public void loadMotor() {
|
||||
ConcurrentLoadingThrustCurveMotorSetDatabase motorLoader = new ConcurrentLoadingThrustCurveMotorSetDatabase(THRUSTCURVE_DIRECTORY);
|
||||
|
@ -1,129 +0,0 @@
|
||||
package net.sf.openrocket.startup;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
|
||||
public class VersionHelper {
|
||||
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
|
||||
private static final int REQUIRED_MAJOR_VERSION = 1;
|
||||
private static final int REQUIRED_MINOR_VERSION = 6;
|
||||
|
||||
// OpenJDK 1.6.0_0-b16 is known to work, 1.6.0_0-b12 does not
|
||||
private static final String BAD_OPENJDK_VERSION = "^1.6.0_0-b([0-9]|1[1-5])$";
|
||||
|
||||
|
||||
/**
|
||||
* Check that the JRE version is high enough.
|
||||
*/
|
||||
static void checkVersion() {
|
||||
|
||||
String[] version = System.getProperty("java.specification.version", "").split("\\.");
|
||||
|
||||
String jreName = System.getProperty("java.vm.name", "(unknown)");
|
||||
String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
|
||||
String jreVendor = System.getProperty("java.vendor", "(unknown)");
|
||||
|
||||
log.info("Running JRE " + jreName + " version " + jreVersion + " by " + jreVendor);
|
||||
|
||||
int major, minor;
|
||||
|
||||
try {
|
||||
major = Integer.parseInt(version[0]);
|
||||
minor = Integer.parseInt(version[1]);
|
||||
|
||||
if (major < REQUIRED_MAJOR_VERSION ||
|
||||
(major == REQUIRED_MAJOR_VERSION && minor < REQUIRED_MINOR_VERSION)) {
|
||||
error(new String[] { "Java SE version 6 is required to run OpenRocket.",
|
||||
"You are currently running " + jreName + " version " +
|
||||
jreVersion + " by " + jreVendor });
|
||||
}
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
confirm(new String[] { "The Java version in use could not be detected.",
|
||||
"OpenRocket requires at least Java SE 6.",
|
||||
"Continue anyway?" });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether OpenJDK is being used, and if it is warn the user about
|
||||
* problems and confirm whether to continue.
|
||||
*/
|
||||
static void checkOpenJDK() {
|
||||
|
||||
if (System.getProperty("java.runtime.name", "").toLowerCase(Locale.ENGLISH).indexOf("icedtea") >= 0 ||
|
||||
System.getProperty("java.vm.name", "").toLowerCase(Locale.ENGLISH).indexOf("openjdk") >= 0) {
|
||||
|
||||
String jreName = System.getProperty("java.vm.name", "(unknown)");
|
||||
String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
|
||||
String jreVendor = System.getProperty("java.vendor", "(unknown)");
|
||||
|
||||
if (jreVersion.matches(BAD_OPENJDK_VERSION)) {
|
||||
|
||||
confirm(new String[] { "Old versions of OpenJDK are known to have problems " +
|
||||
"running OpenRocket.",
|
||||
" ",
|
||||
"You are currently running " + jreName + " version " +
|
||||
jreVersion + " by " + jreVendor,
|
||||
"Do you want to continue?" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////// Helper methods //////////
|
||||
|
||||
/**
|
||||
* Presents an error message to the user and exits the application.
|
||||
*
|
||||
* @param message an array of messages to present.
|
||||
*/
|
||||
private static void error(String[] message) {
|
||||
|
||||
System.err.println();
|
||||
System.err.println("Error starting OpenRocket:");
|
||||
System.err.println();
|
||||
for (int i = 0; i < message.length; i++) {
|
||||
System.err.println(message[i]);
|
||||
}
|
||||
System.err.println();
|
||||
|
||||
|
||||
if (!GraphicsEnvironment.isHeadless()) {
|
||||
|
||||
JOptionPane.showMessageDialog(null, message, "Error starting OpenRocket",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Presents the user with a message dialog and asks whether to continue.
|
||||
* If the user does not select "Yes" the the application exits.
|
||||
*
|
||||
* @param message the message Strings to show.
|
||||
*/
|
||||
private static void confirm(String[] message) {
|
||||
|
||||
if (!GraphicsEnvironment.isHeadless()) {
|
||||
|
||||
if (JOptionPane.showConfirmDialog(null, message, "Error starting OpenRocket",
|
||||
JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user