Example #1
0
    def set_bugs_tabbed_pane(self, request_tab, response_tab):
        bugs_tabbed_pane = JTabbedPane()

        bugs_tabbed_pane.add("Request", request_tab)
        bugs_tabbed_pane.add("Response", response_tab)

        return bugs_tabbed_pane
Example #2
0
    def registerExtenderCallbacks(self, callbacks):
        context.addon = self
        context.version = VERSION
        context.callbacks = callbacks
        context.callbacks.setExtensionName(EXTENSION_NAME)

        api_url = context.settings.load("apiurl", DEFAULT_URI)
        auth_name = context.settings.load("auth_method", AuthMethod.anonymous)

        if auth_name == AuthMethod.email_pass:
            email = context.settings.load("email")
            passwd = context.settings.load("password")
            auth = Auth.email_pass(email, passwd)
        else:
            auth = Auth.anonymous()

        try:
            context.api = YWHApi(api_url, fetcher=BurpHTTP(), auth=auth)
        except APIException:
            context.api = YWHApi(api_url,
                                 fetcher=BurpHTTP(),
                                 auth=Auth.anonymous())

        context.tabs["Programs"] = ProgramsTab()
        context.tabs["Options"] = OptionsTab()
        tab = JTabbedPane(JTabbedPane.TOP)

        for name, panel in context.tabs.items():
            context.callbacks.customizeUiComponent(panel)
            tab.add(name, panel)

        self.getUiComponent = lambda: tab
        context.callbacks.addSuiteTab(self)
        if context.settings.load_bool("autoconnect", False):
            self.connect()
Example #3
0
 def build_ui(self):
     """
     Builds the tabbed pane within the main extension tab
     Tabs are Config and About objects
     """
     ui_tab = JTabbedPane()
     for tab in self.tabs:
         ui_tab.add(tab.getTabCaption(), tab.getUiComponent())
     return ui_tab
Example #4
0
 def build_ui(self):
     """
     Builds the tabbed pane within the main extension tab
     Tabs are Config and About objects
     """
     ui_tab = JTabbedPane()
     for tab in self.tabs:
         ui_tab.add(tab.getTabCaption(), tab.getUiComponent())
     return ui_tab
Example #5
0
    def create_tabbed_pane(self):
        tabbed_pane = JTabbedPane()
        tabbed_pane.add("Advisory", JScrollPane())
        tabbed_pane.add("Request", JScrollPane())
        tabbed_pane.add("Response", JScrollPane())

        self.tabbed_pane = tabbed_pane

        return tabbed_pane
