add partial button fix to annotation and statistics output
[jalview.git] / src / jalview / gui / AnnotationLabels.java
index 1a9541c..445ee11 100755 (executable)
@@ -27,6 +27,7 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.util.MessageManager;
 
@@ -73,6 +74,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
   private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
           .compile("<");
 
+
   String TOGGLE_LABELSCALE = MessageManager
           .getString("label.scale_label_to_column");
 
@@ -291,33 +293,11 @@ public class AnnotationLabels extends JPanel implements MouseListener,
       aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
     }
 
-    refresh(fullRepaint);
+    ap.refresh(fullRepaint);
 
   }
 
   /**
-   * Redraw sensibly.
-   * 
-   * @adjustHeight if true, try to recalculate panel height for visible
-   *               annotations
-   */
-  protected void refresh(boolean adjustHeight)
-  {
-    ap.validateAnnotationDimensions(adjustHeight);
-    ap.addNotify();
-    if (adjustHeight)
-    {
-      // sort, repaint, update overview
-      ap.paintAlignment(true);
-    }
-    else
-    {
-      // lightweight repaint
-      ap.repaint();
-    }
-  }
-
-  /**
    * DOCUMENT ME!
    * 
    * @param e
@@ -419,7 +399,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
             // ann.visible = false;
             // }
             // }
-            refresh(true);
+            ap.refresh(true);
           }
         });
         pop.add(hideType);
@@ -442,7 +422,8 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     if (selectedRow < aa.length)
     {
       final String label = aa[selectedRow].label;
-      if (!aa[selectedRow].autoCalculated)
+      if (!(aa[selectedRow].autoCalculated
+              || label.indexOf("Information Content") > -1))
       {
         if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
         {
@@ -457,14 +438,18 @@ public class AnnotationLabels extends JPanel implements MouseListener,
       }
       else if (label.indexOf("Consensus") > -1)
       {
+
+
         pop.addSeparator();
         // av and sequencegroup need to implement same interface for
+        final AlignmentAnnotation aaa = aa[selectedRow];
+
         final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
-                MessageManager.getString("label.ignore_gaps_consensus"),
+                  MessageManager.getString("label.ignore_gaps_consensus"),
                 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
                         .getIgnoreGapsConsensus() : ap.av
                         .isIgnoreGapsConsensus());
-        final AlignmentAnnotation aaa = aa[selectedRow];
+
         cbmi.addActionListener(new ActionListener()
         {
           @Override
@@ -623,6 +608,178 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         consclipbrd.addActionListener(this);
         pop.add(consclipbrd);
       }
+      else if (label.indexOf("Information Content") > -1) // TODO create labels
+                                                          // in message resource
+                                                          // for these
+      {
+        pop.addSeparator();
+        final AlignmentAnnotation aaa = aa[selectedRow];
+
+        final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
+                "Ignore Below Background Frequency",
+                (aa[selectedRow].groupRef != null)
+                        ? aa[selectedRow].groupRef
+                                .getIgnoreBelowBackground()
+                        : ap.av.isIgnoreBelowBackground());
+
+        cbmi.addActionListener(new ActionListener()
+        {
+          @Override
+          public void actionPerformed(ActionEvent e)
+          {
+            if (aaa.groupRef != null)
+            {
+              // TODO: pass on reference to ap so the view can be updated.
+              aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
+              ap.getAnnotationPanel()
+                      .paint(ap.getAnnotationPanel().getGraphics());
+            }
+            else
+            {
+              ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
+            }
+            ap.alignmentChanged();
+          }
+        });
+        pop.add(cbmi);
+        if (aaa.groupRef != null)
+        {
+          final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
+                  MessageManager.getString("label.show_group_histogram"),
+                  aa[selectedRow].groupRef.isShowInformationHistogram());
+          chist.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              // TODO: pass on reference
+              // to ap
+              // so the
+              // view
+              // can be
+              // updated.
+              aaa.groupRef.setShowInformationHistogram(chist.getState());
+              ap.repaint();
+              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+            }
+          });
+          pop.add(chist);
+          final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
+                  MessageManager.getString("label.show_group_logo"),
+                  aa[selectedRow].groupRef.isShowHMMSequenceLogo());
+          cprofl.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              // TODO: pass on reference
+              // to ap
+              // so the
+              // view
+              // can be
+              // updated.
+              aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
+              ap.repaint();
+              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+            }
+          });
+          pop.add(cprofl);
+          final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
+                  MessageManager.getString("label.normalise_group_logo"),
+                  aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
+          cproflnorm.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+
+              // TODO: pass on reference
+              // to ap
+              // so the
+              // view
+              // can be
+              // updated.
+              aaa.groupRef
+                      .setNormaliseHMMSequenceLogo(cproflnorm.getState());
+              // automatically enable logo display if we're clicked
+              aaa.groupRef.setshowHMMSequenceLogo(true);
+              ap.repaint();
+              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+            }
+          });
+          pop.add(cproflnorm);
+        }
+        else
+        {
+          final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
+                  MessageManager.getString("label.show_histogram"),
+                  av.isShowInformationHistogram());
+          chist.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              // TODO: pass on reference
+              // to ap
+              // so the
+              // view
+              // can be
+              // updated.
+              av.setShowInformationHistogram(chist.getState());
+              ap.alignFrame.setMenusForViewport();
+              ap.repaint();
+              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+            }
+          });
+          pop.add(chist);
+          final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
+                  MessageManager.getString("label.show_logo"),
+                  av.isShowHMMSequenceLogo());
+          cprof.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              // TODO: pass on reference
+              // to ap
+              // so the
+              // view
+              // can be
+              // updated.
+              av.setShowHMMSequenceLogo(cprof.getState());
+              ap.alignFrame.setMenusForViewport();
+              ap.repaint();
+              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+            }
+          });
+          pop.add(cprof);
+          final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
+                  MessageManager.getString("label.normalise_logo"),
+                  av.isNormaliseHMMSequenceLogo());
+          cprofnorm.addActionListener(new ActionListener()
+          {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              // TODO: pass on reference
+              // to ap
+              // so the
+              // view
+              // can be
+              // updated.
+              av.setShowHMMSequenceLogo(true);
+              av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
+              ap.alignFrame.setMenusForViewport();
+              ap.repaint();
+              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+            }
+          });
+          pop.add(cprofnorm);
+        }
+        final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
+        consclipbrd.addActionListener(this);
+        pop.add(consclipbrd);
+      }
     }
     pop.show(this, evt.getX(), evt.getY());
   }
@@ -968,19 +1125,21 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     Alignment ds = new Alignment(dseqs);
     if (av.hasHiddenColumns())
     {
-      omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0,
+      omitHidden = av.getAlignment().getHiddenColumns()
+              .getVisibleSequenceStrings(0,
               sq.getLength(), seqs);
     }
 
     int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
-    List<int[]> hiddenCols = av.getColumnSelection().getHiddenColumns();
+    List<int[]> hiddenCols = av.getAlignment().getHiddenColumns()
+            .getHiddenRegions();
     if (hiddenCols != null)
     {
       alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
               hiddenCols);
     }
-    String output = new FormatAdapter().formatSequences("Fasta", seqs,
-            omitHidden, alignmentStartEnd);
+    String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
+            seqs, omitHidden, alignmentStartEnd);
 
     Toolkit.getDefaultToolkit().getSystemClipboard()
             .setContents(new StringSelection(output), Desktop.instance);
@@ -988,8 +1147,9 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     ArrayList<int[]> hiddenColumns = null;
     if (av.hasHiddenColumns())
     {
-      hiddenColumns = new ArrayList<int[]>();
-      for (int[] region : av.getColumnSelection().getHiddenColumns())
+      hiddenColumns = new ArrayList<>();
+      for (int[] region : av.getAlignment().getHiddenColumns()
+              .getHiddenRegions())
       {
         hiddenColumns.add(new int[] { region[0], region[1] });
       }