avoid race condition by setting sequence logo flag directly rather than via accessor...
[jalview.git] / src / jalview / gui / Jalview2XML.java
index 7a403a0..fd93d7f 100755 (executable)
@@ -19,6 +19,7 @@ package jalview.gui;
 
 import java.awt.Rectangle;
 import java.io.*;
+import java.lang.reflect.InvocationTargetException;
 import java.net.*;
 import java.util.*;
 import java.util.jar.*;
@@ -578,13 +579,14 @@ public class Jalview2XML
           {
             if (frames[f] instanceof AppJmol)
             {
+              // TODO: revise schema to allow many:one PDB id binding to viewer
               jmol = (AppJmol) frames[f];
-              if (!jmol.pdbentry.getId().equals(entry.getId())
+              if (!jmol.jmb.pdbentry[0].getId().equals(entry.getId())
                       && !(entry.getId().length() > 4 && entry.getId()
                               .toLowerCase().startsWith(
-                                      jmol.pdbentry.getId().toLowerCase())))
+                                      jmol.jmb.pdbentry[0].getId().toLowerCase())))
                 continue;
-              matchedFile = jmol.pdbentry.getFile(); // record the file so we
+              matchedFile = jmol.jmb.pdbentry[0].getFile(); // record the file so we
               // can get at it if the ID
               // match is ambiguous (e.g.
               // 1QIP==1qipA)
@@ -595,14 +597,14 @@ public class Jalview2XML
               state.setWidth(jmol.getWidth());
               state.setHeight(jmol.getHeight());
               state.setViewId(jmol.getViewId());
-              String statestring = jmol.viewer.getStateInfo();
+              String statestring = jmol.jmb.viewer.getStateInfo();
               if (state != null)
               {
                 state.setContent(statestring.replaceAll("\n", ""));
               }
-              for (int s = 0; s < jmol.sequence.length; s++)
+              for (int s = 0; s < jmol.jmb.sequence.length; s++)
               {
-                if (jal.findIndex(jmol.sequence[s]) > -1)
+                if (jal.findIndex(jmol.jmb.sequence[s]) > -1)
                 {
                   pdb.addStructureState(state);
                 }
@@ -946,7 +948,7 @@ public class Jalview2XML
         groups[i].setTextCol1(sg.textColour.getRGB());
         groups[i].setTextCol2(sg.textColour2.getRGB());
         groups[i].setTextColThreshold(sg.thresholdTextColour);
-        groups[i].setShowUnconserved(sg.getShowunconserved());
+        groups[i].setShowUnconserved(sg.getShowNonconserved());
         groups[i].setIgnoreGapsinConsensus(sg.getIgnoreGapsConsensus());
         groups[i].setShowConsensusHistogram(sg.isShowConsensusHistogram());
         groups[i].setShowSequenceLogo(sg.isShowSequenceLogo());
@@ -2169,7 +2171,7 @@ public class Jalview2XML
           // newer files have an 'autoCalculated' flag and store calculation
           // state in viewport properties
           jaa.autoCalculated = true; // means annotation will be marked for
-                                     // update at end of load.
+          // update at end of load.
         }
         al.addAnnotation(jaa);
       }
@@ -2233,7 +2235,7 @@ public class Jalview2XML
 
         sg.textColour = new java.awt.Color(groups[i].getTextCol1());
         sg.textColour2 = new java.awt.Color(groups[i].getTextCol2());
