class PrefsPanel(JPanel): """JPanle with gui for tool preferences """ def __init__(self, app): strings = app.strings self.setLayout(GridLayout(3, 2, 5, 5)) userLbl = JLabel(strings.getString("osmose_pref_username")) self.userTextField = JTextField(20) self.userTextField.setToolTipText( strings.getString("osmose_pref_username_tooltip")) levelLbl = JLabel(strings.getString("osmose_pref_level")) self.levels = ["1", "1,2", "1,2,3", "2", "3"] self.levelsCombo = JComboBox(self.levels) self.levelsCombo.setToolTipText( strings.getString("osmose_pref_level_tooltip")) limitLbl = JLabel(strings.getString("osmose_pref_limit")) self.limitTextField = JTextField(20) self.limitTextField.setToolTipText( strings.getString("osmose_pref_limit_tooltip")) self.add(userLbl) self.add(self.userTextField) self.add(levelLbl) self.add(self.levelsCombo) self.add(limitLbl) self.add(self.limitTextField) def update_gui(self, preferences): """Update preferences gui """ self.userTextField.setText(preferences["username"]) self.levelsCombo.setSelectedIndex( self.levels.index(preferences["level"])) self.limitTextField.setText(str(preferences["limit"])) def read_gui(self): """Read preferences from gui """ username = self.userTextField.getText() level = self.levelsCombo.getSelectedItem() limit = self.limitTextField.getText() try: limit = Integer.parseInt(limit) if limit > 500: limit = 500 limit = str(limit) except NumberFormatException: limit = "" preferences = { "username": username.strip(), "level": level, "limit": limit } return preferences
class PrefsPanel(JPanel): """JPanle with gui for tool preferences """ def __init__(self, app): strings = app.strings self.setLayout(GridLayout(3, 2, 5, 5)) userLbl = JLabel(strings.getString("osmose_pref_username")) self.userTextField = JTextField(20) self.userTextField.setToolTipText(strings.getString("osmose_pref_username_tooltip")) levelLbl = JLabel(strings.getString("osmose_pref_level")) self.levels = ["1", "1,2", "1,2,3", "2", "3"] self.levelsCombo = JComboBox(self.levels) self.levelsCombo.setToolTipText(strings.getString("osmose_pref_level_tooltip")) limitLbl = JLabel(strings.getString("osmose_pref_limit")) self.limitTextField = JTextField(20) self.limitTextField.setToolTipText(strings.getString("osmose_pref_limit_tooltip")) self.add(userLbl) self.add(self.userTextField) self.add(levelLbl) self.add(self.levelsCombo) self.add(limitLbl) self.add(self.limitTextField) def update_gui(self, preferences): """Update preferences gui """ self.userTextField.setText(preferences["username"]) self.levelsCombo.setSelectedIndex(self.levels.index(preferences["level"])) self.limitTextField.setText(str(preferences["limit"])) def read_gui(self): """Read preferences from gui """ username = self.userTextField.getText() level = self.levelsCombo.getSelectedItem() limit = self.limitTextField.getText() try: limit = Integer.parseInt(limit) if limit > 500: limit = 500 limit = str(limit) except NumberFormatException: limit = "" preferences = {"username": username.strip(), "level": level, "limit": limit} return preferences
def addDetails(self): jf0 = JFrame() jf0.setTitle("Add Issue"); jf0.setLayout(None); txtEnterIssue = JTextField(); txtEnterIssue.setName("Enter Issue Name"); txtEnterIssue.setToolTipText("Enter Issue Name Here"); txtEnterIssue.setBounds(182, 58, 473, 40); jf0.add(txtEnterIssue); txtEnterIssue.setColumns(10); btnNewButton = JButton("Add"); btnNewButton.setBounds(322, 178, 139, 41); jf0.add(btnNewButton); comboBox = JComboBox(); comboBox.setMaximumRowCount(20); comboBox.setEditable(True); comboBox.setToolTipText("Objective Name"); comboBox.setBounds(182, 125, 473, 40); jf0.add(comboBox); lblNewLabel = JLabel("Issue Name Here"); lblNewLabel.setFont(Font("Tahoma", Font.PLAIN, 16)); lblNewLabel.setBounds(25, 58, 130, 40); jf0.add(lblNewLabel); lblNewLabel_1 = JLabel("Objective Name"); lblNewLabel_1.setFont(Font("Tahoma", Font.PLAIN, 16)); lblNewLabel_1.setBounds(25, 125, 130, 40); jf0.add(lblNewLabel_1); jf0.setVisible(True) jf0.setBounds(400, 300, 700, 300) jf0.EXIT_ON_CLOSE txtEnterIssue.addKeyListener(self)
class BurpExtender(IBurpExtender, IExtensionStateListener, ITab): ext_name = "CompuRacerExtension" ext_version = '1.2' loaded = True t = None def registerExtenderCallbacks(self, callbacks): Cb(callbacks) Cb.callbacks.setExtensionName(self.ext_name) try: global compuracer_communication_lock # option picker item objects (for Java compatibility) item1 = {'key': 'item1', 'name': '2'} item2 = {'key': 'item2', 'name': '3'} item3 = {'key': 'item3', 'name': '4'} item4 = {'key': 'item4', 'name': '5'} item5 = {'key': 'item5', 'name': '10'} item6 = {'key': 'item6', 'name': '15'} item7 = {'key': 'item7', 'name': '20'} item8 = {'key': 'item8', 'name': '25'} item9 = {'key': 'item9', 'name': '50'} item10 = {'key': 'item10', 'name': '100'} # main splitted pane + top pane self._main_splitpane = JSplitPane(JSplitPane.VERTICAL_SPLIT) self._outer_settings_pane = JPanel(BorderLayout()) self._settings_pane = JPanel(GridBagLayout()) c = GridBagConstraints() self.label_1 = JLabel("Number of parallel requests:") c.fill = GridBagConstraints.NONE c.gridx = 0 c.gridy = 0 c.insets = Insets(0, 5, 0, 10) c.anchor = GridBagConstraints.LINE_START self._settings_pane.add(self.label_1, c) self.input_parallel_requests = JComboBox([ Item(item1), Item(item2), Item(item3), Item(item4), Item(item5), Item(item6), Item(item7), Item(item8), Item(item9), Item(item10) ]) self.input_parallel_requests.setSelectedIndex(4) self.input_parallel_requests.setToolTipText( "Select the number of parallel requests that will be sent") self.input_parallel_requests.addActionListener( self.change_parallel_requests) c.gridx = 1 c.gridy = 0 c.insets = Insets(0, 5, 0, 10) self._settings_pane.add(self.input_parallel_requests, c) self.option_allow_redirects = JCheckBox( "Allow redirects", actionPerformed=self.check_allow_redirects) self.option_allow_redirects.setToolTipText( "Select whether redirect responses are followed") c.gridx = 2 c.gridy = 0 c.insets = Insets(0, 20, 0, 10) self._settings_pane.add(self.option_allow_redirects, c) self.option_sync_last_byte = JCheckBox( "Sync last byte", actionPerformed=self.check_sync_last_byte) self.option_sync_last_byte.setToolTipText( "Select whether last byte synchronisation is enabled") c.gridx = 2 c.gridy = 1 c.insets = Insets(0, 20, 0, 0) self._settings_pane.add(self.option_sync_last_byte, c) self.label_2 = JLabel("Send timeout in seconds:") c.gridx = 0 c.gridy = 1 c.insets = Insets(0, 5, 0, 0) self._settings_pane.add(self.label_2, c) self.input_send_timeout = JComboBox([ Item(item2), Item(item4), Item(item5), Item(item7), Item(item9), Item(item10) ]) self.input_send_timeout.setSelectedIndex(3) self.input_send_timeout.setToolTipText( "Select the wait-for-response timeout after sending the request(s)" ) self.input_send_timeout.addActionListener(self.change_send_timeout) c.gridx = 1 c.gridy = 1 c.insets = Insets(0, 5, 0, 0) self._settings_pane.add(self.input_send_timeout, c) self.button_resend_batch = JButton("Resend requests") self.button_resend_batch.setToolTipText( "Resend all requests with the current configuration") self.button_resend_batch.setEnabled(False) self.button_resend_batch.addActionListener( MenuFactory.start_request_transmitter_button) c.gridx = 3 c.gridy = 0 c.insets = Insets(0, 20, 0, 10) self._settings_pane.add(self.button_resend_batch, c) immediate_data_ui_elements[ "parallel_requests"] = self.input_parallel_requests immediate_data_ui_elements[ "allow_redirects"] = self.option_allow_redirects immediate_data_ui_elements[ "sync_last_byte"] = self.option_sync_last_byte immediate_data_ui_elements[ "send_timeout"] = self.input_send_timeout immediate_data_ui_elements[ "resend_batch"] = self.button_resend_batch c = GridBagConstraints() c.anchor = GridBagConstraints.WEST self._outer_settings_pane.add(self._settings_pane, BorderLayout.WEST) self._main_splitpane.setTopComponent(self._outer_settings_pane) self._results_splitpane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) self._main_splitpane.setBottomComponent(self._results_splitpane) # table of log entries self.tabs_right = JTabbedPane() global _textEditors, DEFAULT_RESULTS for i in range(3): _textEditors.append(Cb.callbacks.createTextEditor()) _textEditors[-1].setText(str.encode("\n" + DEFAULT_RESULTS)) self.tabs_right.add("Summary", _textEditors[0].getComponent()) self.tabs_right.add("Full result", _textEditors[1].getComponent()) self.tabs_right.add("Config", _textEditors[2].getComponent()) self._results_splitpane.setRightComponent(self.tabs_right) # tabs with request/response viewers global _requestViewers, _requestPane _requestPane = JTabbedPane() _requestViewers.append( Cb.callbacks.createMessageEditor(None, False)) _requestPane.addTab("Request", _requestViewers[-1].getComponent()) self._results_splitpane.setLeftComponent(_requestPane) # customize our UI components Cb.callbacks.customizeUiComponent(self._settings_pane) Cb.callbacks.customizeUiComponent(self.tabs_right) Cb.callbacks.customizeUiComponent(_requestPane) # add the custom tab to Burp's UI Cb.callbacks.addSuiteTab(self) except RuntimeException as e: callbacks.printError(traceback.format_exc()) e = PyException(e) print("10") print(str(self)) print("{}\t{}\n{}\n".format(e.type, e.value, e.traceback)) Cb.callbacks.registerContextMenuFactory(MenuFactory()) callbacks.registerExtensionStateListener(self) self.start_alive_checker() Cb.callbacks.printOutput('%s v%s extension loaded\n' % (self.ext_name, self.ext_version)) def change_parallel_requests(self, event): global immediate_data try: num_parallel = MenuFactory.item_selected(event) if num_parallel != immediate_data['settings'][0]: self.update_setting(0, num_parallel, "number of parallel requests") except Exception as e: print(e) def change_send_timeout(self, event): global immediate_data try: send_timeout = MenuFactory.item_selected(event) if send_timeout != immediate_data['settings'][4]: self.update_setting(4, send_timeout, "send timeout") except Exception as e: print(e) def check_allow_redirects(self, event): global immediate_data is_selected = MenuFactory.button_selected(event) if is_selected != immediate_data['settings'][2]: self.update_setting(2, is_selected, "allow redirects") def check_sync_last_byte(self, event): global immediate_data is_selected = MenuFactory.button_selected(event) if is_selected != immediate_data['settings'][3]: self.update_setting(3, is_selected, "allow redirects") def resend_batches(self, event): global _storedRequests if _storedRequests is not None: self.sen # helper method for two methods above def update_setting(self, index, new_value, text): global immediate_data success = True print("> Updating {}..".format(text)) old_value = immediate_data['settings'][index] immediate_data['settings'][index] = new_value if MenuFactory.set_immediate_mode_settings( {'settings': immediate_data['settings']}): print("> Success!") else: print("> Failed!") immediate_data['settings'][index] = old_value success = False return success # for ITab def getTabCaption(self): return "CompuRacer" # for ITab def getUiComponent(self): return self._main_splitpane # def getHttpService(self): # global _storedRequest # return _storedRequest.getHttpService() # # def getRequest(self): # global _storedRequest # return _storedRequest.getRequest() # # def getResponse(self): # global _storedRequest # return _storedRequest.getResponse() def start_alive_checker(self): self.t = threading.Thread(name='Alive checker', target=self.alive_checker) self.t.start() def closest_match(self, number, list_of_numbers): return min(list(zip(list_of_numbers, range(len(list_of_numbers)))), key=lambda item: (abs(item[0] - number), item[1])) def alive_checker(self): global compuRacer_ip, compuRacer_port, alive_check_path, racer_alive, immediate_mode, compuracer_communication_lock unloaded = False old_alive = racer_alive parallel_req_options = [2, 3, 4, 5, 10, 15, 20, 25, 50, 100] send_time_options = [3, 5, 10, 20, 50, 100] while not unloaded: try: with compuracer_communication_lock: response = requests.get("http://{}:{}/{}".format( compuRacer_ip, compuRacer_port, alive_check_path), timeout=2) racer_alive = response and response.status_code and response.status_code == 200 success, mode, settings = MenuFactory.get_immediate_mode_settings( ) if success: immediate_data['mode'] = mode immediate_data['settings'] = settings # update UI button states immediate_data_ui_elements[ "parallel_requests"].setSelectedIndex( self.closest_match( immediate_data['settings'][0], parallel_req_options)[1]) immediate_data_ui_elements[ "allow_redirects"].setSelected( bool(immediate_data['settings'][2])) immediate_data_ui_elements[ "sync_last_byte"].setSelected( bool(immediate_data['settings'][3])) immediate_data_ui_elements[ "send_timeout"].setSelectedIndex( self.closest_match( immediate_data['settings'][4], send_time_options)[1]) except Exception as e: # it surely did not work racer_alive = False print(e) if racer_alive and not old_alive: print("> Racer is now alive!") MenuFactory.set_state_of_all_buttons(True) old_alive = True elif not racer_alive and old_alive: print("> Racer became dead!") MenuFactory.set_state_of_all_buttons(False) old_alive = False time.sleep(5) if not self.loaded: unloaded = True def extensionUnloaded(self): print("\n> Unloading..") self.loaded = False self.t.join() print("> Done.")
class QatDialog(ToggleDialog): """ToggleDialog for error type selection and buttons for reviewing errors in sequence """ def __init__(self, name, iconName, tooltip, shortcut, height, app): ToggleDialog.__init__(self, name, iconName, tooltip, shortcut, height) self.app = app tools = app.tools #Main panel of the dialog mainPnl = JPanel(BorderLayout()) mainPnl.setBorder(BorderFactory.createEmptyBorder(0, 1, 1, 1)) ### First tab: errors selection and download ########################### #ComboBox with tools names self.toolsComboModel = DefaultComboBoxModel() for tool in tools: self.add_data_to_models(tool) self.toolsCombo = JComboBox(self.toolsComboModel, actionListener=ToolsComboListener(app)) renderer = ToolsComboRenderer(self.app) renderer.setPreferredSize(Dimension(20, 20)) self.toolsCombo.setRenderer(renderer) self.toolsCombo.setToolTipText(app.strings.getString("Select_a_quality_assurance_tool")) #ComboBox with categories names ("views"), of the selected tool self.viewsCombo = JComboBox(actionListener=ViewsComboListener(app)) self.viewsCombo.setToolTipText(app.strings.getString("Select_a_category_of_error")) #Popup for checks table self.checkPopup = JPopupMenu() #add favourite check self.menuItemAdd = JMenuItem(self.app.strings.getString("Add_to_favourites")) self.menuItemAdd.setIcon(ImageIcon(File.separator.join([self.app.SCRIPTDIR, "tools", "data", "Favourites", "icons", "tool_16.png"]))) self.menuItemAdd.addActionListener(PopupActionListener(self.app)) self.checkPopup.add(self.menuItemAdd) #remove favourite check self.menuItemRemove = JMenuItem(self.app.strings.getString("Remove_from_favourites")) self.menuItemRemove.setIcon(ImageIcon(File.separator.join([self.app.SCRIPTDIR, "tools", "data", "Favourites", "icons", "black_tool_16.png"]))) self.menuItemRemove.addActionListener(PopupActionListener(self.app)) self.checkPopup.add(self.menuItemRemove) #Help link for selected check self.menuItemHelp = JMenuItem(self.app.strings.getString("check_help")) self.menuItemHelp.setIcon(ImageIcon(File.separator.join([self.app.SCRIPTDIR, "images", "icons", "info_16.png"]))) self.checkPopup.add(self.menuItemHelp) self.menuItemHelp.addActionListener(PopupActionListener(self.app)) #Table with checks of selected tool and view self.checksTable = JTable() self.iconrenderer = IconRenderer() self.iconrenderer.setHorizontalAlignment(JLabel.CENTER) scrollPane = JScrollPane(self.checksTable) self.checksTable.setFillsViewportHeight(True) tableSelectionModel = self.checksTable.getSelectionModel() tableSelectionModel.addListSelectionListener(ChecksTableListener(app)) self.checksTable.addMouseListener(ChecksTableClickListener(app, self.checkPopup, self.checksTable)) #Favourite area status indicator self.favAreaIndicator = JLabel() self.update_favourite_zone_indicator() self.favAreaIndicator.addMouseListener(FavAreaIndicatorListener(app)) #label with OSM id of the object currently edited and number of #errors still to review self.checksTextFld = JTextField("", editable=0, border=None, background=None) #checks buttons btnsIconsDir = File.separator.join([app.SCRIPTDIR, "images", "icons"]) downloadIcon = ImageIcon(File.separator.join([btnsIconsDir, "download.png"])) self.downloadBtn = JButton(downloadIcon, actionPerformed=app.on_downloadBtn_clicked, enabled=0) startIcon = ImageIcon(File.separator.join([btnsIconsDir, "start_fixing.png"])) self.startBtn = JButton(startIcon, actionPerformed=app.on_startBtn_clicked, enabled=0) self.downloadBtn.setToolTipText(app.strings.getString("Download_errors_in_this_area")) self.startBtn.setToolTipText(app.strings.getString("Start_fixing_the_selected_errors")) #tab layout panel1 = JPanel(BorderLayout(0, 1)) comboboxesPnl = JPanel(GridLayout(0, 2, 5, 0)) comboboxesPnl.add(self.toolsCombo) comboboxesPnl.add(self.viewsCombo) checksPnl = JPanel(BorderLayout(0, 1)) checksPnl.add(scrollPane, BorderLayout.CENTER) self.statsPanel = JPanel(BorderLayout(4, 0)) self.statsPanel_def_color = self.statsPanel.getBackground() self.statsPanel.add(self.checksTextFld, BorderLayout.CENTER) self.statsPanel.add(self.favAreaIndicator, BorderLayout.LINE_START) checksPnl.add(self.statsPanel, BorderLayout.PAGE_END) checksButtonsPnl = JPanel(GridLayout(0, 2, 0, 0)) checksButtonsPnl.add(self.downloadBtn) checksButtonsPnl.add(self.startBtn) panel1.add(comboboxesPnl, BorderLayout.PAGE_START) panel1.add(checksPnl, BorderLayout.CENTER) panel1.add(checksButtonsPnl, BorderLayout.PAGE_END) ### Second tab: errors fixing ########################################## #label with error stats self.errorTextFld = JTextField("", editable=0, border=None, background=None) #label with current error description self.errorDesc = JLabel("") self.errorDesc.setAlignmentX(0.5) #error buttons errorInfoBtnIcon = ImageProvider.get("info") self.errorInfoBtn = JButton(errorInfoBtnIcon, actionPerformed=app.on_errorInfoBtn_clicked, enabled=0) notErrorIcon = ImageIcon(File.separator.join([btnsIconsDir, "not_error.png"])) self.notErrorBtn = JButton(notErrorIcon, actionPerformed=app.on_falsePositiveBtn_clicked, enabled=0) ignoreIcon = ImageIcon(File.separator.join([btnsIconsDir, "skip.png"])) self.ignoreBtn = JButton(ignoreIcon, actionPerformed=app.on_ignoreBtn_clicked, enabled=0) correctedIcon = ImageIcon(File.separator.join([btnsIconsDir, "corrected.png"])) self.correctedBtn = JButton(correctedIcon, actionPerformed=app.on_correctedBtn_clicked, enabled=0) nextIcon = ImageIcon(File.separator.join([btnsIconsDir, "next.png"])) self.nextBtn = JButton(nextIcon, actionPerformed=app.on_nextBtn_clicked, enabled=0) #self.nextBtn.setMnemonic(KeyEvent.VK_RIGHT) self.errorInfoBtn.setToolTipText(app.strings.getString("open_error_info_dialog")) self.notErrorBtn.setToolTipText(app.strings.getString("flag_false_positive")) self.ignoreBtn.setToolTipText(app.strings.getString("Skip_and_don't_show_me_this_error_again")) self.correctedBtn.setToolTipText(app.strings.getString("flag_corrected_error")) self.nextBtn.setToolTipText(app.strings.getString("Go_to_next_error")) #tab layout self.panel2 = JPanel(BorderLayout()) self.panel2.add(self.errorTextFld, BorderLayout.PAGE_START) self.panel2.add(self.errorDesc, BorderLayout.CENTER) errorButtonsPanel = JPanel(GridLayout(0, 5, 0, 0)) errorButtonsPanel.add(self.errorInfoBtn) errorButtonsPanel.add(self.notErrorBtn) errorButtonsPanel.add(self.ignoreBtn) errorButtonsPanel.add(self.correctedBtn) errorButtonsPanel.add(self.nextBtn) self.panel2.add(errorButtonsPanel, BorderLayout.PAGE_END) #Layout self.tabbedPane = JTabbedPane() self.tabbedPane.addTab(self.app.strings.getString("Download"), None, panel1, self.app.strings.getString("download_tab")) mainPnl.add(self.tabbedPane, BorderLayout.CENTER) self.createLayout(mainPnl, False, None) def add_data_to_models(self, tool): """Add data of a tool to the models of the dialog components """ #tools combobox model if tool == self.app.favouritesTool: self.toolsComboModel.addElement(JSeparator()) self.toolsComboModel.addElement(tool) #views combobox model tool.viewsComboModel = DefaultComboBoxModel() for view in tool.views: tool.viewsComboModel.addElement(view.title) #checks table, one TableModel for each view, of each tool columns = ["", self.app.strings.getString("Check"), self.app.strings.getString("Errors")] for view in tool.views: tableRows = [] for check in view.checks: if check.icon is not None: icon = check.icon else: icon = "" errorsNumber = "" tableRows.append([icon, check.title, errorsNumber]) view.tableModel = MyTableModel(tableRows, columns) def update_favourite_zone_indicator(self): #icon if self.app.favZone is not None: self.favAreaIndicator.setIcon(self.app.favZone.icon) #tooltip messageArguments = array([self.app.favZone.name], String) formatter = MessageFormat("") formatter.applyPattern(self.app.strings.getString("favAreaIndicator_tooltip")) msg = formatter.format(messageArguments) self.favAreaIndicator.setToolTipText(msg) #status self.favAreaIndicator.setVisible(self.app.favouriteZoneStatus) def set_checksTextFld_color(self, color): """Change color of textField under checksTable """ colors = {"white": (255, 255, 255), "black": (0, 0, 0), "green": (100, 200, 0), "red": (200, 0, 0)} if color == "default": self.statsPanel.background = self.statsPanel_def_color self.checksTextFld.foreground = colors["black"] else: self.statsPanel.background = colors[color] self.checksTextFld.foreground = colors["white"] def change_selection(self, source): """Change comboboxes and checks table selections after a selection has been made by the user """ if source in ("menu", "layer", "add favourite"): self.app.selectionChangedFromMenuOrLayer = True self.toolsCombo.setSelectedItem(self.app.selectedTool) self.viewsCombo.setModel(self.app.selectedTool.viewsComboModel) self.viewsCombo.setSelectedItem(self.app.selectedView.title) self.checksTable.setModel(self.app.selectedTableModel) self.refresh_checksTable_columns_geometries() for i, c in enumerate(self.app.selectedView.checks): if c == self.app.selectedChecks[0]: break self.checksTable.setRowSelectionInterval(i, i) self.app.selectionChangedFromMenuOrLayer = False else: self.app.selectionChangedFromMenuOrLayer = False if source == "toolsCombo": self.viewsCombo.setModel(self.app.selectedTool.viewsComboModel) self.viewsCombo.setSelectedIndex(0) elif source == "viewsCombo": self.checksTable.setModel(self.app.selectedTableModel) self.refresh_checksTable_columns_geometries() if self.app.selectedView.checks != []: # favourite checks may be none self.checksTable.setRowSelectionInterval(0, 0) def refresh_checksTable_columns_geometries(self): self.checksTable.getColumnModel().getColumn(0).setCellRenderer(self.iconrenderer) self.checksTable.getColumnModel().getColumn(0).setMaxWidth(25) self.checksTable.getColumnModel().getColumn(2).setMaxWidth(60) def activate_error_tab(self, status): if status: if self.tabbedPane.getTabCount() == 1: self.tabbedPane.addTab(self.app.strings.getString("Fix"), None, self.panel2, self.app.strings.getString("fix_tab")) else: if self.tabbedPane.getTabCount() == 2: self.tabbedPane.remove(1) def update_checks_buttons(self): """This method sets the status of downloadBtn and startBtn """ #none check selected if len(self.app.selectedChecks) == 0: self.downloadBtn.setEnabled(False) self.startBtn.setEnabled(False) else: #some check selected self.downloadBtn.setEnabled(True) if len(self.app.selectedChecks) > 1: self.startBtn.setEnabled(False) else: #only one check is selected self.app.errors = self.app.selectedChecks[0].errors if self.app.errors is None or len(self.app.errors) == 0: #errors file has not been downloaded and parsed yet self.startBtn.setEnabled(False) else: #errors file has been downloaded and parsed if self.app.selectedChecks[0].toDo == 0: #all errors have been corrected self.startBtn.setEnabled(False) else: self.startBtn.setEnabled(True) #self.nextBtn.setEnabled(True) def update_error_buttons(self, mode): """This method sets the status of: ignoreBtn, falsePositiveBtn, correctedBtn, nextBtn """ if mode == "new error": status = True else: status = False if self.app.selectedChecks[0].tool.fixedFeedbackMode is None: self.correctedBtn.setEnabled(False) else: self.correctedBtn.setEnabled(status) if self.app.selectedChecks[0].tool.falseFeedbackMode is None: self.notErrorBtn.setEnabled(False) else: self.notErrorBtn.setEnabled(status) self.errorInfoBtn.setEnabled(status) self.ignoreBtn.setEnabled(status) if mode in ("reset", "review end"): self.nextBtn.setEnabled(False) elif mode in ("errors downloaded", "show stats", "new error"): self.nextBtn.setEnabled(True) def update_text_fields(self, mode, errorInfo=""): """This method updates the text in: checksTextFld, errorDesc, errorTextFld """ self.errorDesc.text = "" if mode == "review end": cheksTextColor = "green" checksText = self.app.strings.getString("All_errors_reviewed.") errorText = self.app.strings.getString("All_errors_reviewed.") elif mode == "reset": cheksTextColor = "default" checksText = "" errorText = "" elif mode == "show stats": cheksTextColor = "default" checksText = "%s %d / %s" % ( self.app.strings.getString("to_do"), self.app.selectedChecks[0].toDo, len(self.app.selectedChecks[0].errors)) #print "checks text", checksText errorText = "%s%s %d / %s" % ( errorInfo, self.app.strings.getString("to_do"), self.app.selectedChecks[0].toDo, len(self.app.selectedChecks[0].errors)) #print "error text", errorText if self.app.selectedError is not None and self.app.selectedError.desc != "": self.errorDesc.text = "<html>%s</html>" % self.app.selectedError.desc self.set_checksTextFld_color(cheksTextColor) self.checksTextFld.text = checksText self.errorTextFld.text = errorText self.update_statsPanel_status() def update_statsPanel_status(self): if self.checksTextFld.text == "" and not self.app.favouriteZoneStatus: self.statsPanel.setVisible(False) else: self.statsPanel.setVisible(True)
class QatDialog(ToggleDialog): """ToggleDialog for error type selection and buttons for reviewing errors in sequence """ def __init__(self, name, iconName, tooltip, shortcut, height, app): ToggleDialog.__init__(self, name, iconName, tooltip, shortcut, height) self.app = app tools = app.tools #Main panel of the dialog mainPnl = JPanel(BorderLayout()) mainPnl.setBorder(BorderFactory.createEmptyBorder(0, 1, 1, 1)) ### First tab: errors selection and download ########################### #ComboBox with tools names self.toolsComboModel = DefaultComboBoxModel() for tool in tools: self.add_data_to_models(tool) self.toolsCombo = JComboBox(self.toolsComboModel, actionListener=ToolsComboListener(app)) renderer = ToolsComboRenderer(self.app) renderer.setPreferredSize(Dimension(20, 20)) self.toolsCombo.setRenderer(renderer) self.toolsCombo.setToolTipText( app.strings.getString("Select_a_quality_assurance_tool")) #ComboBox with categories names ("views"), of the selected tool self.viewsCombo = JComboBox(actionListener=ViewsComboListener(app)) self.viewsCombo.setToolTipText( app.strings.getString("Select_a_category_of_error")) #Popup for checks table self.checkPopup = JPopupMenu() #add favourite check self.menuItemAdd = JMenuItem( self.app.strings.getString("Add_to_favourites")) self.menuItemAdd.setIcon( ImageIcon( File.separator.join([ self.app.SCRIPTDIR, "tools", "data", "Favourites", "icons", "tool_16.png" ]))) self.menuItemAdd.addActionListener(PopupActionListener(self.app)) self.checkPopup.add(self.menuItemAdd) #remove favourite check self.menuItemRemove = JMenuItem( self.app.strings.getString("Remove_from_favourites")) self.menuItemRemove.setIcon( ImageIcon( File.separator.join([ self.app.SCRIPTDIR, "tools", "data", "Favourites", "icons", "black_tool_16.png" ]))) self.menuItemRemove.addActionListener(PopupActionListener(self.app)) self.checkPopup.add(self.menuItemRemove) #Help link for selected check self.menuItemHelp = JMenuItem(self.app.strings.getString("check_help")) self.menuItemHelp.setIcon( ImageIcon( File.separator.join( [self.app.SCRIPTDIR, "images", "icons", "info_16.png"]))) self.checkPopup.add(self.menuItemHelp) self.menuItemHelp.addActionListener(PopupActionListener(self.app)) #Table with checks of selected tool and view self.checksTable = JTable() self.iconrenderer = IconRenderer() self.iconrenderer.setHorizontalAlignment(JLabel.CENTER) scrollPane = JScrollPane(self.checksTable) self.checksTable.setFillsViewportHeight(True) tableSelectionModel = self.checksTable.getSelectionModel() tableSelectionModel.addListSelectionListener(ChecksTableListener(app)) self.checksTable.addMouseListener( ChecksTableClickListener(app, self.checkPopup, self.checksTable)) #Favourite area status indicator self.favAreaIndicator = JLabel() self.update_favourite_zone_indicator() self.favAreaIndicator.addMouseListener(FavAreaIndicatorListener(app)) #label with OSM id of the object currently edited and number of #errors still to review self.checksTextFld = JTextField("", editable=0, border=None, background=None) #checks buttons btnsIconsDir = File.separator.join([app.SCRIPTDIR, "images", "icons"]) downloadIcon = ImageIcon( File.separator.join([btnsIconsDir, "download.png"])) self.downloadBtn = JButton(downloadIcon, actionPerformed=app.on_downloadBtn_clicked, enabled=0) startIcon = ImageIcon( File.separator.join([btnsIconsDir, "start_fixing.png"])) self.startBtn = JButton(startIcon, actionPerformed=app.on_startBtn_clicked, enabled=0) self.downloadBtn.setToolTipText( app.strings.getString("Download_errors_in_this_area")) self.startBtn.setToolTipText( app.strings.getString("Start_fixing_the_selected_errors")) #tab layout panel1 = JPanel(BorderLayout(0, 1)) comboboxesPnl = JPanel(GridLayout(0, 2, 5, 0)) comboboxesPnl.add(self.toolsCombo) comboboxesPnl.add(self.viewsCombo) checksPnl = JPanel(BorderLayout(0, 1)) checksPnl.add(scrollPane, BorderLayout.CENTER) self.statsPanel = JPanel(BorderLayout(4, 0)) self.statsPanel_def_color = self.statsPanel.getBackground() self.statsPanel.add(self.checksTextFld, BorderLayout.CENTER) self.statsPanel.add(self.favAreaIndicator, BorderLayout.LINE_START) checksPnl.add(self.statsPanel, BorderLayout.PAGE_END) checksButtonsPnl = JPanel(GridLayout(0, 2, 0, 0)) checksButtonsPnl.add(self.downloadBtn) checksButtonsPnl.add(self.startBtn) panel1.add(comboboxesPnl, BorderLayout.PAGE_START) panel1.add(checksPnl, BorderLayout.CENTER) panel1.add(checksButtonsPnl, BorderLayout.PAGE_END) ### Second tab: errors fixing ########################################## #label with error stats self.errorTextFld = JTextField("", editable=0, border=None, background=None) #label with current error description self.errorDesc = JLabel("") self.errorDesc.setAlignmentX(0.5) #error buttons errorInfoBtnIcon = ImageProvider.get("info") self.errorInfoBtn = JButton( errorInfoBtnIcon, actionPerformed=app.on_errorInfoBtn_clicked, enabled=0) notErrorIcon = ImageIcon( File.separator.join([btnsIconsDir, "not_error.png"])) self.notErrorBtn = JButton( notErrorIcon, actionPerformed=app.on_falsePositiveBtn_clicked, enabled=0) ignoreIcon = ImageIcon(File.separator.join([btnsIconsDir, "skip.png"])) self.ignoreBtn = JButton(ignoreIcon, actionPerformed=app.on_ignoreBtn_clicked, enabled=0) correctedIcon = ImageIcon( File.separator.join([btnsIconsDir, "corrected.png"])) self.correctedBtn = JButton( correctedIcon, actionPerformed=app.on_correctedBtn_clicked, enabled=0) nextIcon = ImageIcon(File.separator.join([btnsIconsDir, "next.png"])) self.nextBtn = JButton(nextIcon, actionPerformed=app.on_nextBtn_clicked, enabled=0) #self.nextBtn.setMnemonic(KeyEvent.VK_RIGHT) self.errorInfoBtn.setToolTipText( app.strings.getString("open_error_info_dialog")) self.notErrorBtn.setToolTipText( app.strings.getString("flag_false_positive")) self.ignoreBtn.setToolTipText( app.strings.getString("Skip_and_don't_show_me_this_error_again")) self.correctedBtn.setToolTipText( app.strings.getString("flag_corrected_error")) self.nextBtn.setToolTipText(app.strings.getString("Go_to_next_error")) #tab layout self.panel2 = JPanel(BorderLayout()) self.panel2.add(self.errorTextFld, BorderLayout.PAGE_START) self.panel2.add(self.errorDesc, BorderLayout.CENTER) errorButtonsPanel = JPanel(GridLayout(0, 5, 0, 0)) errorButtonsPanel.add(self.errorInfoBtn) errorButtonsPanel.add(self.notErrorBtn) errorButtonsPanel.add(self.ignoreBtn) errorButtonsPanel.add(self.correctedBtn) errorButtonsPanel.add(self.nextBtn) self.panel2.add(errorButtonsPanel, BorderLayout.PAGE_END) #Layout self.tabbedPane = JTabbedPane() self.tabbedPane.addTab(self.app.strings.getString("Download"), None, panel1, self.app.strings.getString("download_tab")) mainPnl.add(self.tabbedPane, BorderLayout.CENTER) self.createLayout(mainPnl, False, None) def add_data_to_models(self, tool): """Add data of a tool to the models of the dialog components """ #tools combobox model if tool == self.app.favouritesTool: self.toolsComboModel.addElement(JSeparator()) self.toolsComboModel.addElement(tool) #views combobox model tool.viewsComboModel = DefaultComboBoxModel() for view in tool.views: tool.viewsComboModel.addElement(view.title) #checks table, one TableModel for each view, of each tool columns = [ "", self.app.strings.getString("Check"), self.app.strings.getString("Errors") ] for view in tool.views: tableRows = [] for check in view.checks: if check.icon is not None: icon = check.icon else: icon = "" errorsNumber = "" tableRows.append([icon, check.title, errorsNumber]) view.tableModel = MyTableModel(tableRows, columns) def update_favourite_zone_indicator(self): #icon if self.app.favZone is not None: self.favAreaIndicator.setIcon(self.app.favZone.icon) #tooltip messageArguments = array([self.app.favZone.name], String) formatter = MessageFormat("") formatter.applyPattern( self.app.strings.getString("favAreaIndicator_tooltip")) msg = formatter.format(messageArguments) self.favAreaIndicator.setToolTipText(msg) #status self.favAreaIndicator.setVisible(self.app.favouriteZoneStatus) def set_checksTextFld_color(self, color): """Change color of textField under checksTable """ colors = { "white": (255, 255, 255), "black": (0, 0, 0), "green": (100, 200, 0), "red": (200, 0, 0) } if color == "default": self.statsPanel.background = self.statsPanel_def_color self.checksTextFld.foreground = colors["black"] else: self.statsPanel.background = colors[color] self.checksTextFld.foreground = colors["white"] def change_selection(self, source): """Change comboboxes and checks table selections after a selection has been made by the user """ if source in ("menu", "layer", "add favourite"): self.app.selectionChangedFromMenuOrLayer = True self.toolsCombo.setSelectedItem(self.app.selectedTool) self.viewsCombo.setModel(self.app.selectedTool.viewsComboModel) self.viewsCombo.setSelectedItem(self.app.selectedView.title) self.checksTable.setModel(self.app.selectedTableModel) self.refresh_checksTable_columns_geometries() for i, c in enumerate(self.app.selectedView.checks): if c == self.app.selectedChecks[0]: break self.checksTable.setRowSelectionInterval(i, i) self.app.selectionChangedFromMenuOrLayer = False else: self.app.selectionChangedFromMenuOrLayer = False if source == "toolsCombo": self.viewsCombo.setModel(self.app.selectedTool.viewsComboModel) self.viewsCombo.setSelectedIndex(0) elif source == "viewsCombo": self.checksTable.setModel(self.app.selectedTableModel) self.refresh_checksTable_columns_geometries() if self.app.selectedView.checks != []: # favourite checks may be none self.checksTable.setRowSelectionInterval(0, 0) def refresh_checksTable_columns_geometries(self): self.checksTable.getColumnModel().getColumn(0).setCellRenderer( self.iconrenderer) self.checksTable.getColumnModel().getColumn(0).setMaxWidth(25) self.checksTable.getColumnModel().getColumn(2).setMaxWidth(60) def activate_error_tab(self, status): if status: if self.tabbedPane.getTabCount() == 1: self.tabbedPane.addTab(self.app.strings.getString("Fix"), None, self.panel2, self.app.strings.getString("fix_tab")) else: if self.tabbedPane.getTabCount() == 2: self.tabbedPane.remove(1) def update_checks_buttons(self): """This method sets the status of downloadBtn and startBtn """ #none check selected if len(self.app.selectedChecks) == 0: self.downloadBtn.setEnabled(False) self.startBtn.setEnabled(False) else: #some check selected self.downloadBtn.setEnabled(True) if len(self.app.selectedChecks) > 1: self.startBtn.setEnabled(False) else: #only one check is selected self.app.errors = self.app.selectedChecks[0].errors if self.app.errors is None or len(self.app.errors) == 0: #errors file has not been downloaded and parsed yet self.startBtn.setEnabled(False) else: #errors file has been downloaded and parsed if self.app.selectedChecks[0].toDo == 0: #all errors have been corrected self.startBtn.setEnabled(False) else: self.startBtn.setEnabled(True) #self.nextBtn.setEnabled(True) def update_error_buttons(self, mode): """This method sets the status of: ignoreBtn, falsePositiveBtn, correctedBtn, nextBtn """ if mode == "new error": status = True else: status = False if self.app.selectedChecks[0].tool.fixedFeedbackMode is None: self.correctedBtn.setEnabled(False) else: self.correctedBtn.setEnabled(status) if self.app.selectedChecks[0].tool.falseFeedbackMode is None: self.notErrorBtn.setEnabled(False) else: self.notErrorBtn.setEnabled(status) self.errorInfoBtn.setEnabled(status) self.ignoreBtn.setEnabled(status) if mode in ("reset", "review end"): self.nextBtn.setEnabled(False) elif mode in ("errors downloaded", "show stats", "new error"): self.nextBtn.setEnabled(True) def update_text_fields(self, mode, errorInfo=""): """This method updates the text in: checksTextFld, errorDesc, errorTextFld """ self.errorDesc.text = "" if mode == "review end": cheksTextColor = "green" checksText = self.app.strings.getString("All_errors_reviewed.") errorText = self.app.strings.getString("All_errors_reviewed.") elif mode == "reset": cheksTextColor = "default" checksText = "" errorText = "" elif mode == "show stats": cheksTextColor = "default" checksText = "%s %d / %s" % ( self.app.strings.getString("to_do"), self.app.selectedChecks[0].toDo, len(self.app.selectedChecks[0].errors)) #print "checks text", checksText errorText = "%s%s %d / %s" % ( errorInfo, self.app.strings.getString("to_do"), self.app.selectedChecks[0].toDo, len(self.app.selectedChecks[0].errors)) #print "error text", errorText if self.app.selectedError is not None and self.app.selectedError.desc != "": self.errorDesc.text = "<html>%s</html>" % self.app.selectedError.desc self.set_checksTextFld_color(cheksTextColor) self.checksTextFld.text = checksText self.errorTextFld.text = errorText self.update_statsPanel_status() def update_statsPanel_status(self): if self.checksTextFld.text == "" and not self.app.favouriteZoneStatus: self.statsPanel.setVisible(False) else: self.statsPanel.setVisible(True)