Skip to content

Commit

Permalink
keep improving
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 22, 2024
1 parent d234d93 commit 02eefb0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
30 changes: 5 additions & 25 deletions src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
import javax.swing.SwingUtilities;

import ai.nets.samj.communication.model.SAMModels;
import ai.nets.samj.gui.SAMJDialog;
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.IJ1PromptsProvider;
import ai.nets.samj.ij.ui.IJSamMethods;
import ai.nets.samj.ij.ui.Consumer;

// TODO I (Carlos) don't know how to develop in IJ2 @Plugin(type = Command.class, menuPath = "Plugins>SAMJ>Annotator")
//TODO I (Carlos) don't know how to develop in IJ2 public class Plugin_SamJAnnotator implements Command {
Expand All @@ -61,9 +60,6 @@ public void run() throws IOException, InterruptedException {

// TODO I (Carlos) don't know how to develop in IJ2 final Logger log = logService.subLogger("SAMJ");
try {

//get list of recognized installations of SAM(s)
final SAMModels availableModels = new SAMModels();

// TODO I (Carlos) don't know how to develop in IJ2 Logger guiSublogger = log.subLogger("PromptsResults window");
SAMJLogger guilogger = new SAMJLogger() {
Expand All @@ -87,26 +83,10 @@ public void run() throws IOException, InterruptedException {


SwingUtilities.invokeLater(() -> {
SAMJDialog samjDialog = new SAMJDialog( availableModels, new IJSamMethods(), guilogger, networkLogger);
//create the GUI adapter between the user inputs/prompts and SAMJ outputs
samjDialog.setPromptsProvider((obj) -> {return new IJ1PromptsProvider((ImagePlus) obj, null);});// TODO log.subLogger("PromptsResults window"));});

JDialog dialog = new JDialog(new JFrame(), "SAMJ Annotator");
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
samjDialog.close();
}
});
dialog.add(samjDialog);
dialog.pack();
dialog.setResizable(false);
dialog.setModal(false);
dialog.setVisible(true);
GUI.center(dialog);
});
MainGUI samjDialog = new MainGUI(new Consumer());
GUI.center(samjDialog);
});
} catch (RuntimeException e) {
//TODO log.error("SAMJ error: "+e.getMessage());
e.printStackTrace();
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/ai/nets/samj/ij/ui/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class Consumer extends ConsumerInterface implements MouseListener, KeyLis
*/
public List<ComboBoxItem> getListOfOpenImages() {
return Arrays.stream(WindowManager.getImageTitles())
.map(title -> new IJComboBoxItem(WindowManager.getImage(title).getID(), (Object) WindowManager.getImage(title)))
.map(title -> new IJComboBoxItem((Object) WindowManager.getImage(title)))
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -165,12 +165,13 @@ public void exportImageLabeling() {
public void activateListeners() {
if (registered) return;
SwingUtilities.invokeLater(() -> {
activeCanvas.removeKeyListener(IJ.getInstance());
activeWindow.removeKeyListener(IJ.getInstance());
activeCanvas.addMouseListener(this);
activeCanvas.addKeyListener(this);
activeWindow.addWindowListener(this);
activeWindow.addKeyListener(this);

activeCanvas.removeKeyListener(IJ.getInstance());
activeWindow.removeKeyListener(IJ.getInstance());
});
registered = true;
}
Expand All @@ -193,10 +194,19 @@ public void deactivateListeners() {
@Override
public void setFocusedImage(Object image) {
activeImage = (ImagePlus) image;
this.activeCanvas = this.activeImage.getCanvas();
this.activeWindow = this.activeImage.getWindow();
if (this.isAddingToRoiManager)
startRoiManager();
}

@Override
public void deselectImage() {
activeImage = null;
this.activeCanvas = null;
this.activeWindow = null;
}

@Override
/**
* when the plugin is closed, close everything
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/ai/nets/samj/ij/ui/IJComboBoxItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Cast;
import net.imglib2.view.Views;

/**
* Implementation of the SAMJ interface {@link ComboBoxItem} that provides the SAMJ GUI
Expand All @@ -42,14 +41,11 @@ public class IJComboBoxItem extends ComboBoxItem {
*
* Combobox item that contains an Object associated to a unique identifier.
* For ImageJ the object is an ImageJ {@link ImagePlus}
* @param uniqueID
* unique indentifier of the combobox element to avoid confusion when there are two images
* with the same name
* @param seq
* the object of interest, whihc in the case of ImageJ is and {@link ImagePlus}
*/
public IJComboBoxItem(int uniqueID, Object seq) {
super(uniqueID, seq);
public IJComboBoxItem(Object seq) {
super(seq);
}

/**
Expand Down

0 comments on commit 02eefb0

Please sign in to comment.