(SystemInfo si)
| 80 | } |
| 81 | |
| 82 | private void init(SystemInfo si) { |
| 83 | OperatingSystem os = si.getOperatingSystem(); |
| 84 | JLabel procLabel = new JLabel(PROCESSES); |
| 85 | add(procLabel, BorderLayout.NORTH); |
| 86 | |
| 87 | JPanel settings = new JPanel(); |
| 88 | |
| 89 | JLabel cpuChoice = new JLabel(" CPU %:"); |
| 90 | settings.add(cpuChoice); |
| 91 | cpuOption.add(perProc); |
| 92 | settings.add(perProc); |
| 93 | cpuOption.add(perSystem); |
| 94 | settings.add(perSystem); |
| 95 | if (SystemInfo.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) { |
| 96 | perSystem.setSelected(true); |
| 97 | } else { |
| 98 | perProc.setSelected(true); |
| 99 | } |
| 100 | |
| 101 | JLabel sortChoice = new JLabel(" Sort by:"); |
| 102 | settings.add(sortChoice); |
| 103 | sortOption.add(cpuButton); |
| 104 | settings.add(cpuButton); |
| 105 | sortOption.add(cumulativeCpuButton); |
| 106 | settings.add(cumulativeCpuButton); |
| 107 | sortOption.add(memButton); |
| 108 | settings.add(memButton); |
| 109 | cpuButton.setSelected(true); |
| 110 | |
| 111 | TableModel model = new DefaultTableModel(parseProcesses(os.getProcesses(null, null, 0), si), COLUMNS); |
| 112 | JTable procTable = new JTable(model); |
| 113 | JScrollPane scrollV = new JScrollPane(procTable); |
| 114 | scrollV.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); |
| 115 | resizeColumns(procTable.getColumnModel()); |
| 116 | |
| 117 | add(scrollV, BorderLayout.CENTER); |
| 118 | add(settings, BorderLayout.SOUTH); |
| 119 | |
| 120 | Timer timer = new Timer(Config.REFRESH_SLOW, e -> { |
| 121 | DefaultTableModel tableModel = (DefaultTableModel) procTable.getModel(); |
| 122 | Object[][] newData = parseProcesses(os.getProcesses(null, null, 0), si); |
| 123 | int rowCount = tableModel.getRowCount(); |
| 124 | for (int row = 0; row < newData.length; row++) { |
| 125 | if (row < rowCount) { |
| 126 | // Overwrite row |
| 127 | for (int col = 0; col < newData[row].length; col++) { |
| 128 | tableModel.setValueAt(newData[row][col], row, col); |
| 129 | } |
| 130 | } else { |
| 131 | // Add row |
| 132 | tableModel.addRow(newData[row]); |
| 133 | } |
| 134 | } |
| 135 | // Delete any extra rows |
| 136 | for (int row = rowCount - 1; row >= newData.length; row--) { |
| 137 | tableModel.removeRow(row); |
| 138 | } |
| 139 | }); |
no test coverage detected