remove name of progress bar when stopping ws refresh progress.
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index c5a9235..b7cccf7 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -57,8 +57,11 @@ public class SequenceFetcher extends JPanel implements Runnable
   private static jalview.ws.SequenceFetcher sfetch = null;
 
   private static String dasRegistry = null;
-  private static boolean _initingFetcher=false;
-  private static Thread initingThread=null;
+
+  private static boolean _initingFetcher = false;
+
+  private static Thread initingThread = null;
+
   /**
    * Blocking method that initialises and returns the shared instance of the
    * SequenceFetcher client
@@ -70,29 +73,39 @@ public class SequenceFetcher extends JPanel implements Runnable
   public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
           final IProgressIndicator guiWindow)
   {
-    if (_initingFetcher && initingThread!=null && initingThread.isAlive())
+    if (_initingFetcher && initingThread != null && initingThread.isAlive())
     {
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar("Waiting for Sequence Database Fetchers to initialise",
+        guiWindow.setProgressBar(
+                "Waiting for Sequence Database Fetchers to initialise",
                 Thread.currentThread().hashCode());
       }
-      // initting happening on another thread - so wait around to see if it finishes.
-      while (_initingFetcher && initingThread!=null && initingThread.isAlive())
+      // initting happening on another thread - so wait around to see if it
+      // finishes.
+      while (_initingFetcher && initingThread != null
+              && initingThread.isAlive())
       {
-        try {Thread.sleep(10);} catch (Exception e){};
+        try
+        {
+          Thread.sleep(10);
+        } catch (Exception e)
+        {
+        }
+        ;
       }
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar("Waiting for Sequence Database Fetchers to initialise",
+        guiWindow.setProgressBar(
+                "Waiting for Sequence Database Fetchers to initialise",
                 Thread.currentThread().hashCode());
       }
     }
     if (sfetch == null
             || dasRegistry != DasSourceBrowser.getDasRegistryURL())
     {
-      _initingFetcher=true;
-      initingThread=Thread.currentThread();
+      _initingFetcher = true;
+      initingThread = Thread.currentThread();
       /**
        * give a visual indication that sequence fetcher construction is occuring
        */
@@ -109,8 +122,8 @@ public class SequenceFetcher extends JPanel implements Runnable
                 initingThread.hashCode());
       }
       sfetch = sf;
-      _initingFetcher=false;
-      initingThread=null;
+      _initingFetcher = false;
+      initingThread = null;
     }
     return sfetch;
   }
@@ -198,11 +211,11 @@ public class SequenceFetcher extends JPanel implements Runnable
     frame.setContentPane(this);
     if (new jalview.util.Platform().isAMac())
     {
-      Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
+      Desktop.addInternalFrame(frame, getFrameTitle(), 400, 240);
     }
     else
     {
-      Desktop.addInternalFrame(frame, getFrameTitle(), 400, 140);
+      Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
     }
   }
 
@@ -220,8 +233,12 @@ public class SequenceFetcher extends JPanel implements Runnable
     dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
     jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
-    jLabel1
-            .setText("Separate multiple accession ids with semi colon \";\"");
+    jLabel1.setText("Separate multiple accession ids with semi colon \";\"");
+
+    replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
+    replacePunctuation
+            .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
+    replacePunctuation.setText("Replace commas with semi-colons");
     ok.setText("OK");
     ok.addActionListener(new ActionListener()
     {
@@ -284,10 +301,13 @@ public class SequenceFetcher extends JPanel implements Runnable
         {
           db = sfetch.getSourceProxy((String) sources.get(database
                   .getSelectedItem()));
-          dbeg.setText("Example query: " + db.getTestQuery());
+          String eq = db.getTestQuery();
+          dbeg.setText("Example query: " + eq);
+          replacePunctuation.setEnabled(!(eq != null && eq.indexOf(",") > -1));
         } catch (Exception ex)
         {
           dbeg.setText("");
+          replacePunctuation.setEnabled(true);
         }
         jPanel2.repaint();
       }
@@ -295,7 +315,10 @@ public class SequenceFetcher extends JPanel implements Runnable
     dbeg.setText("");
     jPanel2.add(database, java.awt.BorderLayout.NORTH);
     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
-    jPanel2.add(jLabel1, java.awt.BorderLayout.SOUTH);
+    JPanel jPanel2a = new JPanel(new BorderLayout());
+    jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
+    jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
+    jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
     // jPanel2.setPreferredSize(new Dimension())
     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
@@ -331,6 +354,8 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   JLabel jLabel1 = new JLabel();
 
+  JCheckBox replacePunctuation = new JCheckBox();
+
   JButton ok = new JButton();
 
   JButton clear = new JButton();
@@ -393,9 +418,19 @@ public class SequenceFetcher extends JPanel implements Runnable
     {
       error += "Please select the source database\n";
     }
-    // TODO: make this transformation optional and configurable
-    com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex(
-            "(\\s|[,; ])+", ";"); // \\s+", "");
+    // TODO: make this transformation more configurable
+    com.stevesoft.pat.Regex empty;
+    if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
+    {
+      empty = new com.stevesoft.pat.Regex(
+      // replace commas and spaces with a semicolon
+              "(\\s|[,; ])+", ";");
+    }
+    else
+    {
+      // just turn spaces and semicolons into single semicolons
+      empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
+    }
     textArea.setText(empty.replaceAll(textArea.getText()));
     // see if there's anthing to search with
     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
@@ -414,9 +449,9 @@ public class SequenceFetcher extends JPanel implements Runnable
     Enumeration en = new StringTokenizer(textArea.getText(), ";");
     try
     {
-      guiWindow.setProgressBar("Fetching Sequences from "
-              + database.getSelectedItem(), Thread.currentThread()
-              .hashCode());
+      guiWindow.setProgressBar(
+              "Fetching Sequences from " + database.getSelectedItem(),
+              Thread.currentThread().hashCode());
       DbSourceProxy proxy = sfetch.getSourceProxy((String) sources
               .get(source));
       if (proxy.getAccessionSeparator() == null)
@@ -445,10 +480,8 @@ public class SequenceFetcher extends JPanel implements Runnable
               indres = proxy.getSequenceRecords(item);
             } catch (OutOfMemoryError oome)
             {
-              new OOMWarning(
-                      "fetching " + item + " from "
-                              + database.getSelectedItem(),oome,
-                      this);
+              new OOMWarning("fetching " + item + " from "
+                      + database.getSelectedItem(), oome, this);
             }
             if (indres != null)
             {
@@ -484,13 +517,10 @@ public class SequenceFetcher extends JPanel implements Runnable
           aresult = proxy.getSequenceRecords(multiacc.toString());
         } catch (OutOfMemoryError oome)
         {
-          new OOMWarning(
-                  "fetching " + multiacc + " from "
-                          + database.getSelectedItem(),oome,
-                  this);
+          new OOMWarning("fetching " + multiacc + " from "
+                  + database.getSelectedItem(), oome, this);
         }
-        
-        
+
       }
 
     } catch (Exception e)