Skip to content

Commit

Permalink
keep connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 22, 2024
1 parent 0654c42 commit c61dbc8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
31 changes: 24 additions & 7 deletions src/main/java/ai/nets/samj/gui/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,7 @@ public class MainGUI extends JFrame {
private boolean isDrawerOpen = false;
private final List<SAMModel> modelList;
private ImageSelectionListener imageListener;
private ModelSelctionListener modelListener;
private ModelDrawerPanelListener modelDrawerListener;
private ConsumerInterface consumer;

Expand Down Expand Up @@ -77,7 +79,7 @@ public MainGUI(List<SAMModel> 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);
Expand Down Expand Up @@ -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);

}
};
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/ai/nets/samj/gui/ModelSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public class ModelSelection extends ComboBoxButtonComp<String> implements PopupM

private SAMModel selected;

private final ModelSelctionListener listener;

private final List<SAMModel> models;


private static final long serialVersionUID = 2478618937640492286L;

private ModelSelection(List<SAMModel> models) {
private ModelSelection(List<SAMModel> models, ModelSelctionListener listener) {
super(new JComboBox<String>());
this.listener = listener;
this.models = models;
for (SAMModel model : models) {
this.cmbBox.addItem(model.getName());
Expand All @@ -34,8 +37,8 @@ private ModelSelection(List<SAMModel> models) {
selected = models.get(cmbBox.getSelectedIndex());
}

protected static ModelSelection create(List<SAMModel> models) {
return new ModelSelection(models);
protected static ModelSelection create(List<SAMModel> models, ModelSelctionListener listener) {
return new ModelSelection(models, listener);
}

protected SAMModel getSelectedModel() {
Expand Down Expand Up @@ -75,6 +78,7 @@ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
} catch (Exception ex) {
ex.printStackTrace();
}
listener.changeDrawerPanel();
}

@Override
Expand All @@ -83,4 +87,9 @@ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
*/
public void popupMenuCanceled(PopupMenuEvent e) {
}

public interface ModelSelctionListener {

void changeDrawerPanel();
}
}
15 changes: 10 additions & 5 deletions src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
}
});
Expand All @@ -139,7 +144,7 @@ private void uninstallModel() {
this.model.getInstallationManger().uninstall();
SwingUtilities.invokeLater(() -> {
listener.setGUIEnabled(true);
listener.setGUIModelInstalled(false);
listener.setGoButtonEnabled(false);
});
});
}
Expand All @@ -148,7 +153,7 @@ public interface ModelDrawerPanelListener {

void setGUIEnabled(boolean enabled);

void setGUIModelInstalled(boolean installed);
void setGoButtonEnabled(boolean installed);
}

}

0 comments on commit c61dbc8

Please sign in to comment.