JAL-2136 New Phyre2 branch + attempt to resynced with develop
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index 67eddca..3ebee11 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import jalview.api.FeatureRenderer;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
@@ -76,6 +77,10 @@ public class ChimeraViewFrame extends StructureViewerBase
 
   private Random random = new Random();
 
+  private int myWidth = 500;
+
+  private int myHeight = 150;
+
   /**
    * Initialise menu options.
    */
@@ -95,35 +100,41 @@ public class ChimeraViewFrame extends StructureViewerBase
     savemenu.setVisible(false); // not yet implemented
     viewMenu.add(fitToWindow);
 
-    JMenuItem writeFeatures = new JMenuItem(
-            MessageManager.getString("label.create_chimera_attributes"));
-    writeFeatures.setToolTipText(MessageManager
-            .getString("label.create_chimera_attributes_tip"));
-    writeFeatures.addActionListener(new ActionListener()
+    /*
+     * exchange of Jalview features and Chimera attributes is for now
+     * an optionally enabled experimental feature
+     */
+    if (Desktop.instance.showExperimental())
     {
-      @Override
-      public void actionPerformed(ActionEvent e)
+      JMenuItem writeFeatures = new JMenuItem(
+              MessageManager.getString("label.create_chimera_attributes"));
+      writeFeatures.setToolTipText(MessageManager
+              .getString("label.create_chimera_attributes_tip"));
+      writeFeatures.addActionListener(new ActionListener()
       {
-        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 mouseEntered(MouseEvent e)
+        @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()
       {
-        buildAttributesMenu(fetchAttributes);
-      }
-    });
-    viewerActionMenu.add(fetchAttributes);
 
+        @Override
+        public void mouseEntered(MouseEvent e)
+        {
+          buildAttributesMenu(fetchAttributes);
+        }
+      });
+      viewerActionMenu.add(fetchAttributes);
+    }
   }
 
   /**
@@ -185,7 +196,9 @@ public class ChimeraViewFrame extends StructureViewerBase
    */
   protected void sendFeaturesToChimera()
   {
-    jmb.sendFeaturesToViewer(getAlignmentPanel());
+    int count = jmb.sendFeaturesToViewer(getAlignmentPanel());
+    statusBar.setText(MessageManager.formatMessage("label.attributes_set",
+            count));
   }
 
   /**
@@ -254,7 +267,7 @@ public class ChimeraViewFrame extends StructureViewerBase
       useAlignmentPanelForSuperposition(ap);
     }
     jmb.setColourBySequence(true);
-    setSize(400, 400); // probably should be a configurable/dynamic default here
+    setSize(myWidth, myHeight);
     initMenus();
 
     addingStructures = false;
@@ -477,7 +490,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     StructureFile pdb = null;
     try
     {
-      String[] curfiles = jmb.getPdbFile(); // files currently in viewer
+      String[] curfiles = jmb.getStructureFiles(); // files currently in viewer
       // TODO: replace with reference fetching/transfer code (validate PDBentry
       // as a DBRef?)
       for (int pi = 0; pi < jmb.getPdbCount(); pi++)
@@ -585,7 +598,8 @@ public class ChimeraViewFrame extends StructureViewerBase
             }
             // Explicitly map to the filename used by Chimera ;
             pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
-                    jmb.getChains()[pos], pe.getFile(), protocol);
+                    jmb.getChains()[pos], pe.getFile(), protocol,
+                    progressBar);
             stashFoundChains(pdb, pe.getFile());
           } catch (OutOfMemoryError oomerror)
           {
@@ -607,6 +621,16 @@ public class ChimeraViewFrame extends StructureViewerBase
       jmb.setFinishedInit(true);
       jmb.setLoadingFromArchive(false);
 
+      /*
+       * ensure that any newly discovered features (e.g. RESNUM)
+       * are added to any open feature settings dialog
+       */
+      FeatureRenderer fr = getBinding().getFeatureRenderer(null);
+      if (fr != null)
+      {
+        fr.featuresAdded();
+      }
+
       // refresh the sequence colours for the new structure(s)
       for (AlignmentPanel ap : _colourwith)
       {
@@ -633,7 +657,7 @@ public class ChimeraViewFrame extends StructureViewerBase
 
   /**
    * Fetch PDB data and save to a local file. Returns the full path to the file,
-   * or null if fetch fails.
+   * or null if fetch fails. TODO: refactor to common with Jmol ? duplication
    * 
    * @param processingEntry
    * @return
@@ -852,19 +876,30 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   /**
-   * Override superclass method to make the 'Chimera' menu always visible, but
-   * 'Superpose with...' only enabled if there is more than one structure shown
+   * Sends commands to align structures according to associated alignment(s).
+   * 
+   * @return
    */
   @Override
-  public void updateTitleAndMenus()
+  protected String alignStructs_withAllAlignPanels()
   {
-    super.updateTitleAndMenus();
-    viewerActionMenu.setVisible(true);
-    viewSelectionMenu.setEnabled(false);
-    if (getBinding().getPdbFile().length > 1
-            && getBinding().getSequence().length > 1)
+    String reply = super.alignStructs_withAllAlignPanels();
+    if (reply != null)
     {
-      viewSelectionMenu.setEnabled(true);
+      statusBar.setText("Superposition failed: " + reply);
     }
+    return reply;
+  }
+
+  @Override
+  protected IProgressIndicator getIProgressIndicator()
+  {
+    return progressBar;
+  }
+
+  @Override
+  protected AAStructureBindingModel getBindingModel()
+  {
+    return jmb;
   }
 }