Merge branch 'develop' into releases/Release_2_11_Branch
[jalview.git] / getdown / src / getdown / launcher / src / main / java / com / threerings / getdown / launcher / Getdown.java
index e1ef2eb..01bf370 100644 (file)
@@ -231,7 +231,9 @@ public abstract class Getdown extends Thread
         Config config = _app.init(true);
         if (preloads) doPredownloads(_app.getResources());
         _ifc = new Application.UpdateInterface(config);
-        _status.setAppbase(_app.getAppbase());
+        if (_status != null) {
+          _status.setAppbase(_app.getAppbase());
+        }
     }
 
     /**
@@ -571,7 +573,7 @@ public abstract class Getdown extends Thread
             // show the patch notes button, if applicable
             if (!StringUtil.isBlank(_ifc.patchNotesUrl)) {
                 createInterfaceAsync(false);
-                EventQueue.invokeLater(new Runnable() {
+                EQinvoke(new Runnable() {
                     public void run () {
                         _patchNotes.setVisible(true);
                     }
@@ -732,8 +734,8 @@ public abstract class Getdown extends Thread
                 }
             }
 
-            _container.setVisible(true);
-            _container.validate();
+            //_container.setVisible(true);
+            //_container.validate();
 
             // if we have a UI open and we haven't been around for at least 5 seconds (the default
             // for min_show_seconds), don't stick a fork in ourselves straight away but give our
@@ -767,12 +769,8 @@ public abstract class Getdown extends Thread
         if (_silent || (_container != null && !reinit)) {
             return;
         }
-/*
-        EventQueue.invokeLater(new Runnable() {
-            public void run () {
-*/
-        try {
-        EventQueue.invokeAndWait(new Runnable() {
+        
+        EQinvoke (new Runnable() {
             public void run () {
                
                 if (_container == null || reinit) {
@@ -818,8 +816,8 @@ public abstract class Getdown extends Thread
                                                  instantSplashPane.setSize(bwidth,bheight);
                                                  instantSplashPane.setPreferredSize(new Dimension(bwidth,bheight));
 
-                                                 _layers.add(instantSplashPane, Integer.valueOf(0));
-                                               
+                                                 _layers.add(instantSplashPane, Integer.valueOf(1));
+                                                 
                                                  _container.setPreferredSize(new Dimension(bwidth,bheight));
                       }
                     } catch (Exception e) {
@@ -835,16 +833,14 @@ public abstract class Getdown extends Thread
                     _patchNotes.setFont(StatusPanel.FONT);
                     _layers.add(_patchNotes);
                     _status = new StatusPanel(_msgs);
-                                       //setStatusAsync("test", stepToGlobalPercent(1), -1L, false);
-                    _layers.add(_status, Integer.valueOf(10));
+                    setStatusAsync("m.initialising", 0, -1L, true);
+                    //_layers.add(_status, Integer.valueOf(2));
                     initInterface();
                 }
                 showContainer();
             }
         });
-        } catch (Exception e) {
-               e.printStackTrace();
-        }
+        
     }
 
     /**
@@ -962,12 +958,7 @@ public abstract class Getdown extends Thread
             createInterfaceAsync(false);
         }
 
-/*
-        EventQueue.invokeLater(new Runnable() {
-            public void run () {
-*/
-        try {
-        EventQueue.invokeAndWait(new Runnable() {
+        EQinvoke(new Runnable() {
             public void run () {
 
                if (_status == null) {
@@ -983,12 +974,19 @@ public abstract class Getdown extends Thread
                     _status.setProgress(0, -1L);
                 } else if (percent >= 0) {
                     _status.setProgress(percent, remaining);
+                } else {
+                       //_status.setStatus("m.initialising", false);
                 }
+                
             }
         });
-        } catch (Exception e) {
-               e.printStackTrace();
+        
+        if (_status != null && ! _addedStatusLayer) {
+               _layers.add(_status, Integer.valueOf(2));
+               _addedStatusLayer = true;
+               initInterface();
         }
+        
     }
 
     protected void reportTrackingEvent (String event, int progress)
@@ -1117,7 +1115,32 @@ public abstract class Getdown extends Thread
             setStatusAsync(null, stepToGlobalPercent(percent), -1L, false);
         }
     };
-
+    
+    // Asynchronous or synchronous progress updates
+    protected void EQinvoke(Runnable r) {
+      
+      try {
+        readConfig(false);
+      } catch (Exception e) {
+        log.warning("Could't read config when invoking GUI action", "Exception", e.getMessage());
+      }
+      if (_ifc != null && (_shownContainer?_ifc.progressSyncAfterShown:_ifc.progressSync)) {
+        try {
+          EventQueue.invokeAndWait(r);
+          //r.run();
+        } catch (Exception e) {
+          log.warning("Tried to invokeAndWait but couldn't. Going to invokeLater instead", "Exception", e.getMessage());
+          EventQueue.invokeLater(r);
+        }
+      } else {
+        EventQueue.invokeLater(r);
+        //r.run();
+      }
+      
+      //try { Thread.sleep(500); } catch (Exception e) {}
+      
+    }
+    
     protected Application _app;
     protected Application.UpdateInterface _ifc = new Application.UpdateInterface(Config.EMPTY);
 
@@ -1130,18 +1153,21 @@ public abstract class Getdown extends Thread
     protected AbortPanel _abort;
     protected RotatingBackgrounds _background;
 
+    protected boolean _addedStatusLayer;
     protected boolean _dead;
     protected boolean _silent;
     protected boolean _launchInSilent;
     protected boolean _noUpdate;
     protected long _startup;
-
     protected Set<Resource> _toInstallResources;
     protected boolean _readyToInstall;
 
     protected boolean _enableTracking = true;
     protected int _reportedProgress = 0;
 
+    protected boolean _shownContainer;
+
     /** Number of minutes to wait after startup before beginning any real heavy lifting. */
     protected int _delay;