Posted by
Michael Schmid on
Jun 22, 2009; 4:18pm
URL: http://imagej.273.s1.nabble.com/dragging-an-big-image-tp3691912p3691913.html
Hi Michael,
you need a listener to 'mouse dragged' events and a second background
thread that moves the image and loads the missing parts (interface
Runnable).
Here is a rough concept:
public class LargeImageViewer implements MouseListener,
MouseMotionListener, Runnable {
//Class vars
x0, y0; //position of mouse down
deltaX, deltaY; //how much the image has been dragged
Thread backgroundThread;
in constructor (or setup if plugin):
get foreground image, get canvas thereof
canvas.addMouseListener(this);
canvas.addMouseMotionListener(this);
destructor, mouseReleased, close or whereever:
canvas.removeMouseListener(this);
canvas.removeMouseMotionListener(this);
public void MouseDragged(MouseEvent e) {
deltaX = e.getX()-x0;
deltaY = e.getY()-y0;
synchronized(this) {notify();}
}
public void mousePressed ...
record x0, y0
backgroundThread = new Thread(this, "ImageDragger");
backgroundThread.start();
public void mouseReleased ...
backgroundThread.interrupt();
public void run() {
while (true) { //i.e., while mouse down
update display(deltaX, deltaY);
synchronized(this) {
try {wait();}
catch(InterruptedException) {return;}
}
}
}
Michael
________________________________________________________________
On 22 Jun 2009, at 16:49, Michael Strupp wrote:
> Hello ImageJ community
>
> I'm writing a plugin for imagej, to view some images that are much
> larger than the windowsize and the RAM. The plugin only loads the
> parts of the image which are currently displayed in the viewer. I
> overwrote the drag tool from imagej to navigate, so I can see all
> parts of the image, which get loaded after the user navigated.
> This all works fine so far, but now I want to improve the usability
> of the plugin. The problem is, that the image does not move while
> the user drags the image, instead it waits some seconds and then
> the new image part gets shown.
>
> I hope some people here have experience with such a problem.
>
> Kind regards,
> Michael