From 241194eb1c6005d7507942625b872d653dea1395 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 20 Mar 2019 15:07:37 +0000 Subject: [PATCH] JAL-3212 getAbsoluteColumn extracted from ScalePanel; todo: tests, reuse --- src/jalview/gui/AlignViewport.java | 43 ++++++++++++++++++++++++++++++++++++ src/jalview/gui/ScalePanel.java | 13 ++--------- 2 files changed, 45 insertions(+), 11 deletions(-) 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) { -- 1.7.10.2