Merge branch 'develop' into feature/JAL-3390hideUnmappedStructure
[jalview.git] / src / jalview / jbgui / GStructureViewer.java
index dfee3e2..485d755 100644 (file)
  */
 package jalview.jbgui;
 
-import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.gui.ColourMenuHelper.ColourChangeListener;
-import jalview.util.ImageMaker.TYPE;
-import jalview.util.MessageManager;
-
 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;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
@@ -38,6 +36,11 @@ import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JRadioButtonMenuItem;
 
+import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
+import jalview.util.ImageMaker.TYPE;
+import jalview.util.MessageManager;
+
 @SuppressWarnings("serial")
 public abstract class GStructureViewer extends JInternalFrame
         implements JalviewStructureDisplayI, ColourChangeListener
@@ -56,6 +59,10 @@ public abstract class GStructureViewer extends JInternalFrame
 
   protected JMenuItem alignStructs;
 
+  protected JCheckBoxMenuItem showAlignmentOnly;
+
+  protected JCheckBoxMenuItem hideHiddenRegions;
+
   protected JMenuItem fitToWindow;
 
   protected JRadioButtonMenuItem seqColour;
@@ -109,7 +116,7 @@ public abstract class GStructureViewer extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
-        pdbFile_actionPerformed(actionEvent);
+        pdbFile_actionPerformed();
       }
     });
 
@@ -142,7 +149,7 @@ public abstract class GStructureViewer extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
-        viewMapping_actionPerformed(actionEvent);
+        viewMapping_actionPerformed();
       }
     });
 
@@ -159,20 +166,19 @@ public abstract class GStructureViewer extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
-        fitToWindow_actionPerformed();
+        getBinding().focusView();
       }
     });
 
     JMenu helpMenu = new JMenu();
     helpMenu.setText(MessageManager.getString("action.help"));
     helpItem = new JMenuItem();
-    helpItem.setText(MessageManager.getString("label.jmol_help"));
     helpItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
-        showHelp_actionPerformed(actionEvent);
+        showHelp_actionPerformed();
       }
     });
     alignStructs = new JMenuItem();
@@ -183,7 +189,7 @@ public abstract class GStructureViewer extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
-        alignStructs_actionPerformed(actionEvent);
+        alignStructsWithAllAlignPanels();
       }
     });
 
@@ -215,20 +221,20 @@ public abstract class GStructureViewer extends JInternalFrame
 
   protected void fitToWindow_actionPerformed()
   {
+    getBinding().focusView();
   }
 
   protected void highlightSelection_actionPerformed()
   {
   }
 
-  protected void viewerColour_actionPerformed(ActionEvent actionEvent)
+  protected void viewerColour_actionPerformed()
   {
   }
 
-  protected abstract String alignStructs_actionPerformed(
-          ActionEvent actionEvent);
+  protected abstract String alignStructsWithAllAlignPanels();
 
-  public void pdbFile_actionPerformed(ActionEvent actionEvent)
+  public void pdbFile_actionPerformed()
   {
 
   }
@@ -238,33 +244,56 @@ public abstract class GStructureViewer extends JInternalFrame
 
   }
 
-  public void viewMapping_actionPerformed(ActionEvent actionEvent)
+  public void viewMapping_actionPerformed()
   {
 
   }
 
-  public void seqColour_actionPerformed(ActionEvent actionEvent)
+  public void seqColour_actionPerformed()
   {
 
   }
 
-  public void chainColour_actionPerformed(ActionEvent actionEvent)
+  public void chainColour_actionPerformed()
   {
 
   }
 
-  public void chargeColour_actionPerformed(ActionEvent actionEvent)
+  public void chargeColour_actionPerformed()
   {
 
   }
 
-  public void background_actionPerformed(ActionEvent actionEvent)
+  public void background_actionPerformed()
   {
 
   }
 
-  public void showHelp_actionPerformed(ActionEvent actionEvent)
+  public void showHelp_actionPerformed()
   {
 
   }
+
+  /**
+   * Saves the unselected entries in the 'View Chain' menu into a list. Entries
+   * are formatted as "pdbid:chainid". Unselected chains should be hidden in the
+   * structure display.
+   */
+  protected void setChainsToHide()
+  {
+    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().split(" ")[0]);
+        }
+      }
+    }
+    getBinding().setChainsToHide(chains);
+  }
 }