Merge branch 'features/JAL-1333' into Release_2_8_2_Branch
[jalview.git] / src / jalview / ext / jmol / JalviewJmolBinding.java
index 1a8fa2d..cadb205 100644 (file)
@@ -35,6 +35,7 @@ import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureListener;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
+import jalview.structures.models.SequenceStructureBindingModel;
 
 import java.awt.Color;
 import java.awt.Container;
@@ -56,26 +57,13 @@ import org.jmol.api.JmolViewer;
 import org.jmol.constant.EnumCallback;
 import org.jmol.popup.JmolPopup;
 
-public abstract class JalviewJmolBinding implements StructureListener,
+public abstract class JalviewJmolBinding extends SequenceStructureBindingModel implements StructureListener,
         JmolStatusListener, SequenceStructureBinding,
         JmolSelectionListener, ComponentListener,
         StructureSelectionManagerProvider
 
 {
   /**
-   * set if Jmol state is being restored from some source - instructs binding
-   * not to apply default display style when structure set is updated for first
-   * time.
-   */
-  private boolean loadingFromArchive = false;
-  
-  /**
-   * second flag to indicate if the jmol viewer should ignore sequence colouring
-   * events from the structure manager because the GUI is still setting up
-   */
-  private boolean loadingFinished = true;
-
-  /**
    * state flag used to check if the Jmol viewer's paint method can be called
    */
   private boolean finishedInit = false;
@@ -330,13 +318,15 @@ public abstract class JalviewJmolBinding implements StructureListener,
 
     String[] files = getPdbFile();
     // check to see if we are still waiting for Jmol files
-    long starttime=System.currentTimeMillis();
-    boolean waiting=true;
-    do {
-      waiting=false;
-      for (String file:files)
+    long starttime = System.currentTimeMillis();
+    boolean waiting = true;
+    do
+    {
+      waiting = false;
+      for (String file : files)
       {
-        try {
+        try
+        {
           // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
           // every possible exception
           StructureMapping[] sm = ssm.getMapping(file);
@@ -353,10 +343,12 @@ public abstract class JalviewJmolBinding implements StructureListener,
         }
       }
       // we wait around for a reasonable time before we give up
-    } while (waiting && System.currentTimeMillis()<(10000+1000*files.length+starttime));
+    } while (waiting
+            && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
     if (waiting)
     {
-      System.err.println("RUNTIME PROBLEM: Jmol seems to be taking a long time to process all the structures.");
+      System.err
+              .println("RUNTIME PROBLEM: Jmol seems to be taking a long time to process all the structures.");
       return;
     }
     StringBuffer selectioncom = new StringBuffer();
@@ -420,7 +412,8 @@ public abstract class JalviewJmolBinding implements StructureListener,
         // Jmol callback has completed.
         if (mapping == null || mapping.length < 1)
         {
-          throw new Error("Implementation error - Jmol seems to be still working on getting its data - report at http://issues.jalview.org/browse/JAL-1016");
+          throw new Error(
+                  "Implementation error - Jmol seems to be still working on getting its data - report at http://issues.jalview.org/browse/JAL-1016");
         }
         int lastPos = -1;
         for (int s = 0; s < sequence[pdbfnum].length; s++)
@@ -486,7 +479,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
           }
         }
       }
-      
+
       // TODO: consider bailing if nmatched less than 4 because superposition
       // not
       // well defined.
@@ -558,14 +551,17 @@ public abstract class JalviewJmolBinding implements StructureListener,
             {
               selectioncom.append("|");
             }
-          } else {
+          }
+          else
+          {
             selcom[pdbfnum] = null;
           }
         }
       }
       for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
       {
-        if (pdbfnum == refStructure || selcom[pdbfnum]==null || selcom[refStructure]==null)
+        if (pdbfnum == refStructure || selcom[pdbfnum] == null
+                || selcom[refStructure] == null)
         {
           continue;
         }
@@ -574,7 +570,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
         command.append(chainNames[pdbfnum]);
         command.append(") against reference (");
         command.append(chainNames[refStructure]);
-        command.append(")\";\ncompare "+nSeconds);
+        command.append(")\";\ncompare " + nSeconds);
         command.append("{");
         command.append(1 + pdbfnum);
         command.append(".1} {");
@@ -633,7 +629,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
   public void colourBySequence(boolean showFeatures,
           jalview.api.AlignmentViewPanel alignmentv)
   {
-    if (!colourBySequence || !loadingFinished)
+    if (!colourBySequence || !isLoadingFinished())
       return;
     if (ssm == null)
     {
@@ -1501,30 +1497,6 @@ public abstract class JalviewJmolBinding implements StructureListener,
     showConsole(false);
   }
 
-  public void setLoadingFromArchive(boolean loadingFromArchive)
-  {
-    this.loadingFromArchive = loadingFromArchive;
-  }
-  
-  /**
-   * 
-   * @return true if Jmol is still restoring state or loading is still going on (see setFinsihedLoadingFromArchive)
-   */
-  public boolean isLoadingFromArchive()
-  {
-    return loadingFromArchive && !loadingFinished;
-  }
-
-  /**
-   * modify flag which controls if sequence colouring events are honoured by the binding. 
-   * Should be true for normal operation
-   * @param finishedLoading
-   */
-  public void setFinishedLoadingFromArchive(boolean finishedLoading)
-  {
-    loadingFinished = finishedLoading;
-  }
-
   public void setBackgroundColour(java.awt.Color col)
   {
     jmolHistory(false);