Speed of processing commands

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Speed of processing commands

AJBell
Dear list,

I am writing a plugin that copies small user selected regions of images and pastes them into new images, using the internal copy and paste functions. The user selects a region by a mouse click, which fires the copy and paste. When I run the plugin, there is a significant delay between the click and the paste, which is not present when the same commands are run separately. Presumably then the delay is caused by the mouse listener, and if this is the case, does anyone know if this delay can be reduced? The code i'm using is shown below.

Andrew Bell
University of Leicester

Relevant part of Mouse-listener from plugin (slow):

public void mousePressed(MouseEvent e) {
           ij.gui.ImageWindow.setNextLocation(location_x,location_y);
        int positionX = canvas.offScreenX(e.getX());
        int positionY = canvas.offScreenY(e.getY());
        IJ.makeRectangle(positionX-TOPEDGE,positionY-TOPEDGE ,WIDTH,HEIGHT);  //WIDTH, HEIGHT, and TOPEDGE (width/2) are defined as final during initialisation  
        IJ.run("Copy");
        IJ.run("Internal Clipboard");

//this section deals with where the pasted image is located on screen
        if(column_counter>5){
                column_counter=0;
                location_y=location_y+LOCATION_OFFSET;
                location_x=1280;
        } else {
                column_counter++;
                location_x=location_x+LOCATION_OFFSET;
        }
}

Seperate plugin (fast):
public class My_Plugin2 implements PlugIn {

        public void run(String arg) {
                ImagePlus imp = IJ.getImage();
                IJ.makeRectangle(200, 200, WIDTH,HEIGHT);  //same WIDTH/HEIGHT params as previously but a default location as not set on a mouse listener
                IJ.run("Copy");
                IJ.run("Internal Clipboard");
        }
}