From: kiramt Date: Wed, 12 Jul 2017 13:58:03 +0000 (+0100) Subject: JAL-2613 Centre alignment at click point X-Git-Tag: Release_2_10_3b1~132^2~30^2~6^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=818aa3cd6fb2d07b54e3b4c283f8580c74bc4b58;p=jalview.git JAL-2613 Centre alignment at click point --- diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index d2912d8..335f1fa 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -240,4 +240,9 @@ public abstract class OverviewDimensions // boxHeight is the height in sequences translated to pixels boxHeight = Math.round((float) vpheight * sequencesHeight / alheight); } + + protected abstract int getLeftXFromCentreX(int mousex, HiddenColumns hidden); + + protected abstract int getTopYFromCentreY(int mousey, + HiddenSequences hidden); } \ No newline at end of file diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index 4bf7694..fe20195 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -26,17 +26,17 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions { resetAlignmentDims(); - int x = mousex; - int y = mousey; + int xAsRes = getLeftXFromCentreX(mousex, hiddenCols); + int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs); - if (x < 0) + if (xAsRes < 0) { - x = 0; + xAsRes = 0; } - if (y < 0) + if (yAsSeq < 0) { - y = 0; + yAsSeq = 0; } // @@ -48,7 +48,7 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions // correction // convert x to residues - this is an absolute position - int xAsRes = Math.round((float) x * alwidth / width); + // int xAsRes = Math.round((float) x * alwidth / width); // get viewport width in residues int vpwidth = ranges.getViewportWidth(); @@ -74,7 +74,7 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions // // convert y to residues - int yAsSeq = Math.round((float) y * alheight / sequencesHeight); + // int yAsSeq = Math.round((float) y * alheight / sequencesHeight); // get viewport height in sequences // add 1 because height includes both endSeq and startSeq @@ -127,4 +127,18 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions alwidth = ranges.getVisibleAlignmentWidth(); alheight = ranges.getVisibleAlignmentHeight(); } + + @Override + protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden) + { + int vpx = Math.round((float) mousex * alwidth / width); + return vpx - ranges.getViewportWidth() / 2; + } + + @Override + protected int getTopYFromCentreY(int mousey, HiddenSequences hidden) + { + int vpy = Math.round((float) mousey * alheight / sequencesHeight); + return vpy - ranges.getViewportHeight() / 2; + } } diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index 4b396a6..be69db9 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -66,19 +66,19 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions public void updateViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { - int x = mousex; - int y = mousey; + int xAsRes = getLeftXFromCentreX(mousex, hiddenCols); + int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs); resetAlignmentDims(); - if (x < 0) + if (xAsRes < 0) { - x = 0; + xAsRes = 0; } - if (y < 0) + if (yAsSeq < 0) { - y = 0; + yAsSeq = 0; } // @@ -90,7 +90,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // correction // convert x to residues - this is an absolute position - int xAsRes = Math.round((float) x * alwidth / width); + // int xAsRes = Math.round((float) x * alwidth / width); // get viewport width in residues int vpwidth = ranges.getViewportWidth(); @@ -124,7 +124,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // // convert y to residues - int yAsSeq = Math.round((float) y * alheight / sequencesHeight); + // int yAsSeq = Math.round((float) y * alheight / sequencesHeight); // get viewport height in sequences int vpheight = ranges.getViewportHeight(); @@ -207,4 +207,20 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions alwidth = ranges.getAbsoluteAlignmentWidth(); alheight = ranges.getAbsoluteAlignmentHeight(); } + + @Override + protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden) + { + int vpx = Math.round((float) mousex * alwidth / width); + return hidden.findColumnPosition(hidden.subtractVisibleColumns( + ranges.getViewportWidth() / 2, vpx)); + } + + @Override + protected int getTopYFromCentreY(int mousey, HiddenSequences hidden) + { + int vpy = Math.round((float) mousey * alheight / sequencesHeight); + return hidden.findIndexWithoutHiddenSeqs(hidden.subtractVisibleRows( + ranges.getViewportHeight() / 2, vpy)); + } } diff --git a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java index 1bc3bfa..fef7548 100644 --- a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java @@ -55,7 +55,7 @@ public class OverviewDimensionsShowHiddenTest ViewportRanges vpranges; - Hashtable hiddenRepSequences = new Hashtable(); + Hashtable hiddenRepSequences = new Hashtable<>(); HiddenColumns hiddenCols = new HiddenColumns(); @@ -209,7 +209,7 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartSeq(), + assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2, Math.round((float) 10 * alheight / od.getSequencesHeight())); assertEquals(vpranges.getStartRes(), 0); @@ -218,14 +218,13 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes(), - Math.round((float) 6 * alwidth / od.getWidth())); + assertEquals(vpranges.getStartRes(), 0); assertEquals(vpranges.getStartSeq(), 0); // overly large boxX value reset to width-boxWidth - mouseClick(od, 100, 6); + mouseClick(od, 101, 6); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); - assertEquals(od.getBoxY(), 6); + assertEquals(od.getBoxY(), 1); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(vpranges.getStartRes(), @@ -241,14 +240,14 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes(), + assertEquals(vpranges.getStartRes() + vpranges.getViewportWidth() / 2, Math.round((float) od.getBoxX() * alwidth / od.getWidth())); // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5 // and round rounds to 508; however we get 507 working with row values // hence the subtraction of 1 assertEquals( - vpranges.getStartSeq(), + vpranges.getStartSeq() + vpranges.getViewportWidth() / 2, Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1); @@ -257,10 +256,10 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes(), + assertEquals(vpranges.getStartRes() + vpranges.getViewportWidth() / 2, Math.round((float) od.getBoxX() * alwidth / od.getWidth())); assertEquals( - vpranges.getStartSeq(), + vpranges.getStartSeq() + vpranges.getViewportHeight() / 2, Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); @@ -274,11 +273,11 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), oldboxx + 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes(), + assertEquals(vpranges.getStartRes() + vpranges.getViewportWidth() / 2, Math.round((float) od.getBoxX() * alwidth / od.getWidth())); assertEquals(od.getBoxY(), oldboxy + 2); assertEquals( - vpranges.getStartSeq(), + vpranges.getStartSeq() + vpranges.getViewportHeight() / 2, Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight()));