JAL-1601 Load and display JPred4 service in AlignFrame
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index 810f40d..62e7b38 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
@@ -38,7 +39,7 @@ import javax.swing.event.InternalFrameEvent;
 
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureRenderer;
-import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.StructureViewerModel;
@@ -51,7 +52,6 @@ import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-
 /**
  * GUI elements for handling an external chimera display
  * 
@@ -62,6 +62,7 @@ public class ChimeraViewFrame extends StructureViewerBase
 {
   private JalviewChimeraBinding jmb;
 
+
   /*
    * Path to Chimera session file. This is set when an open Jalview/Chimera
    * session is saved, or on restore from a Jalview project (if it holds the
@@ -69,10 +70,15 @@ public class ChimeraViewFrame extends StructureViewerBase
    */
   private String chimeraSessionFile = null;
 
+
   private int myWidth = 500;
 
   private int myHeight = 150;
 
+  private JMenuItem writeFeatures = null;
+
+  private JMenu fetchAttributes = null;
+
   /**
    * Initialise menu options.
    */
@@ -84,10 +90,10 @@ public class ChimeraViewFrame extends StructureViewerBase
     savemenu.setVisible(false); // not yet implemented
     viewMenu.add(fitToWindow);
 
-    JMenuItem writeFeatures = new JMenuItem(
+    writeFeatures = new JMenuItem(
             MessageManager.getString("label.create_viewer_attributes"));
-    writeFeatures.setToolTipText(MessageManager
-            .getString("label.create_viewer_attributes_tip"));
+    writeFeatures.setToolTipText(
+            MessageManager.getString("label.create_viewer_attributes_tip"));
     writeFeatures.addActionListener(new ActionListener()
     {
       @Override
@@ -98,10 +104,10 @@ public class ChimeraViewFrame extends StructureViewerBase
     });
     viewerActionMenu.add(writeFeatures);
 
-    final JMenu fetchAttributes = new JMenu(
-            MessageManager.getString("label.fetch_chimera_attributes"));
-    fetchAttributes.setToolTipText(
-            MessageManager.getString("label.fetch_chimera_attributes_tip"));
+    fetchAttributes = new JMenu(MessageManager.formatMessage(
+            "label.fetch_viewer_attributes", getViewerName()));
+    fetchAttributes.setToolTipText(MessageManager.formatMessage(
+            "label.fetch_viewer_attributes_tip", getViewerName()));
     fetchAttributes.addMouseListener(new MouseAdapter()
     {
 
@@ -114,6 +120,16 @@ public class ChimeraViewFrame extends StructureViewerBase
     viewerActionMenu.add(fetchAttributes);
   }
 
+  @Override
+  protected void buildActionMenu()
+  {
+    super.buildActionMenu();
+    // add these back in after menu is refreshed
+    viewerActionMenu.add(writeFeatures);
+    viewerActionMenu.add(fetchAttributes);
+
+  };
+
   /**
    * Query the structure viewer for its residue attribute names and add them as
    * items off the attributes menu
@@ -152,8 +168,8 @@ public class ChimeraViewFrame extends StructureViewerBase
   {
     // todo pull up?
     int count = jmb.sendFeaturesToViewer(getAlignmentPanel());
-    statusBar.setText(
-            MessageManager.formatMessage("label.attributes_set", count));
+    statusBar.setText(MessageManager.formatMessage("label.attributes_set",
+            count, getViewerName()));
   }
 
   /**
@@ -223,7 +239,6 @@ public class ChimeraViewFrame extends StructureViewerBase
     return new JalviewChimeraBindingModel(this,
             ap.getStructureSelectionManager(), pdbentrys, seqs, null);
   }
-
   /**
    * Create a new viewer from saved session state data including Chimera session
    * file
@@ -280,8 +295,7 @@ public class ChimeraViewFrame extends StructureViewerBase
    * @param ap
    */
   public ChimeraViewFrame(PDBEntry[] pe, boolean alignAdded,
-          SequenceI[][] seqs,
-          AlignmentPanel ap)
+          SequenceI[][] seqs, AlignmentPanel ap)
   {
     this();
     setAlignAddedStructures(alignAdded);
@@ -315,11 +329,12 @@ public class ChimeraViewFrame extends StructureViewerBase
 
     if (!jmb.launchChimera())
     {
-      JvOptionPane.showMessageDialog(Desktop.desktop,
+      JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
               MessageManager.formatMessage("label.open_viewer_failed",
                       getViewerName()),
               MessageManager.getString("label.error_loading_file"),
               JvOptionPane.ERROR_MESSAGE);
+      jmb.closeViewer(true);
       this.dispose();
       return;
     }
@@ -412,7 +427,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     if (errormsgs.length() > 0)
     {
 
-      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+      JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
               MessageManager.formatMessage(
                       "label.pdb_entries_couldnt_be_retrieved", new Object[]
                       { errormsgs.toString() }),
@@ -430,9 +445,15 @@ public class ChimeraViewFrame extends StructureViewerBase
           initChimera();
         } catch (Exception ex)
         {
-          Cache.log.error("Couldn't open Chimera viewer!", ex);
+          Console.error("Couldn't open Chimera viewer!", ex);
         }
       }
+      if (!jmb.isViewerRunning())
+      {
+        // nothing to do
+        // TODO: ensure we tidy up JAL-3619
+        return;
+      }
       int num = -1;
       for (PDBEntry pe : filePDB)
       {
@@ -475,12 +496,12 @@ public class ChimeraViewFrame extends StructureViewerBase
                     oomerror);
           } catch (Exception ex)
           {
-            Cache.log.error(
+            Console.error(
                     "Couldn't open " + pe.getFile() + " in Chimera viewer!",
                     ex);
           } finally
           {
-            Cache.log.debug("File locations are " + files);
+            Console.debug("File locations are " + files);
           }
         }
       }
@@ -491,7 +512,8 @@ public class ChimeraViewFrame extends StructureViewerBase
 
       /*
        * ensure that any newly discovered features (e.g. RESNUM)
-       * are added to any open feature settings dialog
+       * are notified to the FeatureRenderer (and added to any 
+       * open feature settings dialog)
        */
       FeatureRenderer fr = getBinding().getFeatureRenderer(null);
       if (fr != null)
@@ -522,6 +544,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     worker = null;
   }
 
+
   @Override
   public void makePDBImage(TYPE imageType)
   {
@@ -535,6 +558,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     return jmb;
   }
 
+
   @Override
   public ViewerType getViewerType()
   {