From fb3bf0094b3a1c6db2a2579861371faa877efcfd Mon Sep 17 00:00:00 2001 From: Barak Tawily Date: Wed, 30 Oct 2024 17:35:51 +0200 Subject: [PATCH 1/4] fix(issue-127): constant list size Signed-off-by: Barak Tawily --- gui/enforcement_detector.py | 4 ++-- gui/interception_filters.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gui/enforcement_detector.py b/gui/enforcement_detector.py index 90d976e..6f89a3e 100644 --- a/gui/enforcement_detector.py +++ b/gui/enforcement_detector.py @@ -65,7 +65,7 @@ def draw(self): self._extender.EDModel = DefaultListModel() self._extender.EDList = JList(self._extender.EDModel) - + self._extender.EDList.setPrototypeCellValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") scrollEDList = JScrollPane(self._extender.EDList) scrollEDList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) scrollEDList.setBounds(80, 175, 300, 110) @@ -274,7 +274,7 @@ def draw_unauthenticated(self): self._extender.EDModelUnauth = DefaultListModel() self._extender.EDListUnauth = JList(self._extender.EDModelUnauth) - + self._extender.EDListUnauth.setPrototypeCellValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") scrollEDListUnauth = JScrollPane(self._extender.EDListUnauth) scrollEDListUnauth.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) scrollEDListUnauth.setBounds(80, 175, 300, 110) diff --git a/gui/interception_filters.py b/gui/interception_filters.py index 72b5b0e..71c1129 100644 --- a/gui/interception_filters.py +++ b/gui/interception_filters.py @@ -55,6 +55,7 @@ def draw(self): self._extender.IFModel = DefaultListModel() self._extender.IFList = JList(self._extender.IFModel) + self._extender.IFList.setPrototypeCellValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") scrollIFList = JScrollPane(self._extender.IFList) scrollIFList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) @@ -225,7 +226,7 @@ def draw(self): ) ) ) - + From 60ae5e38826004d6e1137c6b91ba23f73f7e7f0b Mon Sep 17 00:00:00 2001 From: Barak Tawily Date: Wed, 30 Oct 2024 17:41:51 +0200 Subject: [PATCH 2/4] fix: black filter list to default Signed-off-by: Barak Tawily --- gui/enforcement_detector.py | 3 --- gui/interception_filters.py | 2 -- 2 files changed, 5 deletions(-) diff --git a/gui/enforcement_detector.py b/gui/enforcement_detector.py index 6f89a3e..be6f802 100644 --- a/gui/enforcement_detector.py +++ b/gui/enforcement_detector.py @@ -4,7 +4,6 @@ import sys sys.path.append("..") -from java.awt import Color from javax.swing import JLabel from javax.swing import JList from javax.swing import JPanel @@ -69,7 +68,6 @@ def draw(self): scrollEDList = JScrollPane(self._extender.EDList) scrollEDList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) scrollEDList.setBounds(80, 175, 300, 110) - scrollEDList.setBorder(LineBorder(Color.BLACK)) self._extender.EDAdd = JButton("Add filter", actionPerformed=self.addEDFilter) self._extender.EDAdd.setBounds(390, 85, 120, 30) @@ -278,7 +276,6 @@ def draw_unauthenticated(self): scrollEDListUnauth = JScrollPane(self._extender.EDListUnauth) scrollEDListUnauth.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) scrollEDListUnauth.setBounds(80, 175, 300, 110) - scrollEDListUnauth.setBorder(LineBorder(Color.BLACK)) self._extender.EDAddUnauth = JButton("Add filter", actionPerformed=self.addEDFilterUnauth) diff --git a/gui/interception_filters.py b/gui/interception_filters.py index 71c1129..50da4e6 100644 --- a/gui/interception_filters.py +++ b/gui/interception_filters.py @@ -4,7 +4,6 @@ import sys sys.path.append("..") -from java.awt import Color from javax.swing import JList from javax.swing import JLabel from javax.swing import JPanel @@ -60,7 +59,6 @@ def draw(self): scrollIFList = JScrollPane(self._extender.IFList) scrollIFList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) scrollIFList.setBounds(80, 175, 300, 110) - scrollIFList.setBorder(LineBorder(Color.BLACK)) # Adding some default interception filters # self.IFModel.addElement("Scope items only: (Content is not required)") # commented for better first impression. From 527ddd32639f43d1ab40fd97243d52465ba1f478 Mon Sep 17 00:00:00 2001 From: Barak Tawily Date: Wed, 30 Oct 2024 17:42:33 +0200 Subject: [PATCH 3/4] fix(issue-127): horizontal scroll bar enabled Signed-off-by: Barak Tawily --- gui/interception_filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/interception_filters.py b/gui/interception_filters.py index 50da4e6..bbd2d3e 100644 --- a/gui/interception_filters.py +++ b/gui/interception_filters.py @@ -58,6 +58,7 @@ def draw(self): scrollIFList = JScrollPane(self._extender.IFList) scrollIFList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) + scrollIFList.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) scrollIFList.setBounds(80, 175, 300, 110) # Adding some default interception filters From 96b3fa84a2697d510e2a21324823dcd69fae6269 Mon Sep 17 00:00:00 2001 From: sule01u Date: Tue, 5 Nov 2024 10:37:21 +0800 Subject: [PATCH 4/4] fix-issue-127 The optimized script resolves the flickering issue of the Filter list scrollbar by adjusting scrollbar properties and refresh mechanisms. --- gui/match_replace.py | 383 +++++++++++++++++++++++-------------------- 1 file changed, 201 insertions(+), 182 deletions(-) diff --git a/gui/match_replace.py b/gui/match_replace.py index da8edc7..501c144 100644 --- a/gui/match_replace.py +++ b/gui/match_replace.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- +# coding: utf-8 -from java.awt import Color +from java.awt import Color, Dimension from javax.swing import JList from javax.swing import JPanel from javax.swing import JLabel @@ -12,23 +12,24 @@ from javax.swing import GroupLayout from javax.swing import DefaultListModel from javax.swing.border import LineBorder - import re + class MatchReplace(): def __init__(self, extender): self._extender = extender - + self.scrollMRList = None # Declare scrollMRList as an instance attribute + def draw(self): """ init the match/replace tab """ - #todo add an option to ignore large requests + # todo add an option to ignore large requests padding = 5 labelWidth = 140 labelHeight = 30 editHeight = 110 - editWidth = 300 - buttonWidth = 120 + editWidth = 435 + buttonWidth = 120 buttonHeight = 30 column1X = 10 column2X = column1X + labelWidth + padding @@ -58,7 +59,7 @@ def draw(self): self._extender.MRType = JComboBox(MRStrings) self._extender.MRType.setBounds(column2X, row1Y, editWidth, labelHeight) - + self._extender.MText = JTextArea("", 5, 30) scrollMText = JScrollPane(self._extender.MText) scrollMText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) @@ -75,14 +76,18 @@ def draw(self): self._extender.MRModel = DefaultListModel() self._extender.MRList = JList(self._extender.MRModel) - scrollMRList = JScrollPane(self._extender.MRList) - scrollMRList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) - scrollMRList.setBounds(column2X, row5Y, editWidth, editHeight) - scrollMRList.setBorder(LineBorder(Color.BLACK)) + self._extender.MRList.setVisibleRowCount(5) + + self.scrollMRList = JScrollPane(self._extender.MRList) + self.scrollMRList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) + self.scrollMRList.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) + self.scrollMRList.setBounds(column2X, row5Y, editWidth, editHeight) + self.scrollMRList.setPreferredSize(Dimension(editWidth, editHeight)) + self.scrollMRList.setBorder(LineBorder(Color.BLACK)) - self._extender.MRAdd = JButton("Add filter", actionPerformed=self.addMRFilter) + self._extender.MRAdd = JButton("Add filter", actionPerformed=self.addMRFilter) self._extender.MRAdd.setBounds(column2X, row4Y, buttonWidth, buttonHeight) - self._extender.MRDel = JButton("Remove filter", actionPerformed=self.delMRFilter) + self._extender.MRDel = JButton("Remove filter", actionPerformed=self.delMRFilter) self._extender.MRDel.setBounds(column3X, row5Y, buttonWidth, buttonHeight) self._extender.MRMod = JButton("Modify filter", actionPerformed=self.modMRFilter) self._extender.MRMod.setBounds(column3X, row5Y + buttonHeight + padding, buttonWidth, buttonHeight) @@ -97,174 +102,175 @@ def draw(self): layout.setAutoCreateContainerGaps(True) layout.setHorizontalGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup() - .addComponent( - MRTypeLabel, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - MContent, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - RContent, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - MRLabelList, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - .addGroup(layout.createParallelGroup() - .addComponent( - self._extender.MRType, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - scrollMText, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - scrollRText, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRAdd, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRFeedback, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - scrollMRList, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRMod, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRDel, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - ) - + .addGroup(layout.createParallelGroup() + .addComponent( + MRTypeLabel, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + MContent, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + RContent, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + MRLabelList, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + .addGroup(layout.createParallelGroup() + .addComponent( + self._extender.MRType, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + scrollMText, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + scrollRText, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRAdd, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRFeedback, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self.scrollMRList, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRMod, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRDel, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + ) + layout.setVerticalGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent( - MRTypeLabel, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRType, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent( - MContent, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - scrollMText, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent( - RContent, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - scrollRText, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - .addGroup(layout.createSequentialGroup() - .addComponent( - self._extender.MRAdd, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRFeedback, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent( - MRLabelList, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - scrollMRList, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - ) - .addComponent( - self._extender.MRMod, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) - .addComponent( - self._extender.MRDel, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - GroupLayout.PREFERRED_SIZE, - ) + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent( + MRTypeLabel, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRType, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent( + MContent, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + scrollMText, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent( + RContent, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + scrollRText, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + .addGroup(layout.createSequentialGroup() + .addComponent( + self._extender.MRAdd, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRFeedback, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent( + MRLabelList, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self.scrollMRList, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + ) + .addComponent( + self._extender.MRMod, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) + .addComponent( + self._extender.MRDel, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + GroupLayout.PREFERRED_SIZE, + ) ) def addMRFilter(self, event): typeName = self._extender.MRType.getSelectedItem() match = self._extender.MText.getText() replace = self._extender.RText.getText() - key = typeName + " " + match + "->" + replace + key = "{} {} -> {}".format(typeName, match, replace) + if key in self._extender.badProgrammerMRModel: self._extender.MRFeedback.setText("Match/Replace already exists") return @@ -276,24 +282,37 @@ def addMRFilter(self, event): except re.error: self._extender.MRFeedback.setText("ERROR: Invalid regex") return - self._extender.badProgrammerMRModel[key] = {"match": match, "regexMatch": regexMatch, "replace" : replace, "type": typeName} + + self._extender.badProgrammerMRModel[key] = { + "match": match, + "regexMatch": regexMatch, + "replace": replace, + "type": typeName + } self._extender.MRModel.addElement(key) self._extender.MText.setText("") self._extender.RText.setText("") self._extender.MRFeedback.setText("") + # Refresh and ensure new item is visible + self._extender.MRList.revalidate() + self._extender.MRList.repaint() + self.scrollMRList.revalidate() + self.scrollMRList.repaint() + def delMRFilter(self, event): index = self._extender.MRList.getSelectedIndex() - if not index == -1: + if index != -1: key = self._extender.MRList.getSelectedValue() - del self._extender.badProgrammerMRModel[key] - self._extender.MRList.getModel().remove(index) - + if key in self._extender.badProgrammerMRModel: + del self._extender.badProgrammerMRModel[key] + self._extender.MRModel.remove(index) + def modMRFilter(self, event): index = self._extender.MRList.getSelectedIndex() - if not index == -1: + if index != -1: key = self._extender.MRList.getSelectedValue() - self._extender.MRType.getModel().setSelectedItem(self._extender.badProgrammerMRModel[key]["type"]) + self._extender.MRType.setSelectedItem(self._extender.badProgrammerMRModel[key]["type"]) self._extender.MText.setText(self._extender.badProgrammerMRModel[key]["match"]) self._extender.RText.setText(self._extender.badProgrammerMRModel[key]["replace"]) self.delMRFilter(event)