JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / appletgui / AnnotationLabels.java
index 6aaa033..201cfae 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -20,6 +20,7 @@
  */
 package jalview.appletgui;
 
+import jalview.analysis.AlignmentUtils;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceGroup;
@@ -48,6 +49,7 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Vector;
 
 public class AnnotationLabels extends Panel implements ActionListener,
@@ -211,6 +213,14 @@ public class AnnotationLabels extends Panel implements ActionListener,
       }
 
     }
+    refresh();
+  }
+
+  /**
+   * Adjust size and repaint
+   */
+  protected void refresh()
+  {
     ap.annotationPanel.adjustPanelHeight();
     setSize(getSize().width, ap.annotationPanel.getSize().height);
     ap.validate();
@@ -311,8 +321,8 @@ public class AnnotationLabels extends Panel implements ActionListener,
               .getSize(), f = ap.seqPanelHolder.getSize();
       int dif = evt.getY() - oldY;
 
-      dif /= ap.av.charHeight;
-      dif *= ap.av.charHeight;
+      dif /= ap.av.getCharHeight();
+      dif *= ap.av.getCharHeight();
 
       if ((d.height - dif) > 20 && (f.height + dif) > 20)
       {
@@ -461,6 +471,32 @@ public class AnnotationLabels extends Panel implements ActionListener,
       item = new MenuItem(HIDE);
       item.addActionListener(this);
       popup.add(item);
+
+      /*
+       * Hide all <label>:
+       */
+      if (selectedRow < aa.length)
+      {
+        if (aa[selectedRow].sequenceRef != null)
+        {
+          final String label = aa[selectedRow].label;
+          MenuItem hideType = new MenuItem(
+                  MessageManager.getString("label.hide_all") + " " + label);
+          hideType.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              AlignmentUtils.showOrHideSequenceAnnotations(
+                      ap.av.getAlignment(), Collections.singleton(label),
+                      null, false, false);
+              refresh();
+            }
+          });
+          popup.add(hideType);
+        }
+      }
+
       if (hasHiddenRows)
       {
         item = new MenuItem(SHOWALL);
@@ -482,7 +518,7 @@ public class AnnotationLabels extends Panel implements ActionListener,
                     MessageManager.getString("label.ignore_gaps_consensus"),
                     (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
                             .getIgnoreGapsConsensus() : ap.av
-                            .getIgnoreGapsConsensus());
+                            .isIgnoreGapsConsensus());
             final AlignmentAnnotation aaa = aa[selectedRow];
             cbmi.addItemListener(new ItemListener()
             {
@@ -495,7 +531,7 @@ public class AnnotationLabels extends Panel implements ActionListener,
                 }
                 else
                 {
-                  ap.av.setIgnoreGapsConsensus(cbmi.getState());
+                  ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
                 }
                 ap.paintAlignment(true);
               }
