import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.ToolTipManager;
+import net.sf.openrocket.arch.SystemInfo;
+import net.sf.openrocket.arch.SystemInfo.Platform;
import net.sf.openrocket.communication.UpdateInfo;
import net.sf.openrocket.communication.UpdateInfoRetriever;
import net.sf.openrocket.database.ComponentPresetDatabase;
import net.sf.openrocket.database.Databases;
-import net.sf.openrocket.database.ThrustCurveMotorSet;
-import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;
-import net.sf.openrocket.file.iterator.DirectoryIterator;
-import net.sf.openrocket.file.iterator.FileIterator;
-import net.sf.openrocket.file.motor.MotorLoaderHelper;
import net.sf.openrocket.gui.dialogs.UpdateInfoDialog;
import net.sf.openrocket.gui.main.BasicFrame;
import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.gui.main.SwingExceptionHandler;
import net.sf.openrocket.gui.util.GUIUtil;
-import net.sf.openrocket.gui.util.SimpleFileFilter;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.logging.LogHelper;
-import net.sf.openrocket.motor.Motor;
-import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.util.BuildProperties;
/**
private static final String THRUSTCURVE_DIRECTORY = "datafiles/thrustcurves/";
- /** Block motor loading for this many milliseconds */
- private static AtomicInteger blockLoading = new AtomicInteger(Integer.MAX_VALUE);
-
-
-
/**
* Run when starting up OpenRocket after Application has been set up.
*
VersionHelper.checkVersion();
VersionHelper.checkOpenJDK();
+ // If running on a MAC set up OSX UI Elements.
+ if ( SystemInfo.getPlatform() == Platform.MAC_OS ){
+ OSXStartup.setupOSX();
+ }
+
// Run the actual startup method in the EDT since it can use progress dialogs etc.
log.info("Moving startup to EDT");
SwingUtilities.invokeAndWait(new Runnable() {
log.info("Initializing the splash screen");
Splash.init();
- // Latch which counts the number of background loading processes we need to complete.
- CountDownLatch loading = new CountDownLatch(1);
- ExecutorService exec = Executors.newFixedThreadPool(2, new ThreadFactory() {
-
- @Override
- public Thread newThread(Runnable r) {
- Thread t = new Thread(r);
- t.setPriority(Thread.MIN_PRIORITY);
- return t;
- }
-
- });
-
// Must be done after localization is initialized
ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase();
- exec.submit( new ComponentPresetLoader( loading, componentPresetDao));
+ ConcurrentComponentPresetDatabaseLoader presetLoader = new ConcurrentComponentPresetDatabaseLoader( componentPresetDao );
+ presetLoader.load();
Application.setComponentPresetDao( componentPresetDao );
// Load motors etc.
log.info("Loading databases");
+
loadMotor();
+
Databases.fakeMethod();
try {
- loading.await();
+ presetLoader.await();
} catch ( InterruptedException iex) {
}
log.info("Checking update status");
checkUpdateStatus(updateInfo);
- // Block motor loading for 1.5 seconds to allow window painting to be faster
- blockLoading.set(1500);
}
+ /**
+ * this method is useful for the python bindings.
+ */
+ public static void loadMotor() {
+ ConcurrentLoadingThrustCurveMotorSetDatabase motorLoader = new ConcurrentLoadingThrustCurveMotorSetDatabase(THRUSTCURVE_DIRECTORY);
+ motorLoader.startLoading();
+ Application.setMotorSetDatabase(motorLoader);
+ }
/**
* Check that the JRE is not running headless.
}
- private static void loadMotor() {
-
- log.info("Starting motor loading from " + THRUSTCURVE_DIRECTORY + " in background thread.");
- ThrustCurveMotorSetDatabase db = new ThrustCurveMotorSetDatabase(true) {
-
- @Override
- protected void loadMotors() {
-
- // Block loading until timeout occurs or database is taken into use
- log.info("Blocking motor loading while starting up");
- while (!inUse && blockLoading.addAndGet(-100) > 0) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- }
- log.info("Blocking ended, inUse=" + inUse + " blockLoading=" + blockLoading.get());
-
- // Start loading
- log.info("Loading motors from " + THRUSTCURVE_DIRECTORY);
- long t0 = System.currentTimeMillis();
- int fileCount;
- int thrustCurveCount;
-
- // Load the packaged thrust curves
- List<Motor> list;
- FileIterator iterator = DirectoryIterator.findDirectory(THRUSTCURVE_DIRECTORY,
- new SimpleFileFilter("", false, "eng", "rse"));
- if (iterator == null) {
- throw new IllegalStateException("Thrust curve directory " + THRUSTCURVE_DIRECTORY +
- "not found, distribution built wrong");
- }
- list = MotorLoaderHelper.load(iterator);
- for (Motor m : list) {
- this.addMotor((ThrustCurveMotor) m);
- }
- fileCount = iterator.getFileCount();
-
- thrustCurveCount = list.size();
-
- // Load the user-defined thrust curves
- for (File file : ((SwingPreferences) Application.getPreferences()).getUserThrustCurveFiles()) {
- log.info("Loading motors from " + file);
- list = MotorLoaderHelper.load(file);
- for (Motor m : list) {
- this.addMotor((ThrustCurveMotor) m);
- }
- fileCount++;
- thrustCurveCount += list.size();
- }
-
- long t1 = System.currentTimeMillis();
-
- // Count statistics
- int distinctMotorCount = 0;
- int distinctThrustCurveCount = 0;
- distinctMotorCount = motorSets.size();
- for (ThrustCurveMotorSet set : motorSets) {
- distinctThrustCurveCount += set.getMotorCount();
- }
- log.info("Motor loading done, took " + (t1 - t0) + " ms to load "
- + fileCount + " files/directories containing "
- + thrustCurveCount + " thrust curves which contained "
- + distinctMotorCount + " distinct motors with "
- + distinctThrustCurveCount + " distinct thrust curves.");
- }
-
- };
- db.startLoading();
- Application.setMotorSetDatabase(db);
- }
-
private static void checkUpdateStatus(final UpdateInfoRetriever updateInfo) {
if (updateInfo == null)
return;
timer.start();
}
- private static class ComponentPresetLoader implements Callable {
-
- CountDownLatch latch;
- ComponentPresetDatabase componentPresetDao;
-
- private ComponentPresetLoader( CountDownLatch latch, ComponentPresetDatabase componentPresetDao ) {
- this.componentPresetDao = componentPresetDao;
- this.latch = latch;
- }
-
- @Override
- public Object call() throws Exception {
- componentPresetDao.load("datafiles/presets", "(?i).*orc");
- latch.countDown();
- return null;
- }
-
- }
-
/**
* Handles arguments passed from the command line. This may be used either
* when starting the first instance of OpenRocket or later when OpenRocket is