Skip to content

Commit 2fcf977

Browse files
committed
use montoya api to create context menu highlight colors
1 parent c5e466d commit 2fcf977

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/main/java/swurg/gui/components/menus/ParametersContextMenu.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111
import javax.swing.JTable;
1212
import javax.swing.SwingUtilities;
1313

14+
import burp.api.montoya.MontoyaApi;
15+
import burp.api.montoya.core.HighlightColor;
16+
import burp.api.montoya.ui.swing.SwingUtils;
1417
import swurg.gui.components.tables.renderers.CustomTableCellRenderer;
1518

1619
public class ParametersContextMenu extends JPopupMenu {
1720

21+
private final SwingUtils swingUtils;
22+
1823
private final JTable table;
1924

20-
public ParametersContextMenu(JTable table) {
25+
public ParametersContextMenu(MontoyaApi montoyaApi, JTable table) {
26+
this.swingUtils = montoyaApi.userInterface().swingUtils();
27+
2128
this.table = table;
2229

2330
initComponents();
2431
}
2532

2633
private void initComponents() {
27-
JMenu highlightMenu = createHighlightMenu();
28-
this.add(highlightMenu);
34+
this.add(createHighlightMenu());
2935
}
3036

3137
private void processSelectedRows(Consumer<Integer> action) {
@@ -39,9 +45,12 @@ private void processSelectedRows(Consumer<Integer> action) {
3945
private JMenu createHighlightMenu() {
4046
JMenu highlightMenu = new JMenu("Highlight");
4147

42-
Arrays.asList(null, Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE,
43-
Color.MAGENTA, Color.PINK, Color.GRAY)
44-
.forEach(color -> highlightMenu.add(createHighlightMenuItem(color)));
48+
Arrays.stream(HighlightColor.values())
49+
.forEach(highlightColor -> {
50+
Color color = (highlightColor.compareTo(HighlightColor.NONE) == 0) ? null
51+
: this.swingUtils.colorForHighLight(highlightColor);
52+
highlightMenu.add(createHighlightMenuItem(color));
53+
});
4554

4655
return highlightMenu;
4756
}
@@ -56,9 +65,7 @@ private JMenuItem createHighlightMenuItem(Color color) {
5665
CustomTableCellRenderer renderer = (CustomTableCellRenderer) table.getDefaultRenderer(Object.class);
5766

5867
menuItem.addActionListener(e -> processSelectedRows(index -> {
59-
SwingUtilities.invokeLater(() -> {
60-
renderer.setRowHighlightColor(index, color);
61-
});
68+
SwingUtilities.invokeLater(() -> renderer.setRowHighlightColor(index, color));
6269
}));
6370

6471
return menuItem;

src/main/java/swurg/gui/components/menus/ParserContextMenu.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@
2020
import javax.swing.SwingUtilities;
2121

2222
import burp.api.montoya.MontoyaApi;
23+
import burp.api.montoya.core.HighlightColor;
2324
import burp.api.montoya.http.message.HttpRequestResponse;
2425
import burp.api.montoya.http.message.requests.HttpRequest;
2526
import burp.api.montoya.http.message.responses.HttpResponse;
2627
import burp.api.montoya.scanner.AuditConfiguration;
2728
import burp.api.montoya.scanner.BuiltInAuditConfiguration;
29+
import burp.api.montoya.ui.swing.SwingUtils;
2830
import swurg.gui.components.tables.models.ParserTableModel;
2931
import swurg.gui.components.tables.renderers.CustomTableCellRenderer;
3032

3133
public class ParserContextMenu extends JPopupMenu {
3234

3335
private final MontoyaApi montoyaApi;
36+
private final SwingUtils swingUtils;
3437

3538
private final JTable table;
3639

3740
public ParserContextMenu(MontoyaApi montoyaApi, JTable table) {
3841
this.montoyaApi = montoyaApi;
42+
this.swingUtils = montoyaApi.userInterface().swingUtils();
43+
3944
this.table = table;
4045

4146
initComponents();
@@ -205,9 +210,12 @@ private JMenuItem createSendToComparerMenuItem() {
205210
private JMenu createHighlightMenu() {
206211
JMenu highlightMenu = new JMenu("Highlight");
207212

208-
Arrays.asList(null, Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE,
209-
Color.MAGENTA, Color.PINK, Color.GRAY)
210-
.forEach(color -> highlightMenu.add(createHighlightMenuItem(color)));
213+
Arrays.stream(HighlightColor.values())
214+
.forEach(highlightColor -> {
215+
Color color = (highlightColor.compareTo(HighlightColor.NONE) == 0) ? null
216+
: this.swingUtils.colorForHighLight(highlightColor);
217+
highlightMenu.add(createHighlightMenuItem(color));
218+
});
211219

212220
return highlightMenu;
213221
}
@@ -222,9 +230,7 @@ private JMenuItem createHighlightMenuItem(Color color) {
222230
CustomTableCellRenderer renderer = (CustomTableCellRenderer) table.getDefaultRenderer(Object.class);
223231

224232
menuItem.addActionListener(e -> processSelectedRows(index -> {
225-
SwingUtilities.invokeLater(() -> {
226-
renderer.setRowHighlightColor(index, color);
227-
});
233+
SwingUtilities.invokeLater(() -> renderer.setRowHighlightColor(index, color));
228234
}));
229235

230236
return menuItem;

src/main/java/swurg/gui/views/ParametersPanel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
public class ParametersPanel extends JPanel
4545
implements HttpHandler, TableModelObserver {
4646

47+
private final MontoyaApi montoyaApi;
4748
private final Frame suiteFrame;
4849

4950
private final ParametersTableModel parametersTableModel;
@@ -61,6 +62,7 @@ public class ParametersPanel extends JPanel
6162
private JScrollPane scrollPane;
6263

6364
public ParametersPanel(MontoyaApi montoyaApi) {
65+
this.montoyaApi = montoyaApi;
6466
this.suiteFrame = montoyaApi.userInterface().swingUtils().suiteFrame();
6567

6668
this.parametersTableModel = new ParametersTableModel();
@@ -94,7 +96,7 @@ private void initComponents() {
9496
this.setLayout(new BorderLayout());
9597

9698
TablePanel tablePanel = new TablePanel(parametersTableModel, new CustomTableCellRenderer());
97-
ParametersContextMenu contextMenu = new ParametersContextMenu(tablePanel.getTable());
99+
ParametersContextMenu contextMenu = new ParametersContextMenu(this.montoyaApi, tablePanel.getTable());
98100
tablePanel.setContextMenu(contextMenu);
99101

100102
this.add(createNorthPanel(), BorderLayout.NORTH);

0 commit comments

Comments
 (0)