@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;
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);
SequenceGroup sg = av.getSelectionGroup();
- if (res != -1 && sg != null)
+ if (sg != null)
{
if (res > sg.getStartRes())
{
@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)
{
{
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"));
}
/**
+ * @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
* <p>
*/
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();
if (x < 0)
{
// mouse is over left scale
- return -1;
+ if (!nearestColumn) {
+ return -1;
+ } else {
+ x = 0;
+ }
}
int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
}
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;
* 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())
{
}
@Test(groups = "Functional")
- public void testFindColumn_wrapped()
+ public void testFindColumn_and_FindAlignmentColumn_wrapped()
{
Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
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
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
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
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)
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
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