Merge commit 'alpha/update_2_12_for_2_11_2_series_merge^2' into HEAD
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 59a6cb1..0f01552 100755 (executable)
@@ -100,7 +100,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
   private int availHeight;
 
   private boolean allowFastPaint;
-
   // Don't do this! Graphics handles are supposed to be transient
   // private Graphics2D gg;
 
@@ -209,7 +208,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     int yPos = ypos + charHeight;
     int startX = startx;
     int endX = endx;
-
     if (av.hasHiddenColumns())
     {
       HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
@@ -349,6 +347,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
         }
       }
 
+
       // System.err.println(">>> FastPaint to " + transX + " " + transY + " "
       // + horizontal + " " + vertical + " " + startRes + " " + endRes
       // + " " + startSeq + " " + endSeq);
@@ -357,6 +356,8 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       gg.copyArea(horizontal * charWidth, vertical * charHeight,
               img.getWidth(), img.getHeight(), -horizontal * charWidth,
               -vertical * charHeight);
+
+
       gg.translate(transX, transY);
       drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
       gg.translate(-transX, -transY);
@@ -386,6 +387,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     {
       return;
     }
+
     ViewportRanges ranges = av.getRanges();
     int startRes = ranges.getStartRes();
     int startSeq = ranges.getStartSeq();
@@ -451,7 +453,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
 
       if (av.getWrapAlignment())
       {
-        drawWrappedPanel(gg, availWidth, availHeight, ranges.getStartRes());
+        drawWrappedPanel(gg, width, height, ranges.getStartRes());
       }
       else
       {
@@ -469,7 +471,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       drawCursor(g, startRes, endRes, startSeq, endSeq);
     }
   }
-
   /**
    * Draw an alignment panel for printing
    * 
@@ -518,31 +519,32 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
   }
 
   /**
-   * Using the current font, determine fields labelWidthEast and labelWidthWest,
-   * and return the number of residues that can fill the remaining width
+   * Returns the visible width of the canvas in residues, after allowing for
+   * East or West scales (if shown)
    * 
-   * @param w
+   * @param canvasWidth
    *          the width in pixels (possibly including scales)
    * 
-   * @return the visible width in residues, after allowing for East or West
-   *         scales (if shown)
-   * 
+   * @return
    */
-  public int getWrappedCanvasWidth(int w)
+  public int getWrappedCanvasWidth(int canvasWidth)
   {
     int charWidth = av.getCharWidth();
 
     FontMetrics fm = getFontMetrics(av.getFont());
 
-    int labelWidth = (av.getScaleRightWrapped() || av.getScaleLeftWrapped()
-            ? getLabelWidth(fm)
-            : 0);
+    int labelWidth = 0;
+    
+    if (av.getScaleRightWrapped() || av.getScaleLeftWrapped())
+    {
+      labelWidth = getLabelWidth(fm);
+    }
 
     labelWidthEast = av.getScaleRightWrapped() ? labelWidth : 0;
 
     labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0;
 
-    return (w - labelWidthEast - labelWidthWest) / charWidth;
+    return (canvasWidth - labelWidthEast - labelWidthWest) / charWidth;
   }
 
   /**
@@ -594,7 +596,9 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
           final int startColumn)
   {
     int wrappedWidthInResidues = calculateWrappedGeometry();
+
     av.setWrappedWidth(wrappedWidthInResidues);
+
     ViewportRanges ranges = av.getRanges();
     ranges.setViewportStartAndWidth(startColumn, wrappedWidthInResidues);
 
@@ -634,7 +638,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     availWidth -= (availWidth % charWidth);
     availHeight -= (availHeight % charHeight);
   }
-
   /**
    * Calculates and saves values needed when rendering a wrapped alignment.
    * These depend on many factors, including
@@ -664,7 +667,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
    */
   public int calculateWrappedGeometry(int canvasWidth, int canvasHeight)
   {
-
     int charHeight = av.getCharHeight();
 
     /*
@@ -817,7 +819,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       if (av.getScaleRightWrapped())
       {
         int x = labelWidthWest + viewportWidth * charWidth;
-
         g.translate(x, 0);
         drawVerticalScale(g, startCol, endColumn, ypos, false);
         g.translate(-x, 0);
@@ -903,7 +904,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
           { 5f, 3f }, 0f);
 
   private final static BasicStroke basicStroke = new BasicStroke();
-
   /*
    * Draw a selection group over a wrapped alignment
    */
@@ -920,7 +920,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
             / charWidth;
     int startx = startRes;
     int maxwidth = av.getAlignment().getVisibleWidth();
-
     // JAL-3253-applet had this:
     // // height gap above each panel
     // int charHeight = av.getCharHeight();
@@ -948,10 +947,8 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       }
 
       g.translate(labelWidthWest, 0);
-
       drawUnwrappedSelection(g, group, startx, endx, 0,
               av.getAlignment().getHeight() - 1, ypos);
-
       g.translate(-labelWidthWest, 0);
 
       // update vertical offset
@@ -1297,6 +1294,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     }
   }
 
+
   /**
    * Draw a selection group over an unwrapped alignment
    * 
@@ -1319,7 +1317,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
           int startRes, int endRes, int startSeq, int endSeq, int offset)
   {
     int charWidth = av.getCharWidth();
-
     if (!av.hasHiddenColumns())
     {
       drawPartialGroupOutline(g, group, startRes, endRes, startSeq, endSeq,
@@ -1512,7 +1509,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       g.drawLine(sx + xwidth, oldY, sx + xwidth, sy);
     }
   }
-
   /**
    * Highlights search results in the visible region by rendering as white text
    * on a black background. Any previous highlighting is removed. Answers true
@@ -1528,7 +1524,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     return highlightSearchResults(results, false);
 
   }
-
   /**
    * Highlights search results in the visible region by rendering as white text
    * on a black background. Any previous highlighting is removed. Answers true
@@ -1705,7 +1700,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
   public void propertyChange(PropertyChangeEvent evt)
   {
     String eventName = evt.getPropertyName();
-
     // BH 2019.07.27 removes dead code introduced in aad3650 and simplifies
     // logic, emphasizing no check for ENDRES or ENDSEQ
 
@@ -1893,9 +1887,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
 
     try
     {
-
       Graphics gg = img.getGraphics();
-
       calculateWrappedGeometry();
 
       /*
@@ -1925,7 +1917,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       drawWrappedDecorators(gg, ranges.getStartRes());
 
       gg.dispose();
-
       repaint();
     } finally
     {
@@ -1950,7 +1941,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     }
 
     Graphics gg = img.getGraphics();
-
     ViewportRanges ranges = av.getRanges();
     int viewportWidth = ranges.getViewportWidth();
     int charWidth = av.getCharWidth();
@@ -1978,7 +1968,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       /*
        * white fill first to erase annotations
        */
-
       gg.translate(xOffset, 0);
       gg.setColor(Color.white);
       gg.fillRect(labelWidthWest, ypos, (endRes - startRes + 1) * charWidth,
@@ -1986,7 +1975,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       gg.translate(-xOffset, 0);
 
       drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
-
     }
 
     /*
@@ -2248,7 +2236,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
         }
       }
     }
-
     gg.dispose();
 
     return matchFound;