JAL-3190 rough Proof of Concept of JalviewJS - Chimera
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index 89de2e8..8392606 100644 (file)
@@ -32,6 +32,7 @@ import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.BrowserLauncher;
+import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
@@ -100,41 +101,34 @@ public class ChimeraViewFrame extends StructureViewerBase
     savemenu.setVisible(false); // not yet implemented
     viewMenu.add(fitToWindow);
 
-    /*
-     * exchange of Jalview features and Chimera attributes is for now
-     * an optionally enabled experimental feature
-     */
-    if (Desktop.instance.showExperimental())
+    JMenuItem writeFeatures = new JMenuItem(
+            MessageManager.getString("label.create_chimera_attributes"));
+    writeFeatures.setToolTipText(MessageManager
+            .getString("label.create_chimera_attributes_tip"));
+    writeFeatures.addActionListener(new ActionListener()
     {
-      JMenuItem writeFeatures = new JMenuItem(
-              MessageManager.getString("label.create_chimera_attributes"));
-      writeFeatures.setToolTipText(MessageManager
-              .getString("label.create_chimera_attributes_tip"));
-      writeFeatures.addActionListener(new ActionListener()
-      {
-        @Override
-        public void actionPerformed(ActionEvent e)
-        {
-          sendFeaturesToChimera();
-        }
-      });
-      viewerActionMenu.add(writeFeatures);
-
-      final JMenu fetchAttributes = new JMenu(
-              MessageManager.getString("label.fetch_chimera_attributes"));
-      fetchAttributes.setToolTipText(MessageManager
-              .getString("label.fetch_chimera_attributes_tip"));
-      fetchAttributes.addMouseListener(new MouseAdapter()
+      @Override
+      public void actionPerformed(ActionEvent e)
       {
+        sendFeaturesToChimera();
+      }
+    });
+    viewerActionMenu.add(writeFeatures);
 
-        @Override
-        public void mouseEntered(MouseEvent e)
-        {
-          buildAttributesMenu(fetchAttributes);
-        }
-      });
-      viewerActionMenu.add(fetchAttributes);
-    }
+    final JMenu fetchAttributes = new JMenu(
+            MessageManager.getString("label.fetch_chimera_attributes"));
+    fetchAttributes.setToolTipText(
+            MessageManager.getString("label.fetch_chimera_attributes_tip"));
+    fetchAttributes.addMouseListener(new MouseAdapter()
+    {
+
+      @Override
+      public void mouseEntered(MouseEvent e)
+      {
+        buildAttributesMenu(fetchAttributes);
+      }
+    });
+    viewerActionMenu.add(fetchAttributes);
   }
 
   /**
@@ -202,7 +196,7 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   /**
-   * add a single PDB structure to a new or existing Chimera view
+   * open a single PDB structure in a new Chimera view
    * 
    * @param pdbentry
    * @param seq
@@ -213,30 +207,7 @@ public class ChimeraViewFrame extends StructureViewerBase
           String[] chains, final AlignmentPanel ap)
   {
     this();
-    String pdbId = pdbentry.getId();
-
-    /*
-     * If the PDB file is already loaded, the user may just choose to add to an
-     * existing viewer (or cancel)
-     */
-    if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
-    {
-      return;
-    }
-
-    /*
-     * Check if there are other Chimera views involving this alignment and give
-     * user the option to add and align this molecule to one of them (or cancel)
-     */
-    if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
-    {
-      return;
-    }
 
-    /*
-     * If the options above are declined or do not apply, show the structure in
-     * a new viewer
-     */
     openNewChimera(ap, new PDBEntry[] { pdbentry },
             new SequenceI[][]
             { seq });
@@ -264,7 +235,6 @@ public class ChimeraViewFrame extends StructureViewerBase
 
     if (pdbentrys.length > 1)
     {
-      alignAddedStructures = true;
       useAlignmentPanelForSuperposition(ap);
     }
     jmb.setColourBySequence(true);
@@ -323,17 +293,19 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   /**
-   * create a new viewer containing several structures superimposed using the
-   * given alignPanel.
+   * create a new viewer containing several structures, optionally superimposed
+   * using the given alignPanel.
    * 
    * @param pe
    * @param seqs
    * @param ap
    */
-  public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
+  public ChimeraViewFrame(PDBEntry[] pe, boolean alignAdded,
+          SequenceI[][] seqs,
           AlignmentPanel ap)
   {
     this();
+    setAlignAddedStructures(alignAdded);
     openNewChimera(ap, pe, seqs);
   }
 
@@ -352,29 +324,6 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   /**
-   * Returns a list of any Chimera viewers in the desktop. The list is
-   * restricted to those linked to the given alignment panel if it is not null.
-   */
-  @Override
-  protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
-  {
-    List<StructureViewerBase> result = new ArrayList<>();
-    JInternalFrame[] frames = Desktop.instance.getAllFrames();
-
-    for (JInternalFrame frame : frames)
-    {
-      if (frame instanceof ChimeraViewFrame)
-      {
-        if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
-        {
-          result.add((StructureViewerBase) frame);
-        }
-      }
-    }
-    return result;
-  }
-
-  /**
    * Launch Chimera. If we have a chimera session file name, send Chimera the
    * command to open its saved session file.
    */
@@ -405,7 +354,10 @@ public class ChimeraViewFrame extends StructureViewerBase
       }
     }
 
-    jmb.startChimeraListener();
+    if (!Platform.isJS())
+    {
+       jmb.startChimeraListener();
+    }
   }
 
   /**
@@ -641,7 +593,7 @@ public class ChimeraViewFrame extends StructureViewerBase
         jmb.updateColours(ap);
       }
       // do superposition if asked to
-      if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
+      if (alignAddedStructures)
       {
         new Thread(new Runnable()
         {
@@ -651,7 +603,6 @@ public class ChimeraViewFrame extends StructureViewerBase
             alignStructs_withAllAlignPanels();
           }
         }).start();
-        alignAddedStructures = false;
       }
       addingStructures = false;
     }
@@ -681,7 +632,6 @@ public class ChimeraViewFrame extends StructureViewerBase
 
   private String fetchPdbFile(PDBEntry processingEntry) throws Exception
   {
-    // FIXME: this is duplicated code with Jmol frame ?
     String filePath = null;
     Pdb pdbclient = new Pdb();
     AlignmentI pdbseq = null;
@@ -760,17 +710,10 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  public void eps_actionPerformed(ActionEvent e)
-  {
-    throw new Error(MessageManager
-            .getString("error.eps_generation_not_implemented"));
-  }
-
-  @Override
-  public void png_actionPerformed(ActionEvent e)
+  public void makePDBImage(TYPE imageType)
   {
-    throw new Error(MessageManager
-            .getString("error.png_generation_not_implemented"));
+    throw new UnsupportedOperationException(
+            "Image export for Chimera is not implemented");
   }
 
   @Override