Exemplo n.º 1
0
    def _constructResultsPanel(self, insets):
        resultsPanel = JPanel(GridBagLayout())

        self._progressBar = JProgressBar()
        self._progressBar.setStringPainted(True)
        self._progressBar.setMinimum(0)
        progressBarContraints = GridBagConstraints()
        progressBarContraints.gridx = 0
        progressBarContraints.gridy = 0
        progressBarContraints.fill = GridBagConstraints.HORIZONTAL

        resultsPanel.add(self._progressBar, progressBarContraints)

        self._resultsTableModel = ResultsTableModel(COLUMNS, 0)
        resultsTable = JTable(self._resultsTableModel)
        resultsTable.setAutoCreateRowSorter(True)
        cellRenderer = ColoredTableCellRenderer()
        for index in [5, 6, 7, 8, 9]:
            column = resultsTable.columnModel.getColumn(index)
            column.cellRenderer = cellRenderer
        resultsTable.getColumnModel().getColumn(0).setPreferredWidth(99999999)
        resultsTable.getColumnModel().getColumn(1).setMinWidth(160)
        resultsTable.getColumnModel().getColumn(2).setMinWidth(100)
        resultsTable.getColumnModel().getColumn(3).setMinWidth(80)
        resultsTable.getColumnModel().getColumn(4).setMinWidth(80)
        resultsTable.getColumnModel().getColumn(5).setMinWidth(110)
        resultsTable.getColumnModel().getColumn(6).setMinWidth(110)
        resultsTable.getColumnModel().getColumn(7).setMinWidth(90)
        resultsTable.getColumnModel().getColumn(8).setMinWidth(110)
        resultsTable.getColumnModel().getColumn(9).setMinWidth(110)
        resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)
        resultsScrollPane = JScrollPane(resultsTable)
        resultsScrollPaneConstraints = GridBagConstraints()
        resultsScrollPaneConstraints.gridx = 0
        resultsScrollPaneConstraints.gridy = 1
        resultsScrollPaneConstraints.weightx = 1
        resultsScrollPaneConstraints.weighty = 1
        resultsScrollPaneConstraints.fill = GridBagConstraints.BOTH
        resultsPanel.add(resultsScrollPane, resultsScrollPaneConstraints)

        return resultsPanel
      # ... and save the evaluation CSV file in a new thread
      # to avoid potentially slow operations in the event dispatch thread
      t = Thread(writeAccepted)
      t.setPriority(Thread.NORM_PRIORITY)
      t.start()


