From: gmungoc Date: Wed, 20 Mar 2019 15:07:37 +0000 (+0000) Subject: JAL-3212 getAbsoluteColumn extracted from ScalePanel; todo: tests, reuse X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=241194eb1c6005d7507942625b872d653dea1395;p=jalview.git JAL-3212 getAbsoluteColumn extracted from ScalePanel; todo: tests, reuse --- diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index bc668fd..82dcacd 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1043,4 +1043,47 @@ public class AlignViewport extends AlignmentViewport { this.viewName = viewName; } + + /** + * Answers the absolute column position (0..) (allowing for any hidden + * columns) for the given x position in the viewport. The position is + * restricted to the currently visible range, and to the width of the + * alignment. This method is not applicable, and throws an exception if + * called, if the view is in wrapped mode.
+ * Example + * + * + * @param xPos + * @return + * @throw IllegalStateException + */ + public int getAbsoluteColumn(int xPos) + { + if (getWrapAlignment()) + { + throw new IllegalStateException("Not valid in wrapped mode"); + } + int xCords = Math.max(0, xPos); // treat negative X as zero + int res = (xCords / getCharWidth()) + ranges.getStartRes(); + res = Math.min(res, ranges.getEndRes()); + if (hasHiddenColumns()) + { + res = getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res); + } + res = Math.max(0, res); + return res; + } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index b392c8f..5e7e4a0 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -278,17 +278,8 @@ public class ScalePanel extends JPanel mouseDragging = false; ap.getSeqPanel().stopScrolling(); - int xCords = Math.max(0, evt.getX()); // prevent negative X coordinates - ViewportRanges ranges = av.getRanges(); - int res = (xCords / av.getCharWidth()) - + ranges.getStartRes(); - res = Math.min(res, ranges.getEndRes()); - if (av.hasHiddenColumns()) - { - res = av.getAlignment().getHiddenColumns() - .visibleToAbsoluteColumn(res); - } - res = Math.max(0, res); + int xPos = evt.getX(); + int res = av.getAbsoluteColumn(xPos); if (!stretchingGroup) {