diff --git a/src/main/java/ai/nets/samj/gui/MainGUI.java b/src/main/java/ai/nets/samj/gui/MainGUI.java index 848c5cc..7877457 100644 --- a/src/main/java/ai/nets/samj/gui/MainGUI.java +++ b/src/main/java/ai/nets/samj/gui/MainGUI.java @@ -7,7 +7,9 @@ import ai.nets.samj.communication.model.SAM2Small; 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.ModelSelectionListener; +import ai.nets.samj.ui.UtilityMethods; import ai.nets.samj.utils.Constants; import javax.swing.*; @@ -22,20 +24,36 @@ public class MainGUI extends JFrame { private static final long serialVersionUID = -797293687195076077L; - private JPanel drawerPanel; private boolean isDrawerOpen = false; + private final List modelList; + private ModelSelectionListener modelListener; + private ImageSelectionListener imageListener; private JCheckBox chkRoiManager = new JCheckBox("Add to RoiManager", true); private JCheckBox chkReturnLargest = new JCheckBox("Only return largest ROI", true); private JSwitchButtonNew chkInstant = new JSwitchButtonNew("LIVE", "OFF"); private JButton go = new JButton("Go"); + private JButton btnBatchSAMize = new JButton("Batch SAMize"); private JButton close = new JButton("Close"); private JButton help = new JButton("Help"); private JButton export = new JButton("Export..."); private final ModelSelection cmbModels; private final ImageSelection cmbImages; private JLabel drawerTitle = new JLabel(); + private JPanel drawerPanel; + + + + private static double HEADER_VERTIACAL_RATIO = 0.1; + + private static int MAIN_VERTICAL_SIZE = 400; + private static int MAIN_HORIZONTAL_SIZE = 250; + + private static String MANUAL_STR = "Manual"; + private static String PRESET_STR = "Preset prompts"; + + private static String ROIM_STR = "Selection from ROIManager"; private static final List DEFAULT_MODEL_LIST = new ArrayList<>(); static { @@ -45,25 +63,20 @@ public class MainGUI extends JFrame { DEFAULT_MODEL_LIST.add(new EfficientSAM()); DEFAULT_MODEL_LIST.add(new EfficientViTSAML2()); } - - private static double HEADER_VERTIACAL_RATIO = 0.1; - private static int MAIN_VERTICAL_SIZE = 400; - private static int MAIN_HORIZONTAL_SIZE = 250; + public MainGUI(UtilityMethods methods) { + this(null, methods); + } - public MainGUI() { + public MainGUI(List modelList, UtilityMethods methods) { super(Constants.JAR_NAME + "-" + Constants.SAMJ_VERSION); - ModelSelectionListener modelListener = new ModelSelectionListener() { - @Override - public void modelChanged(SAMModel selectedModel) { - // Perform the action needed when a new model is selected - } - }; - - cmbImages = ImageSelection.create(null, null); + createListeners(); + cmbImages = ImageSelection.create(methods, imageListener); - cmbModels = ModelSelection.create(DEFAULT_MODEL_LIST, modelListener); + if (modelList == null) this.modelList = DEFAULT_MODEL_LIST; + else this.modelList = modelList; + cmbModels = ModelSelection.create(modelList, modelListener); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -204,8 +217,8 @@ private JPanel createSecondComponent() { // Radio buttons JPanel radioPanel = new JPanel(); - JRadioButton radioButton1 = new JRadioButton("Manual", true); - JRadioButton radioButton2 = new JRadioButton("Preset prompts"); + JRadioButton radioButton1 = new JRadioButton(MANUAL_STR, true); + JRadioButton radioButton2 = new JRadioButton(PRESET_STR); ButtonGroup radioGroup = new ButtonGroup(); radioGroup.add(radioButton1); @@ -241,28 +254,27 @@ private JPanel createSecondComponent() { gbc0.fill = GridBagConstraints.NONE; gbc0.weighty = 0.2; gbc0.insets = new Insets(0, 0, 0, 0); - card2.add(new JLabel("Selection from ROIManager"), gbc0); + card2.add(new JLabel(ROIM_STR), gbc0); gbc0.gridy = 1; gbc0.anchor = GridBagConstraints.CENTER; gbc0.fill = GridBagConstraints.BOTH; gbc0.insets = new Insets(0, 0, 10, 0); gbc0.weighty = 0.8; - JButton btnBatchSAMize = new JButton("Batch SAMize"); card2.add(btnBatchSAMize, gbc0); - cardPanel.add(card1, "Option 1"); - cardPanel.add(card2, "Option 2"); + cardPanel.add(card1, MANUAL_STR); + cardPanel.add(card2, PRESET_STR); // Add action listeners to radio buttons radioButton1.addActionListener(e -> { CardLayout cl = (CardLayout) (cardPanel.getLayout()); - cl.show(cardPanel, "Option 1"); + cl.show(cardPanel, MANUAL_STR); }); radioButton2.addActionListener(e -> { CardLayout cl = (CardLayout) (cardPanel.getLayout()); - cl.show(cardPanel, "Option 2"); + cl.show(cardPanel, PRESET_STR); }); @@ -313,8 +325,33 @@ private JPanel createThirdComponent() { return thirdComponent; } + + private void createListeners() { + + modelListener = new ModelSelectionListener() { + @Override + public void modelChanged(SAMModel selectedModel) { + // Perform the action needed when a new model is selected + } + }; + + imageListener = new ImageSelectionListener() { + + @Override + public void modelActionsOnImageChanged() { + // TODO Auto-generated method stub + + } + + @Override + public void imageActionsOnImageChanged() { + // TODO Auto-generated method stub + + } + }; + } public static void main(String[] args) { - SwingUtilities.invokeLater(() -> new MainGUI()); + SwingUtilities.invokeLater(() -> new MainGUI(null)); } }