JAL-914 don't open help window twice
[jalview.git] / src / jalview / gui / AlignFrame.java
index e6b7af4..4168516 100644 (file)
@@ -334,6 +334,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     setMenusFromViewport(viewport);
     buildSortByAnnotationScoresMenu();
     buildTreeMenu();
+    buildShowHideAnnotationMenus();
+    
     if (viewport.wrapAlignment)
     {
       wrapMenuItem_actionPerformed(null);
@@ -4025,6 +4027,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           tm.setText(title);//
           tm.addActionListener(new java.awt.event.ActionListener()
           {
+            @Override
             public void actionPerformed(ActionEvent e)
             {
               NewTreePanel(type, (String) pwtype, title);
@@ -5313,6 +5316,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
     trimrs.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         trimrs.setSelected(trimrs.isSelected());
@@ -5703,6 +5707,95 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
     }
   }
+
+  /**
+   * On menu option, open a panel to allow choice of annotation types to
+   * show/hide.
+   */
+  @Override
+  protected void chooseAnnotations_actionPerformed()
+  {
+    new AnnotationChooser(this.alignPanel);
+  }
+
+  /**
+   * Get a list of unique annotation types for the alignment, optionally
+   * restricted to sequence-specific annotations.
+   */
+  protected List<String> getAnnotationTypes(boolean sequenceSpecificOnly)
+  {
+    // TODO move this to an AlignmentUtils class or similar
+    List<String> types = new ArrayList<String>();
+    for (AlignmentAnnotation aa : alignPanel.getAlignment()
+            .getAlignmentAnnotation())
+    {
+      if (sequenceSpecificOnly && aa.sequenceRef == null)
+      {
+        continue;
+      }
+      String type = aa.label;
+      if (!types.contains(type))
+      {
+        types.add(type);
+      }
+    }
+    return types;
+  }
+
+  /**
+   * Action on selection of an annotation type to Show or Hide.
+   * 
+   * @param type
+   * @param doShow
+   */
+  @Override
+  protected void showHideAnnotation_actionPerformed(String type, boolean doShow)
+  {
+    for (AlignmentAnnotation aa : alignPanel.getAlignment()
+            .getAlignmentAnnotation())
+    {
+      if (type.equals(aa.label))
+      {
+        aa.visible = doShow;
+      }
+    }
+    this.alignPanel.paintAlignment(true);
+  }
+
+  /**
+   * Dynamically build the list of annotation types to show or hide.
+   */
+  @Override
+  protected void buildShowHideAnnotationMenus()
+  {
+    showAnnotations.removeAll();
+    hideAnnotations.removeAll();
+
+    List<String> types = getAnnotationTypes(false);
+    for (final String type : types)
+    {
+      final JMenuItem showitem = new JMenuItem(type);
+      showitem.addActionListener(new java.awt.event.ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          showHideAnnotation_actionPerformed(type, true);
+        }
+      });
+      showAnnotations.add(showitem);
+      final JMenuItem hideitem = new JMenuItem(type);
+      hideitem.addActionListener(new java.awt.event.ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          showHideAnnotation_actionPerformed(type, false);
+        }
+      });
+      hideAnnotations.add(hideitem);
+    }
+  }
 }
 
 class PrintThread extends Thread