Skip to content

Commit d91f6ea

Browse files
committed
fix mouseClick problem in whole-genome view. Click now defined as press & release within 5 pixel radius, as opposed to 1 pixel radius
1 parent 2eb7112 commit d91f6ea

File tree

2 files changed

+59
-40
lines changed

2 files changed

+59
-40
lines changed

src/main/java/org/broad/igv/ui/panel/DataPanel.java

-3
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ public class DataPanel extends JComponent implements Paintable, IGVEventObserver
8080
// Thread pool for loading data
8181
private static final ExecutorService threadExecutor = Executors.newFixedThreadPool(5);
8282

83-
private boolean isWaitingForToolTipText = false;
84-
8583
private DataPanelTool defaultTool;
8684
private DataPanelTool currentTool;
87-
// private Point tooltipTextPosition;
8885
private ReferenceFrame frame;
8986
private DataPanelContainer parent;
9087
private DataPanelPainter painter;

src/main/java/org/broad/igv/ui/panel/RulerPanel.java

+59-37
Original file line numberDiff line numberDiff line change
@@ -348,31 +348,7 @@ private void init() {
348348

349349
MouseInputAdapter mouseAdapter = new MouseInputAdapter() {
350350

351-
int lastMousePressX;
352-
353-
@Override
354-
public void mouseClicked(MouseEvent evt) {
355-
final MouseEvent e = evt;
356-
setCursor(Cursor.getDefaultCursor());
357-
WaitCursorManager.CursorToken token = WaitCursorManager.showWaitCursor();
358-
try {
359-
360-
if (!isWholeGenomeView()) {
361-
double newLocation = frame.getChromosomePosition(e.getX());
362-
frame.centerOnLocation(newLocation);
363-
} else {
364-
for (final ClickLink link : chromosomeRects) {
365-
if (link.region.contains(e.getPoint())) {
366-
final String chrName = link.value;
367-
frame.changeChromosome(chrName, true);
368-
}
369-
}
370-
}
371-
} finally {
372-
WaitCursorManager.removeWaitCursor(token);
373-
}
374-
375-
}
351+
private MouseEvent mouseDown;
376352

377353
@Override
378354
public void mouseMoved(MouseEvent e) {
@@ -410,7 +386,6 @@ public void mouseEntered(MouseEvent e) {
410386

411387
}
412388

413-
414389
@Override
415390
public void mouseDragged(MouseEvent e) {
416391
if (Math.abs(e.getPoint().getX() - dragStart) > 1) {
@@ -420,24 +395,71 @@ public void mouseDragged(MouseEvent e) {
420395
}
421396
}
422397

423-
@Override
424-
public void mousePressed(MouseEvent e) {
425-
dragStart = e.getX();
398+
@Override
399+
public void mousePressed(final MouseEvent e) {
400+
if (e.isPopupTrigger()) {
401+
// ignore
402+
}
403+
else {
404+
dragStart = e.getX();
405+
mouseDown = e;
406+
}
426407
}
427408

409+
428410
@Override
429411
public void mouseReleased(MouseEvent e) {
430-
if (dragging) {
431-
dragEnd = e.getX();
432-
dragging = false;
433-
zoom();
412+
if (e.isPopupTrigger()) {
413+
// ignore
414+
} else {
415+
if (dragging) {
416+
dragEnd = e.getX();
417+
dragging = false;
418+
zoom();
419+
} else {
420+
if (mouseDown != null && distance(mouseDown, e) < 5) {
421+
doMouseClick(e);
422+
}
423+
}
434424
}
435425
}
436426

437-
//@Override
438-
//public void mouseExited(MouseEvent e) {
439-
//dragging = false;
440-
//}
427+
private double distance(MouseEvent e1, MouseEvent e2) {
428+
double dx = e1.getX() - e2.getX();
429+
double dy = e1.getY() - e2.getY();
430+
return Math.sqrt(dx*dx + dy*dy);
431+
}
432+
433+
434+
/**
435+
* mouseClick is not used because in Java a mouseClick is emitted ONLY if the mouse has not moved
436+
* between press and release. This is really difficult to achieve, even if trying.
437+
*
438+
* @param evt
439+
*/
440+
public void doMouseClick(MouseEvent evt) {
441+
final MouseEvent e = evt;
442+
setCursor(Cursor.getDefaultCursor());
443+
WaitCursorManager.CursorToken token = WaitCursorManager.showWaitCursor();
444+
try {
445+
446+
if (!isWholeGenomeView()) {
447+
double newLocation = frame.getChromosomePosition(e.getX());
448+
frame.centerOnLocation(newLocation);
449+
} else {
450+
for (final ClickLink link : chromosomeRects) {
451+
if (link.region.contains(e.getPoint())) {
452+
final String chrName = link.value;
453+
frame.changeChromosome(chrName, true);
454+
}
455+
}
456+
}
457+
} finally {
458+
WaitCursorManager.removeWaitCursor(token);
459+
}
460+
461+
}
462+
441463
};
442464

443465
addMouseMotionListener(mouseAdapter);

0 commit comments

Comments
 (0)