diff --git a/src/main/java/ai/nets/samj/gui/MainGUI.java b/src/main/java/ai/nets/samj/gui/MainGUI.java index c27b807..54b6515 100644 --- a/src/main/java/ai/nets/samj/gui/MainGUI.java +++ b/src/main/java/ai/nets/samj/gui/MainGUI.java @@ -7,6 +7,7 @@ import ai.nets.samj.communication.model.SAM2Tiny; import ai.nets.samj.communication.model.SAMModel; import ai.nets.samj.gui.ImageSelection.ImageSelectionListener; +import ai.nets.samj.gui.ModelSelection.ModelSelctionListener; import ai.nets.samj.gui.components.ModelDrawerPanel; import ai.nets.samj.gui.components.ModelDrawerPanel.ModelDrawerPanelListener; import ai.nets.samj.ui.ConsumerInterface; @@ -30,6 +31,7 @@ public class MainGUI extends JFrame { private boolean isDrawerOpen = false; private final List modelList; private ImageSelectionListener imageListener; + private ModelSelctionListener modelListener; private ModelDrawerPanelListener modelDrawerListener; private ConsumerInterface consumer; @@ -77,7 +79,7 @@ public MainGUI(List modelList, ConsumerInterface consumer) { if (modelList == null) this.modelList = DEFAULT_MODEL_LIST; else this.modelList = modelList; - cmbModels = ModelSelection.create(this.modelList); + cmbModels = ModelSelection.create(this.modelList, modelListener); drawerPanel = ModelDrawerPanel.create(DRAWER_HORIZONTAL_SIZE, this.modelDrawerListener); @@ -410,25 +412,40 @@ private void createListeners() { imageListener = new ImageSelectionListener() { @Override public void modelActionsOnImageChanged() { - // TODO Auto-generated method stub + cmbModels.getSelectedModel().closeProcess(); } @Override public void imageActionsOnImageChanged() { - // TODO Auto-generated method stub + consumer.deactivateListeners(); + consumer.deselectImage(); } }; + modelListener = new ModelSelctionListener() { + + @Override + public void changeDrawerPanel() { + if (drawerPanel.isVisible()) + drawerPanel.setSelectedModel(cmbModels.getSelectedModel()); + + } + }; modelDrawerListener = new ModelDrawerPanelListener() { @Override public void setGUIEnabled(boolean enabled) { - // TODO Auto-generated method stub - + cmbModels.setEnabled(enabled); + cmbImages.setEnabled(enabled); + go.setEnabled(enabled); + chkInstant.setEnabled(enabled); + export.setEnabled(enabled); + retunLargest.setEnabled(enabled); + chkRoiManager.setEnabled(enabled); } @Override - public void setGUIModelInstalled(boolean installed) { - // TODO Auto-generated method stub + public void setGoButtonEnabled(boolean installed) { + go.setEnabled(installed); } }; diff --git a/src/main/java/ai/nets/samj/gui/ModelSelection.java b/src/main/java/ai/nets/samj/gui/ModelSelection.java index 2d868e3..ffc2394 100644 --- a/src/main/java/ai/nets/samj/gui/ModelSelection.java +++ b/src/main/java/ai/nets/samj/gui/ModelSelection.java @@ -19,13 +19,16 @@ public class ModelSelection extends ComboBoxButtonComp implements PopupM private SAMModel selected; + private final ModelSelctionListener listener; + private final List models; private static final long serialVersionUID = 2478618937640492286L; - private ModelSelection(List models) { + private ModelSelection(List models, ModelSelctionListener listener) { super(new JComboBox()); + this.listener = listener; this.models = models; for (SAMModel model : models) { this.cmbBox.addItem(model.getName()); @@ -34,8 +37,8 @@ private ModelSelection(List models) { selected = models.get(cmbBox.getSelectedIndex()); } - protected static ModelSelection create(List models) { - return new ModelSelection(models); + protected static ModelSelection create(List models, ModelSelctionListener listener) { + return new ModelSelection(models, listener); } protected SAMModel getSelectedModel() { @@ -75,6 +78,7 @@ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } catch (Exception ex) { ex.printStackTrace(); } + listener.changeDrawerPanel(); } @Override @@ -83,4 +87,9 @@ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { */ public void popupMenuCanceled(PopupMenuEvent e) { } + + public interface ModelSelctionListener { + + void changeDrawerPanel(); + } } 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 0b9b277..0d4cc50 100644 --- a/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java +++ b/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java @@ -92,12 +92,17 @@ private JPanel createInstallModelComponent() { public void setSelectedModel(SAMModel model) { this.model = model; setTitle(model.getName()); + setInfo(); } - public void setTitle(String title) { + private void setTitle(String title) { drawerTitle.setText(String.format(MODEL_TITLE, title)); } + private void setInfo() { + // TODO + } + @Override public void setVisible(boolean visible) { super.setVisible(visible); @@ -119,14 +124,14 @@ private void installModel() { this.model.getInstallationManger().installEverything(); SwingUtilities.invokeLater(() -> { listener.setGUIEnabled(true); - listener.setGUIModelInstalled(true); + listener.setGoButtonEnabled(true); }); } catch (IOException | InterruptedException | ArchiveException | URISyntaxException | MambaInstallException e) { e.printStackTrace(); SwingUtilities.invokeLater(() -> { listener.setGUIEnabled(true); - listener.setGUIModelInstalled(false); + listener.setGoButtonEnabled(false); }); } }); @@ -139,7 +144,7 @@ private void uninstallModel() { this.model.getInstallationManger().uninstall(); SwingUtilities.invokeLater(() -> { listener.setGUIEnabled(true); - listener.setGUIModelInstalled(false); + listener.setGoButtonEnabled(false); }); }); } @@ -148,7 +153,7 @@ public interface ModelDrawerPanelListener { void setGUIEnabled(boolean enabled); - void setGUIModelInstalled(boolean installed); + void setGoButtonEnabled(boolean installed); } }