class ReportByPointPanelReport(FormPanel): def __init__(self): FormPanel.__init__( self, gvsig.getResource(__file__, "reportbypointpanelreport.xml")) i18Swing = ToolsSwingLocator.getToolsSwingManager() self.setPreferredSize(400, 300) self.txt = JTextPane() self.txt.setEditable(False) self.txt.setCaretPosition(0) i18Swing.setDefaultPopupMenu(self.txt) self.txt.setContentType("text/html") self.pane = JScrollPane(self.txt) #self.setInitHorizontalScroll() self.pane.setVerticalScrollBarPolicy( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) #self.setInitHorizontalScroll() #self.pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) #self.setInitHorizontalScroll() self.jplReport.setLayout(BorderLayout()) self.jplReport.add(self.pane, BorderLayout.CENTER) self.setInitHorizontalScroll() def setHTMLText(self, text): self.txt.setText(text) self.setInitHorizontalScroll() self.txt.setCaretPosition(0) def setInitHorizontalScroll(self): self.pane.getHorizontalScrollBar().setValue(0)
class BurpExtender(IBurpExtender, ITab): def registerExtenderCallbacks(self, callbacks): print "Loading..." self._callbacks = callbacks self._callbacks.setExtensionName('Burp SSL Scanner') # self._callbacks.registerScannerCheck(self) # self._callbacks.registerExtensionStateListener(self) self._helpers = callbacks.getHelpers() # initialize the main scanning event and thread self.scanningEvent = Event() self.scannerThread = None self.targetURL = None # main split pane self._splitpane = JSplitPane(JSplitPane.VERTICAL_SPLIT) self._splitpane.setBorder(EmptyBorder(20, 20, 20, 20)) # sub split pane (top) self._topPanel = JPanel(BorderLayout(10, 10)) self._topPanel.setBorder(EmptyBorder(0, 0, 10, 0)) # Setup Panel : [Target: ] [______________________] [START BUTTON] self.setupPanel = JPanel(FlowLayout(FlowLayout.LEADING, 10, 10)) self.setupPanel.add( JLabel("Target:", SwingConstants.LEFT), BorderLayout.LINE_START) self.hostField = JTextField('', 50) self.setupPanel.add(self.hostField) self.toggleButton = JButton( 'Start scanning', actionPerformed=self.startScan) self.setupPanel.add(self.toggleButton) if 'Professional' in callbacks.getBurpVersion()[0] : self.addToSitemapCheckbox = JCheckBox('Add to sitemap', True) else : self.addToSitemapCheckbox = JCheckBox('Add to sitemap (requires Professional version)', False) self.addToSitemapCheckbox.setEnabled(False) self.setupPanel.add(self.addToSitemapCheckbox) self.scanSiteMapHostCheckbox = JCheckBox('Scan sitemap hosts', True) self.setupPanel.add(self.scanSiteMapHostCheckbox) self._topPanel.add(self.setupPanel, BorderLayout.PAGE_START) # Status bar self.scanStatusPanel = JPanel(FlowLayout(FlowLayout.LEADING, 10, 10)) self.scanStatusPanel.add(JLabel("Status: ", SwingConstants.LEFT)) self.scanStatusLabel = JLabel("Ready to scan", SwingConstants.LEFT) self.scanStatusPanel.add(self.scanStatusLabel) self._topPanel.add(self.scanStatusPanel, BorderLayout.LINE_START) self._splitpane.setTopComponent(self._topPanel) # bottom panel self._bottomPanel = JPanel(BorderLayout(10, 10)) self._bottomPanel.setBorder(EmptyBorder(10, 0, 0, 0)) self.initialText = ('<h1 style="color: red;">Burp SSL Scanner<br />' 'Please note that TLS1.3 is still not supported by this extension.</h1>') self.currentText = self.initialText self.textPane = JTextPane() self.textScrollPane = JScrollPane(self.textPane) self.textPane.setContentType("text/html") self.textPane.setText(self.currentText) self.textPane.setEditable(False) self._bottomPanel.add(self.textScrollPane, BorderLayout.CENTER) self.savePanel = JPanel(FlowLayout(FlowLayout.LEADING, 10, 10)) self.saveButton = JButton('Save to file', actionPerformed=self.saveToFile) self.saveButton.setEnabled(False) self.savePanel.add(self.saveButton) self.clearScannedHostButton = JButton('Clear scanned host', actionPerformed=self.clearScannedHost) self.savePanel.add(self.clearScannedHostButton) self.savePanel.add(JLabel("Clear hosts that were scanned by active scan to enable rescanning", SwingConstants.LEFT)) self._bottomPanel.add(self.savePanel, BorderLayout.PAGE_END) self._splitpane.setBottomComponent(self._bottomPanel) callbacks.customizeUiComponent(self._splitpane) callbacks.addSuiteTab(self) print "SSL Scanner tab loaded" self.scannerMenu = ScannerMenu(self) callbacks.registerContextMenuFactory(self.scannerMenu) print "SSL Scanner custom menu loaded" self.scannerCheck = ScannerCheck(self, self.scanSiteMapHostCheckbox.isSelected) callbacks.registerScannerCheck(self.scannerCheck) print "SSL Scanner check registered" projectConfig = json.loads(self._callbacks.saveConfigAsJson()) scanAccuracy = projectConfig['scanner']['active_scanning_optimization']['scan_accuracy'] scanSpeed = projectConfig['scanner']['active_scanning_optimization']['scan_speed'] print(scanAccuracy, scanSpeed) self.scannedHost = [] print 'SSL Scanner loaded' def startScan(self, ev) : host = self.hostField.text self.scanningEvent.set() if(len(host) == 0): return if host.find("://") == -1: host = "https://" + host try: self.targetURL = URL(host) if(self.targetURL.getPort() == -1): self.targetURL = URL("https", self.targetURL.getHost(), 443, "/") self.hostField.setEnabled(False) self.toggleButton.setEnabled(False) self.saveButton.setEnabled(False) self.addToSitemapCheckbox.setEnabled(False) self.currentText = self.initialText self.textPane.setText(self.currentText) self.updateText("<h2>Scanning %s:%d</h2>" % (self.targetURL.getHost(), self.targetURL.getPort())) print("Scanning %s:%d" % (self.targetURL.getHost(), self.targetURL.getPort())) self.scannerThread = Thread(target=self.scan, args=(self.targetURL, )) self.scannerThread.start() except BaseException as e: self.saveButton.setEnabled(False) print(e) return def scan(self, url, usingBurpScanner=False): def setScanStatusLabel(text) : if not usingBurpScanner : SwingUtilities.invokeLater( ScannerRunnable(self.scanStatusLabel.setText, (text,))) def updateResultText(text) : if not usingBurpScanner : SwingUtilities.invokeLater( ScannerRunnable(self.updateText, (text, ))) if usingBurpScanner : res = result.Result(url, self._callbacks, self._helpers, False) else : res = result.Result(url, self._callbacks, self._helpers, self.addToSitemapCheckbox.isSelected()) host, port = url.getHost(), url.getPort() ### Get project configuration projectConfig = json.loads(self._callbacks.saveConfigAsJson()) if 'scanner' in projectConfig: # scanAccuracy: minimise_false_negatives, normal, minimise_false_positives scanAccuracy = projectConfig['scanner']['active_scanning_optimization']['scan_accuracy'] # scanSpeed: fast, normal, thorough scanSpeed = projectConfig['scanner']['active_scanning_optimization']['scan_speed'] else: scanAccuracy = 'normal' scanSpeed = 'normal' updateResultText('<h2>Scanning speed: %s</h2> %s' % (scanSpeed, test_details.SCANNING_SPEED_INFO[scanSpeed])) updateResultText('<h2>Scanning accuracy: %s</h2> %s' % (scanAccuracy, test_details.SCANNING_ACCURACY_INFO[scanAccuracy])) try : setScanStatusLabel("Checking for supported SSL/TLS versions") con = connection_test.ConnectionTest(res, host, port, scanSpeed, scanAccuracy) con.start() conResultText = '<hr /><br /><h3>' + res.printResult('connectable') + '</h3>' + \ '<ul><li>' + res.printResult('offer_ssl2') + '</li>' + \ '<li>' + res.printResult('offer_ssl3') + '</li>' + \ '<li>' + res.printResult('offer_tls10') + '</li>' + \ '<li>' + res.printResult('offer_tls11') + '</li>' + \ '<li>' + res.printResult('offer_tls12') + '</li></ul>' updateResultText(conResultText) if not res.getResult('connectable') : updateResultText("<h2>Scan terminated (Connection failed)</h2>") raise BaseException('Connection failed') setScanStatusLabel("Checking for supported cipher suites (This can take a long time)") supportedCipher = supportedCipher_test.SupportedCipherTest(res, host, port, scanSpeed, scanAccuracy) supportedCipher.start() setScanStatusLabel("Checking for Cipherlist") cipher = cipher_test.CipherTest(res, host, port, scanSpeed, scanAccuracy) cipher.start() cipherResultText = '<h3>Available ciphers:</h3>' + \ '<ul><li>' + res.printResult('cipher_NULL') + '</li>' + \ '<li>' + res.printResult('cipher_ANON') + '</li>' + \ '<li>' + res.printResult('cipher_EXP') + '</li>' + \ '<li>' + res.printResult('cipher_LOW') + '</li>' + \ '<li>' + res.printResult('cipher_WEAK') + '</li>' + \ '<li>' + res.printResult('cipher_3DES') + '</li>' + \ '<li>' + res.printResult('cipher_HIGH') + '</li>' + \ '<li>' + res.printResult('cipher_STRONG') + '</li></ul>' updateResultText(cipherResultText) setScanStatusLabel("Checking for Heartbleed") heartbleed = heartbleed_test.HeartbleedTest(res, host, port, scanSpeed, scanAccuracy) heartbleed.start() heartbleedResultText = res.printResult('heartbleed') updateResultText(heartbleedResultText) setScanStatusLabel("Checking for CCS Injection") ccs = ccs_test.CCSTest(res, host, port, scanSpeed, scanAccuracy) ccs.start() ccsResultText = res.printResult('ccs_injection') updateResultText(ccsResultText) setScanStatusLabel("Checking for TLS_FALLBACK_SCSV") fallback = fallback_test.FallbackTest(res, host, port, scanSpeed, scanAccuracy) fallback.start() fallbackResultText = res.printResult('fallback_support') updateResultText(fallbackResultText) setScanStatusLabel("Checking for POODLE (SSLv3)") poodle = poodle_test.PoodleTest(res, host, port, scanSpeed, scanAccuracy) poodle.start() poodleResultText = res.printResult('poodle_ssl3') updateResultText(poodleResultText) setScanStatusLabel("Checking for SWEET32") sweet32 = sweet32_test.Sweet32Test(res, host, port, scanSpeed, scanAccuracy) sweet32.start() sweet32ResultText = res.printResult('sweet32') updateResultText(sweet32ResultText) setScanStatusLabel("Checking for DROWN") drown = drown_test.DrownTest(res, host, port, scanSpeed, scanAccuracy) drown.start() drownResultText = res.printResult('drown') updateResultText(drownResultText) setScanStatusLabel("Checking for FREAK") freak = freak_test.FreakTest(res, host, port, scanSpeed, scanAccuracy) freak.start() freakResultText = res.printResult('freak') updateResultText(freakResultText) setScanStatusLabel("Checking for LUCKY13") lucky13 = lucky13_test.Lucky13Test(res, host, port, scanSpeed, scanAccuracy) lucky13.start() lucky13ResultText = res.printResult('lucky13') updateResultText(lucky13ResultText) setScanStatusLabel("Checking for CRIME") crime = crime_test.CrimeTest(res, host, port, scanSpeed, scanAccuracy) crime.start() crimeResultText = res.printResult('crime_tls') updateResultText(crimeResultText) setScanStatusLabel("Checking for BREACH") breach = breach_test.BreachTest(res, host, port, scanSpeed, scanAccuracy) breach.start(self._callbacks, self._helpers) breachResultText = res.printResult('breach') updateResultText(breachResultText) setScanStatusLabel("Checking for BEAST") beast = beast_test.BeastTest(res, host, port, scanSpeed, scanAccuracy) beast.start() beastResultText = res.printResult('beast') updateResultText(beastResultText) setScanStatusLabel("Checking for LOGJAM") logjam = logjam_test.LogjamTest(res, host, port, scanSpeed, scanAccuracy) logjam.start() logjamResultText = res.printResult('logjam_export') + '<br />' + res.printResult('logjam_common') updateResultText(logjamResultText) updateResultText('<h2>Finished scanning</h2><br /><hr /><br /><h2>Summary</h2>') updateResultText('<h2>Supported ciphers (by Protocol)</h2>') updateResultText(res.printCipherList()) updateResultText('<h2>Supported ciphers (by Vulnerability)</h2>') updateResultText(res.printCipherListByVulns()) updateResultText('<h2>Issues found</h2>') updateResultText(res.printAllIssue()) except BaseException as e : print(e) setScanStatusLabel("An error occurred. Please refer to the output/errors tab for more information.") time.sleep(2) if usingBurpScanner : return res.getAllIssue() else : self.scanningEvent.clear() SwingUtilities.invokeLater( ScannerRunnable(self.toggleButton.setEnabled, (True, )) ) SwingUtilities.invokeLater( ScannerRunnable(self.hostField.setEnabled, (True, )) ) SwingUtilities.invokeLater( ScannerRunnable(self.saveButton.setEnabled, (True, )) ) if 'Professional' in self._callbacks.getBurpVersion()[0] : SwingUtilities.invokeLater( ScannerRunnable(self.addToSitemapCheckbox.setEnabled, (True, )) ) setScanStatusLabel("Ready to scan") print("Finished scanning") def updateText(self, stringToAppend): self.currentText += ('<br />' + stringToAppend) self.textPane.setText(self.currentText) def saveToFile(self, event): fileChooser = JFileChooser() if not (self.targetURL is None): fileChooser.setSelectedFile(File("Burp_SSL_Scanner_Result_%s.html" \ % (self.targetURL.getHost()))) else: fileChooser.setSelectedFile(File("Burp_SSL_Scanner_Result.html")) if (fileChooser.showSaveDialog(self.getUiComponent()) == JFileChooser.APPROVE_OPTION): fw = FileWriter(fileChooser.getSelectedFile()) fw.write(self.textPane.getText()) fw.flush() fw.close() print "Saved results to disk" def clearScannedHost(self, event) : self.scannedHost = [] def addHostToScannedList(self, host, port) : self.scannedHost.append([host, port]) def getTabCaption(self): return "SSL Scanner" def getUiComponent(self): return self._splitpane
class DialogPanel(Panel): manImage = None #image manImageSilent = None manLabel = None #label dialogText = None dialogTextScroller = None buttonsPanel = None def speak(self, text): self.dialogText.setText("") self.manLabel.setIcon(self.manImage) class Typer(threading.Thread): def __init__(thrd, text): threading.Thread.__init__(thrd) thrd.text = text def run(thrd): text = thrd.text for i in range(0, len(text)): if text[i] == '-': time.sleep(.05) pass self.dialogText.setText(self.dialogText.getText() + text[i]) time.sleep(.1) self.manLabel.setIcon(self.manImageSilent) Typer(text).start() def __init__(self, inconsolePanel): self.consolePanel = inconsolePanel Panel.__init__(self, "insets 0 0 0 0") self.speak( "My name is Captain danglewood! Help me find my lost crew in this hell pit of unix!!!" ) def initUI(self): self.manImage = ImageIcon('bin/gui/media/' + "danglewood.gif") self.manImageSilent = ImageIcon('bin/gui/media/' + "danglewood-silent.png") self.manLabel = JLabel(self.manImage) self.dialogText = JTextPane() self.dialogText.setEditable(False) self.dialogTextScroller = JScrollPane(self.dialogText) self.dialogText.setBackground(Color(0, 24, 0)) self.dialogText.setForeground(Color.WHITE) self.dialogText.setFont(Font("Arial", Font.BOLD, 15)) self.buttonsPanel = ButtonPanel(self.consolePanel, self) self.dialogText.setText("Welcome to BashED!!!") def addUI(self): self.add(self.buttonsPanel, "cell 0 0, pushy, growy") self.add(self.dialogTextScroller, "cell 1 0, push, grow") self.add(self.manLabel, "cell 2 0")
def __init__(self, ui): JSplitPane.__init__(self, JSplitPane.HORIZONTAL_SPLIT) self._ui = ui # create the executor object self._executor = Executor(self, ui.callbacks) #### # start Left Top split layout jLeftTopPanel = JPanel() jMenuPanel = JPanel() #Load button self.jLoad = JButton(Strings.jLoad_text) self.jLoad.addActionListener(self) #File name text field self.jFileName = JTextField(Strings.jFileName_default, 30) self.jFileName.setHorizontalAlignment(JTextField.CENTER) self.jFileName.setEditable(False) #Save button self.jSave = JButton(Strings.jSave_text) self.jSave.addActionListener(self) #Exit button self.jExit = JButton(Strings.jExit_text) self.jExit.addActionListener(self) #Wiki button (URL) self.jWiki = JButton(Strings.jWiki_title) self.jWiki.setToolTipText(Strings.jWiki_tooltip) self.jWiki.addActionListener(self) # make it borderless self.jWiki.setBorder(EmptyBorder(0, 0, 0, 0)) self.jWiki.setBorderPainted(False) self.jWiki.setContentAreaFilled(False) #Console text area jConsoleText = JTextArea() jConsoleText.setEditable(0) jConsoleText.setWrapStyleWord(1) jConsoleText.setRows(10) #set initial text jConsoleText.setText(Strings.jConsoleText_help) #make scrollable jScrollConsolePane = JScrollPane() jScrollConsolePane.setViewportView(jConsoleText) jMenuPanelLayout = GroupLayout(jMenuPanel) jMenuPanel.setLayout(jMenuPanelLayout) jMenuPanelLayout.setHorizontalGroup( jMenuPanelLayout.createParallelGroup( GroupLayout.Alignment.LEADING). addGroup(jMenuPanelLayout.createSequentialGroup().addContainerGap( ).addComponent(self.jLoad).addComponent( self.jFileName).addPreferredGap( LayoutStyle.ComponentPlacement.RELATED).addComponent( self.jSave).addPreferredGap( LayoutStyle.ComponentPlacement.RELATED). addComponent(self.jWiki).addPreferredGap( LayoutStyle.ComponentPlacement.RELATED).addComponent( self.jExit).addContainerGap())) jMenuPanelLayout.setVerticalGroup( jMenuPanelLayout.createParallelGroup( GroupLayout.Alignment.LEADING).addGroup( jMenuPanelLayout.createSequentialGroup().addGroup( jMenuPanelLayout.createParallelGroup( GroupLayout.Alignment.BASELINE).addComponent( self.jLoad).addComponent( self.jFileName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent( self.jSave).addComponent( self.jWiki).addComponent( self.jExit)))) jLeftTopPanelLayout = GroupLayout(jLeftTopPanel) jLeftTopPanel.setLayout(jLeftTopPanelLayout) jLeftTopPanelLayout.setHorizontalGroup( jLeftTopPanelLayout.createParallelGroup( GroupLayout.Alignment.LEADING).addComponent( jMenuPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE).addComponent( jScrollConsolePane, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, 32767)) jLeftTopPanelLayout.setVerticalGroup( jLeftTopPanelLayout. createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( GroupLayout.Alignment.TRAILING, jLeftTopPanelLayout.createSequentialGroup().addComponent( jMenuPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap( LayoutStyle.ComponentPlacement.RELATED).addComponent( jScrollConsolePane, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, 32767))) # end Left Top split layout #### #### # start Left Down split layout jLeftDownPanel = JPanel() jMenu2Panel = JPanel() #Clear button self.jClear = JButton(Strings.jClear_text) self.jClear.setToolTipText(Strings.jClear_tooltip) self.jClear.addActionListener(self) #Run button self.jRun = JButton(Strings.jRun_text) self.jRun.setToolTipText(Strings.jRun_tooltip) self.jRun.addActionListener(self) #Variables text area jVarsPane = JTextPane() jVarsPane.setFont(Font('Monospaced', Font.PLAIN, 11)) jVarsPane.addFocusListener(self) # set initial value jVarsPane.setText(Strings.jVarsPane_header) # make scrollable jScrollpaneLeftDown = JScrollPane() jScrollpaneLeftDown.setViewportView(jVarsPane) jMenu2PanelLayout = GroupLayout(jMenu2Panel) jMenu2Panel.setLayout(jMenu2PanelLayout) jMenu2PanelLayout.setHorizontalGroup( jMenu2PanelLayout.createParallelGroup( GroupLayout.Alignment.LEADING).addGroup( jMenu2PanelLayout.createSequentialGroup().addContainerGap( ).addComponent(self.jClear).addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, 100, 32767).addComponent(self.jRun).addContainerGap())) jMenu2PanelLayout.setVerticalGroup( jMenu2PanelLayout.createParallelGroup( GroupLayout.Alignment.LEADING).addGroup( jMenu2PanelLayout.createSequentialGroup().addGroup( jMenu2PanelLayout.createParallelGroup( GroupLayout.Alignment.BASELINE).addComponent( self.jClear).addComponent(self.jRun)))) jLeftDownPanelLayout = GroupLayout(jLeftDownPanel) jLeftDownPanel.setLayout(jLeftDownPanelLayout) jLeftDownPanelLayout.setHorizontalGroup( jLeftDownPanelLayout.createParallelGroup( GroupLayout.Alignment.LEADING).addComponent( jMenu2Panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE).addComponent( jScrollpaneLeftDown, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, 32767)) jLeftDownPanelLayout.setVerticalGroup( jLeftDownPanelLayout. createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( GroupLayout.Alignment.TRAILING, jLeftDownPanelLayout.createSequentialGroup().addComponent( jMenu2Panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap( LayoutStyle.ComponentPlacement.RELATED).addComponent( jScrollpaneLeftDown, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, 32767))) # end Left Down split layout #### #### # start Left layout jSplitPaneLeft = JSplitPane(JSplitPane.VERTICAL_SPLIT, jLeftTopPanel, jLeftDownPanel) jSplitPaneLeft.setDividerLocation(300) # end Left layout #### #### # start Right layout jScriptPane = JTextPane() jScriptPane.setFont(Font('Monospaced', Font.PLAIN, 11)) # set initial value jScriptPane.setText(Strings.jScriptPane_header) #jScriptPane.addMouseListener(self) jScrollPaneRight = JScrollPane() jScrollPaneRight.setViewportView(jScriptPane) # end Right layout #### self.setLeftComponent(jSplitPaneLeft) self.setRightComponent(jScrollPaneRight) self.setDividerLocation(450) #Exported variables self.jConsoleText = jConsoleText self.jScrollConsolePane = jScrollConsolePane self.jScriptPane = jScriptPane self.jVarsPane = jVarsPane
class InductionApplet(JApplet): def init(self): global exampleList self.thinFont = Font("Dialog", 0, 10) self.pane = self.getContentPane() self.examples = exampleList.keys() self.examples.sort() self.exampleSelector = JList(self.examples, valueChanged=self.valueChanged) self.exampleSelector.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) self.exampleSelector.setLayoutOrientation(JList.VERTICAL) self.exampleSelector.setPreferredSize(Dimension(150,500)) self.exampleSelector.setBackground(Color(0.95, 0.95, 0.98)) self.exampleSelector.setFont(self.thinFont) self.centerPanel = JPanel(BorderLayout()) self.canvas = GraphCanvas() self.canvas.setApplet(self) self.buttonRow = JPanel(FlowLayout()) self.backButton = JButton("<", actionPerformed = self.backAction) self.backButton.setFont(self.thinFont) self.continueButton = JButton("continue >", actionPerformed=self.continueAction) self.continueButton.setFont(self.thinFont) self.scaleGroup = ButtonGroup() self.linearButton = JRadioButton("linear scale", actionPerformed=self.linearAction) self.linearButton.setSelected(True) self.linearButton.setFont(self.thinFont) self.logarithmicButton = JRadioButton("logarithmic scale", actionPerformed=self.logarithmicAction) self.logarithmicButton.setFont(self.thinFont) self.aboutButton = JButton("About...", actionPerformed=self.aboutAction) self.aboutButton.setFont(self.thinFont) self.scaleGroup.add(self.linearButton) self.scaleGroup.add(self.logarithmicButton) self.buttonRow.add(self.backButton) self.buttonRow.add(self.continueButton) self.buttonRow.add(JLabel(" "*5)) self.buttonRow.add(self.linearButton) self.buttonRow.add(self.logarithmicButton) self.buttonRow.add(JLabel(" "*20)); self.buttonRow.add(self.aboutButton) self.centerPanel.add(self.canvas, BorderLayout.CENTER) self.centerPanel.add(self.buttonRow, BorderLayout.PAGE_END) self.helpText = JTextPane() self.helpText.setBackground(Color(1.0, 1.0, 0.5)) self.helpText.setPreferredSize(Dimension(800,80)) self.helpText.setText(re_sub("[ \\n]+", " ", """ Please select one of the examples in the list on the left! """)) self.pane.add(self.exampleSelector, BorderLayout.LINE_START) self.pane.add(self.centerPanel, BorderLayout.CENTER) self.pane.add(self.helpText, BorderLayout.PAGE_END) self.graph = None self.simulation = None self.touched = "" self.selected = "" self.gfxDriver = None def start(self): self.gfxDriver = awtGfx.Driver(self.canvas) #self.gfxDriver.setAntialias(True) if self.gfxDriver.getSize()[0] < 200: # konqueror java bug work around self.gfxDriver.w = 650 self.gfxDriver.h = 380 self.graph = Graph.Cartesian(self.gfxDriver, 1, 0.0, 1000, 1.0, title="Results", xaxis="Rounds", yaxis="Success Rate") def stop(self): pass def destroy(self): pass def refresh(self): if self.graph != None: self.graph.redraw() def valueChanged(self, e): global exampleList newSelection = self.examples[self.exampleSelector.getSelectedIndex()] if newSelection != self.touched: self.touched = newSelection text = re_sub("[ \\n]+", " ", exampleList[self.touched][-1]) self.helpText.setText(text) if not e.getValueIsAdjusting() and newSelection != self.selected: self.selected = newSelection smallFontPen = copy.copy(Gfx.BLACK_PEN) smallFontPen.fontSize = Gfx.SMALL ex = exampleList[self.selected] myStyleFlags = self.graph.styleFlags if self.simulation != None: self.simulation.stop() self.gfxDriver.resizedGfx() # konqueror 3.5.5 java bug workaround self.graph = Graph.Cartesian(self.gfxDriver, 1, 0.0, ex[3], 1.0, title=ex[0], xaxis="Rounds", yaxis="Success Rate", styleFlags = myStyleFlags, axisPen = smallFontPen, captionPen = smallFontPen) self.zoomFrame = [(1, 0.0, ex[3], 1.0)] self.simulation = Simulation(self.graph, ex[1], ex[2], ex[3], ex[4]) RunAsThread(self.simulation.simulation).start() def determineCurrentZoomFrame(self): i = 0 for zf in self.zoomFrame: if self.graph.x2 <= zf[2]: break i += 1 return i def backAction(self, e): if self.simulation == None: return wasRunning = self.simulation.isRunning self.simulation.stop() if wasRunning or len(self.zoomFrame) <= 1: return zi = self.determineCurrentZoomFrame() if zi > 0 and zi < len(self.zoomFrame): x1, y1, x2, y2 = self.zoomFrame[zi-1] self.graph.adjustRange(x1, y1, x2, y2) def continueAction(self, e): if self.simulation == None: return wasRunning = self.simulation.isRunning self.simulation.stop() zi = self.determineCurrentZoomFrame() if zi == len(self.zoomFrame)-1: if wasRunning or self.simulation.world.round == self.zoomFrame[zi][2]: if self.graph.styleFlags & Graph.LOG_X == 0: self.simulation.rounds *= 2 else: self.simulation.rounds *= 10 self.zoomFrame.append((1, 0.0, self.simulation.rounds, 1.0)) self.graph.adjustRange(1, 0.0, self.simulation.rounds, 1.0) RunAsThread(self.simulation.simulation).start() else: x1, y1, x2, y2 = self.zoomFrame[zi+1] self.graph.adjustRange(x1, y1, x2, y2) def linearAction(self, e): if self.graph != None and (self.graph.styleFlags & Graph.LOG_X) != 0: if self.simulation != None: self.simulation.stop() self.graph.setStyle(self.graph.styleFlags & ~Graph.LOG_X, redraw=True) if self.simulation != None: RunAsThread(self.simulation.simulation).start() def logarithmicAction(self, e): if self.graph != None and (self.graph.styleFlags & Graph.LOG_X) == 0: if self.simulation != None: self.simulation.stop() self.graph.setStyle(self.graph.styleFlags | Graph.LOG_X, redraw=True) if self.simulation != None: RunAsThread(self.simulation.simulation).start() def aboutAction(self, e): aboutText = """Induction Applet v. 0.1 (c) 2007 University of Düsseldorf Authors: Gerhard Schurz, Eckhart Arnold """ aboutText = re_sub(" +", " ", aboutText) JOptionPane.showMessageDialog(self.getContentPane(), aboutText)