From: kiramt Date: Fri, 26 Jan 2018 10:27:46 +0000 (+0000) Subject: JAL-2778 tightened up use of resetAlignmentDims X-Git-Tag: Release_2_10_4~67^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7e74b39c54f5950b8d0e5daf678c4cc4bd25c7f9;p=jalview.git JAL-2778 tightened up use of resetAlignmentDims --- diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index d7f2e61..0235081 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -161,23 +161,25 @@ public abstract class OverviewDimensions public float getPixelsPerCol() { resetAlignmentDims(); - return (float) width / alwidth; + return 1 / widthRatio; } public float getPixelsPerSeq() { resetAlignmentDims(); - return (float) sequencesHeight / alheight; + return 1 / heightRatio; } public void setWidth(int w) { width = w; + widthRatio = (float) alwidth / width; } public void setHeight(int h) { sequencesHeight = h - graphHeight; + heightRatio = (float) alheight / sequencesHeight; } /** @@ -277,14 +279,14 @@ public abstract class OverviewDimensions // boxX, boxY is the x,y location equivalent to startRes, startSeq int xPos = Math.min(startRes, alwidth - vpwidth + 1); - boxX = Math.round((float) xPos * width / alwidth); - boxY = Math.round((float) startSeq * sequencesHeight / alheight); + boxX = Math.round(xPos / widthRatio); + boxY = Math.round(startSeq / heightRatio); // boxWidth is the width in residues translated to pixels - boxWidth = Math.round((float) vpwidth * width / alwidth); + boxWidth = Math.round(vpwidth / widthRatio); // boxHeight is the height in sequences translated to pixels - boxHeight = Math.round((float) vpheight * sequencesHeight / alheight); + boxHeight = Math.round(vpheight / heightRatio); } /** diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index 1cc42bb..f58e711 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -50,6 +50,8 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions public void updateViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + resetAlignmentDims(); + int xAsRes = getLeftXFromCentreX(mousex, hiddenCols); int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs); @@ -61,6 +63,8 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions public void adjustViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + resetAlignmentDims(); + // calculate translation in pixel terms: // get mouse location in viewport coords, add translation in viewport // coords, and update viewport as usual @@ -72,13 +76,16 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions } + /** + * {@inheritDoc} Callers should have already called resetAlignmentDims to + * refresh alwidth, alheight and width/height ratios + */ @Override protected void updateViewportFromTopLeft(int leftx, int topy, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { int xAsRes = leftx; int yAsSeq = topy; - resetAlignmentDims(); if (xAsRes < 0) { @@ -167,6 +174,10 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions heightRatio = (float) alheight / sequencesHeight; } + /** + * {@inheritDoc} Callers should have already called resetAlignmentDims to + * refresh widthRatio + */ @Override protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden) { @@ -174,6 +185,10 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions return vpx - ranges.getViewportWidth() / 2; } + /** + * {@inheritDoc} Callers should have already called resetAlignmentDims to + * refresh heightRatio + */ @Override protected int getTopYFromCentreY(int mousey, HiddenSequences hidden) { @@ -185,6 +200,8 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + resetAlignmentDims(); + // get alignment position of x and box (can get directly from vpranges) and // calculate difference between the positions int vpx = Math.round(x * widthRatio); diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index ec2efa2..eaa3413 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -72,6 +72,8 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions public void updateViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + resetAlignmentDims(); + // convert mousex and mousey to alignment units as well as // translating to top left corner of viewport - this is an absolute position int xAsRes = getLeftXFromCentreX(mousex, hiddenCols); @@ -93,6 +95,8 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions public void adjustViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + resetAlignmentDims(); + // calculate translation in pixel terms: // get mouse location in viewport coords, add translation in viewport // coords, @@ -107,13 +111,16 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions updateViewportFromTopLeft(visXAsRes, visYAsRes, hiddenSeqs, hiddenCols); } + /** + * {@inheritDoc} Callers should have already called resetAlignmentDims to + * refresh alwidth, alheight and width/height ratios + */ @Override protected void updateViewportFromTopLeft(int leftx, int topy, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { int visXAsRes = leftx; int visYAsSeq = topy; - resetAlignmentDims(); if (visXAsRes < 0) { @@ -230,6 +237,11 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions heightRatio = (float) alheight / sequencesHeight; } + + /** + * {@inheritDoc} Callers should have already called resetAlignmentDims to + * refresh widthRatio + */ @Override protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden) { @@ -238,6 +250,10 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions vpx); } + /** + * {@inheritDoc} Callers should have already called resetAlignmentDims to + * refresh heightRatio + */ @Override protected int getTopYFromCentreY(int mousey, HiddenSequences hidden) { @@ -249,6 +265,8 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + resetAlignmentDims(); + // get alignment position of x and box (can get directly from vpranges) and // calculate difference between the positions int vpx = Math.round(x * widthRatio);