JAL-468 JAL-936 sort alignment by tree and autosort for new tree
[jalview.git] / src / jalview / gui / Desktop.java
old mode 100755 (executable)
new mode 100644 (file)
index dbb6955..56bd82f
@@ -48,10 +48,10 @@ import javax.swing.event.MenuListener;
  * 
  * 
  * @author $author$
- * @version $Revision$
+ * @version $Revision: 1.155 $
  */
 public class Desktop extends jalview.jbgui.GDesktop implements
-        DropTargetListener, ClipboardOwner, IProgressIndicator
+        DropTargetListener, ClipboardOwner, IProgressIndicator, jalview.api.StructureSelectionManagerProvider
 {
 
   private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
@@ -232,9 +232,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     showMemusage.setSelected(selmemusage);
     desktop.setBackground(Color.white);
     getContentPane().setLayout(new BorderLayout());
+    // alternate config - have scrollbars - see notes in JAL-153
+    //JScrollPane sp = new JScrollPane();
+    //sp.getViewport().setView(desktop);
+    //getContentPane().add(sp, BorderLayout.CENTER);
     getContentPane().add(desktop, BorderLayout.CENTER);
-    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
-
+      desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
+      
     // This line prevents Windows Look&Feel resizing all new windows to maximum
     // if previous window was maximised
     desktop.setDesktopManager(new MyDesktopManager(
@@ -631,6 +635,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     } catch (java.beans.PropertyVetoException ve)
     {
     }
+    catch (java.lang.ClassCastException cex)
+    {
+      Cache.log.warn("Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869",cex);
+    }
   }
 
   public void lostOwnership(Clipboard clipboard, Transferable contents)
@@ -938,7 +946,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     {
       message.append("\n\n!! Jalview version "
               + jalview.bin.Cache.getProperty("LATEST_VERSION")
-              + " is available for download from http://www.jalview.org !!\n");
+              + " is available for download from "+jalview.bin.Cache.getDefault("www.jalview.org","http://www.jalview.org")+" !!\n");
 
     }
     // TODO: update this text for each release or centrally store it for lite
@@ -1174,11 +1182,18 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
-      java.io.File choice = chooser.getSelectedFile();
+      final Desktop me = this;
+      final java.io.File choice = chooser.getSelectedFile();
+      new Thread(new Runnable()
+      {
+        public void run()
+        {
+
       setProgressBar("Saving jalview project " + choice.getName(),
               choice.hashCode());
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
       // TODO catch and handle errors for savestate
+      // TODO prevent user from messing with the Desktop whilst we're saving
       try
       {
         new Jalview2XML().SaveState(choice);
@@ -1191,12 +1206,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         Cache.log
                 .error("Problems whilst trying to save to "
                         + choice.getName(), ex);
-        JOptionPane.showMessageDialog(this,
+        JOptionPane.showMessageDialog(me,
                 "Error whilst saving current state to " + choice.getName(),
                 "Couldn't save project", JOptionPane.WARNING_MESSAGE);
       }
       setProgressBar(null, choice.hashCode());
-
+        }
+      }).start();
     }
   }
 
@@ -1254,44 +1270,47 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   }
 
   JPanel progressPanel;
-
+  ArrayList<JPanel> fileLoadingPanels=new ArrayList<JPanel>();
   public void startLoading(final String fileName)
   {
     if (fileLoadingCount == 0)
     {
-      addProgressPanel("Loading File: " + fileName + "   ");
-
+      fileLoadingPanels.add(addProgressPanel("Loading File: " + fileName + "   "));
     }
     fileLoadingCount++;
   }
 
-  private JProgressBar addProgressPanel(String string)
+  private JPanel addProgressPanel(String string)
   {
     if (progressPanel == null)
     {
-      progressPanel = new JPanel(new BorderLayout());
+      progressPanel = new JPanel(new GridLayout(1,1));
       totalProgressCount = 0;
+      instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
     }
+    JPanel thisprogress=new JPanel(new BorderLayout(10,5));
     JProgressBar progressBar = new JProgressBar();
     progressBar.setIndeterminate(true);
 
-    progressPanel.add(new JLabel(string), BorderLayout.WEST);
+    thisprogress.add(new JLabel(string), BorderLayout.WEST);
 
-    progressPanel.add(progressBar, BorderLayout.CENTER);
-
-    instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
-    totalProgressCount++;
-    validate();
-    return progressBar;
+    thisprogress.add(progressBar, BorderLayout.CENTER);
+    progressPanel.add(thisprogress);
+    ((GridLayout)progressPanel.getLayout()).setRows(((GridLayout)progressPanel.getLayout()).getRows()+1);
+    ++totalProgressCount;
+    instance.validate();
+    return thisprogress;
   }
 
   int totalProgressCount = 0;
 
-  private void removeProgressPanel(JProgressBar progbar)
+  private void removeProgressPanel(JPanel progbar)
   {
     if (progressPanel != null)
     {
       progressPanel.remove(progbar);
+      GridLayout gl = (GridLayout) progressPanel.getLayout();
+      gl.setRows(gl.getRows()-1);
       if (--totalProgressCount < 1)
       {
         this.getContentPane().remove(progressPanel);
@@ -1306,11 +1325,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     fileLoadingCount--;
     if (fileLoadingCount < 1)
     {
-      if (progressPanel != null)
+      for (JPanel flp : fileLoadingPanels)
       {
-        this.getContentPane().remove(progressPanel);
-        progressPanel = null;
+        removeProgressPanel(flp);
       }
+      fileLoadingPanels.clear();
       fileLoadingCount = 0;
     }
     validate();
@@ -1757,7 +1776,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       if (value == JalviewFileChooser.APPROVE_OPTION)
       {
         java.io.File choice = chooser.getSelectedFile();
-        JProgressBar progpanel = addProgressPanel("Saving VAMSAS Document to "
+        JPanel progpanel = addProgressPanel("Saving VAMSAS Document to "
                 + choice.getName());
         jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
         String warnmsg = null;
@@ -1791,7 +1810,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
   }
 
-  JProgressBar vamUpdate = null;
+  JPanel vamUpdate = null;
 
   /**
    * hide vamsas user gui bits when a vamsas document event is being handled.
@@ -2063,7 +2082,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   /**
    * Progress bars managed by the IProgressIndicator method.
    */
-  private Hashtable progressBars, progressBarHandlers;
+  private Hashtable<Long,JPanel> progressBars;
+  private Hashtable<Long,IProgressIndicatorHandler> progressBarHandlers;
 
   /*
    * (non-Javadoc)
@@ -2074,13 +2094,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     if (progressBars == null)
     {
-      progressBars = new Hashtable();
-      progressBarHandlers = new Hashtable();
+      progressBars = new Hashtable<Long,JPanel>();
+      progressBarHandlers = new Hashtable<Long,IProgressIndicatorHandler>();
     }
 
     if (progressBars.get(new Long(id)) != null)
     {
-      JProgressBar progressPanel = (JProgressBar) progressBars
+      JPanel progressPanel = progressBars
               .remove(new Long(id));
       if (progressBarHandlers.contains(new Long(id)))
       {