@@ -348,31 +348,7 @@ private void init() {
348
348
349
349
MouseInputAdapter mouseAdapter = new MouseInputAdapter () {
350
350
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 ;
376
352
377
353
@ Override
378
354
public void mouseMoved (MouseEvent e ) {
@@ -410,7 +386,6 @@ public void mouseEntered(MouseEvent e) {
410
386
411
387
}
412
388
413
-
414
389
@ Override
415
390
public void mouseDragged (MouseEvent e ) {
416
391
if (Math .abs (e .getPoint ().getX () - dragStart ) > 1 ) {
@@ -420,24 +395,71 @@ public void mouseDragged(MouseEvent e) {
420
395
}
421
396
}
422
397
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
+ }
426
407
}
427
408
409
+
428
410
@ Override
429
411
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
+ }
434
424
}
435
425
}
436
426
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
+
441
463
};
442
464
443
465
addMouseMotionListener (mouseAdapter );
0 commit comments