JAL-1588 refactoring prior to 'save Chimera project'
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index cfac4ef..567a14c 100644 (file)
  */
 package jalview.gui;
 
-import jalview.api.SequenceStructureBinding;
-import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.JalviewFileChooser;
@@ -42,6 +41,7 @@ import jalview.schemes.StrandColourScheme;
 import jalview.schemes.TaylorColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.schemes.ZappoColourScheme;
+import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
@@ -79,26 +79,9 @@ import javax.swing.event.MenuListener;
  *
  */
 public class ChimeraViewFrame extends GStructureViewer implements Runnable,
-        ViewSetProvider, JalviewStructureDisplayI
-
+        ViewSetProvider
 {
-  private JalviewChimeraBindingModel jmb;
-
-  /*
-   * list of sequenceSet ids associated with the view
-   */
-  private ArrayList<String> _aps = new ArrayList<String>();
-
-  /*
-   * list of alignment panels to use for superposition
-   */
-  private Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
-
-  /*
-   * list of alignment panels that are used for colouring structures by aligned
-   * sequences
-   */
-  private Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
+  private JalviewChimeraBinding jmb;
 
   private boolean allChainsSelected = false;
 
@@ -115,8 +98,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
 
   private IProgressIndicator progressBar = null;
 
-  private String viewId = null;
-
   /*
    * pdb retrieval thread.
    */
@@ -144,9 +125,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
       _alignwith = new Vector<AlignmentPanel>();
     }
 
-    // no colour by chain command in Chimera?
-    chainColour.setVisible(false);
-
     // save As not yet implemented
     savemenu.setVisible(false);
 
@@ -247,9 +225,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
         // TODO : Fix multiple seq to one chain issue here.
         ap.getStructureSelectionManager().setMapping(seq, chains,
                 alreadyMapped, AppletFormatAdapter.FILE);
-        if (ap.seqPanel.seqCanvas.fr != null)
+        if (ap.getSeqPanel().seqCanvas.fr != null)
         {
-          ap.seqPanel.seqCanvas.fr.featuresAdded();
+          ap.getSeqPanel().seqCanvas.fr.featuresAdded();
           ap.paintAlignment(true);
         }
 
@@ -264,9 +242,11 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
             final ChimeraViewFrame topView = ((ChimeraViewFrame) frame);
             // JBPNOTE: this looks like a binding routine, rather than a gui
             // routine
-            for (int pe = 0; pe < topView.jmb.pdbentry.length; pe++)
+            for (int pe = 0; pe < topView.jmb.getPdbCount(); pe++)
             {
-              if (topView.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
+              if (topView.jmb.getPdbEntry(pe).getFile()
+                      .equals(
+                      alreadyMapped))
               {
                 topView.jmb.addSequence(pe, seq);
                 topView.addAlignmentPanel(ap);
@@ -552,7 +532,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     jmb.setFinishedInit(false);
     // TODO: consider waiting until the structure/view is fully loaded before
     // displaying
-    jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(true),
+    jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
             getBounds().width, getBounds().height);
     if (command == null)
     {
@@ -636,7 +616,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       String prompt = MessageManager
               .formatMessage("label.confirm_close_chimera", new Object[]
-              { jmb.getViewerTitle(false) });
+              { jmb.getViewerTitle("Chimera", false) });
       prompt = JvSwingUtils.wrapTooltip(true, prompt);
       int confirm = JOptionPane.showConfirmDialog(this, prompt,
               MessageManager.getString("label.close_viewer"),
@@ -670,10 +650,10 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
       String[] curfiles = jmb.getPdbFile(); // files currently in viewer
       // TODO: replace with reference fetching/transfer code (validate PDBentry
       // as a DBRef?)
-      for (int pi = 0; pi < jmb.pdbentry.length; pi++)
+      for (int pi = 0; pi < jmb.getPdbCount(); pi++)
       {
         String file = null;
-        thePdbEntry = jmb.pdbentry[pi];
+        thePdbEntry = jmb.getPdbEntry(pi);
         if (thePdbEntry.getFile() == null)
         {
           /*
@@ -755,7 +735,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
           {
             int pos = filePDBpos.get(num).intValue();
             jmb.openFile(pe);
-            jmb.addSequence(pos, jmb.sequence[pos]);
+            jmb.addSequence(pos, jmb.getSequence()[pos]);
             File fl = new File(pe.getFile());
             String protocol = AppletFormatAdapter.URL;
             try
@@ -769,7 +749,8 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
             }
             // Explicitly map to the filename used by Chimera ;
             // TODO: use pe.getId() instead of pe.getFile() ?
-            jmb.ssm.setMapping(jmb.sequence[pos], null, pe.getFile(),
+            jmb.getSsm().setMapping(jmb.getSequence()[pos], null,
+                    pe.getFile(),
                     protocol);
           } catch (OutOfMemoryError oomerror)
           {
@@ -843,8 +824,13 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       if (progressBar != null)
       {
-        progressBar.setProgressBar(
-                MessageManager.getString("label.state_completed"), hdl);
+        progressBar
+                .setProgressBar(
+                        pdbid
+                                + " "
+                                + MessageManager
+                                        .getString("label.state_completed"),
+                        hdl);
       }
     }
     /*
@@ -917,9 +903,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
     try
     {
-      for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
+      for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
       {
-        cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
+        cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
         cap.appendText("\n");
       }
     } catch (OutOfMemoryError e)
@@ -1087,15 +1073,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     }
   }
 
-  public String getViewId()
-  {
-    if (viewId == null)
-    {
-      viewId = System.currentTimeMillis() + "." + this.hashCode();
-    }
-    return viewId;
-  }
-
   public void updateTitleAndMenus()
   {
     if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
@@ -1105,8 +1082,8 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     }
     setChainMenuItems(jmb.chainNames);
 
-    this.setTitle(jmb.getViewerTitle(true));
-    if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
+    this.setTitle(jmb.getViewerTitle("Chimera", true));
+    if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
     {
       viewerActionMenu.setVisible(true);
     }
@@ -1213,39 +1190,20 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     return ap;
   }
 
-  /**
-   * 
-   * @param ap2
-   * @return true if this Chimera instance is linked with the given alignPanel
-   */
-  public boolean isLinkedWith(AlignmentPanel ap2)
-  {
-    return _aps.contains(ap2.av.getSequenceSetId());
-  }
-
-  public boolean isUsedforaligment(AlignmentPanel ap2)
-  {
-
-    return (_alignwith != null) && _alignwith.contains(ap2);
-  }
-
-  public boolean isUsedforcolourby(AlignmentPanel ap2)
+  @Override
+  public AAStructureBindingModel getBinding()
   {
-    return (_colourwith != null) && _colourwith.contains(ap2);
+    return jmb;
   }
 
   /**
+   * Ask Chimera to save its session to the designated file path. Returns true
+   * if successful, else false.
    * 
-   * @return TRUE if the view is NOT being coloured by sequence associations.
+   * @param filepath
    */
-  public boolean isColouredByChimera()
-  {
-    return !jmb.isColourBySequence();
-  }
-
-  public SequenceStructureBinding getBinding()
+  public boolean saveSession(String filepath)
   {
-    return jmb;
+    return jmb.saveSession(filepath);
   }
-
 }