JAL-2089 Merge branch releases/Release_2_10_Branch to master
[jalview.git] / src / jalview / appletgui / SeqCanvas.java
index bf54c66..821136f 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -24,6 +24,9 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
+import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Color;
 import java.awt.FontMetrics;
@@ -72,7 +75,7 @@ public class SeqCanvas extends Panel
     avcharWidth = av.getCharWidth();
   }
 
-  public AlignViewport getViewport()
+  public AlignmentViewport getViewport()
   {
     return av;
   }
@@ -89,26 +92,29 @@ public class SeqCanvas extends Panel
 
   private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
   {
-    int scalestartx = startx - startx % 10 + 10;
-
+    updateViewport();
     g.setColor(Color.black);
-
-    // NORTH SCALE
-    for (int i = scalestartx; i < endx; i += 10)
+    for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx,
+            endx))
     {
-      int value = i;
-      if (av.hasHiddenColumns())
+      int mpos = mark.column; // (i - startx - 1)
+      if (mpos < 0)
       {
-        value = av.getColumnSelection().adjustForHiddenColumns(value);
+        continue;
       }
+      String mstring = mark.text;
 
-      g.drawString(String.valueOf(value), (i - startx - 1) * avcharWidth,
-              ypos - (avcharHeight / 2));
-
-      g.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2),
-              (ypos + 2) - (avcharHeight / 2),
-              ((i - startx - 1) * avcharWidth) + (avcharWidth / 2),
-              ypos - 2);
+      if (mark.major)
+      {
+        if (mstring != null)
+        {
+          g.drawString(mstring, mpos * avcharWidth, ypos
+                  - (avcharHeight / 2));
+        }
+        g.drawLine((mpos * avcharWidth) + (avcharWidth / 2), (ypos + 2)
+                - (avcharHeight / 2), (mpos * avcharWidth)
+                + (avcharWidth / 2), ypos - 2);
+      }
     }
   }
 
@@ -275,6 +281,7 @@ public class SeqCanvas extends Panel
    * at 0). NOTE 1: The av limits are set in setFont in this class and in the
    * adjustment listener in SeqPanel when the scrollbars move.
    */
+  @Override
   public void update(Graphics g)
   {
     paint(g);
@@ -472,11 +479,10 @@ public class SeqCanvas extends Panel
             continue;
           }
 
-          gg.fillPolygon(new int[]
-          { res * avcharWidth - avcharHeight / 4,
+          gg.fillPolygon(new int[] { res * avcharWidth - avcharHeight / 4,
               res * avcharWidth + avcharHeight / 4, res * avcharWidth },
-                  new int[]
-                  { ypos - (avcharHeight / 2), ypos - (avcharHeight / 2),
+                  new int[] { ypos - (avcharHeight / 2),
+                      ypos - (avcharHeight / 2),
                       ypos - (avcharHeight / 2) + 8 }, 3);
 
         }
@@ -528,11 +534,9 @@ public class SeqCanvas extends Panel
   }
 
   private void drawPanel(Graphics g1, int startRes, int endRes,
-          int startSeq,
-          int endSeq, int offset)
+          int startSeq, int endSeq, int offset)
   {
 
-
     if (!av.hasHiddenColumns())
     {
       draw(g1, startRes, endRes, startSeq, endSeq, offset);
@@ -575,10 +579,17 @@ public class SeqCanvas extends Panel
           g1.translate(-screenY * avcharWidth, 0);
           screenY += blockEnd - blockStart + 1;
           blockStart = hideEnd + 1;
+
+          if (screenY > (endRes - startRes))
+          {
+            // already rendered last block
+            return;
+          }
         }
       }
       if (screenY <= (endRes - startRes))
       {
+        // remaining visible region to render
         blockEnd = blockStart + (endRes - startRes) - screenY;
         g1.translate(screenY * avcharWidth, 0);
         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
@@ -826,8 +837,7 @@ public class SeqCanvas extends Panel
           break;
         }
 
-        group = av.getAlignment().getGroups()
-                .get(groupIndex);
+        group = av.getAlignment().getGroups().get(groupIndex);
       } while (groupIndex < av.getAlignment().getGroups().size());
 
     }