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.1 KB
Raw Blame
package opensuite.ui.theme;

import opensuite.ui.Theme;

import java.awt.*;
import java.awt.geom.RoundRectangle2D;

/**
 * The numbered tabs of Repeater and Intruder: each tab is a small grey pill,
 * 26px tall with 6px between pills, and the selected one carries the accent
 * across its foot. The row is 46px tall and closed by one hairline.
 */
public class PillTabbedPaneUI extends FlatTabbedPaneUI {
    /** Space between two pills; part of each tab's width, left unpainted. */
    public static final int GAP = 6;
    public static final int HEIGHT = 26;

    @Override protected void installDefaults() {
        super.installDefaults();
        tabAreaInsets = new Insets(10, 10, 10, 11);
        tabInsets = new Insets(0, 0, 0, GAP);
        selectedTabPadInsets = new Insets(0, 0, 0, 0);
    }

    @Override protected Insets getTabInsets(int placement, int index) { return tabInsets; }
    @Override protected int calculateTabHeight(int p, int i, int fontHeight) { return HEIGHT; }
    @Override protected int calculateTabWidth(int p, int i, FontMetrics fm) {
        Component c = tabPane.getTabComponentAt(i);
        if (c != null) return c.getPreferredSize().width + GAP;
        return fm.stringWidth(String.valueOf(tabPane.getTitleAt(i))) + 37 + GAP;
    }

    @Override protected void paintTabBackground(Graphics g, int p, int i, int x, int y, int w, int h, boolean sel) {
        if ("+".equals(tabPane.getTitleAt(i))) return;
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        RoundRectangle2D pill = new RoundRectangle2D.Float(x, y, w - GAP, h, 8, 8);
        g2.setColor(Theme.SURFACE);
        g2.fill(pill);
        if (sel) {
            g2.clip(pill);
            // A brighter orange than the main tabs' line, as the reference draws it.
            g2.setColor(Theme.dark ? Theme.ACCENT : new Color(0xFF, 0x66, 0x33));
            g2.fillRect(x, y + h - 3, w - GAP, 3);
        }
        g2.dispose();
    }

    @Override protected void paintTabBorder(Graphics g, int p, int i, int x, int y, int w, int h, boolean sel) {}
}