diff options
author | Keith Packard <keithp@keithp.com> | 2014-05-25 20:55:11 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2014-05-25 20:56:48 -0700 |
commit | 0a6c76fc0525d6588a1d88127f0085f13a02f1af (patch) | |
tree | d7cf76748c86522708b0826237eb031f371e349d /altosuilib/GrabNDrag.java | |
parent | 4ac7797d3efb9cc2d9fae88519f55e40b1050224 (diff) |
altosui/altosuilib/altoslib: Move more stuff out of autosui. Reduce site map memory
Prepare to share with TeleGPS application.
This also has the changes to the site map tile which cache only a few
images and regenerate the flight path on the fly, saving piles of memory
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosuilib/GrabNDrag.java')
-rw-r--r-- | altosuilib/GrabNDrag.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/altosuilib/GrabNDrag.java b/altosuilib/GrabNDrag.java new file mode 100644 index 00000000..5e5fdd52 --- /dev/null +++ b/altosuilib/GrabNDrag.java @@ -0,0 +1,48 @@ +/* + * Copyright © 2010 Anthony Towns <aj@erisian.com.au> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altosuilib_2; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; + +class GrabNDrag extends MouseInputAdapter { + private JComponent scroll; + private Point startPt = new Point(); + + public GrabNDrag(JComponent scroll) { + this.scroll = scroll; + scroll.addMouseMotionListener(this); + scroll.addMouseListener(this); + scroll.setAutoscrolls(true); + } + + public void mousePressed(MouseEvent e) { + startPt.setLocation(e.getPoint()); + } + public void mouseDragged(MouseEvent 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); + } +} |