def __init__(self, parent, title, modal, app): JDialog.__init__(self, parent, title, modal) #Download and Read Dialog border = BorderFactory.createEmptyBorder(5, 7, 5, 7) self.getContentPane().setBorder(border) self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS)) panel = JPanel() panel.setAlignmentX(0.5) panel.setLayout(BoxLayout(panel, BoxLayout.Y_AXIS)) panel.add(Box.createRigidArea(Dimension(0, 10))) self.progressLbl = JLabel(app.strings.getString("downloading_and_reading_errors")) panel.add(self.progressLbl) panel.add(Box.createRigidArea(Dimension(0, 10))) self.progressBar = JProgressBar(0, 100, value=0) panel.add(self.progressBar) self.add(panel) self.add(Box.createRigidArea(Dimension(0, 20))) cancelBtn = JButton(app.strings.getString("cancel"), ImageProvider.get("cancel"), actionPerformed=app.on_cancelBtn_clicked) cancelBtn.setAlignmentX(0.5) self.add(cancelBtn) self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) self.pack()
def __init__(self, parent=None): JDialog.__init__(self, title="My dialog", modal=1) self.contentPane.layout = FlowLayout() self.contentPane.add(JLabel("A dialog!")) self.contentPane.add( JButton("OK", actionPerformed=lambda e, t=self: t.dispose())) self.pack()
def __init__(self, parent, title, modal, app): JDialog.__init__(self, parent, title, modal) #Download and Read Dialog border = BorderFactory.createEmptyBorder(5, 7, 5, 7) self.getContentPane().setBorder(border) self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS)) panel = JPanel() panel.setAlignmentX(0.5) panel.setLayout(BoxLayout(panel, BoxLayout.Y_AXIS)) panel.add(Box.createRigidArea(Dimension(0, 10))) self.progressLbl = JLabel( app.strings.getString("downloading_and_reading_errors")) panel.add(self.progressLbl) panel.add(Box.createRigidArea(Dimension(0, 10))) self.progressBar = JProgressBar(0, 100, value=0) panel.add(self.progressBar) self.add(panel) self.add(Box.createRigidArea(Dimension(0, 20))) cancelBtn = JButton(app.strings.getString("cancel"), ImageProvider.get("cancel"), actionPerformed=app.on_cancelBtn_clicked) cancelBtn.setAlignmentX(0.5) self.add(cancelBtn) self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) self.pack()
def __init__(self, parent=None): JDialog.__init__(self, title="My dialog", modal=1) self.contentPane.layout = FlowLayout() self.contentPane.add(JLabel("A dialog!")) self.contentPane.add(JButton("OK", actionPerformed = lambda e, t=self: t.dispose())) self.pack()
def __init__(self, frame, what): JDialog.__init__(self,frame, what, False) self.frame = frame pane = self.getRootPane().getContentPane() panel = JPanel() panel.add(JLabel('Current population')) self.status = JLabel(" ") panel.add(self.status) pane.add(panel) self.pack() self.show()
def __init__(self, frame, chart, pingFun): JDialog(frame) self.setTitle('Chart Settings') self.setModal(True) self.pingFun = pingFun pane = self.getRootPane().getContentPane() pane.setLayout(GridLayout(7, 2)) pane.add(JLabel('Marker color')) self.markerPanel = self.createColorPanel(chart.markerColor, pane) pane.add(JLabel('Positive selection color')) self.posPanel = self.createColorPanel(chart.posColor, pane) pane.add(JLabel('Neutral color')) self.neuPanel = self.createColorPanel(chart.neuColor, pane) pane.add(JLabel('Balancing selection color ')) self.balPanel = self.createColorPanel(chart.balColor, pane) self.add(JLabel('Label candidate selected loci')) self.selLabel = JCheckBox() self.selLabel.setSelected(chart.labelSelected) self.add(self.selLabel) self.add(JLabel('Label candidate neutral loci')) self.neuLabel = JCheckBox() self.neuLabel.setSelected(chart.labelNeutral) self.add(self.neuLabel) change = JButton('Change') change.setActionCommand('Change') change.addActionListener(self) pane.add(change) exit = JButton('Exit') exit.setActionCommand('Exit') exit.addActionListener(self) pane.add(exit) self.pack()
def __init__(self, frame, what, entries, pingFun): JDialog(frame, what) self.frame = frame self.entries = entries self.pingFun = pingFun pane = self.getRootPane().getContentPane() self.ent_pane, self.ent_list, self.ent = self.createList(entries) pane.add(self.ent_pane, BorderLayout.WEST) actionPanel = JPanel() actionPanel.setLayout(GridLayout(20, 1)) self.text = JTextField(20) actionPanel.add(self.text) change = JButton('Change') change.setActionCommand('Change') change.addActionListener(self) actionPanel.add(change) actionPanel.add(JLabel('')) quit = JButton('Exit') quit.setActionCommand('Exit') quit.addActionListener(self) actionPanel.add(quit) actionPanel.add(JLabel('')) pane.add(actionPanel, BorderLayout.CENTER) self.pack()
def start(self): self.frame = JDialog() #self.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) self.frame.setLocation(0, 1500) self.frame.setSize(1000, 200) self.tableDataModel = DefaultTableModel([], [ "URL", "Code", "Content-Length", "Location", "Mutated Id", "Orig Id" ]) self.jtable = JTable(self.tableDataModel) scrollPane = JScrollPane(self.jtable) self.jtable.setFillsViewportHeight(True) messageEditorOrig = self.callbacks.createMessageEditor(None, False) messageEditorModified = self.callbacks.createMessageEditor( None, False) self.editorSplitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, messageEditorOrig.getComponent(), messageEditorModified.getComponent()) self.editorSplitPane.setResizeWeight(0.5) splitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, self.editorSplitPane) splitPane.setResizeWeight(0.5) class TableSelector(ListSelectionListener): def __init__(self, plugin): self.plugin = plugin def valueChanged(self, event): if not event.getValueIsAdjusting(): selectedRowIndex = self.plugin.jtable.getSelectedRows()[0] self.plugin._rowSelected(selectedRowIndex) self.jtable.getSelectionModel().addListSelectionListener( TableSelector(self)) self.frame.add(splitPane) self.frame.setVisible(True) self.callbacks.registerHttpListener(self) self.callbacks.setExtensionName("Custom Plugin") return
def word_corrections(event): words_string = "" for word in self.word_classifier.words: words_string = words_string + word.upper() + "\n" text = "The words that can be corrected are:\n\n" + words_string dialog = JOptionPane(text, JOptionPane.INFORMATION_MESSAGE) dialog_wrapper = JDialog(self, "Available Words", False) dialog_wrapper.setContentPane(dialog) dialog_wrapper.pack() dialog_wrapper.setVisible(True)
def __init__(self, parent, title): JDialog.__init__(self, parent, title, 1) self.contentPane.layout = BorderLayout() upperPanel = JPanel(FlowLayout()) upperPanel.add(JLabel("New path:")) self.pathField = JTextField(columns=20) upperPanel.add(self.pathField) upperPanel.add(JButton(actionPerformed = self.openFileChooser, icon = \ GUIUtilities.loadIcon("Open.png"))) self.contentPane.add(upperPanel, BorderLayout.CENTER) ok = JButton("Ok", actionPerformed=self.ok, defaultCapable=1) self.contentPane.add(upperPanel, BorderLayout.CENTER) lowerPanel = JPanel(FlowLayout(FlowLayout.RIGHT)) lowerPanel.add(ok) self.rootPane.defaultButton = ok lowerPanel.add(JButton("Cancel", actionPerformed=self.cancel)) self.contentPane.add(lowerPanel, BorderLayout.SOUTH) self.path = None self.tempPath = None
def __init__(self, frame, what, all, removed, pingFun): JDialog.__init__(self, frame, what) self.frame = frame self.all = all self.removed = removed self.pingFun = pingFun pane = self.getRootPane().getContentPane() self.sel_pane, self.sel_list, self.sel = self.createList(all) pane.add(self.sel_pane, BorderLayout.WEST) button_panel = JPanel() button_panel.setLayout(GridLayout(8, 1)) button_panel.add(JLabel('<-- Selected')) button_panel.add(JLabel('Removed -->')) select = JButton('Select') select.setActionCommand('Select') select.addActionListener(self) button_panel.add(select) button_panel.add(JLabel('')) restrict = JButton('Remove') restrict.setActionCommand('Remove') restrict.addActionListener(self) button_panel.add(restrict) button_panel.add(JLabel('')) quit = JButton('Exit') quit.setActionCommand('Exit') quit.addActionListener(self) button_panel.add(quit) button_panel.add(JLabel('')) pane.add(button_panel, BorderLayout.CENTER) self.rem_pane, self.rem_list, self.rem = self.createList(removed) pane.add(self.rem_pane, BorderLayout.EAST) warning_panel = JPanel() warning_panel.add( JLabel( "Warning: Removing/adding loci or pops might take some time!")) pane.add(warning_panel, BorderLayout.NORTH) self.pack()
def __init__(self, frame, what, all, removed, pingFun): JDialog.__init__(self,frame, what) self.frame = frame self.all = all self.removed = removed self.pingFun = pingFun pane = self.getRootPane().getContentPane() self.sel_pane, self.sel_list, self.sel = self.createList(all) pane.add(self.sel_pane, BorderLayout.WEST) button_panel = JPanel() button_panel.setLayout(GridLayout(8,1)) button_panel.add(JLabel('<-- Selected')) button_panel.add(JLabel('Removed -->')) select = JButton('Select') select.setActionCommand('Select') select.addActionListener(self) button_panel.add(select) button_panel.add(JLabel('')) restrict = JButton('Remove') restrict.setActionCommand('Remove') restrict.addActionListener(self) button_panel.add(restrict) button_panel.add(JLabel('')) quit = JButton('Exit') quit.setActionCommand('Exit') quit.addActionListener(self) button_panel.add(quit) button_panel.add(JLabel('')) pane.add(button_panel, BorderLayout.CENTER) self.rem_pane, self.rem_list, self.rem = self.createList(removed) pane.add(self.rem_pane, BorderLayout.EAST) warning_panel = JPanel() warning_panel.add(JLabel("Warning: Removing/adding loci or pops might take some time!")) pane.add(warning_panel, BorderLayout.NORTH) self.pack()
def __init__(self, view, sys): JDialog.__init__(self, view, jEdit.getProperty("jython.pathhandler.title")) self.sys = sys content = self.contentPane content.layout = BorderLayout() upperPanel = JPanel(BorderLayout()) leftPanel = JPanel(BorderLayout(), border = \ BorderFactory.createTitledBorder(jEdit.getProperty("jython.pathhandler.pathborder"))) self.model = DefaultListModel() for s in sys.path: self.model.addElement(s) self.pathlist = JList( self.model, selectionMode=ListSelectionModel.SINGLE_SELECTION) leftPanel.add(JScrollPane(self.pathlist)) rightPanel = JPanel(GridBagLayout()) constraints = GridBagConstraints() constraints.insets = Insets(5, 5, 5, 5) constraints.gridy = GridBagConstraints.RELATIVE constraints.gridx = 0 buttons = [("Plus.png", "New...", self.new), \ ("ButtonProperties.png", "Edit...", self.edit), ("Minus.png", "Remove", self.remove), \ ("ArrowU.png", "Move Up", self.up), \ ("ArrowD.png", "Move down", self.down)] for (i, t, a) in buttons: rightPanel.add(JButton(icon = GUIUtilities.loadIcon(i), \ toolTipText=t, actionPerformed=a), constraints) upperPanel.add(leftPanel, BorderLayout.CENTER) upperPanel.add(rightPanel, BorderLayout.EAST) content.add(upperPanel, BorderLayout.CENTER) lowerPanel = JPanel(FlowLayout(FlowLayout.RIGHT)) self.saveAsk = JCheckBox(jEdit.getProperty("options.jython.saveJythonPathTitle"), \ selected = jEdit.getBooleanProperty("options.jython.saveJythonPath"), actionPerformed = self.saveAsk) ok = JButton("Ok", actionPerformed=self.__ok) lowerPanel.add(self.saveAsk) lowerPanel.add(ok) self.rootPane.defaultButton = ok lowerPanel.add(JButton("Cancel", actionPerformed=self.__cancel)) content.add(lowerPanel, BorderLayout.SOUTH)
def word_corrections(event): words_string = "" for word in self.word_classifier.words: words_string = words_string + word.upper() + "\n" text = "The words that can be corrected are:\n\n" +words_string dialog = JOptionPane(text, JOptionPane.INFORMATION_MESSAGE) dialog_wrapper = JDialog(self,"Available Words",False) dialog_wrapper.setContentPane(dialog) dialog_wrapper.pack() dialog_wrapper.setVisible(True)
def __init__(self, burp_callbacks, typedef, callback): burp_window = None for frame in Frame.getFrames(): if "Burp Suite" in frame.getName(): burp_window = frame break JDialog.__init__(self, burp_window) self._burp_callbacks = burp_callbacks self._type_callback = callback self.setSize(1000, 700) self._original_typedef = typedef self._type_editor = burp_callbacks.createTextEditor() self._type_editor.setEditable(True) self._type_editor.setText(json.dumps(self._original_typedef, indent=4)) splitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) splitPane.setLeftComponent(self._type_editor.getComponent()) splitPane.setRightComponent(self.createButtonPane()) splitPane.setResizeWeight(0.8) self.add(splitPane) self.is_open = True
def valueChanged(self, event): if not event.getValueIsAdjusting(): table = self.table row = table.getSelectedRow() if row > -1: method = table.getModel().getValueAt(row, 0) title = '%s.help( "%s" )' % (self.objName, method) text = self.WASobj.help(method) text = JTextArea(text, 20, 80, font=monoFont) dialog = JDialog( None, # owner title, # title 1, # modal = true layout=BorderLayout(), locationRelativeTo=None) dialog.add(JScrollPane(text), BorderLayout.CENTER) dialog.pack() dialog.setVisible(1)
def makeDialog(self, event): cmd = event.getActionCommand() isModal = (cmd == 'Modal') dialog = JDialog( self.frame, # Try None as owner... # None, # owner title='%d: %s' % (self.boxNum, cmd), modal=isModal, size=(200, 100), locationRelativeTo=self.frame) self.boxNum += 1 dialog.add(JLabel(cmd)) dialog.setVisible(1)
def popup( self, event ) : self.dialog = dialog = JDialog( self.frame, 'Name prompt', 1, layout = GridLayout( 0, 2 ), locationRelativeTo = self.frame ) dialog.add( JLabel( "What's your name?" ) ) self.text = dialog.add( JTextField( 10, actionPerformed = self.enter ) ) self.result = None dialog.pack() dialog.setVisible( 1 ) self.label.setText( 'Name = "%s"' % self.result )
def __init__(self, frame, chart, lociNames, pv, ci, confLines, locusFst, isDominant, fdr): JDialog(frame) self.chart = chart self.frame = frame self.confLines = confLines self.isDominant = isDominant self.fdr = fdr pane = self.getRootPane().getContentPane() pane.setLayout(BorderLayout()) self.initTable(lociNames, pv, ci, locusFst) scrollPane = JScrollPane(self.table) osName = System.getProperty('os.name').lower() if not System.getProperty('java.specification.version')[-1] == '5': self.table.setFillsViewportHeight(True) pane.add(scrollPane, BorderLayout.CENTER) buttonPane = JPanel() sll = JButton('Save loci list') sll.addActionListener(self) sll.setActionCommand('SLL') buttonPane.add(sll) sci = JButton('Save confidence intervals') sci.addActionListener(self) sci.setActionCommand('SCI') buttonPane.add(sci) close = JButton('Close') close.addActionListener(self) close.setActionCommand('Close') buttonPane.add(close) pane.add(buttonPane, BorderLayout.PAGE_END) self.pack()
from jehep.ui import SetEnv from jehep.ui import Editor from javax.swing import JButton, JDialog, JLabel, JPanel, JScrollPane, JTextArea from java.awt import BorderLayout from java.awt import Color from java.awt.event import ActionListener, KeyEvent, KeyListener, MouseListener frame =JDialog(); topPanel = JPanel(); lowerPanel = JPanel(); jDescription = JTextArea(80, 100); helpFile=SetEnv.DirPath+SetEnv.fSep+"Docs"+SetEnv.fSep+"HelpJythonShell.txt"; text=SetEnv.readFile(helpFile); jDescription.setText(text); jDescription.setCaretPosition(0); # jDescription.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); jDescription.setEditable(0) def exitme(event): frame.dispose() jB2 = JButton("Exit", actionPerformed=exitme) lowerPanel.add(jB2); topPanel.setLayout(BorderLayout()); # comments jScrollPane1 = JScrollPane();
def __showModal(params=None): from javax.swing import JDialog windowName = 'GWFileBrowser' if windowName in system.gui.getWindowNames(): window = system.nav.openWindowInstance(windowName, params) system.nav.centerWindow(window) rc = window.getRootContainer() #rc.load() cp = window.getContentPane() window.setVisible(False) dlg = JDialog(None, True) dlg.setContentPane(cp) dlg.setSize(window.getWidth(), window.getHeight()) dlg.setMinimumSize(window.getMinimumSize()) dlg.setMaximumSize(window.getMaximumSize()) dlg.setLocation(window.getX(), window.getY()) #dlg.setLocationRelativeTo(None) dlg.setTitle(window.getTitle()) dlg.setVisible(True) system.nav.closeWindow(window) return rc.Result return None
def __init__(self, app): from java.awt import Dialog from java.awt import CardLayout JDialog.__init__(self, app.preferencesFrame, app.strings.getString("Create_a_new_favourite_zone"), Dialog.ModalityType.DOCUMENT_MODAL) self.app = app border = BorderFactory.createEmptyBorder(5, 7, 7, 7) self.getContentPane().setBorder(border) self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS)) self.FAVAREALAYERNAME = "Favourite zone editing" info = JLabel(self.app.strings.getString("Create_a_new_favourite_zone")) info.setAlignmentX(Component.LEFT_ALIGNMENT) #Name nameLbl = JLabel(self.app.strings.getString("fav_zone_name")) self.nameTextField = JTextField(20) self.nameTextField.setMaximumSize(self.nameTextField.getPreferredSize()) self.nameTextField.setToolTipText(self.app.strings.getString("fav_zone_name_tooltip")) namePanel = JPanel() namePanel.setLayout(BoxLayout(namePanel, BoxLayout.X_AXIS)) namePanel.add(nameLbl) namePanel.add(Box.createHorizontalGlue()) namePanel.add(self.nameTextField) #Country countryLbl = JLabel(self.app.strings.getString("fav_zone_country")) self.countryTextField = JTextField(20) self.countryTextField.setMaximumSize(self.countryTextField.getPreferredSize()) self.countryTextField.setToolTipText(self.app.strings.getString("fav_zone_country_tooltip")) countryPanel = JPanel() countryPanel.setLayout(BoxLayout(countryPanel, BoxLayout.X_AXIS)) countryPanel.add(countryLbl) countryPanel.add(Box.createHorizontalGlue()) countryPanel.add(self.countryTextField) #Type modeLbl = JLabel(self.app.strings.getString("fav_zone_type")) RECTPANEL = "rectangle" POLYGONPANEL = "polygon" BOUNDARYPANEL = "boundary" self.modesStrings = [RECTPANEL, POLYGONPANEL, BOUNDARYPANEL] modesComboModel = DefaultComboBoxModel() for i in (self.app.strings.getString("rectangle"), self.app.strings.getString("delimited_by_a_closed_way"), self.app.strings.getString("delimited_by_an_administrative_boundary")): modesComboModel.addElement(i) self.modesComboBox = JComboBox(modesComboModel, actionListener=self, editable=False) #- Rectangle self.rectPanel = JPanel() self.rectPanel.setLayout(BoxLayout(self.rectPanel, BoxLayout.Y_AXIS)) capturePane = JPanel() capturePane.setLayout(BoxLayout(capturePane, BoxLayout.X_AXIS)) capturePane.setAlignmentX(Component.LEFT_ALIGNMENT) josmP = JPanel() self.captureRBtn = JRadioButton(self.app.strings.getString("capture_area")) self.captureRBtn.addActionListener(self) self.captureRBtn.setSelected(True) self.bboxFromJosmBtn = JButton(self.app.strings.getString("get_current_area"), actionPerformed=self.on_bboxFromJosmBtn_clicked) self.bboxFromJosmBtn.setToolTipText(self.app.strings.getString("get_capture_area_tooltip")) josmP.add(self.bboxFromJosmBtn) capturePane.add(self.captureRBtn) capturePane.add(Box.createHorizontalGlue()) capturePane.add(self.bboxFromJosmBtn) manualPane = JPanel() manualPane.setLayout(BoxLayout(manualPane, BoxLayout.X_AXIS)) manualPane.setAlignmentX(Component.LEFT_ALIGNMENT) self.manualRBtn = JRadioButton(self.app.strings.getString("use_this_bbox")) self.manualRBtn.addActionListener(self) self.bboxTextField = JTextField(20) self.bboxTextField.setMaximumSize(self.bboxTextField.getPreferredSize()) self.bboxTextField.setToolTipText(self.app.strings.getString("fav_bbox_tooltip")) self.bboxTextFieldDefaultBorder = self.bboxTextField.getBorder() self.bboxTextField.getDocument().addDocumentListener(TextListener(self)) manualPane.add(self.manualRBtn) manualPane.add(Box.createHorizontalGlue()) manualPane.add(self.bboxTextField) group = ButtonGroup() group.add(self.captureRBtn) group.add(self.manualRBtn) previewPane = JPanel() previewPane.setLayout(BoxLayout(previewPane, BoxLayout.X_AXIS)) previewPane.setAlignmentX(Component.LEFT_ALIGNMENT) bboxPreviewInfo = JTextField(self.app.strings.getString("coordinates"), editable=0, border=None) bboxPreviewInfo.setMaximumSize(bboxPreviewInfo.getPreferredSize()) self.bboxPreviewTextField = JTextField(20, editable=0, border=None) self.bboxPreviewTextField.setMaximumSize(self.bboxPreviewTextField.getPreferredSize()) previewPane.add(bboxPreviewInfo) previewPane.add(Box.createHorizontalGlue()) previewPane.add(self.bboxPreviewTextField) self.rectPanel.add(capturePane) self.rectPanel.add(Box.createRigidArea(Dimension(0, 10))) self.rectPanel.add(manualPane) self.rectPanel.add(Box.createRigidArea(Dimension(0, 20))) self.rectPanel.add(previewPane) #- Polygon (closed way) drawn by hand self.polygonPanel = JPanel(BorderLayout()) self.polygonPanel.setLayout(BoxLayout(self.polygonPanel, BoxLayout.Y_AXIS)) polyInfo = JLabel("<html>%s</html>" % self.app.strings.getString("polygon_info")) polyInfo.setFont(polyInfo.getFont().deriveFont(Font.ITALIC)) polyInfo.setAlignmentX(Component.LEFT_ALIGNMENT) editPolyPane = JPanel() editPolyPane.setAlignmentX(Component.LEFT_ALIGNMENT) editPolyBtn = JButton(self.app.strings.getString("create_fav_layer"), actionPerformed=self.create_new_zone_editing_layer) editPolyBtn.setToolTipText(self.app.strings.getString("create_fav_layer_tooltip")) editPolyPane.add(editPolyBtn) self.polygonPanel.add(polyInfo) self.polygonPanel.add(Box.createRigidArea(Dimension(0, 15))) self.polygonPanel.add(editPolyPane) self.polygonPanel.add(Box.createRigidArea(Dimension(0, 15))) #- Administrative Boundary self.boundaryPanel = JPanel() self.boundaryPanel.setLayout(BoxLayout(self.boundaryPanel, BoxLayout.Y_AXIS)) boundaryInfo = JLabel("<html>%s</html>" % app.strings.getString("boundary_info")) boundaryInfo.setFont(boundaryInfo.getFont().deriveFont(Font.ITALIC)) boundaryInfo.setAlignmentX(Component.LEFT_ALIGNMENT) boundaryTagsPanel = JPanel(GridLayout(3, 3, 5, 5)) boundaryTagsPanel.setAlignmentX(Component.LEFT_ALIGNMENT) boundaryTagsPanel.add(JLabel("name =")) self.nameTagTextField = JTextField(20) boundaryTagsPanel.add(self.nameTagTextField) boundaryTagsPanel.add(UrlLabel("http://wiki.openstreetmap.org/wiki/Key:admin_level#admin_level", "admin_level =")) self.adminLevelTagTextField = JTextField(20) self.adminLevelTagTextField.setToolTipText(self.app.strings.getString("adminLevel_tooltip")) boundaryTagsPanel.add(self.adminLevelTagTextField) boundaryTagsPanel.add(JLabel(self.app.strings.getString("other_tag"))) self.optionalTagTextField = JTextField(20) self.optionalTagTextField.setToolTipText("key=value") boundaryTagsPanel.add(self.optionalTagTextField) downloadBoundariesPane = JPanel() downloadBoundariesPane.setAlignmentX(Component.LEFT_ALIGNMENT) downloadBoundariesBtn = JButton(self.app.strings.getString("download_boundary"), actionPerformed=self.on_downloadBoundariesBtn_clicked) downloadBoundariesBtn.setToolTipText(self.app.strings.getString("download_boundary_tooltip")) downloadBoundariesPane.add(downloadBoundariesBtn) self.boundaryPanel.add(boundaryInfo) self.boundaryPanel.add(Box.createRigidArea(Dimension(0, 15))) self.boundaryPanel.add(boundaryTagsPanel) self.boundaryPanel.add(Box.createRigidArea(Dimension(0, 10))) self.boundaryPanel.add(downloadBoundariesPane) self.editingPanels = {"rectangle": self.rectPanel, "polygon": self.polygonPanel, "boundary": self.boundaryPanel} #Main buttons self.okBtn = JButton(self.app.strings.getString("OK"), ImageProvider.get("ok"), actionPerformed=self.on_okBtn_clicked) self.cancelBtn = JButton(self.app.strings.getString("cancel"), ImageProvider.get("cancel"), actionPerformed=self.close_dialog) self.previewBtn = JButton(self.app.strings.getString("Preview_zone"), actionPerformed=self.on_previewBtn_clicked) self.previewBtn.setToolTipText(self.app.strings.getString("preview_zone_tooltip")) okBtnSize = self.okBtn.getPreferredSize() viewBtnSize = self.previewBtn.getPreferredSize() viewBtnSize.height = okBtnSize.height self.previewBtn.setPreferredSize(viewBtnSize) #layout self.add(info) self.add(Box.createRigidArea(Dimension(0, 15))) namePanel.setAlignmentX(Component.LEFT_ALIGNMENT) self.add(namePanel) self.add(Box.createRigidArea(Dimension(0, 15))) countryPanel.setAlignmentX(Component.LEFT_ALIGNMENT) self.add(countryPanel) self.add(Box.createRigidArea(Dimension(0, 15))) modeLbl.setAlignmentX(Component.LEFT_ALIGNMENT) self.add(modeLbl) self.add(Box.createRigidArea(Dimension(0, 5))) self.add(self.modesComboBox) self.modesComboBox.setAlignmentX(Component.LEFT_ALIGNMENT) self.add(Box.createRigidArea(Dimension(0, 15))) self.configPanel = JPanel(CardLayout()) self.configPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)) self.configPanel.add(self.rectPanel, RECTPANEL) self.configPanel.add(self.polygonPanel, POLYGONPANEL) self.configPanel.add(self.boundaryPanel, BOUNDARYPANEL) self.configPanel.setAlignmentX(Component.LEFT_ALIGNMENT) self.add(self.configPanel) buttonsPanel = JPanel() buttonsPanel.add(self.okBtn) buttonsPanel.add(self.cancelBtn) buttonsPanel.add(self.previewBtn) buttonsPanel.setAlignmentX(Component.LEFT_ALIGNMENT) self.add(buttonsPanel) self.addWindowListener(self) self.pack()
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 show_detectable_objects_dialog(self, e): parentComponent = SwingUtilities.windowForComponent(self.panel0) self.detectable_obejcts_dialog = JDialog( parentComponent, "List of Objects to Detect", ModalityType.APPLICATION_MODAL) panel = JPanel() self.detectable_obejcts_dialog.add(panel) gbPanel = GridBagLayout() gbcPanel = GridBagConstraints() panel.setLayout(gbPanel) y = 0 x = 0 for line in self.local_settings.getClassesOfInterest(): if y > 15: y = 0 x = x + 1 class_check_box = JCheckBox(line['name']) self.classes_of_interest_checkboxes.append(class_check_box) class_check_box.setEnabled(True) class_check_box.setSelected(line['enabled']) class_check_box.addItemListener(self.on_class_checkbox_clicked) gbcPanel.gridx = x gbcPanel.gridy = y gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(class_check_box, gbcPanel) panel.add(class_check_box) y = y + 1 blank_1_L = JLabel(" ") blank_1_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 1 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_1_L, gbcPanel) panel.add(blank_1_L) deselect_all_button = JButton("Deselect all") deselect_all_button.setEnabled(True) deselect_all_button.addActionListener(self.on_deselect_all_clicked) gbcPanel.gridx = 1 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(deselect_all_button, gbcPanel) panel.add(deselect_all_button) select_all_button = JButton("Select all") select_all_button.setEnabled(True) select_all_button.addActionListener(self.on_select_all_clicked) gbcPanel.gridx = 3 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(select_all_button, gbcPanel) panel.add(select_all_button) blank_2_L = JLabel(" ") blank_2_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 3 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_2_L, gbcPanel) panel.add(blank_2_L) cancel_button = JButton("Cancel") cancel_button.setEnabled(True) cancel_button.addActionListener( self.on_cancel_classes_of_interest_click) gbcPanel.gridx = 1 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(cancel_button, gbcPanel) panel.add(cancel_button) save_button = JButton("Save") save_button.setEnabled(True) save_button.addActionListener(self.on_save_classes_of_interest_click) gbcPanel.gridx = 3 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(save_button, gbcPanel) panel.add(save_button) blank_3_L = JLabel(" ") blank_3_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 5 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_3_L, gbcPanel) panel.add(blank_3_L) self.detectable_obejcts_dialog.pack() screenSize = Toolkit.getDefaultToolkit().getScreenSize() self.detectable_obejcts_dialog.setLocation( int((screenSize.getWidth() / 2) - (self.detectable_obejcts_dialog.getWidth() / 2)), int((screenSize.getHeight() / 2) - (self.detectable_obejcts_dialog.getHeight() / 2))) self.detectable_obejcts_dialog.setVisible(True)
class AutopsyImageClassificationModuleWithUISettingsPanel( IngestModuleIngestJobSettingsPanel): _logger = Logger.getLogger( AutopsyImageClassificationModuleFactory.moduleName) def log(self, level, msg): self._logger.logp(level, self.__class__.__name__, inspect.stack()[1][3], msg) def __init__(self, settings): self.local_settings = settings self.config_location = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'configs.json') self.init_components() self.customize_components() self.check_server_connection(None) self.classes_of_interest_changes_list = list() self.classes_of_interest_checkboxes = list() # Return the settings used def getSettings(self): if not os.path.isfile(self.config_location): self.log( Level.INFO, "Configuration file not found, loading the default configuration" ) self.local_settings.setServerHost(DEFAULT_HOST) self.local_settings.setServerPort(DEFAULT_PORT) self.local_settings.setImageFormats(DEFAULT_IMAGES_FORMAT) self.local_settings.setMinFileSize(DEFAULT_MIN_FILE_SIZE) self.local_settings.setMinProbability(DEFAULT_MIN_PROBABILITY) self.local_settings.setClassesOfInterest( json.loads(DEFAULT_CLASSES_OF_INTEREST)) # self.saveSettings(None) return self.local_settings else: if not os.access(self.config_location, os.R_OK): err_string = "Cannot access configuration file, please review the file permissions" raise IngestModuleException(err_string) with io.open(self.config_location, 'r', encoding='utf-8') as f: self.log(Level.INFO, "Configuration file read") json_configs = json.load(f) self.local_settings.setServerHost(json_configs['server']['host']) self.local_settings.setServerPort(json_configs['server']['port']) image_formats = json_configs['imageFormats'] if not isinstance(image_formats, list) or len(image_formats) == 0: err_string = "Invalid list of image formats given" raise IngestModuleException(err_string) self.local_settings.setImageFormats(image_formats) self.local_settings.setMinFileSize(json_configs['minFileSize']) self.local_settings.setMinProbability( json_configs['minProbability']) self.local_settings.setClassesOfInterest( json_configs['classesOfInterest']) return self.local_settings def check_server_connection(self, e): message_string = "Testing connection with server..." self.log(Level.INFO, message_string) self.message.setText(message_string) self.error_message.setText("") new_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) new_socket.settimeout(1) try: new_socket.connect( (self.host_TF.getText(), int(self.port_TF.getText()))) self.local_settings.setIsServerOnline(True) message_string = "Server is up!" self.log(Level.INFO, message_string) self.message.setText(message_string) except (socket.timeout, socket.error) as e: self.local_settings.setIsServerOnline(False) err_string = "Server is down" self.error_message.setText(err_string) self.message.setText("") self.log(Level.INFO, err_string) finally: new_socket.close() def save_settings(self, e): self.message.setText("") self.log(Level.INFO, "Settings save button clicked!") host = self.host_TF.getText() if not host.strip(): err_string = "Invalid host" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) port = self.port_TF.getText() if not host.strip(): err_string = "Invalid port number" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) image_formats_array = self.image_formats_TF.getText().strip().split( ';') if len(image_formats_array) == 0 or not image_formats_array[0]: err_string = "Invalid image formats" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) min_probability_string = self.min_probability_TF.getText().strip() if not min_probability_string: err_string = "Invalid minimum confidence value" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) min_probability = int(float(min_probability_string)) min_file_size_string = self.min_file_size_TF.getText().strip() if not min_file_size_string: err_string = "Invalid minimum file size" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) min_file_size = int(float(min_file_size_string)) configs = { 'server': { 'host': host, 'port': port }, 'imageFormats': image_formats_array, 'minProbability': min_probability, 'minFileSize': min_file_size, 'classesOfInterest': self.local_settings.getClassesOfInterest() } with io.open(self.config_location, 'w', encoding='utf-8') as f: f.write(json.dumps(configs, ensure_ascii=False)) self.error_message.setText("") message = "Settings saved " self.message.setText(message) self.log(Level.INFO, message + " in " + self.config_location) def open_text_editor(self, e): self.log(Level.INFO, "Lauching external text editor ") if sys.platform == "win32": subprocess.call(["notepad", self.config_location]) else: opener = "open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, self.config_location]) def on_save_classes_of_interest_click(self, e): self.detectable_obejcts_dialog.setVisible(False) for item in self.classes_of_interest_changes_list: for class_oi in self.local_settings.getClassesOfInterest(): if item.getText() == class_oi['name']: self.log( Level.INFO, "match found " + class_oi['name'] + " and is selected " + str(item.isSelected())) class_oi['enabled'] = item.isSelected() break self.classes_of_interest_checkboxes = list() def on_cancel_classes_of_interest_click(self, e): self.detectable_obejcts_dialog.setVisible(False) self.classes_of_interest_changes_list = list() self.classes_of_interest_checkboxes = list() def on_class_checkbox_clicked(self, e): self.classes_of_interest_changes_list.append(e.getSource()) def on_select_all_clicked(self, e): for checkbox in self.classes_of_interest_checkboxes: checkbox.setSelected(True) def on_deselect_all_clicked(self, e): for checkbox in self.classes_of_interest_checkboxes: checkbox.setSelected(False) def show_detectable_objects_dialog(self, e): parentComponent = SwingUtilities.windowForComponent(self.panel0) self.detectable_obejcts_dialog = JDialog( parentComponent, "List of Objects to Detect", ModalityType.APPLICATION_MODAL) panel = JPanel() self.detectable_obejcts_dialog.add(panel) gbPanel = GridBagLayout() gbcPanel = GridBagConstraints() panel.setLayout(gbPanel) y = 0 x = 0 for line in self.local_settings.getClassesOfInterest(): if y > 15: y = 0 x = x + 1 class_check_box = JCheckBox(line['name']) self.classes_of_interest_checkboxes.append(class_check_box) class_check_box.setEnabled(True) class_check_box.setSelected(line['enabled']) class_check_box.addItemListener(self.on_class_checkbox_clicked) gbcPanel.gridx = x gbcPanel.gridy = y gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(class_check_box, gbcPanel) panel.add(class_check_box) y = y + 1 blank_1_L = JLabel(" ") blank_1_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 1 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_1_L, gbcPanel) panel.add(blank_1_L) deselect_all_button = JButton("Deselect all") deselect_all_button.setEnabled(True) deselect_all_button.addActionListener(self.on_deselect_all_clicked) gbcPanel.gridx = 1 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(deselect_all_button, gbcPanel) panel.add(deselect_all_button) select_all_button = JButton("Select all") select_all_button.setEnabled(True) select_all_button.addActionListener(self.on_select_all_clicked) gbcPanel.gridx = 3 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(select_all_button, gbcPanel) panel.add(select_all_button) blank_2_L = JLabel(" ") blank_2_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 3 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_2_L, gbcPanel) panel.add(blank_2_L) cancel_button = JButton("Cancel") cancel_button.setEnabled(True) cancel_button.addActionListener( self.on_cancel_classes_of_interest_click) gbcPanel.gridx = 1 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(cancel_button, gbcPanel) panel.add(cancel_button) save_button = JButton("Save") save_button.setEnabled(True) save_button.addActionListener(self.on_save_classes_of_interest_click) gbcPanel.gridx = 3 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(save_button, gbcPanel) panel.add(save_button) blank_3_L = JLabel(" ") blank_3_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 5 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_3_L, gbcPanel) panel.add(blank_3_L) self.detectable_obejcts_dialog.pack() screenSize = Toolkit.getDefaultToolkit().getScreenSize() self.detectable_obejcts_dialog.setLocation( int((screenSize.getWidth() / 2) - (self.detectable_obejcts_dialog.getWidth() / 2)), int((screenSize.getHeight() / 2) - (self.detectable_obejcts_dialog.getHeight() / 2))) self.detectable_obejcts_dialog.setVisible(True) def customize_components(self): settings = self.getSettings() self.host_TF.setText(settings.getServerHost()) self.port_TF.setText(str(settings.getServerPort())) self.log(Level.INFO, "[customizeComponents]") self.log(Level.INFO, settings.getImageFormats()[0]) self.image_formats_TF.setText(';'.join(settings.getImageFormats())) self.min_probability_TF.setText(str(settings.getMinProbability())) self.min_file_size_TF.setText(str(settings.getMinFileSize())) def init_components(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.host_L = JLabel("Host:") self.host_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.host_L, self.gbcPanel0) self.panel0.add(self.host_L) self.port_L = JLabel("Port:") self.port_L.setEnabled(True) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 2 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.port_L, self.gbcPanel0) self.panel0.add(self.port_L) self.host_TF = JTextField(10) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 2 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.host_TF, self.gbcPanel0) self.panel0.add(self.host_TF) format = NumberFormat.getInstance() format.setGroupingUsed(False) port_formatter = NumberFormatter(format) port_formatter.setValueClass(Integer) port_formatter.setAllowsInvalid(False) port_formatter.setMinimum(Integer(0)) port_formatter.setMaximum(Integer(65535)) self.port_TF = JFormattedTextField(port_formatter) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 2 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.port_TF, self.gbcPanel0) self.panel0.add(self.port_TF) self.blank_1_L = JLabel(" ") self.blank_1_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_1_L, self.gbcPanel0) self.panel0.add(self.blank_1_L) self.image_formats_L = JLabel("Format of images (separator \";\"):") self.port_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 4 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.image_formats_L, self.gbcPanel0) self.panel0.add(self.image_formats_L) self.image_formats_TF = JTextField(10) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.image_formats_TF, self.gbcPanel0) self.panel0.add(self.image_formats_TF) self.blank_2_L = JLabel(" ") self.blank_2_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 6 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_2_L, self.gbcPanel0) self.panel0.add(self.blank_2_L) self.min_probability_L = JLabel("Confidence minimum (%):") self.port_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_probability_L, self.gbcPanel0) self.panel0.add(self.min_probability_L) min_probabilty_formatter = NumberFormatter(format) min_probabilty_formatter.setValueClass(Integer) min_probabilty_formatter.setAllowsInvalid(False) min_probabilty_formatter.setMinimum(Integer(0)) min_probabilty_formatter.setMaximum(Integer(100)) self.min_probability_TF = JFormattedTextField(min_probabilty_formatter) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 8 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_probability_TF, self.gbcPanel0) self.panel0.add(self.min_probability_TF) self.blank_3_L = JLabel(" ") self.blank_3_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_3_L, self.gbcPanel0) self.panel0.add(self.blank_3_L) self.min_file_size_L = JLabel("Minimum file size (KB):") self.min_file_size_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 10 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_file_size_L, self.gbcPanel0) self.panel0.add(self.min_file_size_L) min_file_size_formatter = NumberFormatter(format) min_file_size_formatter.setValueClass(Integer) min_file_size_formatter.setAllowsInvalid(False) min_file_size_formatter.setMinimum(Integer(0)) self.min_file_size_TF = JFormattedTextField(min_file_size_formatter) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_file_size_TF, self.gbcPanel0) self.panel0.add(self.min_file_size_TF) self.blank_4_L = JLabel(" ") self.blank_4_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 12 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_4_L, self.gbcPanel0) self.panel0.add(self.blank_4_L) self.detectable_obejcts_BTN = \ JButton("List of Objects to Detect", actionPerformed=self.show_detectable_objects_dialog) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.detectable_obejcts_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 13 self.gbPanel0.setConstraints(self.detectable_obejcts_BTN, self.gbcPanel0) self.panel0.add(self.detectable_obejcts_BTN) self.blank_5_L = JLabel(" ") self.blank_5_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 14 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_5_L, self.gbcPanel0) self.panel0.add(self.blank_5_L) self.error_message = JLabel("", JLabel.CENTER) self.error_message.setForeground(Color.red) self.error_message.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.error_message, self.gbcPanel0) self.panel0.add(self.error_message) self.message = JLabel("", JLabel.CENTER) self.message.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 16 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.message, self.gbcPanel0) self.panel0.add(self.message) self.save_settings_BTN = JButton("Save Settings", actionPerformed=self.save_settings) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.save_settings_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 17 self.gbPanel0.setConstraints(self.save_settings_BTN, self.gbcPanel0) self.panel0.add(self.save_settings_BTN) self.blank_6_L = JLabel(" ") self.blank_6_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 18 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_6_L, self.gbcPanel0) self.panel0.add(self.blank_6_L) self.blank_7_L = JLabel(" ") self.blank_7_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_7_L, self.gbcPanel0) self.panel0.add(self.blank_7_L) self.check_server_connection_BTN = \ JButton("Check server connection", actionPerformed=self.check_server_connection) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.check_server_connection_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 20 self.gbPanel0.setConstraints(self.check_server_connection_BTN, self.gbcPanel0) self.panel0.add(self.check_server_connection_BTN) self.blank_8_L = JLabel(" ") self.blank_8_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_8_L, self.gbcPanel0) self.panel0.add(self.blank_8_L) self.text_editor_BTN = \ JButton("Open config file", actionPerformed=self.open_text_editor) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.text_editor_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 22 self.gbPanel0.setConstraints(self.text_editor_BTN, self.gbcPanel0) self.panel0.add(self.text_editor_BTN) self.add(self.panel0)
class Plugin(IHttpListener): MUTATE_ID_COLUMN_INDEX = 4 ORIG_ID_COLUMN_INDEX = 5 def __init__(self, callbacks): self.callbacks = callbacks self.helpers = self.callbacks.getHelpers() self.origMessageEditorController = MessageEditorController() self.mutatedMessageEditorController = MessageEditorController() self.origSearchString = replacements.origSearchString self.replacements = replacements.replacements self.requestResponseCache = {} def start(self): self.frame = JDialog() #self.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) self.frame.setLocation(0, 1500) self.frame.setSize(1000, 200) self.tableDataModel = DefaultTableModel([], [ "URL", "Code", "Content-Length", "Location", "Mutated Id", "Orig Id" ]) self.jtable = JTable(self.tableDataModel) scrollPane = JScrollPane(self.jtable) self.jtable.setFillsViewportHeight(True) messageEditorOrig = self.callbacks.createMessageEditor(None, False) messageEditorModified = self.callbacks.createMessageEditor( None, False) self.editorSplitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, messageEditorOrig.getComponent(), messageEditorModified.getComponent()) self.editorSplitPane.setResizeWeight(0.5) splitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, self.editorSplitPane) splitPane.setResizeWeight(0.5) class TableSelector(ListSelectionListener): def __init__(self, plugin): self.plugin = plugin def valueChanged(self, event): if not event.getValueIsAdjusting(): selectedRowIndex = self.plugin.jtable.getSelectedRows()[0] self.plugin._rowSelected(selectedRowIndex) self.jtable.getSelectionModel().addListSelectionListener( TableSelector(self)) self.frame.add(splitPane) self.frame.setVisible(True) self.callbacks.registerHttpListener(self) self.callbacks.setExtensionName("Custom Plugin") return def stop(self): print("Closing!") self.callbacks.removeHttpListener(self) self.frame.dispose() self.jrame = None return def _rowSelected(self, index): #self.splitPane.setLeftComponent( #self.callbacks.createMessageEditor( origId = self.tableDataModel.getValueAt( index, self.ORIG_ID_COLUMN_INDEX).encode('ascii', 'ignore') mutateId = self.tableDataModel.getValueAt( index, self.MUTATE_ID_COLUMN_INDEX).encode('ascii', 'ignore') self.origMessageEditorController.setRequestResponse( self.requestResponseCache[origId]) messageEditorOrig = self.callbacks.createMessageEditor( self.origMessageEditorController, False) messageEditorOrig.setMessage( self.requestResponseCache[origId].getResponse(), False) self.editorSplitPane.setLeftComponent(messageEditorOrig.getComponent()) self.mutatedMessageEditorController.setRequestResponse( self.requestResponseCache[mutateId]) messageEditorMutated = self.callbacks.createMessageEditor( self.mutatedMessageEditorController, False) messageEditorMutated.setMessage( self.requestResponseCache[mutateId].getResponse(), False) self.editorSplitPane.setRightComponent( messageEditorMutated.getComponent()) print(mutateId) print("Row selected") print(str(index)) def _buildResponseHeadersDictionary(self, headers): """Creates key/value lookup from list of headers. Header names are converted to lowercase. If header is returned multiple time, last header has precedence.""" d = {} #Skip first "header", it's the response code line. for i in range(1, len(headers)): (name, value) = headers[i].split(":", 1) d[name.lower()] = value return d def _getDictValueOrEmptyStr(self, d, key): if key in d: return d[key] else: return "" def handleReceivedResponseForModifiedRequest(self, requestResponse): #Get original HTTP Request requestData = StringUtil.fromBytes(requestResponse.getRequest()) requestId = re.search(b"^X-REQUEST-ID: ([^\r]*)", requestData, flags=re.MULTILINE).group(1).encode('ascii') origRequestId = re.search(b"^X-REQUEST-ORIG-ID: ([^\r]*)", requestData, flags=re.MULTILINE).group(1).encode('ascii') print("Keys") print(requestId) print(origRequestId) print(self.requestResponseCache.keys()) self.requestResponseCache[requestId] = requestResponse origRequestResponse = self.requestResponseCache[origRequestId] analyzedOrigResponse = self.helpers.analyzeResponse( origRequestResponse.getResponse()) analayzeMutatedResponse = self.helpers.analyzeResponse( requestResponse.getResponse()) origResponseHeaders = self._buildResponseHeadersDictionary( analyzedOrigResponse.getHeaders()) mutatedResponseHeaders = self._buildResponseHeadersDictionary( analayzeMutatedResponse.getHeaders()) mutatedRequestInfo = self.helpers.analyzeRequest( requestResponse.getHttpService(), requestResponse.getRequest()) model = self.jtable.getModel() model.addRow([ str(mutatedRequestInfo.getUrl()), str(analayzeMutatedResponse.getStatusCode()), self._getDictValueOrEmptyStr(mutatedResponseHeaders, "content-length"), self._getDictValueOrEmptyStr(mutatedResponseHeaders, "location"), requestId, origRequestId ]) print("Modified Request Found: %s %s" % (requestId, origRequestId)) #Get original request and response object from lookup #Get request from lookup def processHttpMessage(self, toolFlag, messageIsRequest, requestResponse): if not messageIsRequest: requestData = StringUtil.fromBytes(requestResponse.getRequest()) #We generated the request, process it if requestData.find(b"X-REQUEST-ID") != -1: self.handleReceivedResponseForModifiedRequest(requestResponse) #Response received for non-mutated request. #Mutate request and send it. else: origRequestResponseUUID = str(uuid.uuid4()) reload(replacements) print("Looking for replacements") for replacement in self.replacements: newRequestData = re.sub(self.origSearchString, replacement, requestData) #If no replacemnets made, don't send any requests if newRequestData != requestData: newRequestUUID = str(uuid.uuid4()) newRequestData = re.sub( b"Host", b"X-REQUEST-ID: " + newRequestUUID + "\r\nHost", requestData) newRequestData = re.sub( b"Host", b"X-REQUEST-ORIG-ID: " + origRequestResponseUUID + "\r\nHost", newRequestData) print("Sending Mutated Request") print(newRequestData) self.requestResponseCache[ origRequestResponseUUID] = requestResponse httpService = requestResponse.getHttpService() self.callbacks.makeHttpRequest(httpService, newRequestData) print("Got here")