Include OSX UI elements.
[debian/openrocket] / core / src / net / sf / openrocket / startup / Startup2.java
index d7206f306e64eba656caa6d8a4e2113c652b739f..85500a361299d3f49668afd4c9c983791406d9a5 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,22 +83,10 @@ 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() {
-
-                       @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 );
                
@@ -140,14 +120,12 @@ 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();
+                       presetLoader.await();
                } catch ( InterruptedException iex) {
                        
                }
@@ -164,6 +142,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 +212,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