From ca106e8dd8c6bd849356c3a75cecc1d7eabd7230 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 29 Aug 2017 09:28:29 +0100 Subject: [PATCH] JAL-2665 Corrected to draw selections for wrapped printing --- src/jalview/gui/AlignmentPanel.java | 4 +-- src/jalview/gui/SeqCanvas.java | 66 ++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 7cd8b50..fe216c0 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1103,7 +1103,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * single graphics context), then reset to (0, scale height) */ alignmentGraphics.translate(alignmentGraphicsOffset, scaleHeight); - getSeqPanel().seqCanvas.drawPanelForPrint(alignmentGraphics, startRes, + getSeqPanel().seqCanvas.drawPanelForPrinting(alignmentGraphics, startRes, endRes, startSeq, endSeq); alignmentGraphics.translate(-alignmentGraphicsOffset, 0); @@ -1231,7 +1231,7 @@ public class AlignmentPanel extends GAlignmentPanel implements pg.translate(idWidth, 0); - getSeqPanel().seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, + getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(pg, pwidth - idWidth, totalHeight, 0); if ((pi * pheight) < totalHeight) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index f0d8c3e..8d8aef3 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -434,7 +434,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * @param endSeq * end sequence of print area */ - public void drawPanelForPrint(Graphics g1, int startRes, int endRes, + public void drawPanelForPrinting(Graphics g1, int startRes, int endRes, int startSeq, int endSeq) { BufferedImage selectImage = drawSelectionGroup(startRes, endRes, @@ -445,6 +445,39 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g1.drawImage(selectImage, 0, 0, this); } + /** + * Draw a wrapped alignment panel for printing + * + * @param g + * Graphics object to draw with + * @param canvasWidth + * width of drawing area + * @param canvasHeight + * height of drawing area + * @param startRes + * start residue of print area + */ + public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth, + int canvasHeight, int startRes) + { + SequenceGroup group = av.getSelectionGroup(); + BufferedImage selectImage = new BufferedImage(canvasWidth, canvasHeight, + BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works + + if (group != null) + { + Graphics2D g2 = selectImage.createGraphics(); + setupSelectionGroup(g2, selectImage); + drawWrappedSelection(g2, group, canvasWidth, canvasHeight, + startRes); + drawWrappedPanel(g, canvasWidth, canvasHeight, startRes); + g2.setComposite( + AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); + g.drawImage(selectImage, 0, 0, this); + g2.dispose(); + } + } + /* * Make a local image by combining the cached image img * with any selection @@ -570,7 +603,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * @param startRes * DOCUMENT ME! */ - public void drawWrappedPanel(Graphics g, int canvasWidth, + private void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) { updateViewport(); @@ -993,16 +1026,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // set up drawing colour Graphics2D g = (Graphics2D) selectionImage.getGraphics(); - // set background to transparent - g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); - g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight()); - - // set up foreground to draw red dashed line - g.setComposite(AlphaComposite.Src); - g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, - BasicStroke.JOIN_ROUND, 3f, new float[] - { 5f, 3f }, 0f)); - g.setColor(Color.RED); + setupSelectionGroup(g, selectionImage); if (!av.getWrapAlignment()) { @@ -1020,6 +1044,24 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } /* + * Set up graphics for selection group + */ + private void setupSelectionGroup(Graphics2D g, + BufferedImage selectionImage) + { + // set background to transparent + g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); + g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight()); + + // set up foreground to draw red dashed line + g.setComposite(AlphaComposite.Src); + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, 3f, new float[] + { 5f, 3f }, 0f)); + g.setColor(Color.RED); + } + + /* * Draw a selection group over an unwrapped alignment * @param g graphics object to draw with * @param group selection group -- 1.7.10.2