JAL-2136 merged and resolved conflicts with 80edaa84d6d9beac9f0d2c71b50b7b56fd393427
[jalview.git] / src / jalview / gui / StructureViewerBase.java
index 41390b1..f42a417 100644 (file)
@@ -24,18 +24,22 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.jbgui.GStructureViewer;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 
 import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
+import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 
 /**
  * Base class with common functionality for JMol, Chimera or other structure
@@ -76,6 +80,8 @@ public abstract class StructureViewerBase extends GStructureViewer
 
   protected Thread worker = null;
 
+  protected boolean allChainsSelected = false;
+
   /**
    * 
    * @param ap2
@@ -331,17 +337,17 @@ public abstract class StructureViewerBase extends GStructureViewer
    * 
    * @param pdbId
    * @param view
-   * @return YES, NO or CANCEL JOptionPane code
+   * @return YES, NO or CANCEL JvOptionPane code
    */
   protected int chooseAlignStructureToViewer(String pdbId,
           StructureViewerBase view)
   {
-    int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+    int option = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
             MessageManager.formatMessage("label.add_pdbentry_to_view",
                     new Object[] { pdbId, view.getTitle() }),
             MessageManager
                     .getString("label.align_to_existing_structure_view"),
-            JOptionPane.YES_NO_CANCEL_OPTION);
+            JvOptionPane.YES_NO_CANCEL_OPTION);
     return option;
   }
 
@@ -376,11 +382,11 @@ public abstract class StructureViewerBase extends GStructureViewer
         continue;
       }
       int option = chooseAlignStructureToViewer(pdbId, view);
-      if (option == JOptionPane.CANCEL_OPTION)
+      if (option == JvOptionPane.CANCEL_OPTION)
       {
         return true;
       }
-      else if (option == JOptionPane.YES_OPTION)
+      else if (option == JvOptionPane.YES_OPTION)
       {
         view.useAlignmentPanelForSuperposition(apanel);
         view.addStructure(pdbentry, seq, chains, true, apanel.alignFrame);
@@ -415,7 +421,7 @@ public abstract class StructureViewerBase extends GStructureViewer
      * create the mappings
      */
     apanel.getStructureSelectionManager().setMapping(seq, chains,
-            pdbFilename, AppletFormatAdapter.FILE, getIProgressIndicator());
+            pdbFilename, DataSourceType.FILE, getIProgressIndicator());
 
     /*
      * alert the FeatureRenderer to show new (PDB RESNUM) features
@@ -476,19 +482,19 @@ public abstract class StructureViewerBase extends GStructureViewer
       /*
        * the PDB file is already loaded
        */
-      int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+      int option = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
               MessageManager.formatMessage(
                       "label.pdb_entry_is_already_displayed",
                       new Object[] { pdbId }), MessageManager
                       .formatMessage(
                               "label.map_sequences_to_visible_window",
                               new Object[] { pdbId }),
-              JOptionPane.YES_NO_CANCEL_OPTION);
-      if (option == JOptionPane.CANCEL_OPTION)
+              JvOptionPane.YES_NO_CANCEL_OPTION);
+      if (option == JvOptionPane.CANCEL_OPTION)
       {
         finished = true;
       }
-      else if (option == JOptionPane.YES_OPTION)
+      else if (option == JvOptionPane.YES_OPTION)
       {
         addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
         finished = true;
@@ -496,4 +502,55 @@ public abstract class StructureViewerBase extends GStructureViewer
     }
     return finished;
   }
+
+  void setChainMenuItems(List<String> chainNames)
+  {
+    chainMenu.removeAll();
+    if (chainNames == null || chainNames.isEmpty())
+    {
+      return;
+    }
+    JMenuItem menuItem = new JMenuItem(
+            MessageManager.getString("label.all"));
+    menuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent evt)
+      {
+        allChainsSelected = true;
+        for (int i = 0; i < chainMenu.getItemCount(); i++)
+        {
+          if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
+          {
+            ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
+          }
+        }
+        showSelectedChains();
+        allChainsSelected = false;
+      }
+    });
+
+    chainMenu.add(menuItem);
+
+    for (String chain : chainNames)
+    {
+      menuItem = new JCheckBoxMenuItem(chain, true);
+      menuItem.addItemListener(new ItemListener()
+      {
+        @Override
+        public void itemStateChanged(ItemEvent evt)
+        {
+          if (!allChainsSelected)
+          {
+            showSelectedChains();
+          }
+        }
+      });
+
+      chainMenu.add(menuItem);
+    }
+  }
+
+  abstract void showSelectedChains();
+
 }