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;
import javax.swing.*;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D;
/**
* A tree whose selection is a rounded band across the whole pane rather than a
* box round the label, on the page colour, with 24px rows. A click anywhere on
* a row selects it. Measurements are the reference's site map tree: the band
* 5px in from each side, the handle 26px in, the icon 38px, the text 55px.
*/
public class RowTree extends JTree {
private int bandLeft = 5, bandRight = 5;
/** How far the selection band stops short of each side of the tree. */
public void setBand(int left, int right) { bandLeft = left; bandRight = right; repaint(); }
/** The distance from a level to its handle, and from the handle to the label. */
public void setIndents(int left, int right) {
if (getUI() instanceof BasicTreeUI ui) { ui.setLeftChildIndent(left); ui.setRightChildIndent(right); }
}
public RowTree(TreeModel model) {
super(model);
setOpaque(false);
setBackground(Theme.BG);
setFont(Ui.PLAIN);
setRowHeight(24);
setBorder(Ui.pad(5, 15, 5, 5));
if (getUI() instanceof BasicTreeUI ui) {
ui.setLeftChildIndent(11);
ui.setRightChildIndent(11);
ui.setCollapsedIcon(handle(false));
ui.setExpandedIcon(handle(true));
}
addMouseListener(new MouseAdapter() {
@Override public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e) || getRowForLocation(e.getX(), e.getY()) >= 0) return;
int row = getClosestRowForLocation(e.getX(), e.getY());
Rectangle r = row < 0 ? null : getRowBounds(row);
// Left of the label is the handle's ground; leave that to the tree.
if (r == null || e.getY() < r.y || e.getY() >= r.y + r.height || e.getX() < r.x) return;
if (e.isControlDown() || e.isMetaDown()) addSelectionRow(row); else setSelectionRow(row);
}
});
}
/** The thin 4 by 8 arrow that opens a branch, or the same turned down. */
private static Icon handle(boolean open) {
return new Icon() {
@Override public int getIconWidth() { return 8; }
@Override public int getIconHeight() { return 8; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2.setColor(Theme.TEXT);
g2.setStroke(new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
Path2D p = new Path2D.Double();
if (open) { p.moveTo(x + 0.6, y + 2.6); p.lineTo(x + 4, y + 5.3); p.lineTo(x + 7.4, y + 2.6); }
else { p.moveTo(x + 2.6, y + 0.6); p.lineTo(x + 5.3, y + 4); p.lineTo(x + 2.6, y + 7.4); }
g2.draw(p);
g2.dispose();
}
};
}
@Override public void setCellRenderer(TreeCellRenderer r) {
// The band is drawn behind the row, so the label itself stays clear.
if (r instanceof DefaultTreeCellRenderer d) {
d.setBackgroundSelectionColor(null);
d.setBorderSelectionColor(null);
d.setBackgroundNonSelectionColor(null);
d.setTextSelectionColor(Theme.TEXT);
d.setIconTextGap(2);
}
super.setCellRenderer(r);
}
private boolean connectors;
/**
* Join each row to the one it belongs under, as the reference's site map
* does: a thin line down from the parent, a stub across to each child, a
* dot where a top-level row sits on the line and a small ring in place of
* the handle on a row with nothing under it. Rows are 27px with these.
*/
public void setConnectors(boolean on) {
connectors = on;
setRowHeight(on ? 27 : 24);
if (getUI() instanceof BasicTreeUI ui) { ui.setLeftChildIndent(on ? 13 : 11); ui.setRightChildIndent(on ? 14 : 11); }
repaint();
}
/** Where a row's handle is centred: where its arrow is, or where one would be. */
private int handleX(Rectangle rowBounds) {
return rowBounds.x - (getUI() instanceof BasicTreeUI ui ? ui.getRightChildIndent() : 11) + 1;
}
private void paintConnectors(Graphics2D g) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g.setStroke(new BasicStroke(1f));
Rectangle clip = g.getClipBounds();
int topDepth = isRootVisible() ? 1 : 2;
for (int row = 0; row < getRowCount(); row++) {
javax.swing.tree.TreePath path = getPathForRow(row);
Rectangle r = getRowBounds(row);
if (path == null || r == null) continue;
double cy = r.y + r.height / 2.0;
int hx = handleX(r);
boolean top = path.getPathCount() <= topDepth;
int trunk; // the line this row hangs from
if (top) trunk = hx - 12;
else {
Rectangle pr = getPathBounds(path.getParentPath());
trunk = pr == null ? hx - 12 : handleX(pr) - 12;
}
// The line carries on down to the next row at this level, if the parent has one.
Object parent = path.getParentPath() == null ? null : path.getParentPath().getLastPathComponent();
boolean lastChild = parent == null
|| getModel().getIndexOfChild(parent, path.getLastPathComponent()) == getModel().getChildCount(parent) - 1;
if (clip != null && (r.y > clip.y + clip.height + 2000 || r.y + r.height < clip.y - 2000)) continue;
g.setColor(Theme.SURFACE_3);
if (!top) {
Rectangle pr = getPathBounds(path.getParentPath());
double from = pr == null ? r.y : pr.y + pr.height / 2.0 + 4;
// Each child draws the piece of the line from the row above it at this level.
g.draw(new java.awt.geom.Line2D.Double(trunk + 0.5, Math.max(from, previousSiblingY(path, r, from)), trunk + 0.5, cy));
boolean leaf = getModel().isLeaf(path.getLastPathComponent());
g.draw(new java.awt.geom.Line2D.Double(trunk + 0.5, cy, hx - (leaf ? 4 : 7), cy));
if (leaf) {
g.setColor(Theme.MUTED);
g.draw(new java.awt.geom.Ellipse2D.Double(hx - 3, cy - 3, 6, 6));
}
} else {
boolean selected = isRowSelected(row);
g.setColor(selected ? Theme.CONTROL : Theme.MUTED);
java.awt.geom.Ellipse2D dot = new java.awt.geom.Ellipse2D.Double(trunk - 2.5, cy - 3, 6, 6);
if (selected) g.fill(dot); else g.draw(dot);
}
}
}
/** The middle of the row before this one under the same parent, or {@code otherwise} for a first child. */
private double previousSiblingY(javax.swing.tree.TreePath path, Rectangle r, double otherwise) {
Object parent = path.getParentPath().getLastPathComponent();
int i = getModel().getIndexOfChild(parent, path.getLastPathComponent());
if (i <= 0) return otherwise;
Rectangle b = getPathBounds(path.getParentPath().pathByAddingChild(getModel().getChild(parent, i - 1)));
return b == null ? otherwise : b.y + b.height / 2.0 + (getModel().isLeaf(getModel().getChild(parent, i - 1)) ? 3 : 0);
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(getBackground());
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Theme.ACCENT_LIGHT);
int[] rows = getSelectionRows();
if (rows != null) for (int row : rows) {
Rectangle r = getRowBounds(row);
if (r != null) g2.fill(new RoundRectangle2D.Float(bandLeft, r.y, getWidth() - bandLeft - bandRight, r.height, 10, 10));
}
if (connectors) paintConnectors(g2);
g2.dispose();
super.paintComponent(g);
}
}