diff --git a/src/main/java/ai/nets/samj/gui/ImageSelection.java b/src/main/java/ai/nets/samj/gui/ImageSelection.java index 6eb874d..eac5a49 100644 --- a/src/main/java/ai/nets/samj/gui/ImageSelection.java +++ b/src/main/java/ai/nets/samj/gui/ImageSelection.java @@ -70,9 +70,10 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { try { ComboBoxItem item = (ComboBoxItem) this.cmbBox.getSelectedItem(); - if (selected != item) { + if (selected == null || selected.getId().equals(item.getId())) { listener.modelActionsOnImageChanged(); listener.imageActionsOnImageChanged(); + selected = item; } } catch (Exception ex) { ex.printStackTrace(); diff --git a/src/main/java/ai/nets/samj/gui/MainGUI.java b/src/main/java/ai/nets/samj/gui/MainGUI.java index 21250d9..9888528 100644 --- a/src/main/java/ai/nets/samj/gui/MainGUI.java +++ b/src/main/java/ai/nets/samj/gui/MainGUI.java @@ -189,6 +189,7 @@ private void loadModel() { private void close() { cmbModels.unLoadModel(); + this.drawerPanel.interruptThreads(); } // Method to create the title panel diff --git a/src/main/java/ai/nets/samj/gui/components/ComboBoxItem.java b/src/main/java/ai/nets/samj/gui/components/ComboBoxItem.java index 8fca2b9..7e83201 100644 --- a/src/main/java/ai/nets/samj/gui/components/ComboBoxItem.java +++ b/src/main/java/ai/nets/samj/gui/components/ComboBoxItem.java @@ -20,6 +20,8 @@ package ai.nets.samj.gui.components; +import java.util.UUID; + import net.imglib2.RandomAccessibleInterval; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; @@ -31,7 +33,7 @@ * @author CArlos Garcia */ public abstract class ComboBoxItem { - final private int id; + final private String id; final private Object value; private static final String SELECT_IMAGE_STR = "Select image"; @@ -43,9 +45,8 @@ public abstract class ComboBoxItem { * @param seq * the object */ - public ComboBoxItem(int uniqueID, Object seq) { - if (uniqueID == -1) throw new IllegalArgumentException("The unique identifier cannot be -1."); - this.id = uniqueID; + public ComboBoxItem(Object seq) { + this.id = UUID.randomUUID().toString(); this.value = seq; } @@ -54,7 +55,7 @@ public ComboBoxItem(int uniqueID, Object seq) { * In this case it is empty, the unique identifier will by -1. */ public ComboBoxItem() { - this.id = -1; + this.id = "-1"; this.value = null; } @@ -62,7 +63,7 @@ public ComboBoxItem() { * * @return the unique identifier of the instance */ - public int getId() { + public String getId() { return id; } diff --git a/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java b/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java index 029c912..8461f8d 100644 --- a/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java +++ b/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java @@ -181,6 +181,7 @@ public void actionPerformed(ActionEvent e) { private void installModel() { SwingUtilities.invokeLater(() -> listener.setGUIEnabled(false)); + SwingUtilities.invokeLater(() -> install.setEnabled(false)); modelInstallThread = new Thread(() ->{ try { this.html.clear(); @@ -292,6 +293,7 @@ private static String formatHTML(String html) { private void uninstallModel() { SwingUtilities.invokeLater(() -> listener.setGUIEnabled(false)); + SwingUtilities.invokeLater(() -> uninstall.setEnabled(false)); startLoadingAnimation("Uninstalling model"); modelInstallThread = new Thread(() ->{ this.model.getInstallationManger().uninstall(); @@ -339,7 +341,7 @@ private void stopLoadingAnimation() { } - private void interruptThreads() { + public void interruptThreads() { if (infoThread != null) this.infoThread.interrupt(); if (installedThread != null)