11package org .zaproxy .zap .extension .customactivescan .view ;
22
3- import org .parosproxy .paros .view .MainPopupMenu ;
43import org .parosproxy .paros .view .View ;
54import org .zaproxy .zap .view .messagecontainer .http .DefaultSingleHttpMessageContainer ;
65
76import javax .swing .*;
8- import javax .swing .text .Position ;
97import java .awt .*;
108
119public class ScanLogPanelPopUp extends JPopupMenu {
1210
11+ private static final long serialVersionUID = 1L ;
1312 private final static org .apache .logging .log4j .Logger LOGGER4J =
1413 org .apache .logging .log4j .LogManager .getLogger ();
1514
16- private MainPopupMenu mainPopupMenu ;
17- private ScanLogPanel scanLogPanel ;
18- private JViewport scanLogViewPort = null ;
15+ final private ScanLogPanel scanLogPanel ;
16+ final private JViewport scanLogViewPort ;
17+
1918 ScanLogPanelPopUp (JScrollPane scanLogScroller , ScanLogPanel scanLogPanel ) {
2019 this .scanLogPanel = scanLogPanel ;
21- this .mainPopupMenu = View .getSingleton ().getPopupMenu ();
2220 this .scanLogViewPort = scanLogScroller .getViewport ();
2321 }
24- private static final long serialVersionUID = 1L ;
25-
2622
27- @ Override
28- public JMenuItem add (JMenuItem item ) {
29- return this .mainPopupMenu .add (item );
30- }
3123 @ Override
3224 public void show (Component invoker , int x , int y ) {
33- /**
34- if (!httpPanelTextArea.isFocusOwner()) {
35- httpPanelTextArea.requestFocusInWindow();
36- }
3725
38- if (httpPanelTextArea.getMessage() instanceof HttpMessage) {
39- SingleHttpMessageContainer messageContainer =
40- new DefaultSingleHttpMessageContainer(
41- messageContainerName,
42- httpPanelTextArea,
43- (HttpMessage) httpPanelTextArea.getMessage());
44- View.getSingleton().getPopupMenu().show(messageContainer, x, y);
45- } else {
46- View.getSingleton().getPopupMenu().show(httpPanelTextArea, x, y);
47- }
48- **/
4926 LOGGER4J .debug ("scanLogPane is " + (scanLogPanel ==null ? "null" : "valid" ));
5027 if (scanLogPanel .getSelectedMessage () != null ) {
5128
@@ -59,13 +36,14 @@ public void show(Component invoker, int x, int y) {
5936 scanLogPanel ,
6037 scanLogPanel .getSelectedMessage ());
6138 Point viewPoint = this .scanLogViewPort .getViewPosition ();
62- // fix popup is showed in outer area of scanLogViewPort
63- this .mainPopupMenu .show (messageContainer , x , y - viewPoint .y );
64-
65- LOGGER4J .debug ("x=" + x + " y=" + y );
39+ // fix popup is showed in outer area of scanLogViewPort y -> y -viewPoint.y
40+ // Don't get the instance of org.parosproxy.paros.view.MainPopupMenu from View.getSingleton().getPopupMenu() directly.
41+ // Because it is not a pure singleton instance. if you get the instance from View.getSingleton().getPopupMenu() and reuse it,
42+ // you may encouter strange behavior that the popup menu enlarge its size each time when it is shown.
43+ View .getSingleton ().getPopupMenu ().show (messageContainer , x , y - viewPoint .y );
44+ LOGGER4J .debug ("x=" + x + " y=" + (y - viewPoint .y ));
6645 } else {
6746 LOGGER4J .debug ("getSelectedMessage is NULL" );
6847 }
69-
7048 }
7149}
0 commit comments