Skip to content

Commit

Permalink
keep iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 22, 2024
1 parent 7d2b914 commit bbadb77
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 54 deletions.
59 changes: 5 additions & 54 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.components.ModelDrawerPanel;
import ai.nets.samj.ui.ConsumerInterface;
import ai.nets.samj.utils.Constants;
import net.imglib2.util.Cast;
Expand Down Expand Up @@ -38,17 +39,15 @@ public class MainGUI extends JFrame {
private JButton close = new JButton("Close");
private JButton help = new JButton("Help");
private JButton export = new JButton("Export...");
private JButton install = new JButton("Install");
private JButton uninstall = new JButton("Uninstall");
private final ModelSelection cmbModels;
private final ImageSelection cmbImages;
private JLabel drawerTitle = new JLabel();
private JPanel drawerPanel;
private ModelDrawerPanel drawerPanel = ModelDrawerPanel.create(DRAWER_HORIZONTAL_SIZE);

private static double HEADER_VERTICAL_RATIO = 0.1;

private static int MAIN_VERTICAL_SIZE = 400;
private static int MAIN_HORIZONTAL_SIZE = 250;
private static int DRAWER_HORIZONTAL_SIZE = 450;

private static String MANUAL_STR = "Manual";
private static String PRESET_STR = "Preset prompts";
Expand Down Expand Up @@ -116,8 +115,6 @@ public MainGUI(List<SAMModel> modelList, ConsumerInterface consumer) {
gbc.weighty = 0.03;
mainPanel.add(createBottomPanel(), gbc);

createDrawerPanel();

// Add the mainPanel and drawerPanel using BorderLayout
add(mainPanel, BorderLayout.CENTER);
add(drawerPanel, BorderLayout.EAST);
Expand Down Expand Up @@ -388,60 +385,14 @@ private JPanel createThirdComponent() {
return thirdComponent;
}

private void createDrawerPanel() {
drawerPanel = new JPanel();
drawerPanel.setLayout(new BorderLayout());
drawerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
drawerTitle.setText("<html><div style='text-align: center; font-size: 15px;'>&nbsp;</html>");
drawerPanel.add(drawerTitle, BorderLayout.NORTH);
drawerPanel.add(createInstallModelComponent(), BorderLayout.SOUTH);
HTMLPane html = new HTMLPane("Arial", "#000", "#CCCCCC", 200, 200);
html.append("Model description");
html.append("Model description");
html.append("Model description");
html.append("");
html.append("i", "Other information");
html.append("i", "References");
drawerPanel.add(html, BorderLayout.CENTER);
drawerPanel.setPreferredSize(new Dimension(200, 0)); // Set preferred width
}

// Method to create the install model component
private JPanel createInstallModelComponent() {
JPanel thirdComponent = new JPanel();
thirdComponent.setLayout(new GridBagLayout());
thirdComponent.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2));
thirdComponent.setBorder(new LineBorder(Color.BLACK));

GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridx = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;

// Install button
gbc.gridy = 0;
thirdComponent.add(this.install, gbc);

// Uninstall button
gbc.gridy = 1;
thirdComponent.add(this.uninstall, gbc);

// Export button (if needed)
gbc.gridy = 2;
thirdComponent.add(this.export, gbc);
thirdComponent.setPreferredSize(new Dimension(0, (int) (MAIN_VERTICAL_SIZE * 0.2)));

return thirdComponent;
}

