JAL-2446 FeatureStore with NCList - work in progress
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 4c04ad3..9bd4a04 100755 (executable)
 package jalview.gui;
 
 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 java.awt.BasicStroke;
 import java.awt.BorderLayout;
@@ -60,8 +62,6 @@ public class SeqCanvas extends JComponent
 
   AlignViewport av;
 
-  SearchResults searchResults = null;
-
   boolean fastPaint = false;
 
   int LABEL_WEST;
@@ -106,6 +106,7 @@ public class SeqCanvas extends JComponent
     charHeight = av.getCharHeight();
     charWidth = av.getCharWidth();
   }
+
   /**
    * DOCUMENT ME!
    * 
@@ -121,25 +122,26 @@ public class SeqCanvas extends JComponent
   private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
   {
     updateViewport();
-    int scalestartx = startx - (startx % 10) + 10;
-
-    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) * charWidth,
-              ypos - (charHeight / 2));
-
-      g.drawLine(((i - startx - 1) * charWidth) + (charWidth / 2),
-              (ypos + 2) - (charHeight / 2), ((i - startx - 1) * charWidth)
-                      + (charWidth / 2),
-              ypos - 2);
+      if (mark.major)
+      {
+        if (mstring != null)
+        {
+          g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
+        }
+        g.drawLine((mpos * charWidth) + (charWidth / 2), (ypos + 2)
+                - (charHeight / 2), (mpos * charWidth) + (charWidth / 2),
+                ypos - 2);
+      }
     }
   }
 
@@ -335,6 +337,7 @@ public class SeqCanvas extends JComponent
    */
 
   // Set this to false to force a full panel paint
+  @Override
   public void paintComponent(Graphics g)
   {
     updateViewport();
@@ -557,12 +560,12 @@ public class SeqCanvas extends JComponent
             continue;
           }
 
-          gg.fillPolygon(new int[]
-          { res * charWidth - charHeight / 4,
-              res * charWidth + charHeight / 4, res * charWidth },
-                  new int[]
-                  { ypos - (charHeight / 2), ypos - (charHeight / 2),
-                      ypos - (charHeight / 2) + 8 }, 3);
+          gg.fillPolygon(
+                  new int[] { res * charWidth - charHeight / 4,
+                      res * charWidth + charHeight / 4, res * charWidth },
+                  new int[] { ypos - (charHeight / 2),
+                      ypos - (charHeight / 2), ypos - (charHeight / 2) + 8 },
+                  3);
 
         }
       }
@@ -591,8 +594,8 @@ public class SeqCanvas extends JComponent
           annotations = new AnnotationPanel(av);
         }
 
-        annotations.renderer.drawComponent(annotations, av, g,
-                -1, startRes, endx + 1);
+        annotations.renderer.drawComponent(annotations, av, g, -1,
+                startRes, endx + 1);
         g.translate(0, -cHeight - ypos - 3);
       }
       g.setClip(clip);
@@ -638,8 +641,7 @@ public class SeqCanvas extends JComponent
    *          DOCUMENT ME!
    */
   public void drawPanel(Graphics g1, int startRes, int endRes,
-          int startSeq,
-          int endSeq, int offset)
+          int startSeq, int endSeq, int offset)
   {
     updateViewport();
     if (!av.hasHiddenColumns())
@@ -683,10 +685,17 @@ public class SeqCanvas extends JComponent
         g1.translate(-screenY * charWidth, 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 * charWidth, 0);
         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
@@ -700,8 +709,7 @@ public class SeqCanvas extends JComponent
   // int startRes, int endRes, int startSeq, int endSeq, int x, int y,
   // int x1, int x2, int y1, int y2, int startx, int starty,
   private void draw(Graphics g, int startRes, int endRes, int startSeq,
-          int endSeq,
-          int offset)
+          int endSeq, int offset)
   {
     g.setFont(av.getFont());
     sr.prepare(g, av.isRenderGaps());
@@ -724,16 +732,17 @@ public class SeqCanvas extends JComponent
 
       if (av.isShowSequenceFeatures())
       {
-        fr.drawSequence(g, nextSeq, startRes, endRes, offset
+        fr.drawSequence(g, nextSeq, startRes,
+                endRes, offset
                 + ((i - startSeq) * charHeight));
       }
 
       // / Highlight search Results once all sequences have been drawn
       // ////////////////////////////////////////////////////////
-      if (searchResults != null)
+      if (av.hasSearchResults())
       {
-        int[] visibleResults = searchResults.getResults(nextSeq, startRes,
-                endRes);
+        int[] visibleResults = av.getSearchResults().getResults(nextSeq,
+                startRes, endRes);
         if (visibleResults != null)
         {
           for (int r = 0; r < visibleResults.length; r += 2)
@@ -831,8 +840,8 @@ public class SeqCanvas extends JComponent
               if (group == av.getSelectionGroup())
               {
                 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
-                        BasicStroke.JOIN_ROUND, 3f, new float[]
-                        { 5f, 3f }, 0f));
+                        BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f },
+                        0f));
                 g.setColor(Color.RED);
               }
               else
@@ -941,8 +950,7 @@ public class SeqCanvas extends JComponent
           break;
         }
 
-        group = av.getAlignment().getGroups()
-                .get(groupIndex);
+        group = av.getAlignment().getGroups().get(groupIndex);
 
       } while (groupIndex < av.getAlignment().getGroups().size());
 
@@ -956,11 +964,11 @@ public class SeqCanvas extends JComponent
    * @param results
    *          DOCUMENT ME!
    */
-  public void highlightSearchResults(SearchResults results)
+  public void highlightSearchResults(SearchResultsI results)
   {
     img = null;
 
-    searchResults = results;
+    av.setSearchResults(results);
 
     repaint();
   }