JAL-3390 Chimera showStructures() respects visible/chain selections
[jalview.git] / src / jalview / jbgui / GStructureViewer.java
index 2094201..418e413 100644 (file)
@@ -28,6 +28,8 @@ import java.awt.BorderLayout;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JInternalFrame;
@@ -270,4 +272,27 @@ public abstract class GStructureViewer extends JInternalFrame
   {
 
   }
+
+  /**
+   * Saves the selected entries in the 'View Chain' menu into a list. Entries are
+   * formatted as "pdbid:chainid". Only the selected chains should be drawn in the
+   * structure display.
+   */
+  protected void setSelectedChains()
+  {
+    List<String> chains = new ArrayList<>();
+    for (int i = 0; i < chainMenu.getItemCount(); i++)
+    {
+      JMenuItem menuItem = chainMenu.getItem(i);
+      if (menuItem instanceof JCheckBoxMenuItem)
+      {
+        JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem;
+        if (item.isSelected())
+        {
+          chains.add(item.getText());
+        }
+      }
+    }
+    getBinding().setChainsToShow(chains);
+  }
 }