JAL-1179 note and patch for exceptions raised when jalview.viewmodel.AlignmentViewpor...
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index 474d392..ad7b995 100644 (file)
@@ -20,7 +20,6 @@ package jalview.gui;
 import java.beans.*;
 import java.io.*;
 import java.util.Hashtable;
-import java.util.Vector;
 
 import java.awt.*;
 import java.awt.event.*;
@@ -921,10 +920,14 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
     {
+      // draw annotation - need to offset for current scroll position
+      int offset=-alabels.scrollOffset;
+      pg.translate(0, offset);
       pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
       alabels.drawComponent((Graphics2D) pg, idWidth);
       pg.translate(idWidth + 3, 0);
       annotationPanel.renderer.drawComponent(annotationPanel, av, (Graphics2D) pg, -1, startRes, endRes + 1);
+      pg.translate(0, -offset);
     }
 
     return Printable.PAGE_EXISTS;
@@ -1072,6 +1075,11 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   void makeAlignmentImage(int type, File file)
   {
+    long progress=System.currentTimeMillis();
+    if (alignFrame!=null) {
+      alignFrame.setProgressBar("Saving "+(type == jalview.util.ImageMaker.PNG ? "PNG image":"EPS file") , progress);
+    }
+    try {
     int maxwidth = av.getAlignment().getWidth();
     if (av.hasHiddenColumns())
     {
@@ -1110,19 +1118,17 @@ public class AlignmentPanel extends GAlignmentPanel implements
     {
 
       jalview.util.ImageMaker im;
+      final String imageAction,imageTitle;
       if (type == jalview.util.ImageMaker.PNG)
       {
-        im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
-                "Create PNG image from alignment", width, height, file,
-                null);
-      }
-      else
-      {
-        im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
-                "Create EPS file from alignment", width, height, file,
-                alignFrame.getTitle());
+      imageAction="Create PNG image from alignment";
+      imageTitle=null;
+      } else {
+        imageAction="Create EPS file from alignment";
+        imageTitle=alignFrame.getTitle();
       }
-
+      im = new jalview.util.ImageMaker(this, type, imageAction, width, height, file,
+                imageTitle);
       if (av.getWrapAlignment())
       {
         if (im.getGraphics() != null)
@@ -1150,6 +1156,13 @@ public class AlignmentPanel extends GAlignmentPanel implements
     {
       ex.printStackTrace();
     }
+    }
+    finally {
+      if (alignFrame!=null)
+      {
+        alignFrame.setProgressBar("Export complete.", progress);
+      }
+    }
   }
 
   /**
@@ -1172,7 +1185,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
   {
     // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
     // ////////////////////////////////////////////
-    int idWidth = getVisibleIdWidth(true);
+    int idWidth = getVisibleIdWidth(false);
     FontMetrics fm = getFontMetrics(av.getFont());
     int scaleHeight = av.charHeight + fm.getDescent();
 
@@ -1381,74 +1394,15 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void updateAnnotation()
   {
-    updateAnnotation(false);
+    updateAnnotation(false, false);
   }
-
   public void updateAnnotation(boolean applyGlobalSettings)
   {
-    // TODO: this should be merged with other annotation update stuff - that
-    // sits on AlignViewport
-    boolean updateCalcs = false;
-    boolean conv = av.isShowGroupConservation();
-    boolean cons = av.isShowGroupConsensus();
-    boolean showprf = av.isShowSequenceLogo();
-    boolean showConsHist = av.isShowConsensusHistogram();
-    boolean normLogo = av.isNormaliseSequenceLogo();
-
-    boolean sortg = true;
-
-    // remove old automatic annotation
-    // add any new annotation
-
-    Vector gr = av.getAlignment().getGroups(); // OrderedBy(av.getAlignment().getSequencesArray());
-    // intersect alignment annotation with alignment groups
-
-    AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation();
-    Hashtable oldrfs = new Hashtable();
-    if (aan != null)
-    {
-      for (int an = 0; an < aan.length; an++)
-      {
-        if (aan[an].autoCalculated && aan[an].groupRef != null)
-        {
-          oldrfs.put(aan[an].groupRef, aan[an].groupRef);
-          av.getAlignment().deleteAnnotation(aan[an]);
-          aan[an] = null;
-        }
-      }
-    }
-    SequenceGroup sg;
-    if (gr != null)
-    {
-      for (int g = 0; g < gr.size(); g++)
-      {
-        updateCalcs = false;
-        sg = (SequenceGroup) gr.elementAt(g);
-        if (applyGlobalSettings || !oldrfs.containsKey(sg))
-        {
-          // set defaults for this group's conservation/consensus
-          sg.setshowSequenceLogo(showprf);
-          sg.setShowConsensusHistogram(showConsHist);
-          sg.setNormaliseSequenceLogo(normLogo);
-        }
-        if (conv)
-        {
-          updateCalcs = true;
-          av.getAlignment().addAnnotation(sg.getConservationRow(), 0);
-        }
-        if (cons)
-        {
-          updateCalcs = true;
-          av.getAlignment().addAnnotation(sg.getConsensus(), 0);
-        }
-        // refresh the annotation rows
-        if (updateCalcs)
-        {
-          sg.recalcConservation();
-        }
-      }
-    }
-    oldrfs.clear();
+    updateAnnotation(applyGlobalSettings,false);
+  }
+  public void updateAnnotation(boolean applyGlobalSettings, boolean preserveNewGroupSettings)
+  {
+    av.updateGroupAnnotationSettings(applyGlobalSettings, preserveNewGroupSettings);
     adjustAnnotationHeight();
   }
 
@@ -1494,4 +1448,22 @@ public class AlignmentPanel extends GAlignmentPanel implements
   {
     new OOMWarning(string,  error, this);
   }
+
+  public FeatureRenderer cloneFeatureRenderer()
+  {
+    
+    return new FeatureRenderer(this);
+  }
+
+  public void updateFeatureRenderer(FeatureRenderer fr)
+  {
+    fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
+  }
+
+  public void updateFeatureRendererFrom(FeatureRenderer fr)
+  {
+    if (seqPanel.seqCanvas.getFeatureRenderer()!=null) {
+      seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);
+    }
+  }
 }