# Create the UI: a 3-column table and a text area next to it
# to show the Motivation column of any selected row:
all = JPanel()
gb = GridBagLayout()
all.setLayout(gb)
c = GridBagConstraints()
table = JTable(TableModel())
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
table.setAutoCreateRowSorter(True) # to sort the view only, not the data in the underlying TableModel
jsp = JScrollPane(table)
jsp.setPreferredSize(Dimension(200, 500))
c.anchor = GridBagConstraints.NORTHWEST
c.fill = GridBagConstraints.BOTH # resize with the frame
gb.setConstraints(jsp, c)
all.add(jsp)
c.gridx = 1
c.weightx = 1.0 # take any additionally available horizontal space
c.weighty = 1.0
textarea = JTextArea()
textarea.setLineWrap(True)
textarea.setWrapStyleWord(True) # wrap text by cutting at whitespace
textarea.setEditable(False) # avoid changing the text, as any changes wouldn't be persisted to disk
font = textarea.getFont().deriveFont(20.0)
textarea.setFont(font)
Exemplo n.º 3
0
class NBPanel():
    """Represents the converted frame from NetBeans."""

    # mostly converted generated code
    def __init__(self):
        self.jScrollPane1 = JScrollPane()
        self.jTable1 = JTable()
        self.jPanel1 = JPanel()
        self.labelName = JLabel()
        self.textName = JTextField()
        self.labelSeverity = JLabel()
        self.comboSeverity = None
        self.labelHost = JLabel()
        self.labelPath = JLabel()
        self.textHost = JTextField()
        self.textPath = JTextField()
        self.tabIssue = JTabbedPane()
        self.panelDescription = JPanel()
        self.panelRequest = JPanel()
        self.panelResponse = JPanel()
        self.panelRemediation = JPanel()

        # setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)

        # setting up the table
        # initial data in the table
        tableData = [[None, None, None, None, None],
                     [None, None, None, None, None],
                     [None, None, None, None, None]]
        tableColumns = ["#", "Issue Type/Name", "Severity", "Host", "Path"]
        # create the table model
        tableModel = table.DefaultTableModel(tableData, tableColumns)
        # model.types = array.array([java.lang.Integer.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class], java.lang.Class)
        # model.canEdit = array.array([False, False, False, False, False], java.lang.Boolean)
        # public Class getColumnClass(int columnIndex) {
        # return types [columnIndex]
        # }
        #
        # public boolean isCellEditable(int rowIndex, int columnIndex) {
        # return canEdit [columnIndex]
        # }

        # set the table model
        # if this fails, we have to use
        self.jTable1.setModel(tableModel)
        self.jTable1.setAutoCreateRowSorter(True)

        # wrap the table in a scrollpane
        self.jScrollPane1.setViewportView(self.jTable1)

        # top panel containing the table
        from java.awt import Color
        self.jPanel1.setBorder(BorderFactory.createLineBorder(Color(0, 0, 0)))

        # create the labels and textfields
        self.labelName.text = "Issue Type/Name"
        self.textName.text = "Issue Name/Type"
        self.labelSeverity.text = "Severity"
        # create and populate the combobox
        self.comboSeverity = JComboBox(
            ["Critical", "High", "Medium", "Low", "Info"])

        self.labelHost.text = "Host"
        self.labelPath.text = "Path"
        self.textHost.text = "Issue Host"
        self.textPath.text = "Issue Path"

        from java.lang import Short
        # description panel
        panelDescriptionLayout = GroupLayout(self.panelDescription)
        self.panelDescription.setLayout(panelDescriptionLayout)
        panelDescriptionLayout.setHorizontalGroup(
            panelDescriptionLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 948, Short.MAX_VALUE))
        panelDescriptionLayout.setVerticalGroup(
            panelDescriptionLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 287, Short.MAX_VALUE))
        self.tabIssue.addTab("Description", self.panelDescription)

        # request tab
        panelRequestLayout = GroupLayout(self.panelRequest)
        self.panelRequest.setLayout(panelRequestLayout)
        panelRequestLayout.setHorizontalGroup(
            panelRequestLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 948, Short.MAX_VALUE))
        panelRequestLayout.setVerticalGroup(
            panelRequestLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 287, Short.MAX_VALUE))
        self.tabIssue.addTab("Request", self.panelRequest)

        # response tab
        panelResponseLayout = GroupLayout(self.panelResponse)
        self.panelResponse.setLayout(panelResponseLayout)
        panelResponseLayout.setHorizontalGroup(
            panelResponseLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 948, Short.MAX_VALUE))
        panelResponseLayout.setVerticalGroup(
            panelResponseLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 287, Short.MAX_VALUE))
        self.tabIssue.addTab("Response", self.panelResponse)

        # remediation tab
        panelRemediationLayout = GroupLayout(self.panelRemediation)
        self.panelRemediation.setLayout(panelRemediationLayout)
        panelRemediationLayout.setHorizontalGroup(
            panelRemediationLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 948, Short.MAX_VALUE))
        panelRemediationLayout.setVerticalGroup(
            panelRemediationLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGap(0, 287, Short.MAX_VALUE))
        self.tabIssue.addTab("Remediation", self.panelRemediation)

        # jpanel1?
        jPanel1Layout = GroupLayout(self.jPanel1)
        self.jPanel1.setLayout(jPanel1Layout)
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).
            addGroup(jPanel1Layout.createSequentialGroup().addContainerGap(
            ).addGroup(
                jPanel1Layout.createParallelGroup(
                    GroupLayout.Alignment.LEADING).
                addGroup(jPanel1Layout.createSequentialGroup().addGroup(
                    jPanel1Layout.createParallelGroup(
                        GroupLayout.Alignment.TRAILING).addComponent(
                            self.labelHost).addComponent(
                                self.labelSeverity).addComponent(
                                    self.labelName)
                ).addPreferredGap(
                    LayoutStyle.ComponentPlacement.UNRELATED).addGroup(
                        jPanel1Layout.createParallelGroup(
                            GroupLayout.Alignment.LEADING).
                        addComponent(self.textName).addGroup(
                            jPanel1Layout.createSequentialGroup().addComponent(
                                self.comboSeverity, GroupLayout.PREFERRED_SIZE,
                                98, GroupLayout.PREFERRED_SIZE).addGap(
                                    0, 0, Short.MAX_VALUE)).
                        addGroup(
                            jPanel1Layout.createSequentialGroup().addComponent(
                                self.textHost, GroupLayout.PREFERRED_SIZE, 330,
                                GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).
                            addComponent(self.labelPath).addPreferredGap(
                                LayoutStyle.ComponentPlacement.RELATED
                            ).addComponent(self.textPath)))).addComponent(
                                self.tabIssue)).addContainerGap()))

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).
            addGroup(jPanel1Layout.createSequentialGroup().addContainerGap(
            ).addGroup(
                jPanel1Layout.createParallelGroup(
                    GroupLayout.Alignment.BASELINE).addComponent(
                        self.labelName).addComponent(
                            self.textName, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
            ).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(
                jPanel1Layout.createParallelGroup(
                    GroupLayout.Alignment.BASELINE).addComponent(
                        self.labelSeverity).addComponent(
                            self.comboSeverity, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
            ).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(
                jPanel1Layout.createParallelGroup(
                    GroupLayout.Alignment.BASELINE).addComponent(
                        self.labelHost).addComponent(
                            self.labelPath).addComponent(
                                self.textHost, GroupLayout.PREFERRED_SIZE,
                                GroupLayout.DEFAULT_SIZE,
                                GroupLayout.PREFERRED_SIZE).addComponent(
                                    self.textPath, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)).
                     addPreferredGap(
                         LayoutStyle.ComponentPlacement.RELATED).addComponent(
                             self.tabIssue).addContainerGap()))

        # create the main panel
        self.panel = JPanel()
        layout = GroupLayout(self.panel)
        self.panel.setLayout(layout)
        layout.setAutoCreateGaps(True)

        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addContainerGap().addGroup(
                    layout.createParallelGroup(
                        GroupLayout.Alignment.LEADING).addComponent(
                            self.jPanel1, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.DEFAULT_SIZE,
                            Short.MAX_VALUE).addComponent(
                                self.jScrollPane1)).addContainerGap()))
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addContainerGap().addComponent(
                    self.jScrollPane1, GroupLayout.PREFERRED_SIZE, 119,
                    GroupLayout.PREFERRED_SIZE).addGap(
                        18, 18,
                        18).addComponent(self.jPanel1,
                                         GroupLayout.DEFAULT_SIZE,
                                         GroupLayout.DEFAULT_SIZE,
                                         Short.MAX_VALUE).addContainerGap()))