Skip to content

Commit

Permalink
better listen to IJ events
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed May 31, 2024
1 parent 717d002 commit 76a4139
Showing 1 changed file with 20 additions and 41 deletions.
61 changes: 20 additions & 41 deletions src/main/java/ai/nets/samj/ij/ui/IJ1PromptsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ai.nets.samj.ij.ui;

import ij.IJ;
import ij.IJEventListener;
import ij.ImagePlus;
import ij.Prefs;
import ij.process.ByteProcessor;
Expand Down Expand Up @@ -79,7 +80,7 @@
* @author Vladimir Ulman
* @author Carlos Garcia
*/
public class IJ1PromptsProvider implements PromptsResultsDisplay, MouseListener, KeyListener, WindowListener {
public class IJ1PromptsProvider implements PromptsResultsDisplay, MouseListener, KeyListener, WindowListener, IJEventListener {
/**
* The image being processed
*/
Expand Down Expand Up @@ -150,18 +151,6 @@ public class IJ1PromptsProvider implements PromptsResultsDisplay, MouseListener,
* All the points being collected that reference the background (ctrl + alt)
*/
private List<Localizable> collecteNegPoints = new ArrayList<Localizable>();
/**
* Consumer to alter the state of the Rectangle ROI button
*/
private BooleanConsumer rectIconConsumer;
/**
* Consumer to alter the state of the Points ROI button
*/
private BooleanConsumer pointsIconConsumer;
/**
* Consumer to alter the state of the Freeline ROI button
*/
private BooleanConsumer freelineIconConsumer;
/**
* The number of words per line in the error message dialogs
*/
Expand Down Expand Up @@ -339,6 +328,7 @@ private void registerListeners() {
activeCanvas.addMouseListener(this);
activeCanvas.addKeyListener(this);
activeWindow.addWindowListener(this);
IJ.addEventListener(this);
}

/**
Expand All @@ -357,19 +347,6 @@ private void deRegisterListeners() {
*/
public void mouseReleased(MouseEvent e) {
if (!this.isRect && !this.isPoints && !this.isFreehand) return;
if (this.isRect && !IJ.getToolName().equals("rectangle")) {
this.rectIconConsumer.accept(false);
this.isRect = false;
return;
} else if (this.isPoints && !IJ.getToolName().equals("point") && !IJ.getToolName().equals("multipoint")) {
this.isPoints = false;
this.pointsIconConsumer.accept(false);
return;
} else if (this.isFreehand && !IJ.getToolName().equals("freeline")) {
this.freelineIconConsumer.accept(false);
this.isFreehand = false;
return;
}
final Roi roi = activeImage.getRoi();
if (roi == null) {
//TODO log.info("Image window: There's no ROI...");
Expand Down Expand Up @@ -639,21 +616,6 @@ public void improveExistingMask(File mask) {
throw new IllegalArgumentException("The file selected does not correspond to an image.");
}
}

@Override
public void setRectIconConsumer(BooleanConsumer consumer) {
this.rectIconConsumer = consumer;
}

@Override
public void setPointsIconConsumer(BooleanConsumer consumer) {
this.pointsIconConsumer = consumer;
}

@Override
public void setFreelineIconConsumer(BooleanConsumer consumer) {
this.freelineIconConsumer = consumer;
}

// ===== unused events =====
@Override
Expand Down Expand Up @@ -682,4 +644,21 @@ public void keyTyped(KeyEvent e) {
@Override
public void keyPressed(KeyEvent e) {
}

@Override
public void eventOccurred(int eventID) {
if (eventID != IJEventListener.TOOL_CHANGED)
return;
if (this.isRect && !IJ.getToolName().equals("rectangle")) {
this.isRect = false;
return;
} else if (this.isPoints && !IJ.getToolName().equals("point") && !IJ.getToolName().equals("multipoint")) {
this.isPoints = false;
return;
} else if (this.isFreehand && !IJ.getToolName().equals("freeline")) {
this.isFreehand = false;
return;
}

}
}

0 comments on commit 76a4139

Please sign in to comment.