Merge remote-tracking branch 'origin/features/JAL-2609fastPaintWrapped'
authorkiramt <k.mourao@dundee.ac.uk>
Tue, 10 Oct 2017 13:34:50 +0000 (14:34 +0100)
committerkiramt <k.mourao@dundee.ac.uk>
Tue, 10 Oct 2017 13:34:50 +0000 (14:34 +0100)
into bug/JAL-2690attemptedmerge

Conflicts:
src/jalview/gui/SeqCanvas.java

1  2 
src/jalview/gui/SeqCanvas.java
src/jalview/gui/SeqPanel.java

@@@ -478,84 -386,35 +478,84 @@@ public class SeqCanvas extends JCompone
        } catch (OutOfMemoryError er)
        {
          System.gc();
 -        System.err.println("SeqCanvas OutOfMemory Redraw Error.\n" + er);
 -        new OOMWarning("Creating alignment image for display", er);
 -
 -        return;
 +        System.err.println("Print image OutOfMemory Error.\n" + er);
 +        new OOMWarning("Creating wrapped alignment image for printing", er);
 +      }
 +      if (selectImage != null)
 +      {
 +        Graphics2D g2 = selectImage.createGraphics();
 +        setupSelectionGroup(g2, selectImage);
 +        drawWrappedSelection(g2, group, canvasWidth, canvasHeight,
 +                startRes);
 +
 +        g2.setComposite(
 +                AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
 +        g.drawImage(selectImage, 0, 0, this);
 +        g2.dispose();
        }
      }
 +  }
  
 -    if (av.antiAlias)
 +  /*
 +   * Make a local image by combining the cached image img
 +   * with any selection
 +   */
 +  private BufferedImage buildLocalImage(BufferedImage selectImage)
 +  {
 +    // clone the cached image
 +    BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
 +            img.getType());
 +    Graphics2D g2d = lcimg.createGraphics();
 +    g2d.drawImage(img, 0, 0, null);
 +
 +    // overlay selection group on lcimg
 +    if (selectImage != null)
      {
 -      gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
 -              RenderingHints.VALUE_ANTIALIAS_ON);
 +      g2d.setComposite(
 +              AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
 +      g2d.drawImage(selectImage, 0, 0, this);
      }
 +    g2d.dispose();
  
 -    gg.setColor(Color.white);
 -    gg.fillRect(0, 0, imgWidth, imgHeight);
 +    return lcimg;
 +  }
  
 -    ViewportRanges ranges = av.getRanges();
 -    if (av.getWrapAlignment())
 +  /*
 +   * Set up a buffered image of the correct height and size for the sequence canvas
 +   */
 +  private BufferedImage setupImage()
 +  {
 +    BufferedImage lcimg = null;
 +
 +    int charWidth = av.getCharWidth();
 +    int charHeight = av.getCharHeight();
++    
 +    int width = getWidth();
 +    int height = getHeight();
 +
 +    width -= (width % charWidth);
 +    height -= (height % charHeight);
 +
 +    if ((width < 1) || (height < 1))
      {
 -      drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes());
 +      return null;
      }
 -    else
 +
 +    try
      {
 -      drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
 -              ranges.getStartSeq(), ranges.getEndSeq(), 0);
 -    }
 +      lcimg = new BufferedImage(width, height,
 +              BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
 +    } catch (OutOfMemoryError er)
 +    {
 +      System.gc();
 +      System.err.println(
 +              "Group image OutOfMemory Redraw Error.\n" + er);
 +      new OOMWarning("Creating alignment image for display", er);
  
 -    g.drawImage(lcimg, 0, 0, this);
 +      return null;
 +    }
  
 +    return lcimg;
    }
  
    /**
Simple merge