From: James Procter Date: Wed, 1 Nov 2023 16:23:30 +0000 (+0000) Subject: JAL-4260 encapsulate logic for resolving nearest column and do better using it in... X-Git-Tag: Release_2_11_4_0~122^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=373ea2f39547c5432fc2922e5d958e1955de14e8;p=jalview.git JAL-4260 encapsulate logic for resolving nearest column and do better using it in wrapped mode for drags/clicks/popups on alignment --- diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 4365845..a186ce6 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -107,11 +107,7 @@ public class ScalePanel extends JPanel @Override public void mousePressed(MouseEvent evt) { - int res = ap.getSeqPanel().findColumn(evt); - - if (res==-1) { - return; - } + int res = ap.getSeqPanel().findAlignmentColumn(evt); min = res; max = res; @@ -283,15 +279,10 @@ public class ScalePanel extends JPanel mouseDragging = false; ap.getSeqPanel().stopScrolling(); - int res = ap.getSeqPanel().findColumn(evt); + int res = ap.getSeqPanel().findAlignmentColumn(evt); if (!stretchingGroup) { - if (res==-1) - { - return; - } - if (evt.isPopupTrigger()) // Windows: mouseReleased { rightMouseButtonPressed(evt, res); @@ -305,7 +296,7 @@ public class ScalePanel extends JPanel SequenceGroup sg = av.getSelectionGroup(); - if (res != -1 && sg != null) + if (sg != null) { if (res > sg.getStartRes()) { @@ -342,15 +333,14 @@ public class ScalePanel extends JPanel @Override public void mouseDragged(MouseEvent evt) { + mouseDragging = true; + int res = ap.getSeqPanel().findAlignmentColumn(evt); - int res = ap.getSeqPanel().findColumn(evt); - if (res==-1) { - return; - } - mouseDragging = true; ColumnSelection cs = av.getColumnSelection(); - min = Math.min(res, min); + + min = Math.min(res,min); max = Math.max(res, max); + SequenceGroup sg = av.getSelectionGroup(); if (sg != null) { @@ -399,19 +389,18 @@ public class ScalePanel extends JPanel { this.setToolTipText(null); reveal = null; - final int res = ap.getSeqPanel().findColumn(evt); - - if (res==-1) - { - return; - } + final int res = ap.getSeqPanel().findAlignmentColumn(evt); highlightAllStructPos(res); if (!av.hasHiddenColumns()) { return; } reveal = av.getAlignment().getHiddenColumns() - .getRegionWithEdgeAtRes(res); + .getRegionWithEdgeAtRes(av.getAlignment().getHiddenColumns().absoluteToVisibleColumn(res)); + if (reveal==null) + { + return; + } ToolTipManager.sharedInstance().registerComponent(this); this.setToolTipText( MessageManager.getString("label.reveal_hidden_columns")); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index ce60be6..d39f937 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -343,6 +343,14 @@ public class SeqPanel extends JPanel } /** + * @param evt + * @return absolute column in alignment nearest to the mouse pointer + */ + int findAlignmentColumn(MouseEvent evt) + { + return findNearestColumn(evt,true); + } + /** * Returns the aligned sequence position (base 0) at the mouse position, or * the closest visible one *

@@ -354,6 +362,15 @@ public class SeqPanel extends JPanel */ int findColumn(MouseEvent evt) { + return findNearestColumn(evt, false); + } + + /** + * @param nearestColumn when false returns negative values for out of bound positions - -1 for scale left/right, <-1 if far to right + * @return nearest absolute column to mouse pointer + */ + private int findNearestColumn(MouseEvent evt, boolean nearestColumn) + { int res = 0; int x = evt.getX(); @@ -377,7 +394,11 @@ public class SeqPanel extends JPanel if (x < 0) { // mouse is over left scale - return -1; + if (!nearestColumn) { + return -1; + } else { + x = 0; + } } int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth()); @@ -387,8 +408,12 @@ public class SeqPanel extends JPanel } if (x >= cwidth * charWidth) { - // mouse is over right scale - return -1; + if (!nearestColumn) { + // mouse is over right scale + return -1; + } else { + x = cwidth*charWidth -1; + } } wrappedBlock = y / cHeight; @@ -405,9 +430,16 @@ public class SeqPanel extends JPanel * rather than right-hand gutter */ x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth()); + if (nearestColumn) + { + x = Math.max(x, 0); + } + res = (x / charWidth) + startRes; res = Math.min(res, av.getRanges().getEndRes()); + } + if (av.hasHiddenColumns()) { diff --git a/test/jalview/gui/ScalePanelTest.java b/test/jalview/gui/ScalePanelTest.java index 1523741..20e72b9 100644 --- a/test/jalview/gui/ScalePanelTest.java +++ b/test/jalview/gui/ScalePanelTest.java @@ -64,6 +64,10 @@ public class ScalePanelTest ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel(); MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, 4, 0, 1, false); + + // check the bounded lookup is not returning negatives + assertEquals(alignFrame.alignPanel.getSeqPanel().findAlignmentColumn(mouse),0); + scalePanel.mousePressed(mouse); scalePanel.mouseDragged(mouse); diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index 4e8758b..d47df46 100644 --- a/test/jalview/gui/SeqPanelTest.java +++ b/test/jalview/gui/SeqPanelTest.java @@ -789,7 +789,7 @@ public class SeqPanelTest } @Test(groups = "Functional") - public void testFindColumn_wrapped() + public void testFindColumn_and_FindAlignmentColumn_wrapped() { Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true"); AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( @@ -811,6 +811,7 @@ public class SeqPanelTest MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); assertEquals(testee.findColumn(evt), 0); + assertEquals(testee.findAlignmentColumn(evt), 0); /* * not quite one charWidth across @@ -819,6 +820,7 @@ public class SeqPanelTest evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); assertEquals(testee.findColumn(evt), 0); + assertEquals(testee.findAlignmentColumn(evt), 0); /* * one charWidth across @@ -827,6 +829,7 @@ public class SeqPanelTest evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); assertEquals(testee.findColumn(evt), 1); + assertEquals(testee.findAlignmentColumn(evt), 1); /* * x over scale left (before drawn columns) results in -1 @@ -840,11 +843,15 @@ public class SeqPanelTest evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); assertEquals(testee.findColumn(evt), -1); + assertEquals(testee.findAlignmentColumn(evt), 0); + x = labelWidth; evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); assertEquals(testee.findColumn(evt), 0); + assertEquals(testee.findAlignmentColumn(evt), 0); + /* * x over right edge of last residue (including scale left) @@ -855,6 +862,8 @@ public class SeqPanelTest evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); assertEquals(testee.findColumn(evt), residuesWide - 1); + assertEquals(testee.findAlignmentColumn(evt), residuesWide-1); + /* * x over scale right (beyond drawn columns) results in -1 @@ -869,7 +878,11 @@ public class SeqPanelTest x += 1; // just over left edge of scale right evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0, false, 0); + // on scale assertEquals(testee.findColumn(evt), -1); + // return right-most column visible + assertEquals(testee.findAlignmentColumn(evt), residuesWide2-1); + // todo add startRes offset, hidden columns