-        sg.setShowunconserved(groups[i].hasShowUnconserved() ? groups[i]
+        sg.setShowNonconserved(groups[i].hasShowUnconserved() ? groups[i]
                 .isShowUnconserved() : false);
         sg.thresholdTextColour = groups[i].getTextColThreshold();
         if (groups[i].hasShowConsensusHistogram())
@@ -2245,7 +2247,7 @@ public class Jalview2XML
         ;
         if (groups[i].hasShowSequenceLogo())
         {
-          sg.setIncludeAllConsSymbols(groups[i].isShowSequenceLogo());
+          sg.setshowSequenceLogo(groups[i].isShowSequenceLogo());
         }
         if (groups[i].hasIgnoreGapsinConsensus())
         {
@@ -2510,14 +2512,15 @@ public class Jalview2XML
                 // create a new Jmol window
                 String state = ids[p].getStructureState(s).getContent();
                 StringBuffer newFileLoc = null;
-                if (state.indexOf("load") > -1)
+                int cp=0;
+                if ((cp=state.indexOf("load ")) > -1)
                 {
-                  newFileLoc = new StringBuffer(state.substring(0, state
-                          .indexOf("\"", state.indexOf("load")) + 1));
+                  newFileLoc = new StringBuffer(state.substring(0, (cp=state
+                          .indexOf("\"", cp+1)+1)));
 
                   newFileLoc.append(jpdb.getFile());
                   newFileLoc.append(state.substring(state.indexOf("\"",
-                          state.indexOf("load \"") + 6)));
+                          cp+1)));
                 }
                 else
                 {
@@ -2533,9 +2536,42 @@ public class Jalview2XML
 
                 if (newFileLoc != null)
                 {
-                  new AppJmol(pdbFile, ids[p].getId(), seq, af.alignPanel,
-                          newFileLoc.toString(), new java.awt.Rectangle(x,
-                                  y, width, height), sviewid);
+                  int histbug = newFileLoc.indexOf("history = ");
+                  histbug+=10;
+                  int diff = histbug==-1 ? -1 : newFileLoc.indexOf(";",histbug); 
+                  String val = (diff==-1) ? null : newFileLoc.substring(histbug,diff); 
+                  if (val!=null && val.length()>=4)
+                  {
+                    if (val.contains("e")) {
+                      if (val.trim().equals("true")) {
+                        val = "1";
+                      } else {
+                        val = "0";
+                      }
+                      newFileLoc.replace(histbug, diff, val);
+                    }
+                  }
+                  final String pdbf=pdbFile, id=ids[p].getId(), fileloc=newFileLoc.toString(),vid=sviewid;
+                  final SequenceI[] sq=seq;
+                  final AlignFrame alf = af;
+                  final java.awt.Rectangle rect = new java.awt.Rectangle(x,
+                          y, width, height);
+                  try {
+                  javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+                    public void run() {
+                      new AppJmol(pdbf, id, sq, alf.alignPanel,
+                              fileloc, rect, vid);
+                    }
+                  });
+                  }
+                  catch (InvocationTargetException ex)
+                  {
+                    System.err.println("Unexpected error when opening Jmol view.");
+                    ex.printStackTrace();
+                  } catch (InterruptedException e)
+                  {
+                    // e.printStackTrace();
+                  }
                 }
 
               }
@@ -2552,7 +2588,7 @@ public class Jalview2XML
                         .setMapping(seq, null, pdbFile,
                                 jalview.io.AppletFormatAdapter.FILE);
 
-                ((AppJmol) comp).addSequence(seq);
+                ((AppJmol) comp).jmb.addSequence(seq);
               }
             }
           }
