A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.
Java application-securityappsecbug-bountyburp-alternativeburp-suitedasthttp-proxyinfosecintercepting-proxyjavaowaspowasp-zappenetration-testingpentestingsecuritysecurity-toolsvulnerability-scannerweb-application-securityweb-security
package opensuite.ui.settings;
import opensuite.core.Settings;
import opensuite.core.SuiteContext;
import opensuite.ui.Glyphs;
import opensuite.ui.OptionsPage;
import opensuite.ui.Theme;
import opensuite.ui.Ui;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/** Settings > User interface pages: Side panel, Message editor, Hotkeys, Display. */
public final class InterfacePages {
private InterfacePages() {}
public static final String[] INSPECTOR_WIDGETS = {"Selection", "Request attributes", "Request query parameters",
"Request body parameters", "Request cookies", "Request headers", "Response headers"};
/** The settings key of one Inspector widget's Show, Open by default or Wrap text. */
public static String inspectorKey(String widget, String what) {
return "inspector." + widget.toLowerCase().replace(' ', '-') + "." + what;
}
/** A stored order of names, with any the store does not know appended and any it should not know dropped. */
public static List<String> ordered(Settings s, String key, String[] all) {
List<String> out = new ArrayList<>();
for (String n : s.get(key, "").split("\\|")) if (List.of(all).contains(n) && !out.contains(n)) out.add(n);
for (String n : all) if (!out.contains(n)) out.add(n);
return out;
}
public static SettingsPage sidePanel(SuiteContext ctx) {
Settings s = ctx.settings();
SettingsPage p = new SettingsPage();
JRadioButton[] pos = SettingsPage.radios(s, "sidepanel.position", "right", new String[]{"left", "right"}, "Left", "Right");
JRadioButton[] mode = SettingsPage.radios(s, "sidepanel.mode", "auto", new String[]{"auto", "collapsed"},
"Auto-expanded when there is enough space", "Always collapsed");
JPanel layout = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
layout.setOpaque(false);
layout.add(SettingsPage.radioGroup("Position", 15, pos));
layout.add(SettingsPage.groupRule());
layout.add(SettingsPage.radioGroup("Display mode", 12, mode));
p.block("Default side panel layout", SettingsPage.Kind.USER,
"Use these settings to choose the default layout for side panels in all tools except Intruder.",
() -> { s.remove("sidepanel.position"); s.remove("sidepanel.mode"); pos[1].setSelected(true); mode[0].setSelected(true); },
layout);
List<String> names = ordered(s, "inspector.order", INSPECTOR_WIDGETS);
String[] what = { "show", "open", "wrap" };
CheckTable table = new CheckTable(new CheckTable.Rows() {
@Override public int count() { return names.size(); }
@Override public String name(int r) { return names.get(r); }
// The selection widget is always there, open, and wrapped: it shows what is selected.
@Override public boolean locked(int r) { return "Selection".equals(names.get(r)); }
@Override public boolean get(int r, int c) { return locked(r) || s.getBool(inspectorKey(names.get(r), what[c]), c == 0); }
@Override public void set(int r, int c, boolean v) { s.setBool(inspectorKey(names.get(r), what[c]), v); }
@Override public void move(int from, int to) {
names.add(to, names.remove(from));
s.set("inspector.order", String.join("|", names));
}
}, "Widget", new String[] { "Show", "Open by default", "Wrap text" }, 83, 205, 120, 179, 150);
p.block("Inspector widgets", SettingsPage.Kind.USER,
"Use these settings to adjust how widgets are displayed in the inspector.",
() -> { SettingsPage.clearPrefix(s, "inspector."); names.clear(); names.addAll(List.of(INSPECTOR_WIDGETS)); table.repaint(); },
table);
return p;
}
public static final String[] REQUEST_VIEWS = {"Pretty", "Raw", "Hex", "Headers", "Query params", "Body params", "Cookies", "Attributes"};
public static final String[] RESPONSE_VIEWS = {"Pretty", "Raw", "Hex", "Render", "Headers"};
/** The settings key of one editor view's Show or Wrap text; the prefix is editor.request. or editor.response. */
public static String viewKey(String prefix, String view, String what) {
return prefix + view.toLowerCase().replace(' ', '-') + "." + what;
}
/** Whether a view is on offer unless set otherwise: the text and rendered views are, the tables are not. */
public static boolean viewShownByDefault(String view) {
return List.of("Pretty", "Raw", "Hex", "Render").contains(view);
}
private static CheckTable viewsTable(Settings s, String prefix, String[] views, Runnable[] reset) {
List<String> names = ordered(s, prefix + "order", views);
String[] what = { "show", "wrap" };
CheckTable table = new CheckTable(new CheckTable.Rows() {
@Override public int count() { return names.size(); }
@Override public String name(int r) { return names.get(r); }
// The text views wrap or not from their own toolbar; only the table views have the setting.
@Override public boolean has(int r, int c) { return c == 0 || !viewShownByDefault(names.get(r)); }
// Raw is always on offer: it is the message as it is.
@Override public boolean fixed(int r, int c) { return c == 0 && "Raw".equals(names.get(r)); }
@Override public boolean get(int r, int c) {
if (fixed(r, c)) return true;
return s.getBool(viewKey(prefix, names.get(r), what[c]), c == 0 && viewShownByDefault(names.get(r)));
}
@Override public void set(int r, int c, boolean v) { s.setBool(viewKey(prefix, names.get(r), what[c]), v); }
@Override public void move(int from, int to) {
names.add(to, names.remove(from));
s.set(prefix + "order", String.join("|", names));
}
}, "Type", new String[] { "Show", "Wrap text" }, 0, 242, 244, 241);
reset[0] = () -> { SettingsPage.clearPrefix(s, prefix); names.clear(); names.addAll(List.of(views)); table.repaint(); };
return table;
}
public static SettingsPage messageEditor(SuiteContext ctx) {
Settings s = ctx.settings();
SettingsPage p = new SettingsPage();
Runnable[] resetRequest = new Runnable[1], resetResponse = new Runnable[1];
CheckTable requestViews = viewsTable(s, "editor.request.", REQUEST_VIEWS, resetRequest);
CheckTable responseViews = viewsTable(s, "editor.response.", RESPONSE_VIEWS, resetResponse);
p.block("Message editor request views", SettingsPage.Kind.USER,
"Use these settings to adjust which views are available from the toolbar above each request and in which order they appear.",
() -> resetRequest[0].run(), requestViews);
p.block("Message editor response views", SettingsPage.Kind.USER,
"Use these settings to adjust which views are available from the toolbar above each response and in which order they appear.",
() -> resetResponse[0].run(), responseViews);
JTextField font = Ui.field(s.get("editor.font", "Monospaced " + Theme.FONT_SIZE + "pt"));
font.setEditable(false);
font.setFocusable(false);
font.setHorizontalAlignment(SwingConstants.CENTER);
Ui.sized(font, 314);
JPanel fontRow = new JPanel();
fontRow.setLayout(new BoxLayout(fontRow, BoxLayout.X_AXIS));
fontRow.setOpaque(false);
JButton change = Ui.button("Change font ...");
change.addActionListener(e -> {
String[] families = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
JComboBox<String> fam = Ui.combo(families);
fam.setSelectedItem(s.get("editor.font", "Monospaced " + Theme.FONT_SIZE + "pt").replaceAll(" \\d+pt$", ""));
JSpinner size = new JSpinner(new SpinnerNumberModel(Theme.FONT_SIZE, 6, 40, 1));
JPanel f = Ui.form("Family:", fam, "Size:", size);
f.setBorder(Ui.pad(10, 10, 10, 10));
if (JOptionPane.showConfirmDialog(change, f, "Message editor font", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
String v = fam.getSelectedItem() + " " + size.getValue() + "pt";
s.set("editor.font", v); font.setText(v);
}
});
JLabel fontLabel = opensuite.ui.Sections.caption("Font:");
for (Component c : new Component[] { fontLabel, Box.createHorizontalStrut(5), font, Box.createHorizontalStrut(5), change }) fontRow.add(c);
fontRow.setPreferredSize(new Dimension(fontLabel.getPreferredSize().width + 10 + 314 + change.getPreferredSize().width, Ui.tall(22)));
p.block("HTTP message display", SettingsPage.Kind.USER,
"Use these settings to control how HTTP messages are displayed.",
() -> SettingsPage.clearPrefix(s, "editor.display."),
fontRow, opensuite.ui.Sections.gap(10),
SettingsPage.check(s, "editor.display.highlightRequest", true, "Highlight request syntax"),
SettingsPage.check(s, "editor.display.highlightResponse", true, "Highlight response syntax"),
SettingsPage.check(s, "editor.display.prettyByDefault", true, "Pretty print by default"),
SettingsPage.check(s, "editor.display.hideDecodedOnHover", false, "Hide decoded text on hover"));
JRadioButton[] cs = SettingsPage.radios(s, "editor.charset", "auto", new String[]{"auto", "platform", "raw", "specific"},
"Recognize automatically based on message headers", "Use the platform default (UTF-8)", "Display as raw bytes", "Use a specific character set:");
JComboBox<String> charset = SettingsPage.combo(s, "editor.charset.name", java.nio.charset.Charset.availableCharsets().keySet().toArray(new String[0]), "UTF-8");
p.block("Character sets", SettingsPage.Kind.USER,
"The character set used to display message bodies.",
() -> { s.set("editor.charset", "auto"); s.set("editor.charset.name", "UTF-8"); },
cs[0], cs[1], cs[2], Ui.row(cs[3], charset));
p.block("HTML rendering", SettingsPage.Kind.USER,
"Controls whether the Render view may fetch images, stylesheets and scripts referenced by a page.",
() -> s.setBool("render.allowHttp", false),
SettingsPage.check(s, "render.allowHttp", false, "Make additional HTTP requests if required to render the page"));
p.block("HTTP message search", SettingsPage.Kind.USER,
"Default options for the search bar at the bottom of each message editor.",
() -> SettingsPage.clearPrefix(s, "editor.search."),
Ui.row(SettingsPage.check(s, "editor.search.caseSensitive", false, "Case sensitive"),
SettingsPage.check(s, "editor.search.regex", false, "Regex"),
SettingsPage.check(s, "editor.search.autoScroll", false, "Auto-scroll to match when text changes")));
p.block("Hide request headers", SettingsPage.Kind.USER,
"Headers that the Pretty view collapses by default, so that the relevant part of a request is immediately visible.",
() -> { s.setBool("editor.hideRequestHeaders", false); s.set("editor.hideRequestHeaders.list", ""); },
SettingsPage.check(s, "editor.hideRequestHeaders", false, "Hide the following headers by default:"),
new ListBox(s, "editor.hideRequestHeaders.list", List.of("accept", "accept-encoding", "accept-language", "if-modified-since", "if-none-match",
"priority", "sec-ch-ua", "sec-ch-ua-mobile", "sec-ch-ua-platform", "sec-fetch-dest", "sec-fetch-mode", "sec-fetch-site", "sec-fetch-user", "upgrade-insecure-requests"), "Enter a new header"));
p.block("Hide response headers", SettingsPage.Kind.USER,
"Headers that the Pretty view collapses by default in responses.",
() -> { s.setBool("editor.hideResponseHeaders", false); s.set("editor.hideResponseHeaders.list", ""); },
SettingsPage.check(s, "editor.hideResponseHeaders", false, "Hide the following headers by default:"),
new ListBox(s, "editor.hideResponseHeaders.list", List.of("accept-ranges", "alt-svc", "cache-control", "cf-ray", "connection", "content-security-policy",
"cross-origin-embedder-policy", "cross-origin-opener-policy", "cross-origin-resource-policy", "date", "etag", "expires", "last-modified", "nel",
"report-to", "server", "strict-transport-security", "vary", "via", "x-content-type-options", "x-frame-options", "x-xss-protection"), "Enter a new header"));
return p;
}
/** A list with Remove / Clear and an Add field, persisted as newline-separated text. */
static final class ListBox extends JPanel {
ListBox(Settings s, String key, List<String> defaults, String placeholder) {
super(new BorderLayout(8, 0));
setOpaque(false);
DefaultListModel<String> m = new DefaultListModel<>();
String cur = s.get(key, "");
for (String v : cur.isEmpty() ? defaults : List.of(cur.split("\n"))) if (!v.isBlank()) m.addElement(v);
Runnable save = () -> { StringBuilder sb = new StringBuilder(); for (int i = 0; i < m.size(); i++) sb.append(m.get(i)).append('\n'); s.set(key, sb.toString()); };
JList<String> list = new JList<>(m);
list.setFont(Ui.PLAIN);
JButton remove = Ui.button("Remove"), clear = Ui.button("Clear");
remove.addActionListener(e -> { int i = list.getSelectedIndex(); if (i >= 0) { m.remove(i); save.run(); } });
clear.addActionListener(e -> { m.clear(); save.run(); });
JTextField entry = Ui.field("");
entry.putClientProperty("JTextField.placeholderText", placeholder);
JButton add = Ui.button("Add");
add.addActionListener(e -> { if (!entry.getText().isBlank()) { m.addElement(entry.getText().strip()); entry.setText(""); save.run(); } });
entry.addActionListener(e -> add.doClick());
JScrollPane sp = Ui.scroll(list);
sp.setPreferredSize(new Dimension(420, 120));
add(Ui.buttonColumn(remove, clear), BorderLayout.WEST);
add(sp, BorderLayout.CENTER);
add(Ui.row(add, entry), BorderLayout.SOUTH);
}
}
public static SettingsPage hotkeys(SuiteContext ctx) { return new HotkeysPage(ctx.settings()); }
public static SettingsPage display(SuiteContext ctx, JComponent existingDisplay) {
Settings s = ctx.settings();
SettingsPage p = new SettingsPage();
JComboBox<String> fontSize = SettingsPage.combo(s, "ui.fontSize", new String[]{"10", "11", "12", "13", "14", "15", "16", "18", "20"}, String.valueOf(Theme.FONT_SIZE)); // unset, it follows the desktop
JRadioButton light = Ui.radio("Light", !Theme.darkPreferred());
JRadioButton dark = Ui.radio("Dark", Theme.darkPreferred());
ButtonGroup g = new ButtonGroup(); g.add(light); g.add(dark);
java.awt.event.ItemListener theme = e -> {
boolean wantDark = dark.isSelected();
if (wantDark == Theme.dark || e.getStateChange() != java.awt.event.ItemEvent.SELECTED) return;
opensuite.ui.Restart.ask(dark, ctx, "the " + (wantDark ? "dark" : "light") + " theme", () -> {
s.set("ui.theme", wantDark ? "dark" : "light");
try { java.util.prefs.Preferences.userRoot().node("opensuite.v1").put("ui.theme", wantDark ? "dark" : "light"); } catch (Exception ignore) { }
if (opensuite.ui.UiScale.relaunchWith(opensuite.ui.UiScale.desired(), opensuite.ui.Restart.arguments(ctx))) System.exit(0);
}, () -> (Theme.dark ? dark : light).setSelected(true));
};
light.addItemListener(theme); dark.addItemListener(theme);
Ui.sized(fontSize, 72);
light.setBorder(Ui.pad(0, 2, 0, 0));
dark.setBorder(Ui.pad(0, 2, 0, 0));
JLabel themeLabel = opensuite.ui.Sections.caption("Theme:");
themeLabel.setPreferredSize(new Dimension(54, 18));
JPanel themeRow = SettingsPage.line(22, themeLabel, light, 30, dark);
themeRow.setBorder(Ui.pad(5, 0, 0, 0));
themeRow.setPreferredSize(new Dimension(themeRow.getPreferredSize().width, 25));
p.block("Appearance", SettingsPage.Kind.USER,
"Use these settings to control the appearance of the user interface. Changing the theme restarts the application so that it applies to every panel.",
() -> { s.remove("ui.fontSize"); }, // back to following the desktop
SettingsPage.line(22, opensuite.ui.Sections.caption("Font size:"), 5, fontSize), themeRow);
if (existingDisplay != null) p.addSection(existingDisplay);
// A scale chosen by hand is what "configure" means here; left alone, the system's own setting applies.
boolean byHand = opensuite.ui.UiScale.hasSaved();
JCheckBox configure = Ui.check("Configure scaling settings", byHand);
JCheckBox systemDpi = Ui.check("Use system DPI settings", false);
JComboBox<String> factor = Ui.combo(new String[]{"1.0", "1.25", "1.5", "1.75", "2.0", "2.5", "3.0"});
factor.setSelectedItem(String.valueOf(opensuite.ui.UiScale.desired()));
Ui.sized(factor, 72);
JLabel factorLabel = opensuite.ui.Sections.caption("Scale factor:");
Runnable enable = () -> {
systemDpi.setEnabled(configure.isSelected());
boolean manual = configure.isSelected() && !systemDpi.isSelected();
factor.setEnabled(manual);
factorLabel.setEnabled(manual);
};
enable.run();
configure.addActionListener(e -> {
// Ticked, it starts from the system's setting; unticked, nothing is chosen by hand any more.
systemDpi.setSelected(configure.isSelected());
opensuite.ui.UiScale.clearSaved();
enable.run();
});
systemDpi.addActionListener(e -> {
if (systemDpi.isSelected()) opensuite.ui.UiScale.clearSaved();
enable.run();
});
boolean[] puttingBack = {false};
factor.addActionListener(e -> {
if (!factor.isEnabled() || puttingBack[0]) return;
double want;
try { want = Double.parseDouble(String.valueOf(factor.getSelectedItem())); } catch (Exception ignore) { return; }
double now = opensuite.ui.UiScale.desired();
if (Math.abs(want - now) < 0.001 && opensuite.ui.UiScale.hasSaved()) return;
opensuite.ui.Restart.ask(factor, ctx, "the new scale",
() -> opensuite.ui.UiScale.changeTo(want, opensuite.ui.Restart.arguments(ctx)),
() -> { puttingBack[0] = true; try { factor.setSelectedItem(String.valueOf(now)); } finally { puttingBack[0] = false; } });
});
JPanel factorRow = SettingsPage.line(22, factorLabel, 5, factor);
JComponent dpiRow = OptionsPage.indent(systemDpi, 32), factorIndented = OptionsPage.indent(factorRow, 30);
dpiRow.setBorder(BorderFactory.createCompoundBorder(Ui.pad(4, 0, 0, 0), dpiRow.getBorder()));
factorIndented.setBorder(BorderFactory.createCompoundBorder(Ui.pad(4, 0, 0, 0), factorIndented.getBorder()));
p.restoreMark().block("Scaling", SettingsPage.Kind.USER,
"Use these settings to control the appearance on high-resolution displays. Changing the scale factor restarts the application.",
() -> { opensuite.ui.UiScale.clearSaved(); configure.setSelected(false); systemDpi.setSelected(false); enable.run(); },
configure, dpiRow, factorIndented);
p.block("Title bar appearance", SettingsPage.Kind.USER,
"Choose whether the top-level menu is merged with your system's title bar. Disable this to use your operating system's window styling. Restart for any changes to take effect.",
() -> s.setBool("ui.mergeTitleBar", !opensuite.core.Os.MAC),
SettingsPage.check(s, "ui.mergeTitleBar", !opensuite.core.Os.MAC, "Merge top-level menu with system title bar"));
JRadioButton[] zebra = SettingsPage.radios(s, "ui.zebra", "on", new String[]{"on", "off"}, "Zebra stripe", "No zebra stripe");
TablePreview striped = new TablePreview(true, zebra[0]), plain = new TablePreview(false, zebra[1]);
// Tables everywhere follow the choice at once.
java.awt.event.ItemListener restripe = e -> {
if (e.getStateChange() != java.awt.event.ItemEvent.SELECTED) return;
UIManager.put("Table.alternateRowColor", zebra[0].isSelected() ? new javax.swing.plaf.ColorUIResource(Theme.ACCENT_FAINT) : null);
for (Window w : Window.getWindows()) w.repaint();
};
zebra[0].addItemListener(restripe);
zebra[1].addItemListener(restripe);
JPanel previews = new JPanel(null);
previews.setOpaque(false);
// The two tiles are drawings, an eighth larger at the usual 13px as the reference's are.
double k = 1 + Ui.fontGrowth() / 16.0;
int tw = (int) Math.round(162 * k), th = (int) Math.round(89 * k), second = 2 + tw + 67; // the gap between them stays
previews.setPreferredSize(new Dimension((int) Math.round(432 * k), th + 35 + Ui.fontGrowth()));
striped.setBounds(2, 2, tw, th);
plain.setBounds(second, 2, tw, th);
zebra[0].setBounds(2, th + 16, 200, Ui.tall(18));
zebra[1].setBounds(second, th + 16, 200, Ui.tall(18));
for (JComponent c : new JComponent[] { striped, plain, zebra[0], zebra[1] }) previews.add(c);
p.block("Table appearance", SettingsPage.Kind.USER,
"Use this setting to control the interface and behaviour of your tables.",
() -> { s.set("ui.zebra", "on"); zebra[0].setSelected(true); },
previews);
JRadioButton[] ev = SettingsPage.radios(s, "ui.issueEvidence", "grouped", new String[]{"grouped", "ungrouped"}, "Grouped evidence", "Ungrouped evidence");
p.block("Issues", SettingsPage.Kind.USER,
"Control how the evidence for an issue is displayed: grouped by request, or one item per piece of evidence.",
() -> { s.set("ui.issueEvidence", "grouped"); s.setBool("ui.expandEvidence", false); },
Ui.row(ev[0], Box.createHorizontalStrut(60), ev[1]),
SettingsPage.check(s, "ui.expandEvidence", false, "Expand evidence groups by default"));
p.block("Title bar actions", SettingsPage.Kind.USER,
"Choose the actions shown as icons in the title bar, and the order in which they appear. The settings cog is always shown at the end.",
() -> s.set("ui.titleActions", ""),
Ui.note("Drag to reorder. Click the X to remove."),
new TitleActions(s));
return p;
}
/**
* A corner of a table as a picture of one row style: striped or not. The
* one in force is framed in blue, and clicking either chooses it.
*/
private static final class TablePreview extends JComponent {
private final boolean striped;
private final JRadioButton choice;
TablePreview(boolean striped, JRadioButton choice) {
this.striped = striped;
this.choice = choice;
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
addMouseListener(new java.awt.event.MouseAdapter() {
@Override public void mousePressed(java.awt.event.MouseEvent e) { if (!choice.isSelected()) choice.doClick(); }
});
choice.addItemListener(e -> { if (getParent() != null) getParent().repaint(); });
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
opensuite.ui.Theme.textSmoothing(g2);
double k = 1 + Ui.fontGrowth() / 16.0;
g2.scale(k, k);
int w = (int) Math.round(getWidth() / k), h = (int) Math.round(getHeight() / k);
java.awt.geom.RoundRectangle2D card = new java.awt.geom.RoundRectangle2D.Float(1, 1, w - 2, h - 2, 8, 8);
g2.setColor(Theme.CONTROL_TINT);
g2.fill(card);
Shape before = g2.getClip();
g2.clip(card);
// The table's top-left corner: it runs off the card at the right and the bottom.
g2.setColor(Theme.CONTENT);
g2.fillRect(13, 12, w, h);
g2.setFont(Ui.PLAIN.deriveFont(13f));
FontMetrics fm = g2.getFontMetrics();
for (int r = 0; r < 3; r++) {
int y = 12 + r * 26;
if (striped && r == 1) { g2.setColor(Theme.dark ? Theme.BG : new Color(0xFA, 0xFA, 0xFA)); g2.fillRect(13, y, w, 26); }
g2.setColor(Theme.TEXT);
g2.drawString("Data", 23, y + (26 - fm.getHeight()) / 2 + fm.getAscent());
}
g2.setClip(before);
if (choice.isSelected()) {
g2.setColor(Theme.CONTROL);
g2.setStroke(new BasicStroke(2f));
g2.draw(new java.awt.geom.RoundRectangle2D.Float(1, 1, w - 2, h - 2, 8, 8));
} else {
g2.setColor(Theme.BORDER);
g2.draw(new java.awt.geom.RoundRectangle2D.Float(1.5f, 0.5f, w - 3, h - 1, 8, 8));
}
g2.dispose();
}
}
/** The reorderable list of title bar actions, with an add button and an X per row. */
static final class TitleActions extends JPanel {
static final String[] ALL = {"Open browser", "Open command palette", "Open search window"};
private final Settings s;
private final List<String> order = new ArrayList<>();
TitleActions(Settings s) {
super(new BorderLayout(0, 4));
this.s = s;
setOpaque(false);
String cur = s.get("ui.titleActions", "");
order.addAll(cur.isEmpty() ? List.of(ALL[0], ALL[1]) : List.of(cur.split("\\|")));
rebuild();
}
private void save() { s.set("ui.titleActions", String.join("|", order)); }
private void rebuild() {
removeAll();
JPanel top = new JPanel(new BorderLayout());
top.setOpaque(false);
JButton add = Glyphs.button(Glyphs.plus(16, Theme.ICON), "Add an action", () -> {
List<String> missing = new ArrayList<>();
for (String a : ALL) if (!order.contains(a)) missing.add(a);
if (missing.isEmpty()) return;
Object pick = JOptionPane.showInputDialog(this, "Action:", "Add title bar action", JOptionPane.PLAIN_MESSAGE, null, missing.toArray(), missing.get(0));
if (pick != null) { order.add(String.valueOf(pick)); save(); rebuild(); }
});
top.add(add, BorderLayout.EAST);
add(top, BorderLayout.NORTH);
JPanel rows = new JPanel();
rows.setLayout(new BoxLayout(rows, BoxLayout.Y_AXIS));
rows.setOpaque(false);
for (int i = 0; i < order.size(); i++) {
final int idx = i;
String name = order.get(i);
JPanel row = new JPanel(new BorderLayout(8, 0));
row.setOpaque(true);
row.setBackground(Theme.SURFACE);
row.setBorder(Ui.pad(4, 8, 4, 8));
row.setMaximumSize(new Dimension(420, 32));
Icon ic = switch (name) { case "Open browser" -> Glyphs.search(16, Theme.ICON); case "Open command palette" -> Glyphs.chevronRight(); default -> Glyphs.search(16, Theme.ICON); };
JLabel l = new JLabel(name, ic, SwingConstants.LEADING);
l.setFont(Ui.PLAIN);
JPanel right = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 0));
right.setOpaque(false);
right.add(Glyphs.button(Glyphs.arrow(14, Theme.ICON, 2), "Move up", () -> { if (idx > 0) { order.add(idx - 1, order.remove(idx)); save(); rebuild(); } }));
right.add(Glyphs.button(Glyphs.arrow(14, Theme.ICON, 1), "Move down", () -> { if (idx < order.size() - 1) { order.add(idx + 1, order.remove(idx)); save(); rebuild(); } }));
right.add(Glyphs.button(Glyphs.cross(14, Theme.ICON), "Remove", () -> { order.remove(idx); save(); rebuild(); }));
row.add(l, BorderLayout.CENTER);
row.add(right, BorderLayout.EAST);
rows.add(row);
rows.add(Box.createVerticalStrut(4));
}
add(rows, BorderLayout.CENTER);
revalidate();
repaint();
}
}
}