Skip to content

Commit

Permalink
keep iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 21, 2024
1 parent 10f5a98 commit ca6c5de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/main/java/ai/nets/samj/gui/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import ai.nets.samj.communication.model.SAM2Tiny;
import ai.nets.samj.communication.model.SAMModel;
import ai.nets.samj.gui.ModelSelection.ModelSelectionListener;
import ai.nets.samj.gui.components.ComboBoxButtonComp;
import ai.nets.samj.gui.components.ComboBoxItem;
import ai.nets.samj.utils.Constants;

import javax.swing.*;
Expand Down Expand Up @@ -133,17 +131,17 @@ private JPanel createCenterPanel() {

// First component: Rectangular area with line border
gbc.gridy = 0;
gbc.weighty = 0.45;
gbc.weighty = 0.25;
centerPanel.add(createFirstComponent(), gbc);

// Second component: Radio button with changing panel
gbc.gridy = 1;
gbc.weighty = 0.45;
gbc.weighty = 0.5;
centerPanel.add(createSecondComponent(), gbc);

// Third component: Two checkboxes and a button
gbc.gridy = 2;
gbc.weighty = 0.1;
gbc.weighty = 0.25;
centerPanel.add(createThirdComponent(), gbc);

return centerPanel;
Expand Down Expand Up @@ -177,26 +175,27 @@ private JPanel createFirstComponent() {
JPanel firstComponent = new JPanel();
firstComponent.setLayout(new GridBagLayout());
firstComponent.setBorder(new LineBorder(Color.BLACK));

GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2, 2, 2, 2); // Insets around components
gbc.insets = new Insets(2, 2, 5, 2); // Adjust insets as needed
gbc.gridx = 0;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;

// Add the first component
gbc.gridy = 0;
gbc.weighty = 0.33; // Adjust weighty if necessary
firstComponent.add(this.cmbModels, gbc);

// Add the second component
gbc.gridy = 1;
firstComponent.add(this.cmbImages, gbc);

// Add the button
gbc.gridy = 2;
gbc.insets = new Insets(2, 2, 2, 2); // Adjust insets as needed
firstComponent.add(go, gbc);

//cmbModels.setPreferredSize(new Dimension(MAIN_HORIZONTAL_SIZE, (int) (MAIN_VERTICAL_SIZE * 0.05)));
//cmbImages.setPreferredSize(new Dimension(MAIN_HORIZONTAL_SIZE, (int) (MAIN_VERTICAL_SIZE * 0.05)));
firstComponent.setPreferredSize(new Dimension(0, (int) (MAIN_VERTICAL_SIZE * 0.2)));

return firstComponent;
}
Expand Down Expand Up @@ -260,6 +259,7 @@ private JPanel createSecondComponent() {
gbc.gridy = 1;
gbc.weighty = 0.9;
secondComponent.add(cardPanel, gbc);
secondComponent.setPreferredSize(new Dimension(0, (int) (MAIN_VERTICAL_SIZE * 0.30)));

return secondComponent;
}
Expand Down Expand Up @@ -293,7 +293,7 @@ private JPanel createThirdComponent() {
//gbc.weighty = 1.0; // Allows the button to move with resizing
//gbc.anchor = GridBagConstraints.NORTH;
thirdComponent.add(processButton, gbc);
thirdComponent.setPreferredSize(new Dimension(0, 0));
thirdComponent.setPreferredSize(new Dimension(0, (int) (MAIN_VERTICAL_SIZE * 0.15)));

return thirdComponent;
}
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/ai/nets/samj/gui/components/ComboBoxButtonComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
Expand All @@ -19,16 +21,27 @@ public class ComboBoxButtonComp<T> extends JPanel {
private static final double RATIO_CBX_BTN = 10.0;

public ComboBoxButtonComp(JComboBox<T> modelCombobox) {
// Populate the JComboBox with models
this.cmbBox = modelCombobox;
btn.setMargin(new Insets(2, 3, 2, 2));

// Set layout manager to null for absolute positioning
setLayout(null);
// Use GridBagLayout instead of null layout
setLayout(new GridBagLayout());

// Add components to the panel
add(modelCombobox);
add(btn);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 0, 0); // Adjust insets as needed
gbc.fill = GridBagConstraints.BOTH;
gbc.gridy = 0;

// Add the JComboBox with weightx corresponding to RATIO_CBX_BTN
gbc.gridx = 0;
gbc.weightx = RATIO_CBX_BTN;
gbc.weighty = 1;
add(cmbBox, gbc);

// Add the JButton with weightx of 1
gbc.gridx = 1;
gbc.weightx = 1.0;
add(btn, gbc);

// Add a ComponentListener to the button to adjust font size
btn.addComponentListener(new ComponentAdapter() {
Expand All @@ -41,7 +54,7 @@ public void componentResized(ComponentEvent e) {

@Override
public void doLayout() {
int inset = 5; // Separation between components and edges
int inset = 2; // Separation between components and edges
int totalInsets = inset * 3; // Left, middle, and right insets

int width = getWidth();
Expand All @@ -55,8 +68,8 @@ public void doLayout() {
int btnWidth = availableWidth - comboWidth;

int x = inset;
int y = inset;
int componentHeight = height - (2 * inset); // Account for top and bottom insets
int y = 0;
int componentHeight = height; // Account for top and bottom insets

// Set bounds for the JComboBox
cmbBox.setBounds(x, y, comboWidth, componentHeight);
Expand Down

0 comments on commit ca6c5de

Please sign in to comment.