Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / startup / Startup2.java
index d7206f306e64eba656caa6d8a4e2113c652b739f..6b7b49cdfc962aa351b6321b77f44831a8006788 100644 (file)
@@ -4,37 +4,24 @@ import java.awt.GraphicsEnvironment;
 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;
 
 /**
@@ -67,6 +54,11 @@ public class Startup2 {
                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() {
@@ -91,24 +83,24 @@ public class Startup2 {
                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(1, new ThreadFactory() {
+               // Must be done after localization is initialized
+               ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase(true) {
 
                        @Override
-                       public Thread newThread(Runnable r) {
-                               Thread t = new Thread(r);
-                               t.setPriority(Thread.MIN_PRIORITY);
-                               return t;
+                       protected void load() {
+                               ConcurrentComponentPresetDatabaseLoader presetLoader = new ConcurrentComponentPresetDatabaseLoader( this );
+                               presetLoader.load();
+                               try {
+                                       presetLoader.await();
+                               } catch ( InterruptedException iex) {
+                                       
+                               }
                        }
                        
-               });
-
-               // Must be done after localization is initialized
-               ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase();
-               exec.submit( new ComponentPresetLoader( loading, componentPresetDao));
-               
+               };
                Application.setComponentPresetDao( componentPresetDao );
+
+               componentPresetDao.startLoading();
                
                // Setup the uncaught exception handler
                log.info("Registering exception handler");
@@ -140,17 +132,10 @@ public class Startup2 {
                // Load motors etc.
                log.info("Loading databases");
                
-               ConcurrentLoadingThrustCurveMotorSetDatabase motorLoader = new ConcurrentLoadingThrustCurveMotorSetDatabase(THRUSTCURVE_DIRECTORY);
-               motorLoader.startLoading();
-               Application.setMotorSetDatabase(motorLoader);
-
+               loadMotor();
+               
                Databases.fakeMethod();
                
-               try {
-                       loading.await();
-               } catch ( InterruptedException iex) {
-                       
-               }
 
                // Starting action (load files or open new document)
                log.info("Opening main application window");
@@ -164,6 +149,14 @@ public class Startup2 {
                
        }
        
+       /**
+        * 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.
@@ -226,28 +219,6 @@ public class Startup2 {
                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 {
-                       long start = System.currentTimeMillis();
-                       componentPresetDao.load("datafiles/presets", "(?i).*orc");
-                       latch.countDown();
-                       long end = System.currentTimeMillis();
-                       log.debug("Time to load presets: " + (end-start) + "ms");
-                       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