JAL-1588 part work save/restore of Chimera session
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index bc985df..4e313b5 100644 (file)
@@ -27,6 +27,7 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
+import jalview.gui.Jalview2XML.ViewerData;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -97,6 +98,11 @@ public class ChimeraViewFrame extends StructureViewerBase
    */
   private Thread worker = null;
 
+  /*
+   * Path to Chimera session file - set in saveSession()
+   */
+  private String chimeraSessionFile = "";
+
   /**
    * Initialise menu options.
    */
@@ -336,115 +342,21 @@ public class ChimeraViewFrame extends StructureViewerBase
     openNewChimera(ap, pe, seqs);
   }
 
-  public AlignmentPanel[] getAllAlignmentPanels()
-  {
-    AlignmentPanel[] t, list = new AlignmentPanel[0];
-    for (String setid : _aps)
-    {
-      AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
-      if (panels != null)
-      {
-        t = new AlignmentPanel[list.length + panels.length];
-        System.arraycopy(list, 0, t, 0, list.length);
-        System.arraycopy(panels, 0, t, list.length, panels.length);
-        list = t;
-      }
-    }
-
-    return list;
-  }
-
-  /**
-   * set the primary alignmentPanel reference and add another alignPanel to the
-   * list of ones to use for colouring and aligning
-   * 
-   * @param nap
-   */
-  public void addAlignmentPanel(AlignmentPanel nap)
-  {
-    if (getAlignmentPanel() == null)
-    {
-      setAlignmentPanel(nap);
-    }
-    if (!_aps.contains(nap.av.getSequenceSetId()))
-    {
-      _aps.add(nap.av.getSequenceSetId());
-    }
-  }
-
   /**
-   * remove any references held to the given alignment panel
+   * Create a new viewer from saved session state data.
    * 
-   * @param nap
+   * @param viewerData
+   * @param af
    */
-  public void removeAlignmentPanel(AlignmentPanel nap)
-  {
-    try
-    {
-      _alignwith.remove(nap);
-      _colourwith.remove(nap);
-      if (getAlignmentPanel() == nap)
-      {
-        setAlignmentPanel(null);
-        for (AlignmentPanel aps : getAllAlignmentPanels())
-        {
-          if (aps != nap)
-          {
-            setAlignmentPanel(aps);
-            break;
-          }
-        }
-      }
-    } catch (Exception ex)
-    {
-    }
-    if (getAlignmentPanel() != null)
-    {
-      buildActionMenu();
-    }
-  }
-
-  public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
-  {
-    addAlignmentPanel(nap);
-    if (!_alignwith.contains(nap))
-    {
-      _alignwith.add(nap);
-    }
-  }
-
-  public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
-  {
-    if (_alignwith.contains(nap))
-    {
-      _alignwith.remove(nap);
-    }
-  }
-
-  public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
-          boolean enableColourBySeq)
-  {
-    useAlignmentPanelForColourbyseq(nap);
-    getBinding().setColourBySequence(enableColourBySeq);
-    seqColour.setSelected(enableColourBySeq);
-    viewerColour.setSelected(!enableColourBySeq);
-  }
-
-  public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
+  public ChimeraViewFrame(ViewerData viewerData, AlignFrame af)
   {
-    addAlignmentPanel(nap);
-    if (!_colourwith.contains(nap))
-    {
-      _colourwith.add(nap);
-    }
-  }
-
-  public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
-  {
-    if (_colourwith.contains(nap))
-    {
-      _colourwith.remove(nap);
-    }
+    super();
+    String chimeraSessionFile = viewerData.stateData;
+    openNewChimera(af.alignPanel, new PDBEntry[]
+    {}, new SequenceI[][]
+    {});
+    initChimera("open " + chimeraSessionFile);
+    // TODO restore mappings
   }
 
   /**
@@ -1175,9 +1087,26 @@ public class ChimeraViewFrame extends StructureViewerBase
    * if successful, else false.
    * 
    * @param filepath
+   * @see getStateInfo
    */
   public boolean saveSession(String filepath)
   {
-    return jmb.saveSession(filepath);
+    boolean result = jmb.saveSession(filepath);
+    if (result)
+    {
+      this.chimeraSessionFile = filepath;
+    }
+    return result;
+  }
+
+  /**
+   * Returns the file path of the Chimera session file the last time it was
+   * saved. If it was never saved, returns an empty string. There is no
+   * guarantee that the Chimera session has not changed since it was saved.
+   */
+  @Override
+  public String getStateInfo()
+  {
+    return this.chimeraSessionFile;
   }
 }