|
Hi,
I want to put an ImageCanvas on a JPanel, to make an 'ImagePanel' (cfr
ImageWindow). However when I try the result, Polygon selection, Segmented
line selection, Freehand line, Freehand selection and Angle Tool, don't work
properly any more: when you drag the mouse, no lines appear as they should.
Only when I release the mousebutton, I get the shape. I really can't figure
out what the problem is, I've tried different implementations, looked at the
code of ImageCanvas and roi.handleMouseDrag,... but nothing works.
Can anyone help? Thanks in advance!
This is the code I'm using:
public class ImagePanel_Test3 implements PlugIn {
public void run(String arg) {
ImagePlus imagePlus = WindowManager.getCurrentImage();
ImagePanel panel = new ImagePanel (imagePlus);
JFrame frame = new JFrame ("Testframe");
frame.setSize (400,400);
frame.getContentPane().add(panel);
frame.setVisible (true);
}
class ImagePanel extends JPanel {
protected ImagePlus imagePlus;
protected ImageCanvas imageCanvas;
public ImagePanel (ImagePlus imp){
super();
imagePlus = imp;
imageCanvas = new ImageCanvas2(imp);
setLayout(new ImageLayout(imageCanvas));
add(imageCanvas);
}
}
class ImageCanvas2 extends ImageCanvas {
ImagePlus imagePlus;
public ImageCanvas2(ImagePlus imp) {
super (imp);
imagePlus = imp;
}
public void mouseMoved (MouseEvent e) {
super.mouseMoved(e);
super.repaint();
}
public void mouseDragged (MouseEvent e) {
super.mouseDragged(e);
super.repaint();
}
public void mousePressed (MouseEvent e){
super.mousePressed(e);
super.repaint();
}
public void mouseReleased (MouseEvent e){
super.mouseReleased(e);
super.repaint();
}
public void mouseClicked (MouseEvent e) {
super.mouseClicked(e);
super.repaint();
}
}
}
|