merge
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index fb94c05..c330a92 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -20,7 +20,6 @@
  */
 package jalview.gui;
 
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
@@ -115,7 +114,7 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   private static Thread initingThread = null;
 
-  int x = 0;
+  int debounceTrap = 0;
   /**
    * Blocking method that initialises and returns the shared instance of the
    * SequenceFetcher client
@@ -178,8 +177,7 @@ public class SequenceFetcher extends JPanel implements Runnable
       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar(MessageManager.getString("status.init_sequence_database_fetchers"),
-                Thread.currentThread().hashCode());
+        guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
       }
       lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
               .getLocalSourceString()).hashCode();
@@ -190,9 +188,10 @@ public class SequenceFetcher extends JPanel implements Runnable
     return sfetch;
   }
 
+  private IProgressIndicator progressIndicator;
   public SequenceFetcher(IProgressIndicator guiIndic)
   {
-    final IProgressIndicator guiWindow = guiIndic;
+    this.progressIndicator = guiIndic;
     final SequenceFetcher us = this;
     // launch initialiser thread
     Thread sf = new Thread(new Runnable()
@@ -201,9 +200,9 @@ public class SequenceFetcher extends JPanel implements Runnable
       @Override
       public void run()
       {
-        if (getSequenceFetcherSingleton(guiWindow) != null)
+        if (getSequenceFetcherSingleton(progressIndicator) != null)
         {
-          us.initGui(guiWindow);
+          us.initGui(progressIndicator);
         }
         else
         {
@@ -357,17 +356,16 @@ public class SequenceFetcher extends JPanel implements Runnable
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        x++;
+        debounceTrap++;
         String currentSelection = database.getSelectedItem();
 
         if (!currentSelection.equalsIgnoreCase("pdb"))
         {
             otherSourceAction();
         }
-        if (currentSelection.equalsIgnoreCase("pdb") && ((x % 2) == 0))
+        if (currentSelection.equalsIgnoreCase("pdb") && ((debounceTrap % 2) == 0))
         {
-          frame.dispose();
-          new EBIFetchPanel();
+          pdbSourceAction();
         }
 
       }
@@ -388,10 +386,13 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   }
 
-  private void hideX()
+  private void pdbSourceAction()
   {
-    this.setVisible(false);
+    databaseButt.setText(database.getSelectedItem());
+    new PDBSearchPanel(this);
+    frame.dispose();
   }
+
   private void otherSourceAction()
   {
     try
@@ -772,7 +773,7 @@ public class SequenceFetcher extends JPanel implements Runnable
   AlignmentI parseResult(String result, String title)
   {
     String format = new IdentifyFile().Identify(result, "Paste");
-    Alignment sequences = null;
+    AlignmentI sequences = null;
     if (FormatAdapter.isValidFormat(format))
     {
       sequences = null;
@@ -814,6 +815,10 @@ public class SequenceFetcher extends JPanel implements Runnable
 
     if (al != null && al.getHeight() > 0)
     {
+      if (title == null)
+      {
+        title = getDefaultRetrievalTitle();
+      }
       if (alignFrame == null)
       {
         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
@@ -826,10 +831,6 @@ public class SequenceFetcher extends JPanel implements Runnable
           // Alignments?
         }
 
-        if (title == null)
-        {
-          title = getDefaultRetrievalTitle();
-        }
         SequenceFeature[] sfs = null;
         List<SequenceI> alsqs;
         synchronized (alsqs = al.getSequences())
@@ -863,21 +864,7 @@ public class SequenceFetcher extends JPanel implements Runnable
       }
       else
       {
-        for (int i = 0; i < al.getHeight(); i++)
-        {
-          alignFrame.viewport.getAlignment().addSequence(
-                  al.getSequenceAt(i)); // this
-          // also
-          // creates
-          // dataset
-          // sequence
-          // entries
-        }
-        alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
-                .getHeight());
-        alignFrame.viewport.getAlignment().getWidth();
-        alignFrame.viewport.firePropertyChange("alignment", null,
-                alignFrame.viewport.getAlignment().getSequences());
+        alignFrame.viewport.addAlignment(al, title);
       }
     }
     return al;
@@ -897,4 +884,14 @@ public class SequenceFetcher extends JPanel implements Runnable
       }
     });
   }
+
+  public IProgressIndicator getProgressIndicator()
+  {
+    return progressIndicator;
+  }
+
+  public void setProgressIndicator(IProgressIndicator progressIndicator)
+  {
+    this.progressIndicator = progressIndicator;
+  }
 }