From 24b3db7a46158fe7bf82c208472740f8b7c76448 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 18 Jul 2017 12:12:23 +0100 Subject: [PATCH] JAL-2611 Better --- src/jalview/appletgui/OverviewPanel.java | 67 ++++++++-- src/jalview/gui/OverviewPanel.java | 3 +- src/jalview/viewmodel/OverviewDimensions.java | 4 +- .../viewmodel/OverviewDimensionsHideHidden.java | 6 +- .../viewmodel/OverviewDimensionsShowHidden.java | 141 ++++---------------- 5 files changed, 90 insertions(+), 131 deletions(-) diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index b3c4a37..76c4e86 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -29,6 +29,7 @@ import jalview.viewmodel.ViewportListenerI; import java.awt.BorderLayout; import java.awt.CheckboxMenuItem; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.Panel; import java.awt.PopupMenu; @@ -57,6 +58,8 @@ public class OverviewPanel extends Panel implements Runnable, private boolean updateRunning = false; + private boolean draggingBox = false; + public OverviewPanel(AlignmentPanel alPanel) { this.av = alPanel.av; @@ -118,28 +121,62 @@ public class OverviewPanel extends Panel implements Runnable, @Override public void mouseMoved(MouseEvent evt) { + if (od.isPositionInBox(evt.getX(), evt.getY())) + { + // display drag cursor at mouse position + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + } + else + { + // reset cursor + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } @Override public void mousePressed(MouseEvent evt) { - mouseAction(evt); + if ((evt.getModifiers() + & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) + { + if (!Platform.isAMac()) + { + showPopupMenu(evt); + } + } + else + { + if (!od.isPositionInBox(evt.getX(), evt.getY())) + { + // don't do anything if the mouse press is in the overview's box + // (wait to see if it's a drag instead) + // otherwise update the viewport + od.updateViewportFromMouse(evt.getX(), evt.getY(), + 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) { - mouseAction(evt); + if (draggingBox) + { + draggingBox = false; + } } @Override public void mouseDragged(MouseEvent evt) { - mouseAction(evt); - } - - private void mouseAction(MouseEvent evt) - { if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { if (!Platform.isAMac()) @@ -149,8 +186,20 @@ public class OverviewPanel extends Panel implements Runnable, } else { - od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment() - .getHiddenSequences(), av.getAlignment().getHiddenColumns()); + if (draggingBox) + { + // set the mouse position as a fixed point in the box + // and drag relative to that position + 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()); + } ap.paintAlignment(false); } } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 5fbefb5..1c01108 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -115,6 +115,8 @@ public class OverviewPanel extends JPanel implements Runnable, { if (draggingBox) { + // set the mouse position as a fixed point in the box + // and drag relative to that position od.adjustViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment().getHiddenSequences(), av.getAlignment().getHiddenColumns()); @@ -199,7 +201,6 @@ public class OverviewPanel extends JPanel implements Runnable, }); - updateOverviewImage(); } diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index c63fb3c..caa36fc 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -58,9 +58,9 @@ public abstract class OverviewDimensions protected int alheight; - protected int transX; + protected int fixedX; - protected int transY; + protected int fixedY; /** * Create an OverviewDimensions object diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index ec79954..513596e 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -41,7 +41,7 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions int vpx = Math.round((float) mousex * alwidth / width); int vpy = Math.round((float) mousey * alheight / sequencesHeight); - updateViewportFromTopLeft(vpx + transX, vpy + transY, hiddenSeqs, + updateViewportFromTopLeft(vpx + fixedX, vpy + fixedY, hiddenSeqs, hiddenCols); } @@ -173,8 +173,8 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions int vpy = Math.round((float) y * alheight / sequencesHeight); - transX = ranges.getStartRes() - vpx; - transY = ranges.getStartSeq() - vpy; + fixedX = ranges.getStartRes() - vpx; + fixedY = ranges.getStartSeq() - vpy; } diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index 4ab27de..efffe6f 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -69,7 +69,12 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions int xAsRes = getLeftXFromCentreX(mousex, hiddenCols); int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs); - updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols); + int visXAsRes = hiddenCols.findColumnPosition(xAsRes); + yAsSeq = hiddenSeqs.adjustForHiddenSeqs( + hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq)); + int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq); + + updateViewportFromTopLeft(visXAsRes, visYAsSeq, hiddenSeqs, hiddenCols); } @Override @@ -81,126 +86,31 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // coords, // convert back to pixel coords int vpx = Math.round((float) mousex * alwidth / width); - // int visXAsRes = hiddenCols.findColumnPosition(vpx); + int visXAsRes = hiddenCols.findColumnPosition(vpx) + fixedX; int vpy = Math.round((float) mousey * alheight / sequencesHeight); - // int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy); - - System.out.println("vpx: " + vpx); - // System.out.println("VisXAsRes: " + visXAsRes); - System.out.println("transX: " + transX); - // updateViewportFromTopLeft(vpx + transX, vpy + transY, - // hiddenSeqs, - // hiddenCols); - - int xAsRes = vpx + transX; - int yAsSeq = vpy + transY; - - resetAlignmentDims(); - - if (xAsRes < 0) - { - xAsRes = 0; - } - - if (yAsSeq < 0) - { - yAsSeq = 0; - } - - // - // Convert x value to residue position - // - - // need to determine where scrollCol should be, given x - // to do this also need to know width of viewport, and some hidden column - // correction - - // convert x to residues - this is an absolute position - // int xAsRes = Math.round((float) x * alwidth / width); - - // get viewport width in residues - int vpwidth = ranges.getViewportWidth(); - - // get where x should be when accounting for hidden cols - // if x is in a hidden col region, shift to left - but we still need - // absolute position - // so convert back after getting visible region position - // int visXAsRes = hiddenCols.findColumnPosition(xAsRes); - int visXAsRes = xAsRes; - - // check in case we went off the edge of the alignment - int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1); - /* if (visXAsRes + vpwidth - 1 > visAlignWidth) - { - // went past the end of the alignment, adjust backwards - - // if last position was before the end of the alignment, need to update - if (ranges.getEndRes() < visAlignWidth) - { - visXAsRes = hiddenCols.findColumnPosition(hiddenCols - .subtractVisibleColumns(vpwidth - 1, alwidth - 1)); - } - else - { - visXAsRes = ranges.getStartRes(); - } - }*/ - - // - // Convert y value to sequence position - // - - // convert y to residues - // int yAsSeq = Math.round((float) y * alheight / sequencesHeight); - - // get viewport height in sequences - int vpheight = ranges.getViewportHeight(); - - // get where y should be when accounting for hidden rows - // if y is in a hidden row region, shift up - but we still need absolute - // position, - // so convert back after getting visible region position - yAsSeq = hiddenSeqs.adjustForHiddenSeqs( - hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq)); - - // check in case we went off the edge of the alignment - int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight); - int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq); - if (visYAsSeq + vpheight - 1 > visAlignHeight) - { - // went past the end of the alignment, adjust backwards - if (ranges.getEndSeq() < visAlignHeight) - { - visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs( - hiddenSeqs.subtractVisibleRows(vpheight - 1, alheight - 1)); - } - else - { - visYAsSeq = ranges.getStartSeq(); - } - } + int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + fixedY; - // update viewport - ranges.setStartRes(visXAsRes); - ranges.setStartSeq(visYAsSeq); + updateViewportFromTopLeft(visXAsRes, visYAsRes, + hiddenSeqs, + hiddenCols); } @Override - protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq, + protected void updateViewportFromTopLeft(int visXAsRes, int visYAsSeq, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { resetAlignmentDims(); - if (xAsRes < 0) + if (visXAsRes < 0) { - xAsRes = 0; + visXAsRes = 0; } - if (yAsSeq < 0) + if (visYAsSeq < 0) { - yAsSeq = 0; + visYAsSeq = 0; } // @@ -221,7 +131,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // if x is in a hidden col region, shift to left - but we still need // absolute position // so convert back after getting visible region position - int visXAsRes = hiddenCols.findColumnPosition(xAsRes); + // check in case we went off the edge of the alignment int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1); @@ -255,12 +165,11 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // if y is in a hidden row region, shift up - but we still need absolute // position, // so convert back after getting visible region position - yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs - .findIndexWithoutHiddenSeqs(yAsSeq)); + // check in case we went off the edge of the alignment int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight); - int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq); + if (visYAsSeq + vpheight - 1 > visAlignHeight) { // went past the end of the alignment, adjust backwards @@ -305,6 +214,8 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq()); int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq()); + System.out.println("Update box: startres: " + startRes); + setBoxPosition(startRes, startSeq, endRes - startRes + 1, endSeq - startSeq + 1); } @@ -353,13 +264,11 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions { // 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); + fixedX = ranges.getStartRes() - hiddenCols.findColumnPosition(vpx); - transX = ranges.getStartRes() - visXAsRes; - transY = ranges.getStartSeq() - visYAsRes; + int vpy = Math.round((float) y * alheight / sequencesHeight); + fixedY = ranges.getStartSeq() + - hiddenSeqs.findIndexWithoutHiddenSeqs(vpy); } } -- 1.7.10.2