Skip to content

Commit

Permalink
modify GUI from consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 3, 2024
1 parent cae6b94 commit 441af69
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
6 changes: 0 additions & 6 deletions src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/ai/nets/samj/ij/ui/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
/**
Expand Down Expand Up @@ -173,7 +178,6 @@ public void exportImageLabeling() {

@Override
public void activateListeners() {
System.out.println("mm");
if (registered) return;
activeCanvas.addMouseListener(this);
activeCanvas.addKeyListener(this);
Expand All @@ -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;
Expand Down Expand Up @@ -611,6 +622,16 @@ void addToRoiManager(final List<Mask> 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) {}
Expand Down

0 comments on commit 441af69

Please sign in to comment.