Example #6
0
class View:
    def __init__(self):
        self.data = Data()
        self.checklist = self.data.get_checklist()
        self.issues = self.data.get_issues()

        self.set_checklist_tree()
        self.set_tree()
        self.set_pane()
        self.set_tabbed_panes()
        self.set_settings()

        self.set_tsl()

    def set_checklist(self, file_name):
        self.data.set_checklist(file_name)
        self.checklist = self.data.get_checklist()

    def get_checklist(self):
        return self.checklist

    def get_issues(self):
        return self.issues

    # TODO: Create the checklist dynamically for all nodes based on JSON structure
    # Creates a DefaultMutableTreeNode using the JSON file data
    def set_checklist_tree(self):
        self.checklist_tree = DefaultMutableTreeNode("HUNT - Methodology")

        for item in self.checklist:
            node = DefaultMutableTreeNode(item)
            self.checklist_tree.add(node)

            is_functionality = node.toString() == "Functionality"

            if is_functionality:
                functionality_node = node

        functionality = self.checklist["Functionality"]

        # TODO: Sort the functionality by name and by test name
        for functionality_name in functionality:
            tests = functionality[functionality_name]["tests"]
            node = DefaultMutableTreeNode(functionality_name)

            for test_name in tests:
                node.add(DefaultMutableTreeNode(test_name))

            functionality_node.add(node)

    def get_checklist_tree(self):
        return self.checklist_tree

    # Creates a JTree object from the checklist
    def set_tree(self):
        self.tree = JTree(self.checklist_tree)
        self.tree.getSelectionModel().setSelectionMode(
            TreeSelectionModel.SINGLE_TREE_SELECTION)

    def get_tree(self):
        return self.tree

    # TODO: Change to briefcase icon for brief, P1-P5 icons for vulns,
    #       bullseye icon for Targets, etc
    # Create a JSplitPlane with a JTree to the left and JTabbedPane to right
    def set_pane(self):
        status = JTextArea()
        status.setLineWrap(True)
        status.setText("Nothing selected")
        self.status = status

        self.pane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                               JScrollPane(self.tree), JTabbedPane())

        self.pane.setDividerLocation(310)
        self.pane.getLeftComponent().setMinimumSize(Dimension(310, 300))

    def get_pane(self):
        return self.pane

    # Creates the tabs dynamically using data from the JSON file
    def set_tabbed_panes(self):
        functionality = self.checklist["Functionality"]
        self.tabbed_panes = {}

        for functionality_name in functionality:
            tests = functionality[functionality_name]["tests"]

            for test_name in tests:
                key = functionality_name + "." + test_name
                tabbed_pane = self.set_tabbed_pane(functionality_name,
                                                   test_name)
                self.tabbed_panes[key] = self.tabbed_pane

    def get_tabbed_panes(self):
        return self.tabbed_panes

    # Creates a JTabbedPane for each vulnerability per functionality
    def set_tabbed_pane(self, functionality_name, test_name):
        description_tab = self.set_description_tab(functionality_name,
                                                   test_name)
        bugs_tab = self.set_bugs_tab()
        resources_tab = self.set_resource_tab(functionality_name, test_name)
        notes_tab = self.set_notes_tab()

        self.tabbed_pane = JTabbedPane()
        self.tabbed_pane.add("Description", description_tab)
        self.tabbed_pane.add("Bugs", bugs_tab)
        self.tabbed_pane.add("Resources", resources_tab)
        self.tabbed_pane.add("Notes", notes_tab)

    # Creates the description panel
    def set_description_tab(self, fn, vn):
        description_text = str(
            self.checklist["Functionality"][fn]["tests"][vn]["description"])
        description_textarea = JTextArea()
        description_textarea.setLineWrap(True)
        description_textarea.setText(description_text)
        description_panel = JScrollPane(description_textarea)

        return description_panel

    # TODO: Add functionality to remove tabs
    # Creates the bugs panel
    def set_bugs_tab(self):
        bugs_tab = JTabbedPane()

        return bugs_tab

    # Creates the resources panel
    def set_resource_tab(self, fn, vn):
        resource_urls = self.checklist["Functionality"][fn]["tests"][vn][
            "resources"]
        resource_text = ""

        for url in resource_urls:
            resource_text = resource_text + str(url) + "\n"

        resource_textarea = JTextArea()
        resource_textarea.setLineWrap(True)
        resource_textarea.setWrapStyleWord(True)
        resource_textarea.setText(resource_text)
        resources_panel = JScrollPane(resource_textarea)

        return resources_panel

    def set_notes_tab(self):
        notes_textarea = JTextArea()

        return notes_textarea

    def set_tsl(self):
        self.tsl = TSL(self)
        self.tree.addTreeSelectionListener(self.tsl)

        return

    def get_tsl(self):
        return self.tsl

    def set_settings(self):
        self.settings = JPanel()
        layout = GroupLayout(self.settings)
        self.settings.setLayout(layout)
        layout.setAutoCreateGaps(True)

        load_file_button = JButton("Load JSON File")
        load_file_button.setActionCommand("load")
        load_file_button.addActionListener(
            SettingsAction(self, load_file_button, None))
        save_file_button = JButton("Save JSON File")
        save_file_button.setActionCommand("save")
        save_file_button.addActionListener(
            SettingsAction(None, save_file_button, self.tabbed_panes))

        horizontal_group1 = layout.createParallelGroup(
            GroupLayout.Alignment.LEADING)
        horizontal_group1.addComponent(load_file_button)
        horizontal_group1.addComponent(save_file_button)

        horizontal_group = layout.createSequentialGroup()
        horizontal_group.addGroup(horizontal_group1)

        layout.setHorizontalGroup(horizontal_group)

        vertical_group1 = layout.createParallelGroup(
            GroupLayout.Alignment.BASELINE)
        vertical_group1.addComponent(load_file_button)
        vertical_group2 = layout.createParallelGroup(
            GroupLayout.Alignment.BASELINE)
        vertical_group2.addComponent(save_file_button)

        vertical_group = layout.createSequentialGroup()
        vertical_group.addGroup(vertical_group1)
        vertical_group.addGroup(vertical_group2)

        layout.setVerticalGroup(vertical_group)

    def get_settings(self):
        return self.settings

    def set_request_tab_pane(self, request_response):
        raw_request = request_response.getRequest()
        request_body = StringUtil.fromBytes(raw_request)
        request_body = request_body.encode("utf-8")

        request_tab_textarea = JTextArea(request_body)
        request_tab_textarea.setLineWrap(True)

        return JScrollPane(request_tab_textarea)

    def set_response_tab_pane(self, request_response):
        raw_response = request_response.getResponse()
        response_body = StringUtil.fromBytes(raw_response)
        response_body = response_body.encode("utf-8")

        response_tab_textarea = JTextArea(response_body)
        response_tab_textarea.setLineWrap(True)

        return JScrollPane(response_tab_textarea)

    def set_bugs_tabbed_pane(self, request_tab, response_tab):
        bugs_tabbed_pane = JTabbedPane()

        bugs_tabbed_pane.add("Request", request_tab)
        bugs_tabbed_pane.add("Response", response_tab)

        return bugs_tabbed_pane
