From f02e65ac3b489b25e5514d9972838af04298c148 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 13 Nov 2017 19:40:06 +0000 Subject: [PATCH] JAL-2811 Tidy --- src/jalview/gui/SeqCanvas.java | 98 +++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 2d040a3..394a0b6 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1275,61 +1275,65 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // define our cursor image BufferedImage cursorImage = null; - int yoffset = 0; - int xoffset = 0; - int startx = startRes; - int endx = endRes; - if (av.getWrapAlignment()) + // don't do work unless we have to + if (av.cursorMode && cursorY >= startSeq && cursorY <= endSeq) { - // work out the correct offsets for the cursor - int charHeight = av.getCharHeight(); - int charWidth = av.getCharWidth(); - int canvasWidth = getWidth(); - int canvasHeight = getHeight(); - - // height gap above each panel - int hgap = charHeight; - if (av.getScaleAboveWrapped()) + int yoffset = 0; + int xoffset = 0; + int startx = startRes; + int endx = endRes; + if (av.getWrapAlignment()) { - hgap += charHeight; - } - - int cWidth = (canvasWidth - labelWidthEast - labelWidthWest) - / charWidth; - int cHeight = av.getAlignment().getHeight() * charHeight; - - endx = startx + cWidth - 1; - int ypos = hgap; // vertical offset + // work out the correct offsets for the cursor + int charHeight = av.getCharHeight(); + int charWidth = av.getCharWidth(); + int canvasWidth = getWidth(); + int canvasHeight = getHeight(); + + // height gap above each panel + int hgap = charHeight; + if (av.getScaleAboveWrapped()) + { + hgap += charHeight; + } - // iterate down the wrapped panels - while ((ypos <= canvasHeight) && (endx < cursorX)) - { - // update vertical offset - ypos += cHeight + getAnnotationHeight() + hgap; + int cWidth = (canvasWidth - labelWidthEast - labelWidthWest) + / charWidth; + int cHeight = av.getAlignment().getHeight() * charHeight; - // update horizontal offset - startx += cWidth; endx = startx + cWidth - 1; - } - yoffset = ypos; - xoffset = labelWidthWest; - } + int ypos = hgap; // vertical offset - if (av.cursorMode && cursorY >= startSeq && cursorY <= endSeq - && cursorX >= startx && cursorX <= endx) - { - // get a new image of the correct size - cursorImage = setupImage(); - Graphics2D g = (Graphics2D) cursorImage.getGraphics(); + // iterate down the wrapped panels + while ((ypos <= canvasHeight) && (endx < cursorX)) + { + // update vertical offset + ypos += cHeight + getAnnotationHeight() + hgap; - // get the character the cursor is drawn at - SequenceI seq = av.getAlignment().getSequenceAt(cursorY); - char s = seq.getCharAt(cursorX); + // update horizontal offset + startx += cWidth; + endx = startx + cWidth - 1; + } + yoffset = ypos; + xoffset = labelWidthWest; + } - seqRdr.drawCursor(g, s, - xoffset + (cursorX - startx) * av.getCharWidth(), - yoffset + (cursorY - startSeq) * av.getCharHeight()); - g.dispose(); + // now check if cursor is within range for x values + if (cursorX >= startx && cursorX <= endx) + { + // get a new image of the correct size + cursorImage = setupImage(); + Graphics2D g = (Graphics2D) cursorImage.getGraphics(); + + // get the character the cursor is drawn at + SequenceI seq = av.getAlignment().getSequenceAt(cursorY); + char s = seq.getCharAt(cursorX); + + seqRdr.drawCursor(g, s, + xoffset + (cursorX - startx) * av.getCharWidth(), + yoffset + (cursorY - startSeq) * av.getCharHeight()); + g.dispose(); + } } return cursorImage; -- 1.7.10.2