JAL-2388 Make startRes,startSeq,endRes,endSeq private with get/setters
[jalview.git] / src / jalview / appletgui / SeqCanvas.java
index 522151c..fd74c4a 100755 (executable)
 package jalview.appletgui;
 
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
 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;
@@ -48,8 +50,6 @@ public class SeqCanvas extends Panel
 
   AlignViewport av;
 
-  SearchResults searchResults = null;
-
   boolean fastPaint = false;
 
   int cursorX = 0;
@@ -90,26 +90,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);
+      }
     }
   }
 
@@ -213,12 +216,12 @@ public class SeqCanvas extends Panel
     // Its possible on certain browsers that the call to fastpaint
     // is faster than it can paint, so this check here catches
     // this possibility
-    if (lastsr + horizontal != av.startRes)
+    if (lastsr + horizontal != av.getStartRes())
     {
-      horizontal = av.startRes - lastsr;
+      horizontal = av.getStartRes() - lastsr;
     }
 
-    lastsr = av.startRes;
+    lastsr = av.getStartRes();
 
     fastPaint = true;
     gg.copyArea(horizontal * avcharWidth, vertical * avcharHeight, imgWidth
@@ -226,7 +229,8 @@ public class SeqCanvas extends Panel
             imgHeight - vertical * avcharHeight, -horizontal * avcharWidth,
             -vertical * avcharHeight);
 
-    int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq, transX = 0, transY = 0;
+    int sr = av.getStartRes(), er = av.getEndRes(), ss = av.getStartSeq(), es = av
+            .getEndSeq(), transX = 0, transY = 0;
 
     if (horizontal > 0) // scrollbar pulled right, image to the left
     {
@@ -241,9 +245,10 @@ public class SeqCanvas extends Panel
     else if (vertical > 0) // scroll down
     {
       ss = es - vertical;
-      if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
+      if (ss < av.getStartSeq()) // ie scrolling too fast, more than a page at a
+                                 // time
       {
-        ss = av.startSeq;
+        ss = av.getStartSeq();
       }
       else
       {
@@ -253,9 +258,9 @@ public class SeqCanvas extends Panel
     else if (vertical < 0)
     {
       es = ss - vertical;
-      if (es > av.endSeq)
+      if (es > av.getEndSeq())
       {
-        es = av.endSeq;
+        es = av.getEndSeq();
       }
     }
 
@@ -276,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);
@@ -327,11 +333,12 @@ public class SeqCanvas extends Panel
 
     if (av.getWrapAlignment())
     {
-      drawWrappedPanel(gg, imgWidth, imgHeight, av.startRes);
+      drawWrappedPanel(gg, imgWidth, imgHeight, av.getStartRes());
     }
     else
     {
-      drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, 0);
+      drawPanel(gg, av.getStartRes(), av.getEndRes(), av.getStartSeq(),
+              av.getEndSeq(), 0);
     }
 
     g.drawImage(img, 0, 0, this);
@@ -417,7 +424,7 @@ public class SeqCanvas extends Panel
 
     av.setWrappedWidth(cWidth);
 
-    av.endRes = av.startRes + cWidth;
+    av.setEndRes(av.getStartRes() + cWidth);
 
     int endx;
     int ypos = hgap;
@@ -473,11 +480,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);
 
         }
@@ -529,11 +535,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);
@@ -576,10 +580,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);
@@ -622,9 +633,10 @@ public class SeqCanvas extends Panel
 
       // / Highlight search Results once all sequences have been drawn
       // ////////////////////////////////////////////////////////
-      if (searchResults != null)
+      if (av.hasSearchResults())
       {
-        int[] visibleResults = searchResults.getResults(nextSeq, startRes,
+        int[] visibleResults = av.getSearchResults().getResults(nextSeq,
+                startRes,
                 endRes);
         if (visibleResults != null)
         {
@@ -827,17 +839,15 @@ public class SeqCanvas extends Panel
           break;
         }
 
-        group = av.getAlignment().getGroups()
-                .get(groupIndex);
+        group = av.getAlignment().getGroups().get(groupIndex);
       } while (groupIndex < av.getAlignment().getGroups().size());
 
     }
   }
 
-  public void highlightSearchResults(SearchResults results)
+  public void highlightSearchResults(SearchResultsI results)
   {
-    searchResults = results;
-
+    av.setSearchResults(results);
     repaint();
   }