Example #7
0
class ModelView(JFrame):
    
    def __init__(self, controller):
        '''
        Creates a new window displaying a schematic view of an ATF file, 
        following the guidelines and mockup agreed with project owners.
        '''
        
        #Give reference to controller to delegate action response
        self.controller = controller
        
        #Make text area occupy all available space and resize with parent window
        self.setLayout(BorderLayout())
        
        self.mainPanel = JTabbedPane()
        self.mainPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        self.add(self.mainPanel, BorderLayout.CENTER)
        
        #Set empty dictionary of tab panels
        self.objectTabs = {}

        #Will need scrolling controls
        scrollingArea = JScrollPane(self.mainPanel)
        
        #Add to parent panel
        self.add(scrollingArea, BorderLayout.CENTER)
        
        #TODO: Where to get/store this information?
        self.languages = { "akk-x-stdbab": "Akkadian Standard Babylonian", \
                          "akk": "Akkadian", "sux": "", "a":"", \
                          "akk-x-oldbab":"Akkadian Old Babylonian", "qpc": "", \
                          "na": "", "nb": "", "x/n": "", \
                          "akk-x-neoass": "Akkadian Neo Assyrian"}
        
        
    def addObject(self, objectID):
        """
        Creates new empty JPanel that'll contain the model for one object in 
        the ATF file.
        """
        objectPanel = JPanel()
        objectPanel.setLayout(BoxLayout(objectPanel, BoxLayout.PAGE_AXIS))
        
        self.objectTabs[objectID] = objectPanel
  
        
    def display(self): 
        """
        Put together all elements in main panel and display.
        """
        #Add all object tabs to window
        for objectID, tabPanel in self.objectTabs.iteritems():
            self.mainPanel.add(objectID, tabPanel)
        
        #Set up main model window
        self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
        self.setTitle("ATF Model View")
        self.pack()
        self.setLocationRelativeTo(None)

        #Display model window
        self.visible = 1
        
    def addLine(self, objectID, category, text):
        """
        Add a new panel containing the text corresponding to one line in the 
        ATF file. 
        This panel will show the line type (ruling, comment, text, 
        translation...), followed by the line content and a group of icons to 
        add, edit or remove the line.
        """
        linePanel = JPanel()
        linePanel.setLayout(BorderLayout())
        
        label = JLabel(category)
        
        combo = JComboBox(text)
        
        buttonsPanel = JPanel()
        addButton = JButton("Add")
        editButton = JButton("Edit")
        deleteButton = JButton("Delete")
        buttonsPanel.add(addButton)
        buttonsPanel.add(editButton)
        buttonsPanel.add(deleteButton)
        
        linePanel.add(label, BorderLayout.WEST)
        linePanel.add(combo, BorderLayout.CENTER)
        linePanel.add(buttonsPanel, BorderLayout.EAST)
        
        #Add metadataPanel to object tab in main panel
        self.objectTabs[objectID].add(linePanel)
    
    #Protocols not yet in model parsed object
    #def addMetadata(self, project, language, protocols):
    def addMetadata(self, objectID, project, language):
        """
        Add a JTable at the top of the object tab containing the metadata of
        the object presented in that tab.
        """
        metadataPanel = JPanel()
        #TODO: Need to count protocols to set up Grid dimension
        metadataPanel.setLayout(GridLayout(3,2))
        
        projectLabel = JLabel("Project: ")
        projectValue = JLabel(project)
        
        #TODO Check language not found
        languageLabel = JLabel("Language: ")
        languageValue = JLabel(self.languages[language])
        
        #TODO Protocols not yet in parsed object
        protocolsLabel = JLabel("ATF Protocols: ")
        protocolsBox = JComboBox()
        #for protocol in protocols:
        #    protocolBox.add(protocol)
        
        metadataPanel.add(projectLabel)
        metadataPanel.add(projectValue)
        metadataPanel.add(languageLabel)
        metadataPanel.add(languageValue)
        metadataPanel.add(protocolsLabel)
        metadataPanel.add(protocolsBox)
        
        #Add metadataPanel to object tab in main panel
        self.objectTabs[objectID].add(metadataPanel)
        
        

    
    #def addSide(self, sideType, content):
        
        
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.")
Example #9
0
class ModelView(JFrame):
    '''
    Initializes the ATF model view and sets its layout.
    '''
    def __init__(self, controller):
        '''
        Creates a new window displaying a schematic view of an ATF file,
        following the guidelines and mockup agreed with project owners.
        '''

        # Give reference to controller to delegate action response
        self.controller = controller

        # Get list of projects, languages and protocols from config settings
        self.languages = self.controller.config['languages']
        self.protocols = self.controller.config['protocols']
        self.projects = self.controller.config['projects']

        # Make text area occupy all available space and resize with parent
        # window
        self.setLayout(BorderLayout())

        self.mainPanel = JTabbedPane()
        self.mainPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT)
        self.add(self.mainPanel, BorderLayout.CENTER)

        # Set empty dictionary of tab panels
        self.objectTabs = {}

        # Will need scrolling controls
        scrollingArea = JScrollPane(self.mainPanel)

        # Add notice panel
        self.add(self.addNotice(), BorderLayout.NORTH)

        # Add to parent panel
        self.add(scrollingArea, BorderLayout.CENTER)

    def addObject(self, objectID):
        """
        Creates new empty JPanel that'll contain the model for one object in
        the ATF file.
        """
        objectPanel = JPanel()
        objectPanel.setLayout(BoxLayout(objectPanel, BoxLayout.PAGE_AXIS))

        self.objectTabs[objectID] = objectPanel

    def display(self):
        """
        Put together all elements in main panel and display.
        """
        # Add all object tabs to window
        for objectID, tabPanel in self.objectTabs.iteritems():
            self.mainPanel.add(objectID, tabPanel)

        # Set up main model window
        self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
        self.setTitle("ATF Model View")
        self.pack()
        self.setLocationRelativeTo(None)

        # Display model window
        self.visible = 1

    def addLine(self, objectID, category, text):
        """
        Add a new panel containing the text corresponding to one line in the
        ATF file.
        This panel will show the line type (ruling, comment, text,
        translation...), followed by the line content and a group of icons to
        add, edit or remove the line.
        """
        linePanel = JPanel()
        linePanel.setLayout(BorderLayout())

        label = JLabel(category)

        combo = JComboBox(text)
        combo.setEditable(True)
        combo.setPreferredSize(Dimension(500, 20))
        combo.setSize(combo.getPreferredSize())
        combo.setMinimumSize(combo.getPreferredSize())
        combo.setMaximumSize(combo.getPreferredSize())

        buttonsPanel = JPanel()
        addButton = JButton("Add")
        editButton = JButton("Edit")
        deleteButton = JButton("Delete")
        buttonsPanel.add(addButton)
        buttonsPanel.add(editButton)
        buttonsPanel.add(deleteButton)

        linePanel.add(label, BorderLayout.WEST)
        linePanel.add(combo, BorderLayout.CENTER)
        linePanel.add(buttonsPanel, BorderLayout.EAST)

        # Add metadataPanel to object tab in main panel
        self.objectTabs[objectID].add(linePanel)

    # Protocols not yet in model parsed object
    # def addMetadata(self, project, language, protocols):
    def addMetadata(self, objectID, project, language):
        """
        Add a JTable at the top of the object tab containing the metadata of
        the object presented in that tab.
        """
        metadataPanel = JPanel()
        # TODO: Need to count protocols to set up Grid dimension
        metadataPanel.setLayout(GridLayout(3, 2))

        projectLabel = JLabel("Project: ")
        projectValue = JLabel(project)

        languageLabel = JLabel("Language: ")
        languageValue = JLabel(language)
        # If language code is in the settings, then display name instead
        # of code
        for lang, code in self.languages.iteritems():
            if code == language:
                languageValue.setText(lang)

        # TODO Protocols not yet in parsed object
        protocolsLabel = JLabel("ATF Protocols: ")
        protocolsBox = JComboBox(self.protocols)

        metadataPanel.add(projectLabel)
        metadataPanel.add(projectValue)
        metadataPanel.add(languageLabel)
        metadataPanel.add(languageValue)
        metadataPanel.add(protocolsLabel)
        metadataPanel.add(protocolsBox)

        # Add metadataPanel to object tab in main panel
        self.objectTabs[objectID].add(metadataPanel)

    def addNotice(self):
        """
        Add a panel that notifies the user about the model view not being
        ready yet.
        """
        panel = JPanel()
        panel.setBackground(Color.yellow)
        label = JLabel("Please note Nammu's model view is under "
                       "construction.")
        panel.add(label)
        return panel
