From 8e44580cbe978f1570d4d2ac13d3dd7cd470ecf7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 May 2014 15:39:13 -0700 Subject: altosuilib: Add distance measuring line to site map. Use any modifier or button other than the left one to draw a line on the map. The length of the line is shown at the start of the line. Signed-off-by: Keith Packard --- altosuilib/GrabNDrag.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'altosuilib/GrabNDrag.java') diff --git a/altosuilib/GrabNDrag.java b/altosuilib/GrabNDrag.java index 5e5fdd52..4426f7a3 100644 --- a/altosuilib/GrabNDrag.java +++ b/altosuilib/GrabNDrag.java @@ -33,16 +33,23 @@ class GrabNDrag extends MouseInputAdapter { scroll.setAutoscrolls(true); } + public static boolean grab_n_drag(MouseEvent e) { + return e.getModifiers() == InputEvent.BUTTON1_MASK; + } + public void mousePressed(MouseEvent e) { - startPt.setLocation(e.getPoint()); + if (grab_n_drag(e)) + startPt.setLocation(e.getPoint()); } public void mouseDragged(MouseEvent e) { - int xd = e.getX() - startPt.x; - int yd = e.getY() - startPt.y; + if (grab_n_drag(e)) { + int xd = e.getX() - startPt.x; + int yd = e.getY() - startPt.y; - Rectangle r = scroll.getVisibleRect(); - r.x -= xd; - r.y -= yd; - scroll.scrollRectToVisible(r); + Rectangle r = scroll.getVisibleRect(); + r.x -= xd; + r.y -= yd; + scroll.scrollRectToVisible(r); + } } } -- cgit v1.2.3