private void toggleDrawer() {
if (isDrawerOpen) {
if (drawerPanel.isVisible()) {
drawerPanel.setVisible(false);
this.cmbModels.getButton().setText("▶");
setSize(getWidth() - drawerPanel.getPreferredSize().width, getHeight());
} else {
drawerPanel.setVisible(true);
drawerPanel.setTitle(cmbModels.getSelectedModel().getName());
this.cmbModels.getButton().setText("◀");
setSize(getWidth() + drawerPanel.getPreferredSize().width, getHeight());
}
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/ai/nets/samj/gui/components/ImageDrawerPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package ai.nets.samj.gui.components;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import ai.nets.samj.gui.HTMLPane;

public class ImageDrawerPanel extends JPanel {

private JLabel drawerTitle = new JLabel();
private JButton install = new JButton("Install");
private JButton uninstall = new JButton("Uninstall");

private int hSize;

private static final String MODEL_TITLE = "<html><div style='text-align: center; font-size: 15px;'>%s</html>";


private ImageDrawerPanel(int hSize) {
this.hSize = hSize;
createDrawerPanel();
}

public static ImageDrawerPanel create(int hSize) {
return new ImageDrawerPanel(hSize);
}

private void createDrawerPanel() {
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
drawerTitle.setText(String.format(MODEL_TITLE, "&nbsp;"));
this.add(drawerTitle, BorderLayout.NORTH);
this.add(createInstallModelComponent(), BorderLayout.SOUTH);
HTMLPane html = new HTMLPane("Arial", "#000", "#CCCCCC", 200, 200);
html.append("Model description");
html.append("Model description");
html.append("Model description");
html.append("");
html.append("i", "Other information");
html.append("i", "References");
this.add(html, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(hSize, 0)); // Set preferred width
}

// Method to create the install model component
private JPanel createInstallModelComponent() {
JPanel thirdComponent = new JPanel();
thirdComponent.setLayout(new GridBagLayout());
thirdComponent.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2));
thirdComponent.setBorder(new LineBorder(Color.BLACK));

GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;

// Install button
gbc.gridx = 0;
thirdComponent.add(this.install, gbc);

// Uninstall button
gbc.gridx = 1;
thirdComponent.add(this.uninstall, gbc);

return thirdComponent;
}

public void setTitle(String title) {
drawerTitle.setText(String.format(MODEL_TITLE, title));
}

@Override
public void setVisible(boolean visible) {
this.isOpen = visible;
super.setVisible(visible);
}

}
90 changes: 90 additions & 0 deletions src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package ai.nets.samj.gui.components;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import ai.nets.samj.gui.HTMLPane;

public class ModelDrawerPanel extends JPanel {

private JLabel drawerTitle = new JLabel();
private JButton install = new JButton("Install");
private JButton uninstall = new JButton("Uninstall");


private int hSize;

private static final String MODEL_TITLE = "<html><div style='text-align: center; font-size: 15px;'>%s</html>";


private ModelDrawerPanel(int hSize) {
this.hSize = hSize;
createDrawerPanel();
}

public static ModelDrawerPanel create(int hSize) {
return new ModelDrawerPanel(hSize);
}

private void createDrawerPanel() {
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
drawerTitle.setText(String.format(MODEL_TITLE, "&nbsp;"));
this.add(drawerTitle, BorderLayout.NORTH);
this.add(createInstallModelComponent(), BorderLayout.SOUTH);
HTMLPane html = new HTMLPane("Arial", "#000", "#CCCCCC", 200, 200);
html.append("Model description");
html.append("Model description");
html.append("Model description");
html.append("");
html.append("i", "Other information");
html.append("i", "References");
this.add(html, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(hSize, 0)); // Set preferred width
}

// Method to create the install model component
private JPanel createInstallModelComponent() {
JPanel thirdComponent = new JPanel();
thirdComponent.setLayout(new GridBagLayout());
thirdComponent.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2));
thirdComponent.setBorder(new LineBorder(Color.BLACK));

GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;

// Install button
gbc.gridx = 0;
thirdComponent.add(this.install, gbc);

// Uninstall button
gbc.gridx = 1;
thirdComponent.add(this.uninstall, gbc);

return thirdComponent;
}

public void setTitle(String title) {
drawerTitle.setText(String.format(MODEL_TITLE, title));
}

@Override
public void setVisible(boolean visible) {
this.isOpen = visible;
super.setVisible(visible);
}

}

0 comments on commit bbadb77

Please sign in to comment.