JAL-2351 first refactoring and outline of read/write Jmol properties
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index e76f11e..bac8f60 100644 (file)
@@ -26,10 +26,9 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
-import jalview.ext.rbvi.chimera.ChimeraCommands;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
 import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.io.StructureFile;
@@ -62,7 +61,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Random;
 import java.util.Vector;
@@ -72,7 +70,6 @@ import javax.swing.JColorChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 import javax.swing.event.MenuEvent;
@@ -86,7 +83,7 @@ import javax.swing.event.MenuListener;
  */
 public class ChimeraViewFrame extends StructureViewerBase
 {
-  private JalviewChimeraBinding jmb;
+  JalviewChimeraBinding jmb;
 
   private boolean allChainsSelected = false;
 
@@ -106,7 +103,8 @@ public class ChimeraViewFrame extends StructureViewerBase
    */
   private void initMenus()
   {
-    viewerActionMenu.setText(MessageManager.getString("label.chimera"));
+    String chimera = MessageManager.getString("label.chimera");
+    viewerActionMenu.setText(chimera);
     viewerColour.setText(MessageManager
             .getString("label.colour_with_chimera"));
     viewerColour.setToolTipText(MessageManager
@@ -167,43 +165,39 @@ public class ChimeraViewFrame extends StructureViewerBase
     viewerActionMenu.add(alpanels);
     viewerActionMenu.addMenuListener(new MenuListener()
     {
-
       @Override
       public void menuSelected(MenuEvent e)
       {
         handler.itemStateChanged(null);
       }
-
       @Override
       public void menuDeselected(MenuEvent e)
       {
-        // TODO Auto-generated method stub
       }
-
       @Override
       public void menuCanceled(MenuEvent e)
       {
-        // TODO Auto-generated method stub
       }
     });
 
     JMenuItem writeFeatures = new JMenuItem(
-            MessageManager.getString("label.create_chimera_attributes"));
-    writeFeatures.setToolTipText(MessageManager
-            .getString("label.create_chimera_attributes_tip"));
+            MessageManager.getString("label.create_viewer_attributes"));
+    writeFeatures.setToolTipText(MessageManager.formatMessage(
+            "label.create_viewer_attributes_tip", chimera));
     writeFeatures.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        sendFeaturesToChimera();
+        sendFeaturesToViewer();
       }
     });
     viewerActionMenu.add(writeFeatures);
 
-    final JMenu fetchAttributes = new JMenu("Fetch Chimera attributes");
-    fetchAttributes
-            .setToolTipText("Copy Chimera attribute to Jalview feature");
+    final JMenu fetchAttributes = new JMenu(MessageManager.formatMessage(
+            "label.fetch_viewer_attributes", chimera));
+    fetchAttributes.setToolTipText(MessageManager.formatMessage(
+            "label.fetch_viewer_attributes_tip", chimera));
     fetchAttributes.addMouseListener(new MouseAdapter()
     {
 
@@ -214,55 +208,16 @@ public class ChimeraViewFrame extends StructureViewerBase
       }
     });
     viewerActionMenu.add(fetchAttributes);
-
-  }
-
-  /**
-   * Query Chimera for its residue attribute names and add them as items off the
-   * attributes menu
-   * 
-   * @param attributesMenu
-   */
-  protected void buildAttributesMenu(JMenu attributesMenu)
-  {
-    List<String> atts = jmb.sendChimeraCommand("list resattr", true);
-    if (atts == null)
-    {
-      return;
-    }
-    attributesMenu.removeAll();
-    Collections.sort(atts);
-    for (String att : atts)
-    {
-      final String attName = att.split(" ")[1];
-
-      /*
-       * ignore 'jv_*' attributes, as these are Jalview features that have
-       * been transferred to residue attributes in Chimera!
-       */
-      if (!attName.startsWith(ChimeraCommands.NAMESPACE_PREFIX))
-      {
-        JMenuItem menuItem = new JMenuItem(attName);
-        menuItem.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
-            getChimeraAttributes(attName);
-          }
-        });
-        attributesMenu.add(menuItem);
-      }
-    }
   }
 
   /**
-   * Read residues in Chimera with the given attribute name, and set as features
-   * on the corresponding sequence positions (if any)
+   * Asks Chimera for residues with the given attribute name, and set as
+   * features on the corresponding sequence positions (if any)
    * 
    * @param attName
    */
