JAL-2773 add new flag to paintAlignment(updateOverview,updateStructures) and first...
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 3dee5a8..12d1369 100755 (executable)
@@ -31,6 +31,7 @@ import jalview.schemes.ResidueProperties;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 import jalview.viewmodel.ViewportListenerI;
+import jalview.viewmodel.ViewportRanges;
 
 import java.awt.AlphaComposite;
 import java.awt.Color;
@@ -284,7 +285,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
 
     if (anot.length < av.getColumnSelection().getMax())
     {
-      Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
+      Annotation[] temp = new Annotation[av.getColumnSelection().getMax()
+              + 2];
       System.arraycopy(anot, 0, temp, 0, anot.length);
       anot = temp;
       aa[activeRow].annotations = anot;
@@ -412,8 +414,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
           anot[index] = new Annotation(label, "", type, 0);
         }
 
-        anot[index].secondaryStructure = type != 'S' ? type : label
-                .length() == 0 ? ' ' : label.charAt(0);
+        anot[index].secondaryStructure = type != 'S' ? type
+                : label.length() == 0 ? ' ' : label.charAt(0);
         anot[index].displayCharacter = label;
 
       }
@@ -657,15 +659,18 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   {
     if (graphStretch > -1)
     {
-      av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
-              - evt.getY();
-      if (av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight < 0)
+      av.getAlignment()
+              .getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
+                      - evt.getY();
+      if (av.getAlignment()
+              .getAlignmentAnnotation()[graphStretch].graphHeight < 0)
       {
-        av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight = 0;
+        av.getAlignment()
+                .getAlignmentAnnotation()[graphStretch].graphHeight = 0;
       }
       graphStretchY = evt.getY();
       adjustPanelHeight();
-      ap.paintAlignment(true);
+      ap.paintAlignment(false, false);
     }
     else
     {
@@ -819,8 +824,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       int seqIndex = av.getAlignment().findIndex(seqref);
       if (seqIndex != -1)
       {
-        text.append(", ")
-                .append(MessageManager.getString("label.sequence"))
+        text.append(", ").append(MessageManager.getString("label.sequence"))
                 .append(" ").append(seqIndex + 1);
         char residue = seqref.getCharAt(column);
         if (!Comparison.isGap(residue))
@@ -829,16 +833,17 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
           String name;
           if (av.getAlignment().isNucleotide())
           {
-            name = ResidueProperties.nucleotideName.get(String
-                    .valueOf(residue));
-            text.append(" Nucleotide: ").append(
-                    name != null ? name : residue);
+            name = ResidueProperties.nucleotideName
+                    .get(String.valueOf(residue));
+            text.append(" Nucleotide: ")
+                    .append(name != null ? name : residue);
           }
           else
           {
-            name = 'X' == residue ? "X" : ('*' == residue ? "STOP"
-                    : ResidueProperties.aa2Triplet.get(String
-                            .valueOf(residue)));
+            name = 'X' == residue ? "X"
+                    : ('*' == residue ? "STOP"
+                            : ResidueProperties.aa2Triplet
+                                    .get(String.valueOf(residue)));
             text.append(" Residue: ").append(name != null ? name : residue);
           }
           int residuePos = seqref.findPosition(column);
@@ -912,8 +917,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         return;
       }
     }
-    imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + 1)
-            * av.getCharWidth();
+    imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes()
+            + 1) * av.getCharWidth();
     if (imgWidth < 1)
     {
       return;
@@ -923,8 +928,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     {
       try
       {
-        image = new BufferedImage(imgWidth, ap.getAnnotationPanel()
-                .getHeight(), BufferedImage.TYPE_INT_RGB);
+        image = new BufferedImage(imgWidth,
+                ap.getAnnotationPanel().getHeight(),
+                BufferedImage.TYPE_INT_RGB);
       } catch (OutOfMemoryError oom)
       {
         try
@@ -954,8 +960,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       imageFresh = true;
     }
 
-    drawComponent(gg, av.getRanges().getStartRes(), av.getRanges()
-            .getEndRes() + 1);
+    drawComponent(gg, av.getRanges().getStartRes(),
+            av.getRanges().getEndRes() + 1);
     imageFresh = false;
     g.drawImage(image, 0, 0, this);
   }
@@ -971,7 +977,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
    * @param horizontal
    *          repaint with horizontal shift in alignment
    */
-  public void fastPaint(int horizontal, boolean isresize)
+  public void fastPaint(int horizontal)
   {
     if ((horizontal == 0) || gg == null
             || av.getAlignment().getAlignmentAnnotation() == null
@@ -985,45 +991,20 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     int sr = av.getRanges().getStartRes();
     int er = av.getRanges().getEndRes() + 1;
     int transX = 0;
-    long stime;
-    long mtime;
 
-    if (isresize)
-    {
-      imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes()
-              + 1) * av.getCharWidth();
+    long stime = System.currentTimeMillis();
+    gg.copyArea(0, 0, imgWidth, getHeight(),
+            -horizontal * av.getCharWidth(), 0);
+    long mtime = System.currentTimeMillis();
 
-      if (imgWidth > 0)
-      {
-        BufferedImage newimage = new BufferedImage(imgWidth,
-                ap.getAnnotationPanel().getHeight(),
-                BufferedImage.TYPE_INT_ARGB);
-
-        gg = (Graphics2D) newimage.getGraphics();
-        gg.setFont(av.getFont());
-        gg.drawImage(image, null, 0, 0);
-        image = newimage;
-
-        transX = (er - horizontal - sr) * av.getCharWidth();
-        sr = er - horizontal - sr;
-      }
+    if (horizontal > 0) // scrollbar pulled right, image to the left
+    {
+      transX = (er - sr - horizontal) * av.getCharWidth();
+      sr = er - horizontal;
     }
-    else
+    else if (horizontal < 0)
     {
-      stime = System.currentTimeMillis();
-      gg.copyArea(0, 0, imgWidth, getHeight(),
-              -horizontal * av.getCharWidth(), 0);
-      mtime = System.currentTimeMillis();
-
-      if (horizontal > 0) // scrollbar pulled right, image to the left
-      {
-        transX = (er - sr - horizontal) * av.getCharWidth();
-        sr = er - horizontal;
-      }
-      else if (horizontal < 0)
-      {
-        er = sr - horizontal;
-      }
+      er = sr - horizontal;
     }
 
     gg.translate(transX, 0);
@@ -1070,8 +1051,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       // and draw a faded image until the calculation
       // has completed
       if (lastImageGood
-              && (fadedImage == null || fadedImage.getWidth() != imgWidth || fadedImage
-                      .getHeight() != image.getHeight()))
+              && (fadedImage == null || fadedImage.getWidth() != imgWidth
+                      || fadedImage.getHeight() != image.getHeight()))
       {
         // System.err.println("redraw faded image ("+(fadedImage==null ?
         // "null image" : "") + " lastGood="+lastImageGood+")");
@@ -1083,8 +1064,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         fadedG.setColor(Color.white);
         fadedG.fillRect(0, 0, imgWidth, image.getHeight());
 
-        fadedG.setComposite(AlphaComposite.getInstance(
-                AlphaComposite.SRC_OVER, .3f));
+        fadedG.setComposite(
+                AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .3f));
         fadedG.drawImage(image, 0, 0, this);
 
       }
@@ -1125,8 +1106,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
 
       return;
     }
-    lastImageGood = renderer.drawComponent(this, av, g, activeRow,
-            startRes, endRes);
+    lastImageGood = renderer.drawComponent(this, av, g, activeRow, startRes,
+            endRes);
     if (!lastImageGood && fadedImage == null)
     {
       fadedImage = oldFaded;
@@ -1195,14 +1176,14 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   public void propertyChange(PropertyChangeEvent evt)
   {
     // Respond to viewport range changes (e.g. alignment panel was scrolled)
-    if (evt.getPropertyName().equals("startres"))
-    {
-      fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), false);
-    }
-    else if (evt.getPropertyName().equals("endres"))
+    // Both scrolling and resizing change viewport ranges: scrolling changes
+    // both start and end points, but resize only changes end values.
+    // Here we only want to fastpaint on a scroll, with resize using a normal
+    // paint, so scroll events are identified as changes to the horizontal or
+    // vertical start value.
+    if (evt.getPropertyName().equals(ViewportRanges.STARTRES))
     {
-      // resize
-      fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), true);
+      fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
     }
   }
 }