sclass ImageSurfaceDragger extends ImageSurfaceMouseHandler { sbool debug = true; Point start, startScroll; int dx, dy; *() {} *(ImageSurface is) { if (containsInstance(is.tools, ImageSurfaceDragger)) ret; this.register(is); } public void mousePressed(MouseEvent e) { JScrollPane sp = enclosingScrollPane(is); if (sp == null) ret; if (e.getButton() == MouseEvent.BUTTON1) { start = e.getLocationOnScreen(); startScroll = new Point( scrollBarValue(sp.getHorizontalScrollBar()), scrollBarValue(sp.getVerticalScrollBar())); } } public void mouseDragged(MouseEvent e) { if (start == null) ret; JScrollPane sp = enclosingScrollPane(is); if (sp == null) ret; Point p = e.getLocationOnScreen(); //if (debug) print("ImageSurfaceDragger: drag " + p.x + "/" + p.y); setScrollBarValue(sp.getHorizontalScrollBar(), -(p.x-start.x)+startScroll.x); setScrollBarValue(sp.getVerticalScrollBar(), -(p.y-start.y)+startScroll.y); } public void mouseReleased(MouseEvent e) { mouseDragged(e); start = null; } }