Skip to content

Commit

Permalink
Better formatting when listing plugins in dialog box prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielsherry committed May 18, 2024
1 parent cd0f7e4 commit 14df838
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
public class StratusText {

public static String lineWrapHTML(Component c, String text) {
return "<html>" + lineWrap(c, text).replace("\n", "<br/>") + "</html>";
return "<html>" + lineWrapHTMLInline(c, text) + "</html>";
}

public static String lineWrapHTML(Component c, String text, int width) {
return "<html>" + lineWrap(c, text, width).replace("\n", "<br/>") + "</html>";
return "<html>" + lineWrapHTMLInline(c, text, width) + "</html>";
}

public static String lineWrapHTMLInline(Component c, String text) {
return lineWrap(c, text).replace("\n", "<br/>");
}

public static String lineWrapHTMLInline(Component c, String text, int width) {
return lineWrap(c, text, width).replace("\n", "<br/>");
}

public static String lineWrap(Component c, String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.peakaboo.framework.plural.monitor.TaskMonitor;
import org.peakaboo.framework.plural.monitor.swing.TaskMonitorPanel;
import org.peakaboo.framework.stratus.api.Stratus;
import org.peakaboo.framework.stratus.api.StratusText;
import org.peakaboo.framework.stratus.api.hookins.FileDrop;
import org.peakaboo.framework.stratus.api.icons.StockIcon;
import org.peakaboo.framework.stratus.components.ComponentStrip;
Expand Down Expand Up @@ -197,10 +198,7 @@ private void remove(PluginDescriptor<? extends BoltPlugin> plugin) {
return;
}

new LayerDialog(
"Delete Plugin Container?",
"Are you sure you want to delete the container with the plugins:\n\n" + listToUL(container.getPlugins()),
StockIcon.BADGE_QUESTION)
new LayerDialog("Delete Plugin Bundle?", descriptorsToHTML(container.getPlugins()))
.addRight(
new FluentButton("Delete").withAction(() -> {
plugin.getContainer().delete();
Expand All @@ -213,20 +211,28 @@ private void remove(PluginDescriptor<? extends BoltPlugin> plugin) {

}

private String listToUL(List<?> stuff) {
private String descriptorsToHTML(List<?> stuff) {

StringBuilder buff = new StringBuilder();
buff.append("<ul>");
for (Object o : stuff) {
String name = o.toString();
if (o instanceof PluginDescriptor<?> plugin) {
name = plugin.getName() + " (v" + plugin.getVersion() + ")";
if (!buff.isEmpty()) {
buff.append("<br>");
}
buff.append(descriptorToHTML(plugin));
} else {
throw new RuntimeException("Item was not a plugin descriptor");
}
buff.append("<li>" + name + "</li>");
}
buff.append("</ul>");
return buff.toString();

}

private String descriptorToHTML(PluginDescriptor<?> plugin) {
// The details panel is just a convenient component which hasn't had its default font properties changes
String wrappedDescription = StratusText.lineWrapHTMLInline(details, plugin.getDescription(), 400);
return String.format("<div style='padding: 5px;'><div style='font-size: 20pt;'>%s</div><div style='font-size: 10pt; padding-bottom: 5px;'>version %s</div><div style=''>%s</div></div>", plugin.getName(), plugin.getVersion(), wrappedDescription);
}


/**
Expand Down Expand Up @@ -279,10 +285,7 @@ private boolean addFileToManager(File file, BoltPluginRegistry<? extends BoltPlu
BoltContainer<? extends BoltPlugin> container = manager.importOrUpgradeFile(file);

this.reload();
new LayerDialog(
"Imported New Plugins",
"Peakboo successfully imported the following plugin(s):\n" + listToUL(container.getPlugins()),
StockIcon.BADGE_INFO).showIn(parent);
new LayerDialog("Imported New Plugins", descriptorsToHTML(container.getPlugins())).showIn(parent);

return true;

Expand Down

0 comments on commit 14df838

Please sign in to comment.