I’m reviving an ImageJ Java plugin from 2020.  It  uses a KeyListener.
The new build does not get any keypresses.  I’ve looked at the current  
documentation, and can’t find a problem.  The plugin is fairly large.  I’ll try 
to make a minimal version - but would be happy to share it on my  ImageJ Update 
Site (see below).

Remember - this plugin worked fine in 2020, but now fails.

Here is what I think is the relevant code:

        // listen to keyboard - stop IJ from listening!
        win = ipl.getWindow();  // delayed until we are SURE it's visible
        IJ.log("win = "+win);
        canvas = win.getCanvas();
        IJ.log("canvas = "+canvas);
        win.removeKeyListener(IJ.getInstance());
        canvas.removeKeyListener(IJ.getInstance());
        IJ.log("removed IJ Listeners");
        win.addKeyListener(this);
        canvas.addKeyListener(this);
        ImagePlus.addImageListener(this);
        IJ.log("added Listeners");

…

        win.requestFocus();
        IJ.log("sampling...”);
        category = sampleAt(xList.get(currentSamplePoint),
                                            yList.get(currentSamplePoint));
        IJ.log("sampled”);

…

        while(true)
            {
                synchronized(this)
                    {
                        IJ.log("waiting...");
                        wait(); // keyPressed wakes us
                        IJ.log("woken up!");
                    }

…

                // key pressed!
                // keyCode, keyChar, and modifiers are current
                If(keyCode == KeyEvent.VK_SPACE) return -1; // DELETE does not 
work
                if(keyCode == KeyEvent.VK_ENTER) return -2; // no mas!
                int category = keyCode - KeyEvent.VK_1; // 1-based keys; 
0-based category
                if(category < 0) continue; // try again!
                if(category >= choices.length) continue; // try again!
                return category; // good category!
            }
...
    @Override
        public void keyPressed(KeyEvent e) 
    {
        IJ.log("keyPressed");
        keyCode = e.getKeyCode();
        keyChar = e.getKeyChar();
        modifiers = e.getModifiers();
        IJ.log("   "+keyCode+"   "+keyChar+"   "+modifiers);
        synchronized(this)
            {
                IJ.log("notifying");
                notify();
                IJ.log("notified");
            }
    }

And here is the IJ Log:

win = 16385_175994_R_IR_OCT_20120429-09_8C3F4720.bmp
canvas = ij.gui.ImageCanvas[canvas1,5,44,384x496]
removed IJ Listeners
added Listeners
sampling...
sampleAt(90.05, 63.05)
waiting...

It looks to me as if we  “wait” and then never get a KeyPress event.

When I press keys, I seem to get the usual ImageJ responses (does this mean 
that the IJ Listeners were NOT removed?



Update site: CreativeComputation
Plugin name: AVL_Area_Fraction

—
Kenneth Sloan
[email protected]
Vision is the art of seeing what is invisible to others.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Reply via email to