JAL-3253-applet comments/Overrides only
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index 8037fed..b8e3b33 100755 (executable)
@@ -64,9 +64,9 @@ import javax.swing.SwingConstants;
  * If the selected source is Uniprot or PDB, a free text search panel is opened
  * instead to perform the search and selection.
  */
+@SuppressWarnings("serial")
 public class SequenceFetcher extends JPanel implements Runnable
 {
-  private static jalview.ws.SequenceFetcher sfetch = null;
 
   JLabel exampleAccession;
 
@@ -97,20 +97,6 @@ public class SequenceFetcher extends JPanel implements Runnable
   volatile boolean _isConstructing = false;
 
   /**
-   * Returns the shared instance of the SequenceFetcher client
-   * 
-   * @return
-   */
-  public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton()
-  {
-    if (sfetch == null)
-    {
-      sfetch = new jalview.ws.SequenceFetcher();
-    }
-    return sfetch;
-  }
-
-  /**
    * Constructor given a client to receive any status or progress messages
    * (currently either the Desktop, or an AlignFrame panel)
    * 
@@ -132,7 +118,7 @@ public class SequenceFetcher extends JPanel implements Runnable
           final String selectedDb, final String queryString)
   {
     this.progressIndicator = guiIndic;
-    getSequenceFetcherSingleton();
+
     this.guiWindow = progressIndicator;
 
     if (progressIndicator instanceof AlignFrame)
@@ -145,8 +131,8 @@ public class SequenceFetcher extends JPanel implements Runnable
 
     frame = new JInternalFrame();
     frame.setContentPane(this);
-    int height = Platform.isAMac() ? 240 : 180;
-    Desktop.addInternalFrame(frame, getFrameTitle(), true, 400, height);
+    Desktop.addInternalFrame(frame, getFrameTitle(), true, 400, 
+               Platform.isAMacAndNotJS() ? 240 : 180);
   }
 
   private String getFrameTitle()
@@ -164,7 +150,8 @@ public class SequenceFetcher extends JPanel implements Runnable
     database = new JComboBox<>();
     database.setFont(JvSwingUtils.getLabelFont());
     database.setPrototypeDisplayValue("ENSEMBLGENOMES   ");
-    String[] sources = new jalview.ws.SequenceFetcher().getSupportedDb();
+    String[] sources = jalview.ws.SequenceFetcher.getInstance()
+            .getSupportedDb();
     Arrays.sort(sources, String.CASE_INSENSITIVE_ORDER);
     database.addItem(MessageManager.getString("action.select_ddbb"));
     for (String source : sources)
@@ -187,13 +174,13 @@ public class SequenceFetcher extends JPanel implements Runnable
 
         if ("pdb".equalsIgnoreCase(currentSelection))
         {
-          new PDBFTSPanel(SequenceFetcher.this);
           frame.dispose();
+          new PDBFTSPanel(SequenceFetcher.this);
         }
         else if ("uniprot".equalsIgnoreCase(currentSelection))
         {
-          new UniprotFTSPanel(SequenceFetcher.this);
           frame.dispose();
+          new UniprotFTSPanel(SequenceFetcher.this);
         }
         else
         {
@@ -207,11 +194,11 @@ public class SequenceFetcher extends JPanel implements Runnable
     JLabel jLabel1 = new JLabel(MessageManager
             .getString("label.separate_multiple_accession_ids"));
     jLabel1.setFont(new Font("Verdana", Font.ITALIC, 11));
-    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
+    jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
 
     replacePunctuation = new JCheckBox(
             MessageManager.getString("label.replace_commas_semicolons"));
-    replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
+    replacePunctuation.setHorizontalAlignment(SwingConstants.LEFT);
     replacePunctuation.setFont(new Font("Verdana", Font.ITALIC, 11));
     okBtn = new JButton(MessageManager.getString("action.ok"));
     okBtn.addActionListener(new ActionListener()
@@ -315,7 +302,8 @@ public class SequenceFetcher extends JPanel implements Runnable
   {
     StringBuilder sb = new StringBuilder();
     HashSet<String> hs = new HashSet<>();
-    for (DbSourceProxy dbs : sfetch.getSourceProxy(db))
+    for (DbSourceProxy dbs : jalview.ws.SequenceFetcher.getInstance()
+            .getSourceProxy(db))
     {
       String tq = dbs.getTestQuery();
       if (hs.add(tq)) // not a duplicate source
@@ -331,7 +319,7 @@ public class SequenceFetcher extends JPanel implements Runnable
   }
 
   /**
-   * Action on selected a database other than Uniprot or PDB is to enable or
+   * Action on selecting a database other than Uniprot or PDB is to enable or
    * disable 'Replace commas', and await input in the query field
    */
   protected void otherSourceAction()
@@ -340,8 +328,7 @@ public class SequenceFetcher extends JPanel implements Runnable
     {
       String eq = exampleAccession.getText();
       // TODO this should be a property of the SequenceFetcher whether commas
-      // are and
-      // colons are allowed in the IDs...
+      // are allowed in the IDs...
 
       boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
       replacePunctuation.setEnabled(enablePunct);
@@ -418,13 +405,17 @@ public class SequenceFetcher extends JPanel implements Runnable
     /*
      * tidy inputs and check there is something to search for
      */
-    String text = textArea.getText();
+    String t0 = textArea.getText();
+    String text = t0.trim();
     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
     {
       text = text.replace(",", ";");
     }
-    text = text.replaceAll("(\\s|[,; ])+", ";");
-    textArea.setText(text);
+    text = text.replaceAll("(\\s|[; ])+", ";");
+    if (!t0.equals(text)) 
+    {
+         textArea.setText(text);
+    }
     if (text.isEmpty())
     {
       // todo i18n
@@ -460,12 +451,11 @@ public class SequenceFetcher extends JPanel implements Runnable
     List<String> presultTitle = new ArrayList<>();
     List<AlignmentI> presult = new ArrayList<>();
     List<AlignmentI> aresult = new ArrayList<>();
-    List<DbSourceProxy> sources = sfetch
+    List<DbSourceProxy> sources = jalview.ws.SequenceFetcher.getInstance()
             .getSourceProxy((String) database.getSelectedItem());
     Iterator<DbSourceProxy> proxies = sources.iterator();
-    String[] qries;
-    List<String> nextFetch = Arrays
-            .asList(qries = textArea.getText().split(";"));
+    String[] qries = textArea.getText().trim().split(";");
+    List<String> nextFetch = Arrays.asList(qries);
     Iterator<String> en = Arrays.asList(new String[0]).iterator();
     int nqueries = qries.length;
 
@@ -751,13 +741,14 @@ public class SequenceFetcher extends JPanel implements Runnable
 
     for (String q : queries)
     {
-      DBRefEntry dbr = new DBRefEntry();
-      dbr.setSource(proxy.getDbSource());
-      dbr.setVersion(null);
+       // BH 2019.01.25 dbr is never used.
+//      DBRefEntry dbr = new DBRefEntry();
+//      dbr.setSource(proxy.getDbSource());
+//      dbr.setVersion(null);
       String accId = proxy.getAccessionIdFromQuery(q);
-      dbr.setAccessionId(accId);
+//      dbr.setAccessionId(accId);
       boolean rfound = false;
-      for (int r = 0; r < rs.length; r++)
+      for (int r = 0, nr = rs.length; r < nr; r++)
       {
         if (rs[r] != null)
         {
@@ -824,7 +815,7 @@ public class SequenceFetcher extends JPanel implements Runnable
         {
           af.getViewport().applyFeaturesStyle(preferredFeatureColours);
         }
-        if (Cache.getDefault("HIDE_INTRONS", true))
+        if (Cache.getDefault(Preferences.HIDE_INTRONS, true))
         {
           af.hideFeatureColumns(SequenceOntologyI.EXON, false);
         }
@@ -836,7 +827,8 @@ public class SequenceFetcher extends JPanel implements Runnable
 
         try
         {
-          af.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false));
+          af.setMaximum(
+                  Cache.getDefault(Preferences.SHOW_FULLSCREEN, false));
         } catch (Exception ex)
         {
         }
@@ -857,7 +849,7 @@ public class SequenceFetcher extends JPanel implements Runnable
       @Override
       public void run()
       {
-        JvOptionPane.showInternalMessageDialog(Desktop.desktop, error,
+        JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), error,
                 MessageManager.getString("label.error_retrieving_data"),
                 JvOptionPane.WARNING_MESSAGE);
       }