getCounter multipoint tool java

Hi,

I’m making a plugin where I want to measure the amount of (user-defined) point selection in an image. I created a KeyListener which will measure the amount of selected points (using the crosshair/multi-point tool). However, when I’m running the script, the result table ends up with several lines with line number 1 (independent from the amount of points I add). When I use the getCounter() function I always get the result 2. Does anybody know what I’m doing wrong and what I’ve to chance?

This is my code;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import ij.IJ;
import ij.ImagePlus;
import ij.gui.Toolbar;
import ij.plugin.filter.Analyzer;

public class AddKeyListener implements KeyListener {
    ImagePlus imp;

    public AddKeyListener(ImagePlus ip) {
        imp = IJ.getImage();
        imp.show();
        imp.getCanvas().addKeyListener(this);
        imp.getCanvas().setFocusable(true);
    }

    public void processBefore() {
        Toolbar a = new Toolbar();
        a.setTool(Toolbar.CROSSHAIR); //selects the multi-point tool

    }

    public void processAfter() {
        Analyzer analysis = new Analyzer(imp);
        analysis.measure();
        System.out.println(analysis.getCounter()); // get amount of selections?



        // remove this key listener to be safe
        imp.getCanvas().removeKeyListener(this);
    }

    public void run() {
        processBefore();
        // process After is called on keypress
    }

    @Override
    public void keyTyped(KeyEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
    }

    @Override
    public void keyReleased(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_SPACE) {
            processAfter();
        }
    }
}

My resultstable looks like this

Area Mean StdDev Min Max X Y Slice
1 0 0 0 0 0 59.669 36.752 1
1 0 5 0 5 5 66.154 33.726 1
1 0 77 0 77 77 73.289 33.726 1
1 0 0 0 0 0 81.504 36.536 1
1 0 1 0 1 1 78.045 40.644 1
amount of crosshairs = 2