diff --git a/src/main/java/ai/nets/samj/gui/ModelSelection.java b/src/main/java/ai/nets/samj/gui/ModelSelection.java index 5614d29..ee0ad77 100644 --- a/src/main/java/ai/nets/samj/gui/ModelSelection.java +++ b/src/main/java/ai/nets/samj/gui/ModelSelection.java @@ -1,21 +1,20 @@ package ai.nets.samj.gui; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.io.IOException; import java.util.List; import javax.swing.JButton; import javax.swing.JComboBox; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; import ai.nets.samj.gui.components.ComboBoxButtonComp; import net.imglib2.RandomAccessibleInterval; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; -import ai.nets.samj.annotation.Mask; import ai.nets.samj.communication.model.SAMModel; -public class ModelSelection extends ComboBoxButtonComp implements PopupMenuListener { +public class ModelSelection extends ComboBoxButtonComp implements ItemListener { private SAMModel selected; @@ -33,7 +32,7 @@ private ModelSelection(List models, ModelSelectionListener listener) { for (SAMModel model : models) { this.cmbBox.addItem(model.getName()); } - cmbBox.addPopupMenuListener(this); + cmbBox.addItemListener(this); selected = models.get(cmbBox.getSelectedIndex()); } @@ -65,37 +64,24 @@ protected void unLoadModel() { } @Override - /** - * Nothing - */ - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - } - - @Override - /** - * Check if the image selected has been changed once the combobox pop up is closed - */ - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - try { - SAMModel nSelectedModel = models.get(cmbBox.getSelectedIndex()); - if (nSelectedModel != selected) { - unLoadModel(); - listener.changeGUI(); - selected = nSelectedModel; + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + try { + SAMModel nSelectedModel = models.get(cmbBox.getSelectedIndex()); + // checks if indeed a different model is selected (from what was selected before) + if (nSelectedModel != selected) { + unLoadModel(); + listener.changeGUI(); + selected = nSelectedModel; + } + } catch (Exception ex) { + ex.printStackTrace(); } - } catch (Exception ex) { - ex.printStackTrace(); + listener.changeDrawerPanel(); } - listener.changeDrawerPanel(); } - @Override - /** - * Nothing - */ - public void popupMenuCanceled(PopupMenuEvent e) { - } - + public interface ModelSelectionListener { void changeDrawerPanel();