Example #10
0
class ModelView(JFrame):
    '''
    Initializes the ATF model view and sets its layout.
    '''
    def __init__(self, controller):
        '''
        Creates a new window displaying a schematic view of an ATF file,
        following the guidelines and mockup agreed with project owners.
        '''

        # Give reference to controller to delegate action response
        self.controller = controller

        # Get list of projects, languages and protocols from config settings
        self.languages = self.controller.config['languages']
        self.protocols = self.controller.config['protocols']
        self.projects = self.controller.config['projects']

        # Make text area occupy all available space and resize with parent
        # window
        self.setLayout(BorderLayout())

        self.mainPanel = JTabbedPane()
        self.mainPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT)
        self.add(self.mainPanel, BorderLayout.CENTER)

        # Set empty dictionary of tab panels
        self.objectTabs = {}

        # Will need scrolling controls
        scrollingArea = JScrollPane(self.mainPanel)

        # Add notice panel
        self.add(self.addNotice(), BorderLayout.NORTH)

        # Add to parent panel
        self.add(scrollingArea, BorderLayout.CENTER)

    def addObject(self, objectID):
        """
        Creates new empty JPanel that'll contain the model for one object in
        the ATF file.
        """
        objectPanel = JPanel()
        objectPanel.setLayout(BoxLayout(objectPanel, BoxLayout.PAGE_AXIS))

        self.objectTabs[objectID] = objectPanel

    def display(self):
        """
        Put together all elements in main panel and display.
        """
        # Add all object tabs to window
        for objectID, tabPanel in self.objectTabs.iteritems():
            self.mainPanel.add(objectID, tabPanel)

        # Set up main model window
        self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
        self.setTitle("ATF Model View")
        self.pack()
        self.setLocationRelativeTo(None)

        # Display model window
        self.visible = 1

    def addLine(self, objectID, category, text):
        """
        Add a new panel containing the text corresponding to one line in the
        ATF file.
        This panel will show the line type (ruling, comment, text,
        translation...), followed by the line content and a group of icons to
        add, edit or remove the line.
        """
        linePanel = JPanel()
        linePanel.setLayout(BorderLayout())

        label = JLabel(category)

        combo = JComboBox(text)
        combo.setEditable(True)
        combo.setPreferredSize(Dimension(500, 20))
        combo.setSize(combo.getPreferredSize())
        combo.setMinimumSize(combo.getPreferredSize())
        combo.setMaximumSize(combo.getPreferredSize())

        buttonsPanel = JPanel()
        addButton = JButton("Add")
        editButton = JButton("Edit")
        deleteButton = JButton("Delete")
        buttonsPanel.add(addButton)
        buttonsPanel.add(editButton)
        buttonsPanel.add(deleteButton)

        linePanel.add(label, BorderLayout.WEST)
        linePanel.add(combo, BorderLayout.CENTER)
        linePanel.add(buttonsPanel, BorderLayout.EAST)

        # Add metadataPanel to object tab in main panel
        self.objectTabs[objectID].add(linePanel)

    # Protocols not yet in model parsed object
    # def addMetadata(self, project, language, protocols):
    def addMetadata(self, objectID, project, language):
        """
        Add a JTable at the top of the object tab containing the metadata of
        the object presented in that tab.
        """
        metadataPanel = JPanel()
        # TODO: Need to count protocols to set up Grid dimension
        metadataPanel.setLayout(GridLayout(3, 2))

        projectLabel = JLabel("Project: ")
        projectValue = JLabel(project)

        languageLabel = JLabel("Language: ")
        languageValue = JLabel(language)
        # If language code is in the settings, then display name instead
        # of code
        for lang, code in self.languages.iteritems():
            if code == language:
                languageValue.setText(lang)

        # TODO Protocols not yet in parsed object
        protocolsLabel = JLabel("ATF Protocols: ")
        protocolsBox = JComboBox(self.protocols)

        metadataPanel.add(projectLabel)
        metadataPanel.add(projectValue)
        metadataPanel.add(languageLabel)
        metadataPanel.add(languageValue)
        metadataPanel.add(protocolsLabel)
        metadataPanel.add(protocolsBox)

        # Add metadataPanel to object tab in main panel
        self.objectTabs[objectID].add(metadataPanel)

    def addNotice(self):
        """
        Add a panel that notifies the user about the model view not being
        ready yet.
        """
        panel = JPanel()
        panel.setBackground(Color.yellow)
        label = JLabel("Please note Nammu's model view is under "
                       "construction.")
        panel.add(label)
        return panel