@@ -504,7 +540,8 @@ public class AnnotationLabels extends Panel implements ActionListener,
             if (aaa.groupRef != null)
             {
               final CheckboxMenuItem chist = new CheckboxMenuItem(
-                      MessageManager.getString("label.show_group_histogram"),
+                      MessageManager
+                              .getString("label.show_group_histogram"),
                       aa[selectedRow].groupRef.isShowConsensusHistogram());
               chist.addItemListener(new ItemListener()
               {
@@ -543,7 +580,8 @@ public class AnnotationLabels extends Panel implements ActionListener,
 
               popup.add(cprofl);
               final CheckboxMenuItem cprofn = new CheckboxMenuItem(
-                      MessageManager.getString("label.normalise_group_logo"),
+                      MessageManager
+                              .getString("label.normalise_group_logo"),
                       aa[selectedRow].groupRef.isNormaliseSequenceLogo());
               cprofn.addItemListener(new ItemListener()
               {
@@ -566,7 +604,8 @@ public class AnnotationLabels extends Panel implements ActionListener,
             else
             {
               final CheckboxMenuItem chist = new CheckboxMenuItem(
-                      MessageManager.getString("label.show_histogram"), av.isShowConsensusHistogram());
+                      MessageManager.getString("label.show_histogram"),
+                      av.isShowConsensusHistogram());
               chist.addItemListener(new ItemListener()
               {
                 public void itemStateChanged(ItemEvent e)
@@ -588,7 +627,8 @@ public class AnnotationLabels extends Panel implements ActionListener,
               });
               popup.add(chist);
               final CheckboxMenuItem cprof = new CheckboxMenuItem(
-                      MessageManager.getString("label.show_logo"), av.isShowSequenceLogo());
+                      MessageManager.getString("label.show_logo"),
+                      av.isShowSequenceLogo());
               cprof.addItemListener(new ItemListener()
               {
                 public void itemStateChanged(ItemEvent e)
@@ -611,7 +651,8 @@ public class AnnotationLabels extends Panel implements ActionListener,
               });
               popup.add(cprof);
               final CheckboxMenuItem cprofn = new CheckboxMenuItem(
-                      MessageManager.getString("label.normalise_logo"), av.isNormaliseSequenceLogo());
+                      MessageManager.getString("label.normalise_logo"),
+                      av.isNormaliseSequenceLogo());
               cprofn.addItemListener(new ItemListener()
               {
                 public void itemStateChanged(ItemEvent e)
@@ -674,36 +715,44 @@ public class AnnotationLabels extends Panel implements ActionListener,
         {
           if (evt.getClickCount() == 1)
           {
-            ap.seqPanel.ap.idPanel.highlightSearchResults(Arrays
-                    .asList(new SequenceI[]
-                    { aa[selectedRow].sequenceRef }));
+            ap.seqPanel.ap.idPanel
+                    .highlightSearchResults(Arrays
+                            .asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
           }
           else if (evt.getClickCount() >= 2)
           {
             ap.seqPanel.ap.idPanel.highlightSearchResults(null);
             SequenceGroup sg = ap.av.getSelectionGroup();
-            if (sg!=null)
+            if (sg != null)
             {
-              // we make a copy rather than edit the current selection if no modifiers pressed
+              // we make a copy rather than edit the current selection if no
+              // modifiers pressed
               // see Enhancement JAL-1557
               if (!(evt.isControlDown() || evt.isShiftDown()))
               {
                 sg = new SequenceGroup(sg);
                 sg.clear();
                 sg.addSequence(aa[selectedRow].sequenceRef, false);
-              } else {
+              }
+              else
+              {
                 if (evt.isControlDown())
                 {
                   sg.addOrRemove(aa[selectedRow].sequenceRef, true);
-                } else {
-                  // notionally, we should also add intermediate sequences from last added sequence ?
+                }
+                else
+                {
+                  // notionally, we should also add intermediate sequences from
+                  // last added sequence ?
                   sg.addSequence(aa[selectedRow].sequenceRef, true);
                 }
               }
-            } else {
+            }
+            else
+            {
               sg = new SequenceGroup();
               sg.setStartRes(0);
-              sg.setEndRes(ap.av.getAlignment().getWidth()-1);
+              sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
               sg.addSequence(aa[selectedRow].sequenceRef, false);
             }
             ap.av.setSelectionGroup(sg);
@@ -740,8 +789,7 @@ public class AnnotationLabels extends Panel implements ActionListener,
       for (int[] region : av.getColumnSelection().getHiddenColumns())
       {
         jalview.appletgui.AlignFrame.copiedHiddenColumns
-                .addElement(new int[]
-                { region[0], region[1] });
+                .addElement(new int[] { region[0], region[1] });
       }
     }
   }
@@ -813,7 +861,7 @@ public class AnnotationLabels extends Panel implements ActionListener,
               dragEvent.getY());
     }
 
-    if (!av.wrapAlignment && ((aa == null) || (aa.length < 1)))
+    if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
     {
       g.setColor(Color.black);
       g.drawString(MessageManager.getString("label.right_click"), 2, 8);