more focus fixing (JAL-943)
[jalview.git] / src / jalview / gui / Desktop.java
index 56bd82f..5dadeb3 100644 (file)
@@ -43,6 +43,8 @@ import javax.swing.*;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
+import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader;
+
 /**
  * Jalview Desktop
  * 
@@ -57,6 +59,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
 
   /**
+   * news reader - null if it was never started.
+   */
+  private BlogReader jvnews=null;
+
+  /**
    * @param listener
    * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
    */
@@ -267,6 +274,18 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
     showConsole(showjconsole);
 
+    showNews.setVisible(false);
+    final Desktop me = this;
+    // Thread off the news reader, in case there are connection problems.
+    new Thread( new Runnable() {
+      @Override
+      public void run()
+      {
+        jvnews = new BlogReader(me);
+        showNews.setVisible(true);
+      }
+    }).start();
+    
     this.addWindowListener(new WindowAdapter()
     {
       public void windowClosing(WindowEvent evt)
@@ -285,7 +304,24 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         }
       }
     });
-
+    this.addFocusListener(new FocusListener()
+    {
+      
+      @Override
+      public void focusLost(FocusEvent e)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public void focusGained(FocusEvent e)
+      {
+        Cache.log.debug("Relaying windows after focus gain");
+        // make sure that we sort windows properly after we gain focus
+        instance.relayerWindows();
+      }
+    });
     this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
     // Spawn a thread that shows the splashscreen
     SwingUtilities.invokeLater(new Runnable()
@@ -328,6 +364,35 @@ public class Desktop extends jalview.jbgui.GDesktop implements
             });
   }
 
+  protected void showNews_actionPerformed(ActionEvent e)
+  {
+    showNews(showNews.isSelected());
+  }
+  void showNews(boolean visible)
+  {
+    {
+      jvnews.setVisible(visible);
+      showNews.setSelected(visible);
+      if (visible)
+      {
+        jvnews.refreshNews();
+        jvnews.toFront();
+        // try real hard to get focus when the news is first opened
+        new Thread(new Runnable() {
+          @Override
+          public void run()
+          {
+            while (jvnews.isVisible() && !jvnews.requestFocusInWindow())
+            {
+              try { Thread.sleep(50); } catch (InterruptedException x) {}; 
+            }
+            
+          }
+        }).start();
+      }
+    }
+  }
+
   /**
    * recover the last known dimensions for a jalview window
    * 
@@ -914,6 +979,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
       jconsole.stopConsole();
     }
+    if (jvnews!=null)
+    {
+      storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
+      
+    }
+      
     System.exit(0);
   }
 
@@ -1946,6 +2017,17 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
   }
 
+  /**
+   * fixes stacking order after a modal dialog to ensure windows that should be on top actually are
+   */
+  public void relayerWindows()
+  {
+    if (jvnews!=null && jvnews.isVisible())
+    {
+      jvnews.toFront();
+    }
+  }
+
   protected JMenuItem groovyShell;
 
   public void doGroovyCheck()
@@ -2221,7 +2303,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       // register PCS handler for desktop.
       discoverer.addPropertyChangeListener(changeSupport);
     }
-    if (Cache.getDefault("SHOW_JWS1_SERVICES", true))
+    // JAL-940 - disabled JWS1 service configuration - always start discoverer until we phase out completely
+    if (true)
     {
       (t0 = new Thread(discoverer)).start();
     }