From eb2e3276b62ef033703f9b55bbddfdff3fe384df Mon Sep 17 00:00:00 2001 From: James Procter Date: Wed, 6 Sep 2023 14:44:33 +0100 Subject: [PATCH] JAL-4259 construct a new SequenceRenderer when rendering an MSA to an exporter --- src/jalview/api/SequenceRenderer.java | 17 ++++++++++ src/jalview/appletgui/SeqCanvas.java | 4 ++- src/jalview/appletgui/SequenceRenderer.java | 3 +- src/jalview/gui/SeqCanvas.java | 47 ++++++++++++++++----------- src/jalview/gui/SequenceRenderer.java | 1 + 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/jalview/api/SequenceRenderer.java b/src/jalview/api/SequenceRenderer.java index 54f7fb6..d5d07ef 100644 --- a/src/jalview/api/SequenceRenderer.java +++ b/src/jalview/api/SequenceRenderer.java @@ -20,10 +20,12 @@ */ package jalview.api; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; import java.awt.Color; +import java.awt.Graphics; public interface SequenceRenderer { @@ -31,4 +33,19 @@ public interface SequenceRenderer Color getResidueColour(SequenceI seq, int position, FeatureColourFinder finder); + /** + * Configure the Graphics canvas and render options for the renderer + * @param g - the canvas to render to + * @param renderGaps - when true, gap characters will be included when rendered + * + */ + void prepare(Graphics g, boolean renderGaps); + + void drawSequence(SequenceI nextSeq, SequenceGroup[] findAllGroups, + int startRes, int endRes, int i); + + void drawHighlightedText(SequenceI nextSeq, int i, int j, int k, int l); + + void drawCursor(Graphics g, char s, int i, int j); + } diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 3b79f12..735046e 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -644,7 +644,9 @@ public class SeqCanvas extends Panel implements ViewportListenerI if (av.cursorMode && cursorY == i && cursorX >= startRes && cursorX <= endRes) { - sr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * avcharWidth, + char s = nextSeq.getCharAt(cursorX); + + sr.drawCursor(g,s, (cursorX - startRes) * avcharWidth, offset + ((i - startSeq) * avcharHeight)); } } diff --git a/src/jalview/appletgui/SequenceRenderer.java b/src/jalview/appletgui/SequenceRenderer.java index eab6e39..34ad217 100755 --- a/src/jalview/appletgui/SequenceRenderer.java +++ b/src/jalview/appletgui/SequenceRenderer.java @@ -353,7 +353,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer } } - public void drawCursor(SequenceI seq, int res, int x1, int y1) + public void drawCursor(Graphics graphics, char s, int x1, int y1) { int pady = av.getCharHeight() / 5; int charOffset = 0; @@ -363,7 +363,6 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer graphics.setColor(Color.white); - char s = seq.getCharAt(res); if (av.validCharWidth) { diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 39039eb..537af58 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -35,6 +35,7 @@ import java.util.List; import javax.swing.JPanel; +import jalview.api.SequenceRenderer; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; @@ -107,7 +108,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI { this.av = ap.av; fr = new FeatureRenderer(ap); - seqRdr = new SequenceRenderer(av); + seqRdr = new jalview.gui.SequenceRenderer(av); setLayout(new BorderLayout()); PaintRefresher.Register(this, av.getSequenceSetId()); setBackground(Color.white); @@ -355,7 +356,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI /** @j2sNative xxi = this.img */ gg.translate(transX, transY); - drawPanel(gg, startRes, endRes, startSeq, endSeq, 0); + drawPanel(seqRdr, gg, startRes, endRes, startSeq, endSeq, 0); gg.translate(-transX, -transY); gg.dispose(); @@ -455,11 +456,11 @@ public class SeqCanvas extends JPanel implements ViewportListenerI if (av.getWrapAlignment()) { - drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes()); + drawWrappedPanel(seqRdr, gg, getWidth(), getHeight(), ranges.getStartRes()); } else { - drawPanel(gg, startRes, endRes, startSeq, endSeq, 0); + drawPanel(seqRdr,gg, startRes, endRes, startSeq, endSeq, 0); } drawSelectionGroup(gg, startRes, endRes, startSeq, endSeq); @@ -491,7 +492,8 @@ public class SeqCanvas extends JPanel implements ViewportListenerI public void drawPanelForPrinting(Graphics g1, int startRes, int endRes, int startSeq, int endSeq) { - drawPanel(g1, startRes, endRes, startSeq, endSeq, 0); + SequenceRenderer localSeqR = new jalview.gui.SequenceRenderer(av); + drawPanel(localSeqR,g1, startRes, endRes, startSeq, endSeq, 0); drawSelectionGroup((Graphics2D) g1, startRes, endRes, startSeq, endSeq); } @@ -511,7 +513,8 @@ public class SeqCanvas extends JPanel implements ViewportListenerI public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth, int canvasHeight, int startRes) { - drawWrappedPanel(g, canvasWidth, canvasHeight, startRes); + SequenceRenderer localSeqR = new jalview.gui.SequenceRenderer(av); + drawWrappedPanel(localSeqR, g, canvasWidth, canvasHeight, startRes); SequenceGroup group = av.getSelectionGroup(); if (group != null) @@ -608,7 +611,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI * @param startColumn * the first column (0...) of the alignment to draw */ - public void drawWrappedPanel(Graphics g, int canvasWidth, + public void drawWrappedPanel(SequenceRenderer seqRdr, Graphics g, int canvasWidth, int canvasHeight, final int startColumn) { int wrappedWidthInResidues = calculateWrappedGeometry(canvasWidth, @@ -637,7 +640,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI { int endColumn = Math.min(maxWidth, start + wrappedWidthInResidues - 1); - drawWrappedWidth(g, ypos, start, endColumn, canvasHeight); + drawWrappedWidth(seqRdr, g, ypos, start, endColumn, canvasHeight); ypos += wrappedRepeatHeightPx; start += wrappedWidthInResidues; currentWidth++; @@ -730,7 +733,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI * @param endColumn * @param canvasHeight */ - protected void drawWrappedWidth(Graphics g, final int ypos, + protected void drawWrappedWidth(SequenceRenderer seqRdr, Graphics g, final int ypos, final int startColumn, final int endColumn, final int canvasHeight) { @@ -759,7 +762,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI g.fillRect(0, ypos, (endx - startColumn + 1) * charWidth, wrappedRepeatHeightPx); - drawPanel(g, startColumn, endx, 0, av.getAlignment().getHeight() - 1, + drawPanel(seqRdr, g, startColumn, endx, 0, av.getAlignment().getHeight() - 1, ypos); int cHeight = av.getAlignment().getHeight() * av.getCharHeight(); @@ -963,6 +966,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI * are hidden column markers in the visible region, then each sub-region * between the markers is drawn separately, followed by the hidden column * marker. + * @param localSeqR - sequence renderer implementation - when null, uses the one used for rendering interactive GUI * * @param g1 * the graphics context, positioned at the first residue to be drawn @@ -977,15 +981,19 @@ public class SeqCanvas extends JPanel implements ViewportListenerI * @param yOffset * vertical offset at which to draw (for wrapped alignments) */ - public void drawPanel(Graphics g1, final int startRes, final int endRes, + public void drawPanel(SequenceRenderer localSeqR, Graphics g1, final int startRes, final int endRes, final int startSeq, final int endSeq, final int yOffset) { int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); + if (localSeqR==null) + { + localSeqR = seqRdr; + } if (!av.hasHiddenColumns()) { - draw(g1, startRes, endRes, startSeq, endSeq, yOffset); + draw(localSeqR, g1, startRes, endRes, startSeq, endSeq, yOffset); } else { @@ -1009,7 +1017,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI */ g1.translate(screenY * charWidth, 0); - draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset); + draw(localSeqR, g1, blockStart, blockEnd, startSeq, endSeq, yOffset); /* * draw the downline of the hidden column marker (ScalePanel draws the @@ -1034,6 +1042,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI /** * Draws a region of the visible alignment + * @param seqRdr * * @param g1 * @param startRes @@ -1047,7 +1056,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI * @param yOffset * vertical offset at which to draw (for wrapped alignments) */ - private void draw(Graphics g, int startRes, int endRes, int startSeq, + private void draw(SequenceRenderer seqRdr, Graphics g, int startRes, int endRes, int startSeq, int endSeq, int offset) { int charHeight = av.getCharHeight(); @@ -1667,7 +1676,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight(); Graphics gg = img.getGraphics(); gg.translate(transX, transY); - drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0); + drawPanel(seqRdr, gg, firstCol, lastCol, firstSeq, lastSeq, 0); gg.translate(-transX, -transY); gg.dispose(); } @@ -1819,7 +1828,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI if (scrollX < 0) { int startRes = ranges.getStartRes(); - drawWrappedWidth(gg, wrappedSpaceAboveAlignment, startRes, + drawWrappedWidth(seqRdr,gg, wrappedSpaceAboveAlignment, startRes, startRes - scrollX - 1, getHeight()); } else @@ -1893,7 +1902,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI wrappedRepeatHeightPx); gg.translate(-xOffset, 0); - drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight); + drawWrappedWidth(seqRdr, gg, ypos, startRes, endRes, canvasHeight); } @@ -1926,7 +1935,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI if (startRes < ranges.getVisibleAlignmentWidth()) { - drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight); + drawWrappedWidth(seqRdr, gg, ypos, startRes, endRes, canvasHeight); } /* @@ -2147,7 +2156,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI { matchFound = true; gg.translate(transX, transY); - drawPanel(gg, displayColumn, displayColumn, seqNo, seqNo, + drawPanel(seqRdr,gg, displayColumn, displayColumn, seqNo, seqNo, yOffset); gg.translate(-transX, -transY); } diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 43fef15..fedcc37 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -70,6 +70,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer * @param b * DOCUMENT ME! */ + @Override public void prepare(Graphics g, boolean renderGaps) { graphics = g; -- 1.7.10.2