From 66a8cb51d08c8b6780e9b6ccd1d363fa09c3e2d2 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 14 Jul 2017 14:31:51 +0100 Subject: [PATCH] JAL-2611 First pass, not thrilled with hidden column behaviour --- src/jalview/gui/OverviewPanel.java | 29 +++++++++++- src/jalview/viewmodel/OverviewDimensions.java | 24 +++++++--- .../viewmodel/OverviewDimensionsHideHidden.java | 44 ++++++++++++++++++- .../viewmodel/OverviewDimensionsShowHidden.java | 46 ++++++++++++++++++++ 4 files changed, 133 insertions(+), 10 deletions(-) diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 35a3148..0f276d7 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -65,6 +65,8 @@ public class OverviewPanel extends JPanel implements Runnable, private boolean showHidden = true; + private boolean draggingBox = false; + /** * Creates a new OverviewPanel object. * @@ -110,9 +112,18 @@ public class OverviewPanel extends JPanel implements Runnable, if (!SwingUtilities.isRightMouseButton(evt) && !av.getWrapAlignment()) { - od.updateViewportFromMouse(evt.getX(), evt.getY(), av + if (draggingBox) + { + od.adjustViewportFromMouse(evt.getX(), + evt.getY(), av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + } + else + { + od.updateViewportFromMouse(evt.getX(), evt.getY(), av .getAlignment().getHiddenSequences(), av.getAlignment() .getHiddenColumns()); + } } } @@ -156,6 +167,22 @@ public class OverviewPanel extends JPanel implements Runnable, av.getAlignment().getHiddenSequences(), av.getAlignment().getHiddenColumns()); } + else + { + draggingBox = true; + od.setDragPoint(evt.getX(), evt.getY(), + av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + } + } + } + + @Override + public void mouseReleased(MouseEvent evt) + { + if (draggingBox) + { + draggingBox = false; } } diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index 68318ee..c63fb3c 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -58,6 +58,10 @@ public abstract class OverviewDimensions protected int alheight; + protected int transX; + + protected int transY; + /** * Create an OverviewDimensions object * @@ -191,6 +195,15 @@ public abstract class OverviewDimensions public abstract void updateViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); + public abstract void adjustViewportFromMouse(int mousex, int mousey, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); + + public abstract void setDragPoint(int x, int y, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); + + protected abstract void updateViewportFromTopLeft(int mousex, int mousey, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); + /** * Set the overview panel's box position to match the viewport * @@ -239,6 +252,8 @@ public abstract class OverviewDimensions // boxHeight is the height in sequences translated to pixels boxHeight = Math.round((float) vpheight * sequencesHeight / alheight); + + System.out.println("Update box: x: " + boxX); } /** @@ -252,13 +267,8 @@ public abstract class OverviewDimensions */ public boolean isPositionInBox(int x, int y) { - return (x > boxX && y > boxY && boxX + x < boxWidth - && boxY + y < boxHeight); - } - - public void setMousePosition(int x, int y) - { - + return (x > boxX && y > boxY && x < boxX + boxWidth + && y < boxY + boxHeight); } protected abstract int getLeftXFromCentreX(int mousex, HiddenColumns hidden); diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index c5ce19b..ec79954 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -24,11 +24,35 @@ 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); + updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols); + + } + + @Override + public void adjustViewportFromMouse(int mousex, int mousey, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) + { + // calculate translation in pixel terms: + // get mouse location in viewport coords, add translation in viewport + // coords, and update viewport as usual + int vpx = Math.round((float) mousex * alwidth / width); + int vpy = Math.round((float) mousey * alheight / sequencesHeight); + + updateViewportFromTopLeft(vpx + transX, vpy + transY, hiddenSeqs, + hiddenCols); + + } + + @Override + protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) + { + + resetAlignmentDims(); + if (xAsRes < 0) { xAsRes = 0; @@ -138,4 +162,20 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions int vpy = Math.round((float) mousey * alheight / sequencesHeight); return vpy - ranges.getViewportHeight() / 2; } + + @Override + public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs, + HiddenColumns hiddenCols) + { + // get alignment position of x and box (can get directly from vpranges) and + // calc difference + int vpx = Math.round((float) x * alwidth / width); + + int vpy = Math.round((float) y * alheight / sequencesHeight); + + transX = ranges.getStartRes() - vpx; + transY = ranges.getStartSeq() - vpy; + + } + } diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index 1bd96ab..af95c45 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -69,6 +69,33 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions int xAsRes = getLeftXFromCentreX(mousex, hiddenCols); int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs); + updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols); + } + + @Override + public void adjustViewportFromMouse(int mousex, int mousey, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) + { + // calculate translation in pixel terms: + // get mouse location in viewport coords, add translation in viewport + // coords, + // convert back to pixel coords + int vpx = Math.round((float) mousex * alwidth / width); + int visXAsRes = hiddenCols.findColumnPosition(vpx); + + int vpy = Math.round((float) mousey * alheight / sequencesHeight); + int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy); + + updateViewportFromTopLeft(visXAsRes + transX, visYAsRes + transY, + hiddenSeqs, + hiddenCols); + } + + @Override + protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) + { + resetAlignmentDims(); if (xAsRes < 0) @@ -174,6 +201,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions public void setBoxPosition(HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { + // work with absolute values of startRes and endRes int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes()); int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes()); @@ -222,4 +250,22 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions int vpy = Math.round((float) mousey * alheight / sequencesHeight); return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy); } + + @Override + public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs, + HiddenColumns hiddenCols) + { + { + // get alignment position of x and box (can get directly from vpranges) and calc difference + int vpx = Math.round((float) x * alwidth / width); + int visXAsRes = hiddenCols.findColumnPosition(vpx); + + int vpy = Math.round((float) y * alheight / sequencesHeight); + int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy); + + transX = ranges.getStartRes() - visXAsRes; + transY = ranges.getStartSeq() - visYAsRes; + } + } + } -- 1.7.10.2