diff --git a/src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java b/src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java index ad95587..2c20aac 100644 --- a/src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java +++ b/src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java @@ -19,19 +19,13 @@ */ package ai.nets.samj.ij; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.io.IOException; -import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.SwingUtilities; -import ai.nets.samj.communication.model.SAMModels; import ai.nets.samj.gui.MainGUI; import ai.nets.samj.ui.SAMJLogger; import ij.ImageJ; -import ij.ImagePlus; import ij.gui.GUI; import ij.plugin.PlugIn; import ai.nets.samj.ij.ui.Consumer; diff --git a/src/main/java/ai/nets/samj/ij/ui/Consumer.java b/src/main/java/ai/nets/samj/ij/ui/Consumer.java index bca66f9..abd8213 100644 --- a/src/main/java/ai/nets/samj/ij/ui/Consumer.java +++ b/src/main/java/ai/nets/samj/ij/ui/Consumer.java @@ -23,6 +23,7 @@ import ai.nets.samj.models.AbstractSamJ; import ai.nets.samj.ui.ConsumerInterface; import ij.IJ; +import ij.IJEventListener; import ij.ImagePlus; import ij.Prefs; import ij.WindowManager; @@ -52,7 +53,7 @@ * * @author Carlos Garcia Lopez de Haro */ -public class Consumer extends ConsumerInterface implements MouseListener, KeyListener, WindowListener { +public class Consumer extends ConsumerInterface implements MouseListener, KeyListener, WindowListener, IJEventListener { /** * The image being processed */ @@ -130,6 +131,10 @@ public class Consumer extends ConsumerInterface implements MouseListener, KeyLis * Whether the SAMJ specific listeners are registered or not. */ private boolean registered = false; + + public Consumer() { + IJ.addEventListener(this); + } @Override /** @@ -173,7 +178,6 @@ public void exportImageLabeling() { @Override public void activateListeners() { - System.out.println("mm"); if (registered) return; activeCanvas.addMouseListener(this); activeCanvas.addKeyListener(this); @@ -199,6 +203,13 @@ public void deactivateListeners() { registered = false; } + @Override + public boolean isValidPromptSelected() { + return Toolbar.getToolName().equals("rectangle") + || Toolbar.getToolName().equals("point") + || Toolbar.getToolName().equals("multipoint"); + } + @Override public void setFocusedImage(Object image) { activeImage = (ImagePlus) image; @@ -611,6 +622,16 @@ void addToRoiManager(final List polys, final String promptShape) { this.annotatedMask.push(polys); } + @Override + public void eventOccurred(int eventID) { + if (eventID != IJEventListener.TOOL_CHANGED) + return; + boolean isvalid = IJ.getToolName().equals("rectangle") + || IJ.getToolName().equals("point") + || IJ.getToolName().equals("multipoint"); + this.callback.validPromptChosen(isvalid); + } + // ===== unused events ===== @Override public void mouseEntered(MouseEvent e) {}