From 7208c10ccf26770030d6e5a1c45d3e4b72a8f15e Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Fri, 22 Nov 2024 20:04:07 +0100 Subject: [PATCH] more improvements in the user experience --- .../samj/communication/model/SAM2Tiny.java | 2 +- .../samj/communication/model/SAMModel.java | 4 +- src/main/java/ai/nets/samj/gui/HTMLPane.java | 43 +++++++++---------- .../samj/gui/components/ModelDrawerPanel.java | 13 +++++- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/main/java/ai/nets/samj/communication/model/SAM2Tiny.java b/src/main/java/ai/nets/samj/communication/model/SAM2Tiny.java index 64b3a80..6526d71 100644 --- a/src/main/java/ai/nets/samj/communication/model/SAM2Tiny.java +++ b/src/main/java/ai/nets/samj/communication/model/SAM2Tiny.java @@ -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; diff --git a/src/main/java/ai/nets/samj/communication/model/SAMModel.java b/src/main/java/ai/nets/samj/communication/model/SAMModel.java index d2dc7ea..8f26e0c 100644 --- a/src/main/java/ai/nets/samj/communication/model/SAMModel.java +++ b/src/main/java/ai/nets/samj/communication/model/SAMModel.java @@ -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; } diff --git a/src/main/java/ai/nets/samj/gui/HTMLPane.java b/src/main/java/ai/nets/samj/gui/HTMLPane.java index 6b26cc1..52451a1 100644 --- a/src/main/java/ai/nets/samj/gui/HTMLPane.java +++ b/src/main/java/ai/nets/samj/gui/HTMLPane.java @@ -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; @@ -70,50 +71,43 @@ private void create() { header += "\n"; header += "
\n"; header += "\n"; header += "\n"; header += "\n"; footer += "\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) { @@ -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; } } diff --git a/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java b/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java index 5c01332..e5eae43 100644 --- a/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java +++ b/src/main/java/ai/nets/samj/gui/components/ModelDrawerPanel.java @@ -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) { @@ -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 } @@ -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(() -> { @@ -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) {