Skip to content

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.

2.2 KB
Raw Blame
package opensuite.ui;

import javax.swing.*;
import java.awt.*;
import java.util.function.IntConsumer;

/**
 * The pieces of a docked side panel that are the same wherever one appears:
 * its 38px heading line with the width switch and the close mark, and the
 * settings gear at the foot of the tab strip.
 */
public final class SidePanel {
    private SidePanel() {}

    /**
     * The heading line.
     *
     * @param onWidth told 0 for the narrow panel and 1 for the wide one
     * @param onClose run when the close mark is pressed
     */
    public static JPanel header(String title, int side, IntConsumer onSide, Runnable onClose) {
        JPanel head = new JPanel(new BorderLayout());
        head.setBackground(Theme.BG);
        head.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createMatteBorder(0, 0, 1, 0, Theme.BORDER), Ui.pad(0, 10, 0, 4)));
        head.setPreferredSize(new Dimension(10, 39 + Math.round((Theme.FONT_SIZE - Theme.DEFAULT_FONT_SIZE) * 1.5f)));   // 42 at 13px, as measured
        head.add(Ui.heading(title), BorderLayout.WEST);
        JPanel right = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
        right.setOpaque(false);
        right.add(LayoutIcons.createDockSide(side, onSide));
        right.add(Box.createHorizontalStrut(6));
        JButton close = Glyphs.button(Glyphs.cross(19, Theme.TEXT), "Close this panel", onClose);
        close.setBorder(BorderFactory.createEmptyBorder());
        Ui.sized(close, 27);
        right.add(close);
        JPanel wrap = new JPanel(new GridBagLayout());
        wrap.setOpaque(false);
        wrap.add(right);
        head.add(wrap, BorderLayout.EAST);
        return head;
    }

    /** The gear at the foot of a tab strip, in its own 38px cell under a hairline. */
    public static JComponent gear(String tip, Runnable action) {
        JButton b = Glyphs.button(Glyphs.gear(17, Theme.TEXT), tip, action);
        b.setBorder(BorderFactory.createEmptyBorder());
        JPanel cell = new JPanel(new GridBagLayout());
        cell.setOpaque(false);
        cell.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Theme.BORDER));
        cell.setPreferredSize(new Dimension(VerticalTab.WIDTH, 38));
        cell.add(b);
        return cell;
    }
}