JAL-564 (annotation panel height adjustment) and alignment annotation popup menu...
authorjprocter <Jim Procter>
Mon, 14 Feb 2011 10:56:51 +0000 (10:56 +0000)
committerjprocter <Jim Procter>
Mon, 14 Feb 2011 10:56:51 +0000 (10:56 +0000)
src/jalview/appletgui/AnnotationLabels.java

index cef84cc..2344719 100755 (executable)
@@ -23,6 +23,7 @@ import java.awt.*;
 import java.awt.event.*;
 import java.awt.image.BufferedImage;
 
+
 import jalview.datamodel.*;
 
 public class AnnotationLabels extends Panel implements ActionListener,
@@ -67,31 +68,21 @@ public class AnnotationLabels extends Panel implements ActionListener,
     setLayout(null);
 
     /**
-     * this retrieves the adjustable height glyph from resources. we don't use it at the moment.
-    java.net.URL url = getClass().getResource("/images/idwidth.gif");
-    Image temp = null;
-
-    if (url != null)
-    {
-      temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
-    }
-
-    try
-    {
-      MediaTracker mt = new MediaTracker(this);
-      mt.addImage(temp, 0);
-      mt.waitForID(0);
-    } catch (Exception ex)
-    {
-    }
-
-    BufferedImage bi = new BufferedImage(temp.getHeight(this),
-            temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
-    Graphics2D g = (Graphics2D) bi.getGraphics();
-    g.rotate(Math.toRadians(90));
-    g.drawImage(temp, 0, -bi.getWidth(this), this);
-    image = (Image) bi;
-*/
+     * this retrieves the adjustable height glyph from resources. we don't use
+     * it at the moment. java.net.URL url =
+     * getClass().getResource("/images/idwidth.gif"); Image temp = null;
+     * 
+     * if (url != null) { temp =
+     * java.awt.Toolkit.getDefaultToolkit().createImage(url); }
+     * 
+     * try { MediaTracker mt = new MediaTracker(this); mt.addImage(temp, 0);
+     * mt.waitForID(0); } catch (Exception ex) { }
+     * 
+     * BufferedImage bi = new BufferedImage(temp.getHeight(this),
+     * temp.getWidth(this), BufferedImage.TYPE_INT_RGB); Graphics2D g =
+     * (Graphics2D) bi.getGraphics(); g.rotate(Math.toRadians(90));
+     * g.drawImage(temp, 0, -bi.getWidth(this), this); image = (Image) bi;
+     */
     addMouseListener(this);
     addMouseMotionListener(this);
   }
