JAL-1753 ChimeraViewFrame hosts its own ProgressBar
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 Jun 2015 12:40:55 +0000 (13:40 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 Jun 2015 12:40:55 +0000 (13:40 +0100)
resources/lang/Messages.properties
src/jalview/gui/ChimeraViewFrame.java

index c068728..f5b920b 100644 (file)
@@ -1149,6 +1149,8 @@ status.das_feature_fetching_complete = DAS Feature Fetching Complete
 status.fetching_db_refs = Fetching db refs
 status.loading_cached_pdb_entries = Loading Cached PDB Entries
 status.searching_for_pdb_structures = Searching for PDB Structures
+status.opening_file = opening file
+status.colouring_chimera = Colouring Chimera
 label.font_doesnt_have_letters_defined = Font doesn't have letters defined\nso cannot be used\nwith alignment data
 label.font_too_small = Font size is too small
 label.error_loading_file_params = Error loading file {0}
@@ -1241,4 +1243,4 @@ info.enter_search_text_here = Enter Search Text Here
 info.enter_search_text_to_enable = Enter Search Text to Enable
 info.search_in_annotation_label = Search in {0} Label
 info.search_in_annotation_description = Search in {0} Description
-info.change_threshold_mode_to_enable = Change Threshold Mode to Enable
\ No newline at end of file
+info.change_threshold_mode_to_enable = Change Threshold Mode to Enable
index 4372617..fdc7d0b 100644 (file)
@@ -32,6 +32,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -104,6 +105,8 @@ public class ChimeraViewFrame extends StructureViewerBase
    */
   private String chimeraSessionFile = null;
 
+  private Random random = new Random();
+
   /**
    * Initialise menu options.
    */
@@ -304,6 +307,17 @@ public class ChimeraViewFrame extends StructureViewerBase
     { seq });
   }
 
+  /**
+   * Create a helper to manage progress bar display
+   */
+  protected void createProgressBar()
+  {
+    if (progressBar == null)
+    {
+      progressBar = new ProgressBar(statusPanel, statusBar);
+    }
+  }
+
   protected boolean hasPdbId(String pdbId)
   {
     return jmb.hasPdbId(pdbId);
@@ -312,7 +326,8 @@ public class ChimeraViewFrame extends StructureViewerBase
   private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
           SequenceI[][] seqs)
   {
-    progressBar = ap.alignFrame;
+    createProgressBar();
+
     jmb = new JalviewChimeraBindingModel(this,
             ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
     addAlignmentPanel(ap);
@@ -692,6 +707,8 @@ public class ChimeraViewFrame extends StructureViewerBase
           try
           {
             int pos = filePDBpos.get(num).intValue();
+            long startTime = startProgressBar("Chimera "
+                    + MessageManager.getString("status.opening_file"));
             jmb.openFile(pe);
             jmb.addSequence(pos, jmb.getSequence()[pos]);
             File fl = new File(pe.getFile());
@@ -704,6 +721,9 @@ public class ChimeraViewFrame extends StructureViewerBase
               }
             } catch (Throwable e)
             {
+            } finally
+            {
+              stopProgressBar("", startTime);
             }
             // Explicitly map to the filename used by Chimera ;
             // TODO: use pe.getId() instead of pe.getFile() ?
@@ -765,13 +785,9 @@ public class ChimeraViewFrame extends StructureViewerBase
     Pdb pdbclient = new Pdb();
     AlignmentI pdbseq = null;
     String pdbid = processingEntry.getId();
-    long hdl = pdbid.hashCode() - System.currentTimeMillis();
-    if (progressBar != null)
-    {
-      progressBar.setProgressBar(MessageManager.formatMessage(
-              "status.fetching_pdb", new Object[]
-              { pdbid }), hdl);
-    }
+    long hdl = startProgressBar(MessageManager.formatMessage(
+            "status.fetching_pdb", new Object[]
+            { pdbid }));
     try
     {
       pdbseq = pdbclient.getSequenceRecords(pdbid);
@@ -780,16 +796,9 @@ public class ChimeraViewFrame extends StructureViewerBase
       new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
     } finally
     {
-      if (progressBar != null)
-      {
-        progressBar
-                .setProgressBar(
-                        pdbid
-                                + " "
-                                + MessageManager
-                                        .getString("label.state_completed"),
-                        hdl);
-      }
+      String msg = pdbid + " "
+              + MessageManager.getString("label.state_completed");
+      stopProgressBar(msg, hdl);
     }
     /*
      * If PDB data were saved and are not invalid (empty alignment), return the
@@ -805,6 +814,33 @@ public class ChimeraViewFrame extends StructureViewerBase
     return filePath;
   }
 
+  /**
+   * Convenience method to update the progress bar if there is one. Be sure to
+   * call stopProgressBar with the returned handle to remove the message.
+   * 
+   * @param msg
+   * @param handle
+   */
+  public long startProgressBar(String msg)
+  {
+    // TODO would rather have startProgress/stopProgress as the
+    // IProgressIndicator interface
+    long tm = random.nextLong();
+    if (progressBar != null)
+    {
+      progressBar.setProgressBar(msg, tm);
+    }
+    return tm;
+  }
+
+  public void stopProgressBar(String msg, long handle)
+  {
+    if (progressBar != null)
+    {
+      progressBar.setProgressBar(msg, handle);
+    }
+  }
+
   @Override
   public void pdbFile_actionPerformed(ActionEvent actionEvent)
   {