def __init__(self, parent, title, modal, app): border = BorderFactory.createEmptyBorder(5, 7, 5, 7) self.getContentPane().setBorder(border) self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS)) #Intro falsePositivePng = File.separator.join( [app.SCRIPTDIR, "images", "icons", "not_error36.png"]) introLbl = JMultilineLabel( app.strings.getString("manual_false_positives_info")) introLbl.setMaxWidth(600) #Table table = JTable() columns = [ app.strings.getString("Tool"), app.strings.getString("Check"), app.strings.getString("Error_id"), app.strings.getString("OSM_id") ] self.tableModel = MyTableModel([], columns) table.setModel(self.tableModel) scrollPane = JScrollPane(table) scrollPane.setAlignmentX(0.0) #OK button btnPanel = JPanel(FlowLayout(FlowLayout.CENTER)) okBtn = JButton("OK", ImageProvider.get("ok"), actionPerformed=self.on_okBtn_clicked) btnPanel.add(okBtn) btnPanel.setAlignmentX(0.0) #Layout headerPnl = JPanel() headerPnl.setLayout(BoxLayout(headerPnl, BoxLayout.X_AXIS)) headerPnl.add(JLabel(ImageIcon(falsePositivePng))) headerPnl.add(Box.createRigidArea(Dimension(10, 0))) headerPnl.add(introLbl) headerPnl.setAlignmentX(0.0) self.add(headerPnl) self.add(Box.createRigidArea(Dimension(0, 10))) self.add(scrollPane) self.add(Box.createRigidArea(Dimension(0, 10))) self.add(btnPanel) self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) self.pack()
def __init__(self, parent, title, modal, app): border = BorderFactory.createEmptyBorder(5, 7, 5, 7) self.getContentPane().setBorder(border) self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS)) #Intro falsePositivePng = File.separator.join([app.SCRIPTDIR, "images", "icons", "not_error36.png"]) introLbl = JMultilineLabel(app.strings.getString("manual_false_positives_info")) introLbl.setMaxWidth(600) #Table table = JTable() columns = [app.strings.getString("Tool"), app.strings.getString("Check"), app.strings.getString("Error_id"), app.strings.getString("OSM_id")] self.tableModel = MyTableModel([], columns) table.setModel(self.tableModel) scrollPane = JScrollPane(table) scrollPane.setAlignmentX(0.0) #OK button btnPanel = JPanel(FlowLayout(FlowLayout.CENTER)) okBtn = JButton("OK", ImageProvider.get("ok"), actionPerformed=self.on_okBtn_clicked) btnPanel.add(okBtn) btnPanel.setAlignmentX(0.0) #Layout headerPnl = JPanel() headerPnl.setLayout(BoxLayout(headerPnl, BoxLayout.X_AXIS)) headerPnl.add(JLabel(ImageIcon(falsePositivePng))) headerPnl.add(Box.createRigidArea(Dimension(10, 0))) headerPnl.add(introLbl) headerPnl.setAlignmentX(0.0) self.add(headerPnl) self.add(Box.createRigidArea(Dimension(0, 10))) self.add(scrollPane) self.add(Box.createRigidArea(Dimension(0, 10))) self.add(btnPanel) self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) self.pack()
class ErrorInfoDialog(JDialog, HyperlinkListener): """Dialog which shows info regarding the currently selcted error, so that the user can copy its info and send a message to the user who possibly made the error. """ def __init__(self, app): #java import from javax.swing import JPanel, JButton, JLabel, ImageIcon,\ JScrollPane, BorderFactory, WindowConstants,\ BoxLayout, Box from java.awt import FlowLayout, Dimension, Component from java.io import File #josm import from org.openstreetmap.josm import Main from org.openstreetmap.josm.tools import ImageProvider from org.openstreetmap.josm.gui.widgets import HtmlPanel, UrlLabel JDialog.__init__(self, Main.parent, app.strings.getString("error_info_title"), True) self.app = app self.setSize(400, 480) border = BorderFactory.createEmptyBorder(5, 7, 5, 7) self.getContentPane().setBorder(border) self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS)) #Intro intro = HtmlPanel("<html><i>%s</i></html>" % self.app.strings.getString("error_info_intro")) intro.setAlignmentX(Component.LEFT_ALIGNMENT) #User info userLbl = JLabel(self.app.strings.getString("Last_user")) userLbl.setAlignmentX(JLabel.LEFT_ALIGNMENT) self.userInfoPanel = HtmlPanel() self.userInfoPanel.getEditorPane().addHyperlinkListener(self) self.userInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT) #Panel with current error's info errorLbl = JLabel(self.app.strings.getString("Error_info")) errorLbl.setAlignmentX(JLabel.LEFT_ALIGNMENT) self.errorInfoPanel = HtmlPanel() self.errorInfoPanel.getEditorPane().addHyperlinkListener(self) self.scrollPane = JScrollPane(self.errorInfoPanel) self.scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT) #OK button btnPanel = JPanel(FlowLayout(FlowLayout.CENTER)) okBtn = JButton(self.app.strings.getString("OK"), ImageProvider.get("ok"), actionPerformed=self.on_okBtn_clicked) btnPanel.add(okBtn) btnPanel.setAlignmentX(Component.LEFT_ALIGNMENT) #Layout self.add(intro) self.add(Box.createRigidArea(Dimension(0, 7))) self.add(userLbl) self.add(Box.createRigidArea(Dimension(0, 5))) self.add(self.userInfoPanel) self.add(Box.createRigidArea(Dimension(0, 7))) self.add(errorLbl) self.add(Box.createRigidArea(Dimension(0, 5))) self.add(self.scrollPane) self.add(Box.createRigidArea(Dimension(0, 7))) self.add(btnPanel) self.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE) def update(self): """Update information shown by the dialog with those of currently selected error """ from java.net import URL, URLEncoder from javax.xml.parsers import DocumentBuilderFactory error = self.app.selectedError check = error.check view = check.view tool = view.tool #user info if error.user is not None: errorUserName = error.user.getName() errorUserId = str(error.user.getId()) #download user info from OSM API accountDate = None changesetsNumber = None if errorUserId in self.app.users: userInfo = self.app.users[errorUserId] accountDate = userInfo["account date"] changesetsNumber = userInfo["changesets number"] else: docFactory = DocumentBuilderFactory.newInstance() docBuilder = docFactory.newDocumentBuilder() url = URL("http://api.openstreetmap.org/api/0.6/user/" + errorUserId) try: stream = url.openStream() doc = docBuilder.parse(stream) rootElement = doc.getDocumentElement() userNode = rootElement.getElementsByTagName("user").item(0) accountDate = userNode.getAttributes().getNamedItem("account_created").getNodeValue() changesetsNode = rootElement.getElementsByTagName("changesets").item(0) changesetsNumber = changesetsNode.getAttributes().getNamedItem("count").getNodeValue() except: print "I could not download user info from:\n", url pass if accountDate is not None: self.app.users[errorUserId] = {"account date": accountDate, "changesets number": changesetsNumber} #user links encodedErrorUserName = URLEncoder.encode(errorUserName, "UTF-8").replace("+", "%20") userUrl = "http://www.openstreetmap.org/user/%s/" % encodedErrorUserName msgUrl = "http://www.openstreetmap.org/message/new/%s" % encodedErrorUserName #update user info text = "<html><table>" text += "<tr><td>%s</td>" % self.app.strings.getString("User_name") text += "<td><a href='%s'>%s</a></td></tr>" % (userUrl, errorUserName) if accountDate is not None: text += "<tr>" text += "<td>%s</td>" % self.app.strings.getString("Changesets") text += "<td>%s</td>" % changesetsNumber text += "</tr><tr>" text += "<td>%s</td>" % self.app.strings.getString("Mapper_since") text += "<td>%s</td>" % accountDate[:10] text += "</tr>" text += "</table>" text += "<a href='%s'>%s</a>" % (msgUrl, self.app.strings.getString("Send_a_message")) text += "</html>" self.userInfoPanel.setText(text) #error info text = "<html>" #tool text += "%s:<br>%s" % (self.app.strings.getString("Error_reported_by_the_tool"), tool.title) if tool.uri != "": text += "<br>%s" % self.link(tool.uri) #error type if not tool.isLocal: text += "<br><br>%s:" % self.app.strings.getString("Type_of_error") text += "<br>%s --> %s" % (view.title, check.title) #error help, usually a link to a Wiki page describing this errror type #error link, e.g. a link to the error on the tool web page for propName, prop in ((self.app.strings.getString("Error_help"),\ check.helpUrl), (self.app.strings.getString("Error_link"), tool.error_url(error))): if prop != "": text += "<br><br>%s:" % propName text += "<br>%s" % self.link(prop) #error description, usually some info contained in the error file if error.desc != "": text += "<br><br>%s:" % self.app.strings.getString("Description") text += "<br>%s" % error.desc #OSM object if error.osmId != "": osmType = {"n": "node", "w": "way", "r": "relation"} osmLinks = "" osmIds = error.osmId.split("_") for i, osmId in enumerate(osmIds): osmIdUrl = "http://www.openstreetmap.org/%s/%s" % (osmType[osmId[0]], osmId[1:]) osmLinks += self.link(osmIdUrl) if i != len(osmIds) - 1: osmLinks += "<br>" text += "<br><br>%s:" % self.app.strings.getString("OSM_objects") text += "<br>%s" % osmLinks #OSM changeset if error.changeset is not None: changesetUrl = "http://www.openstreetmap.org/changeset/%s" % error.changeset text += "<br><br>%s:" % self.app.strings.getString("OSM_changeset") text += "<br>%s" % self.link(changesetUrl) text += "</html>" #Update error info self.errorInfoPanel.setText(text) self.show() def link(self, url): link = "<a href='%s'>%s</a>" % (url, url) return link def hyperlinkUpdate(self, e): if e.getEventType() == HyperlinkEvent.EventType.ACTIVATED: OpenBrowser.displayUrl(e.getURL().toString()) def on_okBtn_clicked(self, event): """Dispose Error Info Dialog when ok button is clicked """ self.hide()
def initGUI(self): # # Manual tab # tabPane = JTabbedPane(JTabbedPane.TOP) reqRestabPane = JTabbedPane(JTabbedPane.TOP) splitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) tabPane.addTab("Repeater", splitPane) splitPane2 = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) splitPane.setLeftComponent(splitPane2) panel1 = JPanel() panel2 = JPanel() splitPane2.setLeftComponent(panel1) splitPane2.setRightComponent(panel2) splitPane.setRightComponent(reqRestabPane) panel1.setLayout(BoxLayout(panel1,BoxLayout.Y_AXIS)) panel2.setLayout(BoxLayout(panel2,BoxLayout.Y_AXIS)) self.requestPanel = self._callbacks.createMessageEditor(None, False) self.responsePanel = self._callbacks.createMessageEditor(None, False) label1 = JLabel("files and folders") self.lblFilename = JLabel("File name") label3 = JLabel("Response") self.editField = self._callbacks.createMessageEditor(None, True) self.dirList = JList([], valueChanged = self.listSelect) listFileDirPane = JScrollPane(self.dirList) ## Set left align listFileDirPane.setAlignmentX(Component.LEFT_ALIGNMENT) btnPanel = JPanel() btnGo = JButton("Compress & Go", actionPerformed = self.btnGoClick) btnSave = JButton("Save", actionPerformed = self.btnSaveClick) btnClear = JButton("Clear", actionPerformed = self.btnClearClick) btnReset = JButton("Reset", actionPerformed = self.btnResetRepeaterClick) btnPanel.add(btnGo) btnPanel.add(btnSave) btnPanel.add(btnReset) btnPanel.add(btnClear) btnPanel.setLayout(BoxLayout(btnPanel,BoxLayout.X_AXIS)) panel1.add(label1) panel1.add(listFileDirPane) panel2.add(self.lblFilename) panel2.add(self.editField.getComponent()) panel2.add(btnPanel) reqRestabPane.addTab("Response",self.responsePanel.getComponent()) reqRestabPane.addTab("Request",self.requestPanel.getComponent()) splitPane.setResizeWeight(0.6) # # Scanner tab # scanSplitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) tabPane.addTab("Scanner", scanSplitPane) scanSplitPane2 = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) scanSplitPane.setLeftComponent(scanSplitPane2) scanPanel1 = JPanel() scanPanel2 = JPanel() scanPanel3 = JPanel() scanSplitPane2.setLeftComponent(scanPanel1) scanSplitPane2.setRightComponent(scanPanel2) scanSplitPane.setRightComponent(scanPanel3) scanPanel1.setLayout(BoxLayout(scanPanel1,BoxLayout.Y_AXIS)) scanPanel2.setLayout(BoxLayout(scanPanel2,BoxLayout.Y_AXIS)) scanPanel3.setLayout(BoxLayout(scanPanel3,BoxLayout.Y_AXIS)) scanLabel1 = JLabel("files and folders") self.scanLblFilename = JLabel("File name") scanLabel3 = JLabel("<html><h3>Config scanner</h3></html>") scanLabel4 = JLabel("<html><h3>Scanner status</h3></html>") scanLabel5 = JLabel("""<html> <div> <h3>Notice</h3> <ul> <li>Possible to run only a scan at time</li> <li>Work with .zip file only</li> <li>Cannot continue after exit Burp</li> </ul> </div> </html>""") self.scannerStatusLabel = JLabel("<html><i style='color:grey'> Not Running</i></html>") self.checkboxScanFilename = JCheckBox("Also scan zip filename (this may be upload several files to server)") self.scanEditField = self._callbacks.createMessageEditor(None, False) self.scanDirList = JList([], valueChanged = self.scanListSelect) scanListFileDirPane = JScrollPane(self.scanDirList) ## Set left align scanListFileDirPane.setAlignmentX(Component.LEFT_ALIGNMENT) scanBtnPanel = JPanel() self.scanBtnGo = JButton("Set insertion point", actionPerformed = self.btnSetInsertionPointClick) self.scanBtnSave = JButton("Send to scanner", actionPerformed = self.btnScanClick) self.scanBtnClearInsertionPoint = JButton("Clear insertion points", actionPerformed = self.scanBtnClearInsClick) self.scanBtnClear = JButton("Clear", actionPerformed = self.scanBtnClearClick) self.scanBtnCancel = JButton("Cancel", actionPerformed = self.cancelScan) scanBtnPanel.add(self.scanBtnGo) scanBtnPanel.add(self.scanBtnSave) scanBtnPanel.add(self.scanBtnClearInsertionPoint) scanBtnPanel.add(self.scanBtnClear) scanBtnPanel.setLayout(BoxLayout(scanBtnPanel,BoxLayout.X_AXIS)) scanPanel1.add(scanLabel1) scanPanel1.add(scanListFileDirPane) scanPanel2.add(self.scanLblFilename) scanPanel2.add(self.scanEditField.getComponent()) scanPanel2.add(scanBtnPanel) scanPanel3.add(scanLabel3) scanPanel3.add(self.checkboxScanFilename) scanPanel3.add(scanLabel4) scanPanel3.add(self.scannerStatusLabel) scanPanel3.add(self.scanBtnCancel) self.scanBtnCancel.setEnabled(False) scanPanel3.add(scanLabel5) scanSplitPane.setResizeWeight(0.6) self.tab = tabPane
def __init__(self, extender): super(BeautifierOptionsPanel, self).__init__() self._extender = extender self.contentWrapper = JPanel(GridBagLayout()) self.setViewportView(self.contentWrapper) self.getVerticalScrollBar().setUnitIncrement(16) self.addMouseListener(self.RequestFocusListener( self)) # Let textArea lose focus when click empty area innerContainer = JPanel(GridBagLayout()) innerContainer.setFocusable( True ) # make sure the maxSizeText TextField is not focused when BeautifierOptionsPanel display # generalOptionPanel and it's inner component maxSizeLabel = JLabel("Max Size: ") self.maxSizeText = JTextField(5) self.maxSizeText.setHorizontalAlignment(SwingConstants.RIGHT) self.maxSizeText.addFocusListener(self.MaxSizeTextListener(self)) sizeUnitLabel = JLabel("KB") generalOptionPanel = JPanel(GridBagLayout()) generalOptionPanel.setBorder( BorderFactory.createTitledBorder("General Options")) gbc = GridBagConstraints() gbc.anchor = GridBagConstraints.WEST gbc.gridx = 0 gbc.gridy = 0 generalOptionPanel.add(maxSizeLabel, gbc) gbc.fill = GridBagConstraints.HORIZONTAL gbc.gridx = 1 gbc.gridy = 0 generalOptionPanel.add(self.maxSizeText, gbc) gbc.fill = GridBagConstraints.NONE gbc.gridx = 2 gbc.gridy = 0 gbc.weightx = 1.0 generalOptionPanel.add(sizeUnitLabel, gbc) gbc = GridBagConstraints() gbc.fill = GridBagConstraints.BOTH gbc.gridx = 1 gbc.gridy = 0 gbc.gridheight = 2 innerContainer.add(generalOptionPanel, gbc) # messageTabOptionPanel and it's inner component self.messageTabFormatCheckBoxs = [] for f in supportedFormats: ckb = JCheckBox(f) ckb.addItemListener(self.messageTabFormatListener) self.messageTabFormatCheckBoxs.append(ckb) messageTabOptionPanel = JPanel() messageTabOptionPanel.setLayout( BoxLayout(messageTabOptionPanel, BoxLayout.Y_AXIS)) messageTabOptionPanel.setBorder( BorderFactory.createTitledBorder("Enable in MessageEditorTab")) for b in self.messageTabFormatCheckBoxs: messageTabOptionPanel.add(b) gbc.gridx = 1 gbc.gridy = 2 gbc.gridheight = 9 innerContainer.add(messageTabOptionPanel, gbc) # replaceResponsePanel and it's inner component self.chkEnableReplace = JCheckBox("Enable") self.chkEnableReplace.addItemListener(self.repalceResponseBoxListener) replaceResponseFormatLabel = JLabel("Format") self.replaceResponseFormatCheckBoxs = [] for f in supportedFormats: ckb = JCheckBox(f) ckb.addItemListener(self.replaceResponseFormatListener) self.replaceResponseFormatCheckBoxs.append(ckb) replaceResponseIncludeLabel = JLabel( "Include URL that matches below(one item one line)") self.URLIncludeTextArea = JTextArea(6, 32) self.URLIncludeTextArea.addFocusListener( self.URLIncludeFocusListener(self)) URLIncludeScrollPane = JScrollPane(self.URLIncludeTextArea) URLIncludeScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT) replaceResponseExcludeLabel = JLabel( "Exclude URL that matches below(one item one line)") self.URLExcludeTextArea = JTextArea(5, 32) self.URLExcludeTextArea.addFocusListener( self.URLExcludeFocusListener(self)) URLExcludeScrollPane = JScrollPane(self.URLExcludeTextArea) URLExcludeScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT) replaceResponsePanel = JPanel() replaceResponsePanel.setLayout( BoxLayout(replaceResponsePanel, BoxLayout.Y_AXIS)) replaceResponsePanel.setBorder( BorderFactory.createTitledBorder("Replace PROXY Response")) replaceResponsePanel.add(self.chkEnableReplace) replaceResponsePanel.add(Box.createVerticalStrut(10)) replaceResponsePanel.add(replaceResponseFormatLabel) for b in self.replaceResponseFormatCheckBoxs: replaceResponsePanel.add(b) replaceResponsePanel.add(Box.createVerticalStrut(10)) replaceResponsePanel.add(replaceResponseIncludeLabel) replaceResponsePanel.add(URLIncludeScrollPane) replaceResponsePanel.add(Box.createVerticalStrut(10)) replaceResponsePanel.add(replaceResponseExcludeLabel) replaceResponsePanel.add(URLExcludeScrollPane) gbc.gridy = 11 innerContainer.add(replaceResponsePanel, gbc) # let innerContainer keep away from left and up gbc = GridBagConstraints() gbc.gridx = 1 gbc.gridy = 1 self.contentWrapper.add(Box.createHorizontalStrut(15), gbc) # gbc.ipadx = gbc.ipady = 25 gbc.gridx = 2 self.contentWrapper.add(innerContainer, gbc) # let innerContainer stay left side gbc = GridBagConstraints() gbc.gridx = 3 gbc.gridy = 2 gbc.gridwidth = 1 gbc.weightx = gbc.weighty = 1 paddingPanel = JPanel() self.contentWrapper.add(paddingPanel, gbc) self.setDefaultOptionDisplay()