@@ -2698,85 +2734,91 @@ public class Jalview2XML
       else if (view.getBgColour().startsWith("Annotation"))
       {
         // int find annotation
-        for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)
+        if (af.viewport.alignment.getAlignmentAnnotation() != null)
         {
-          if (af.viewport.alignment.getAlignmentAnnotation()[i].label
-                  .equals(view.getAnnotationColours().getAnnotation()))
+          for (int i = 0; i < af.viewport.alignment
+                  .getAlignmentAnnotation().length; i++)
           {
-            if (af.viewport.alignment.getAlignmentAnnotation()[i]
-                    .getThreshold() == null)
+            if (af.viewport.alignment.getAlignmentAnnotation()[i].label
+                    .equals(view.getAnnotationColours().getAnnotation()))
             {
-              af.viewport.alignment.getAlignmentAnnotation()[i]
-                      .setThreshold(new jalview.datamodel.GraphLine(view
-                              .getAnnotationColours().getThreshold(),
-                              "Threshold", java.awt.Color.black)
-
-                      );
-            }
+              if (af.viewport.alignment.getAlignmentAnnotation()[i]
+                      .getThreshold() == null)
+              {
+                af.viewport.alignment.getAlignmentAnnotation()[i]
+                        .setThreshold(new jalview.datamodel.GraphLine(view
+                                .getAnnotationColours().getThreshold(),
+                                "Threshold", java.awt.Color.black)
 
-            if (view.getAnnotationColours().getColourScheme()
-                    .equals("None"))
-            {
-              cs = new AnnotationColourGradient(af.viewport.alignment
-                      .getAlignmentAnnotation()[i], new java.awt.Color(view
-                      .getAnnotationColours().getMinColour()),
-                      new java.awt.Color(view.getAnnotationColours()
-                              .getMaxColour()), view.getAnnotationColours()
-                              .getAboveThreshold());
-            }
-            else if (view.getAnnotationColours().getColourScheme()
-                    .startsWith("ucs"))
-            {
-              cs = new AnnotationColourGradient(af.viewport.alignment
-                      .getAlignmentAnnotation()[i], GetUserColourScheme(
-                      jms, view.getAnnotationColours().getColourScheme()),
-                      view.getAnnotationColours().getAboveThreshold());
-            }
-            else
-            {
-              cs = new AnnotationColourGradient(af.viewport.alignment
-                      .getAlignmentAnnotation()[i], ColourSchemeProperty
-                      .getColour(al, view.getAnnotationColours()
-                              .getColourScheme()), view
-                      .getAnnotationColours().getAboveThreshold());
-            }
+                        );
+              }
 
-            // Also use these settings for all the groups
-            if (al.getGroups() != null)
-            {
-              for (int g = 0; g < al.getGroups().size(); g++)
+              if (view.getAnnotationColours().getColourScheme().equals(
+                      "None"))
               {
-                jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) al
-                        .getGroups().elementAt(g);
+                cs = new AnnotationColourGradient(af.viewport.alignment
+                        .getAlignmentAnnotation()[i], new java.awt.Color(
+                        view.getAnnotationColours().getMinColour()),
+                        new java.awt.Color(view.getAnnotationColours()
+                                .getMaxColour()), view
+                                .getAnnotationColours().getAboveThreshold());
+              }
+              else if (view.getAnnotationColours().getColourScheme()
+                      .startsWith("ucs"))
+              {
+                cs = new AnnotationColourGradient(af.viewport.alignment
+                        .getAlignmentAnnotation()[i],
+                        GetUserColourScheme(jms, view
+                                .getAnnotationColours().getColourScheme()),
+                        view.getAnnotationColours().getAboveThreshold());
+              }
+              else
+              {
+                cs = new AnnotationColourGradient(af.viewport.alignment
+                        .getAlignmentAnnotation()[i], ColourSchemeProperty
+                        .getColour(al, view.getAnnotationColours()
+                                .getColourScheme()), view
+                        .getAnnotationColours().getAboveThreshold());
+              }
 
-                if (sg.cs == null)
+              // Also use these settings for all the groups
+              if (al.getGroups() != null)
+              {
+                for (int g = 0; g < al.getGroups().size(); g++)
                 {
-                  continue;
-                }
+                  jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) al
+                          .getGroups().elementAt(g);
 
-                /*
-                 * if
-                 * (view.getAnnotationColours().getColourScheme().equals("None"
-                 * )) { sg.cs = new AnnotationColourGradient(
-                 * af.viewport.alignment.getAlignmentAnnotation()[i], new
-                 * java.awt.Color(view.getAnnotationColours(). getMinColour()),
-                 * new java.awt.Color(view.getAnnotationColours().
-                 * getMaxColour()),
-                 * view.getAnnotationColours().getAboveThreshold()); } else
-                 */
-                {
-                  sg.cs = new AnnotationColourGradient(
-                          af.viewport.alignment.getAlignmentAnnotation()[i],
-                          sg.cs, view.getAnnotationColours()
-                                  .getAboveThreshold());
-                }
+                  if (sg.cs == null)
+                  {
+                    continue;
+                  }
+
+                  /*
+                   * if
+                   * (view.getAnnotationColours().getColourScheme().equals("None"
+                   * )) { sg.cs = new AnnotationColourGradient(
+                   * af.viewport.alignment.getAlignmentAnnotation()[i], new
+                   * java.awt.Color(view.getAnnotationColours().
+                   * getMinColour()), new
+                   * java.awt.Color(view.getAnnotationColours().
+                   * getMaxColour()),
+                   * view.getAnnotationColours().getAboveThreshold()); } else
+                   */
+                  {
+                    sg.cs = new AnnotationColourGradient(
+                            af.viewport.alignment.getAlignmentAnnotation()[i],
+                            sg.cs, view.getAnnotationColours()
+                                    .getAboveThreshold());
+                  }
 
+                }
               }
+
+              break;
             }
 
-            break;
           }
-
         }
       }
       else
@@ -2835,11 +2877,11 @@ public class Jalview2XML
     }
     if (view.hasShowSequenceLogo())
     {
-      af.viewport.setShowSequenceLogo(view.getShowSequenceLogo());
+      af.viewport.showSequenceLogo = view.getShowSequenceLogo();
     }
     else
     {
-      af.viewport.setShowSequenceLogo(false);
+      af.viewport.showSequenceLogo = false;
     }
     if (view.hasShowDbRefTooltip())
     {
@@ -2942,7 +2984,6 @@ public class Jalview2XML
     }
 
     af.setMenusFromViewport(af.viewport);
-    af.alignPanel.updateAnnotation(false); // recompute any autoannotation
     // TODO: we don't need to do this if the viewport is aready visible.
     Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(), view
             .getHeight());