-  protected void getChimeraAttributes(String attName)
+  @Override
+  protected void getResidueAttributes(String attName)
   {
     jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel());
   }
@@ -274,7 +229,8 @@ public class ChimeraViewFrame extends StructureViewerBase
    * <p>
    * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A
    */
-  protected void sendFeaturesToChimera()
+  @Override
+  protected void sendFeaturesToViewer()
   {
     jmb.sendFeaturesToViewer(getAlignmentPanel());
   }
@@ -469,10 +425,10 @@ public class ChimeraViewFrame extends StructureViewerBase
 
     if (!jmb.launchChimera())
     {
-      JOptionPane.showMessageDialog(Desktop.desktop,
+      JvOptionPane.showMessageDialog(Desktop.desktop,
               MessageManager.getString("label.chimera_failed"),
               MessageManager.getString("label.error_loading_file"),
-              JOptionPane.ERROR_MESSAGE);
+              JvOptionPane.ERROR_MESSAGE);
       this.dispose();
       return;
     }
@@ -586,18 +542,18 @@ public class ChimeraViewFrame extends StructureViewerBase
                 "label.confirm_close_chimera",
                 new Object[] { jmb.getViewerTitle("Chimera", false) });
         prompt = JvSwingUtils.wrapTooltip(true, prompt);
-        int confirm = JOptionPane.showConfirmDialog(this, prompt,
+        int confirm = JvOptionPane.showConfirmDialog(this, prompt,
                 MessageManager.getString("label.close_viewer"),
-                JOptionPane.YES_NO_CANCEL_OPTION);
+                JvOptionPane.YES_NO_CANCEL_OPTION);
         /*
          * abort closure if user hits escape or Cancel
          */
-        if (confirm == JOptionPane.CANCEL_OPTION
-                || confirm == JOptionPane.CLOSED_OPTION)
+        if (confirm == JvOptionPane.CANCEL_OPTION
+                || confirm == JvOptionPane.CLOSED_OPTION)
         {
           return;
         }
-        closeChimera = confirm == JOptionPane.YES_OPTION;
+        closeChimera = confirm == JvOptionPane.YES_OPTION;
       }
       jmb.closeViewer(closeChimera);
     }
@@ -686,11 +642,11 @@ public class ChimeraViewFrame extends StructureViewerBase
     if (errormsgs.length() > 0)
     {
 
-      JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
               .formatMessage("label.pdb_entries_couldnt_be_retrieved",
                       new Object[] { errormsgs.toString() }),
               MessageManager.getString("label.couldnt_load_file"),
-              JOptionPane.ERROR_MESSAGE);
+              JvOptionPane.ERROR_MESSAGE);
     }
 
     if (files.length() > 0)
@@ -721,12 +677,12 @@ public class ChimeraViewFrame extends StructureViewerBase
             jmb.openFile(pe);
             jmb.addSequence(pos, jmb.getSequence()[pos]);
             File fl = new File(pe.getFile());
-            String protocol = AppletFormatAdapter.URL;
+            DataSourceType protocol = DataSourceType.URL;
             try
             {
               if (fl.exists())
               {
-                protocol = AppletFormatAdapter.FILE;
+                protocol = DataSourceType.FILE;
               }
             } catch (Throwable e)
             {
@@ -1291,4 +1247,10 @@ public class ChimeraViewFrame extends StructureViewerBase
   {
     return jmb;
   }
+
+  @Override
+  protected List<String> getResidueAttributeNames()
+  {
+    return jmb.getResidueAttributes();
+  }
 }