@@ -232,7 +223,7 @@ public class AnnotationLabels extends Panel implements ActionListener,
 
   public void mouseMoved(MouseEvent evt)
   {
-    resizePanel = evt.getY() < 10;
+    resizePanel = evt.getY() < 10 && evt.getX() < 14;
 
     int row = getSelectedRow(evt.getY() + scrollOffset);
 
@@ -266,25 +257,31 @@ public class AnnotationLabels extends Panel implements ActionListener,
 
     if (resizePanel)
     {
-      Dimension d = ap.annotationPanelHolder.getSize(),e = ap.annotationSpaceFillerHolder.getSize();;
+      Dimension d = ap.annotationPanelHolder.getSize(), e = ap.annotationSpaceFillerHolder
+              .getSize(), f = ap.seqPanelHolder.getSize();
       int dif = evt.getY() - oldY;
 
       dif /= ap.av.charHeight;
       dif *= ap.av.charHeight;
 
-      if ((d.height - dif) > 20)
+      if ((d.height - dif) > 20 && (f.height + dif) > 20)
       {
-        
-        setSize(new Dimension(e.width,d.height-dif));
-        ap.annotationSpaceFillerHolder.setSize(new Dimension(e.width, d.height - dif));
-        ap.annotationPanelHolder.setSize(new Dimension(d.width, d.height - dif));
-        ap.apvscroll.setValues(ap.apvscroll.getValue(), d.height-dif, 0, ap.annotationPanel.adjustPanelHeight(false));
-        
+        ap.annotationPanel.setSize(d.width, d.height - dif);
+        setSize(new Dimension(e.width, d.height - dif));
+        ap.annotationSpaceFillerHolder.setSize(new Dimension(e.width,
+                d.height - dif));
+        ap.annotationPanelHolder.setSize(new Dimension(d.width, d.height
+                - dif));
+        ap.apvscroll.setValues(ap.apvscroll.getValue(), d.height - dif, 0,
+                ap.annotationPanel.calcPanelHeight());
+        f.height += dif;
+        ap.seqPanelHolder.setPreferredSize(f);
+        ap.setScrollValues(av.getStartRes(), av.getStartSeq());
         ap.validate();
-        //ap.paintAlignment(true);
+        // ap.paintAlignment(true);
+        ap.addNotify();
       }
 
-      ap.addNotify();
     }
     else
     {
@@ -306,7 +303,7 @@ public class AnnotationLabels extends Panel implements ActionListener,
 
   public void mouseEntered(MouseEvent evt)
   {
-    if (evt.getY() < 10)
+    if (evt.getY() < 10 && evt.getX() < 14)
     {
       resizePanel = true;
       repaint();
@@ -333,6 +330,10 @@ public class AnnotationLabels extends Panel implements ActionListener,
   public void mousePressed(MouseEvent evt)
   {
     oldY = evt.getY();
+    if (resizePanel)
+    {
+      return;
+    }
     // todo: move below to mouseClicked ?
     selectedRow = getSelectedRow(evt.getY() + scrollOffset);
 
@@ -377,27 +378,123 @@ public class AnnotationLabels extends Panel implements ActionListener,
       item = new MenuItem(OUTPUT_TEXT);
       item.addActionListener(this);
       popup.add(item);
-
-      if (aa[selectedRow] == ap.av.consensus)
+      if (selectedRow < aa.length)
       {
-        popup.addSeparator();
-        final CheckboxMenuItem cbmi = new CheckboxMenuItem(
-                "Ignore Gaps In Consensus", ap.av.getIgnoreGapsConsensus());
-
-        cbmi.addItemListener(new ItemListener()
+        if (aa[selectedRow].autoCalculated)
         {
-          public void itemStateChanged(ItemEvent e)
+          if (aa[selectedRow].label.indexOf("Consensus") > -1)
           {
-            ap.av.setIgnoreGapsConsensus(cbmi.getState());
-            ap.paintAlignment(true);
+            popup.addSeparator();
+            final CheckboxMenuItem cbmi = new CheckboxMenuItem(
+                    "Ignore Gaps In Consensus",
+                    (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
+                            .getIgnoreGapsConsensus() : ap.av
+                            .getIgnoreGapsConsensus());
+            final AlignmentAnnotation aaa = aa[selectedRow];
+            cbmi.addItemListener(new ItemListener()
+            {
+              public void itemStateChanged(ItemEvent e)
+              {
+                if (aaa.groupRef != null)
+                {
+                  // TODO: pass on reference to ap so the view can be updated.
+                  aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
+                }
+                else
+                {
+                  ap.av.setIgnoreGapsConsensus(cbmi.getState());
+                }
+                ap.paintAlignment(true);
+              }
+            });
+            popup.add(cbmi);
+            if (aaa.groupRef != null)
+            {
+              final CheckboxMenuItem chist = new CheckboxMenuItem(
+                      "Show Group Histogram",
+                      aa[selectedRow].groupRef.isShowConsensusHistogram());
+              chist.addItemListener(new ItemListener()
+              {
+                public void itemStateChanged(ItemEvent e)
+                {
+                  // TODO: pass on reference
+                  // to ap
+                  // so the
+                  // view
+                  // can be
+                  // updated.
+                  aaa.groupRef.setShowConsensusHistogram(chist.getState());
+                  ap.repaint();
+                  // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+                }
+              });
+              popup.add(chist);
+              final CheckboxMenuItem cprofl = new CheckboxMenuItem(
+                      "Show Group Logo",
+                      aa[selectedRow].groupRef.isShowSequenceLogo());
+              cprofl.addItemListener(new ItemListener()
+              {
+                public void itemStateChanged(ItemEvent e)
+                {
+                  // TODO: pass on reference
+                  // to ap
+                  // so the
+                  // view
+                  // can be
+                  // updated.
+                  aaa.groupRef.setshowSequenceLogo(cprofl.getState());
+                  ap.repaint();
+                  // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+                }
+              });
+              popup.add(cprofl);
+            }
+            else
+            {
+              final CheckboxMenuItem chist = new CheckboxMenuItem(
+                      "Show Histogram", av.isShowConsensusHistogram());
+              chist.addItemListener(new ItemListener()
+              {
+                public void itemStateChanged(ItemEvent e)
+                {
+                  // TODO: pass on reference
+                  // to ap
+                  // so the
+                  // view
+                  // can be
+                  // updated.
+                  av.setShowConsensusHistogram(chist.getState());
+                  ap.repaint();
+                  // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+                }
+              });
+              popup.add(chist);
+              final CheckboxMenuItem cprof = new CheckboxMenuItem(
+                      "Show Logo", av.isShowSequenceLogo());
+              cprof.addItemListener(new ItemListener()
+              {
+                public void itemStateChanged(ItemEvent e)
+                {
+                  // TODO: pass on reference
+                  // to ap
+                  // so the
+                  // view
+                  // can be
+                  // updated.
+                  av.setShowSequenceLogo(cprof.getState());
+                  ap.repaint();
+                  // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
+                }
+              });
+              popup.add(cprof);
+            }
+
+            item = new MenuItem(COPYCONS_SEQ);
+            item.addActionListener(this);
+            popup.add(item);
           }
-        });
-        popup.add(cbmi);
-        item = new MenuItem(COPYCONS_SEQ);
-        item.addActionListener(this);
-        popup.add(item);
+        }
       }
-
       popup.show(this, evt.getX(), evt.getY());
     }
     else