Skip to content

Commit

Permalink
more improvements in the user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 22, 2024
1 parent 58d10c9 commit 7208c10
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public SAM2Tiny() {
this.fullName = "SAM-2: Segment Anything Model 2 (Tiny)";
this.githubLink = "https://github.com/facebookresearch/segment-anything-2";
this.paperLink = "https://ai.meta.com/research/publications/sam-2-segment-anything-in-images-and-videos/";
this.githubName = "https://github.com/facebookresearch/segment-anything-2";
this.githubName = "facebookresearch/segment-anything-2";
this.paperName = "SAM 2: Segment Anything in Images and Videos";
this.speedRank = 3;
this.performanceRank = 3;
this.size = 155.9;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ai/nets/samj/communication/model/SAMModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ public String getDescription() {
String description = String.format(HTML_MODEL_FORMAT, fullName, "" + size,
"" + speedRank, "" + performanceRank, githubLink, githubName, paperLink, paperName);
boolean installed = this.isInstalled();
description += this.isHeavy & installed ? CAUTION_STRING : "";
description += installed ? "" : HTML_NOT_INSTALLED;
description = this.isHeavy & installed ? CAUTION_STRING + description: description;
description = installed ? description : HTML_NOT_INSTALLED + description;
return description;
}

Expand Down
43 changes: 20 additions & 23 deletions src/main/java/ai/nets/samj/gui/HTMLPane.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package ai.nets.samj.gui;

import java.awt.Dimension;

import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.text.BadLocationException;
Expand Down Expand Up @@ -70,50 +71,43 @@ private void create() {
header += "<!DOCTYPE HTML>\n";
header += "<html><head>\n";
header += "<style>\n";
// CSS Reset
header += "* {\n";
header += " margin: 0;\n";
header += " padding: 0;\n";
header += " box-sizing: border-box;\n";
header += "}\n";
header += "body {\n";
header += " background-color: " + background + ";\n";
header += " color: " + color + ";\n";
header += " font-family: '" + font + "', sans-serif;\n";
header += " margin: 5px;\n";
header += " font-size: 9px;\n"; // Base font size reduced
header += "}\n";
header += "h2 {\n";
header += " color: #333333;\n";
header += " font-size: 1.2em;\n"; // Reduced font size
header += " margin-bottom: 5px;\n";
header += " border-bottom: 1px solid #e0e0e0;\n";
header += " padding-bottom: 5px;\n";
header += " font-size: 1.2em;\n"; // Adjust as needed
// No margin or padding
header += "}\n";
header += "table {\n";
header += " width: 100%;\n";
header += " border-collapse: collapse;\n";
header += " margin-bottom: 5px;\n";
// No margin or padding
header += "}\n";
header += "th, td {\n";
header += " text-align: left;\n";
header += " padding: 4px;\n"; // Reduced padding
header += " font-size: 1.0em;\n"; // Reduced font size
header += "}\n";
header += "th {\n";
header += " background-color: #f2f2f2;\n";
header += " width: 40%;\n"; // Adjusted width
header += "}\n";
header += "tr:nth-child(even) td {\n";
header += " background-color: #fafafa;\n";
header += "}\n";
header += "a {\n";
header += " color: #1a0dab;\n";
header += " text-decoration: none;\n";
header += "}\n";
header += "a:hover {\n";
header += " text-decoration: underline;\n";
header += " padding: 4px;\n"; // Adjust as needed
header += " font-size: 1.0em;\n";
header += "}\n";
// Additional styles...
header += "</style>\n";
header += "</head>\n";
header += "<body>\n";
footer += "</body></html>\n";
setEditable(false);
setContentType("text/html; charset=UTF-8");
// Remove margins and borders from JEditorPane
this.setMargin(new Insets(0, 0, 0, 0));
this.setBorder(BorderFactory.createEmptyBorder());
}

public void append(String content) {
Expand All @@ -138,6 +132,9 @@ public JScrollPane getPane() {
JScrollPane scroll = new JScrollPane(this, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setPreferredSize(dim);
// Remove borders from JScrollPane
scroll.setBorder(BorderFactory.createEmptyBorder());
scroll.setViewportBorder(BorderFactory.createEmptyBorder());
return scroll;
}
}
13 changes: 12 additions & 1 deletion src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ private ModelDrawerPanel(int hSize, ModelDrawerPanelListener listener) {
this.hSize = hSize;
this.listener = listener;
createDrawerPanel();
this.install.addActionListener(this);
this.uninstall.addActionListener(this);
}

public static ModelDrawerPanel create(int hSize, ModelDrawerPanelListener listener) {
Expand All @@ -73,7 +75,7 @@ private void createDrawerPanel() {
html.append("");
html.append("i", "Other information");
html.append("i", "References");
this.add(html, BorderLayout.CENTER);
this.add(html.getPane(), BorderLayout.CENTER);
this.setPreferredSize(new Dimension(hSize, 0)); // Set preferred width
}

Expand Down Expand Up @@ -106,6 +108,10 @@ public void setSelectedModel(SAMModel model) {
this.model = model;
setTitle(model.getName());
setInfo();
setButtons();
}

private void setButtons() {
install.setEnabled(false);
uninstall.setEnabled(false);
installedThread = new Thread(() -> {
Expand Down Expand Up @@ -173,12 +179,17 @@ private void installModel() {

private void uninstallModel() {
SwingUtilities.invokeLater(() -> listener.setGUIEnabled(false));
startLoadingAnimation("Uninstalling model");
modelInstallThread = new Thread(() ->{
this.model.getInstallationManger().uninstall();
stopLoadingAnimation();
SwingUtilities.invokeLater(() -> {
this.setInfo();
setButtons();
listener.setGUIEnabled(true);
});
});
modelInstallThread.start();
}

private void startLoadingAnimation(String message) {
Expand Down

0 comments on commit 7208c10

Please sign in to comment.