MCPcopy Index your code
hub / github.com/10cks/fofaEX / loadFileIntoTable

Method loadFileIntoTable

src/main/java/plugins/CommonExecute.java:95–166  ·  view source on GitHub ↗
(File file)

Source from the content-addressed store, hash-verified

93 }
94
95 public static void loadFileIntoTable(File file) {
96
97 // 重新设置表格头,以便新的渲染器生效
98 JTableHeader header = getjTableHeader(table);
99 table.setTableHeader(header);
100
101 adjustColumnWidths(table); // 自动调整列宽
102 JScrollPane scrollPane = new JScrollPane(table);
103
104 table.setRowHeight(24); // 设置表格的行高
105 table.setFillsViewportHeight(true);
106
107 panel.removeAll();
108 panel.add(scrollPane, BorderLayout.CENTER);
109
110 // 设置表格的默认渲染器
111 table.setDefaultRenderer(Object.class, new SelectedCellBorderHighlighter());
112
113 try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
114 String line;
115 List<Map<String, Object>> data = new ArrayList<>();
116 Vector<String> columnNames = new Vector<>();
117 boolean columnsDefined = false;
118
119 while ((line = reader.readLine()) != null) {
120 line = line.trim();
121 if (!line.isEmpty()) {
122 try {
123 JsonObject jsonObject = JsonParser.parseString(line).getAsJsonObject();
124 Map<String, Object> map = new LinkedHashMap<>();
125
126 for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
127 String key = entry.getKey();
128 Object value = entry.getValue().getAsString();
129 map.put(key, value);
130
131 if (!columnsDefined) {
132 columnNames.add(key);
133 }
134 }
135 data.add(map);
136 columnsDefined = true;
137 }catch (JsonSyntaxException ex) {
138 ex.printStackTrace();
139 JOptionPane.showMessageDialog(null, "Execute Failed!", "JSON Error", JOptionPane.ERROR_MESSAGE);
140 return;
141 }
142 }
143 }
144
145 Vector<Vector<Object>> dataVector = new Vector<>();
146 for (Map<String, Object> datum : data) {
147 Vector<Object> row = new Vector<>();
148 for (String columnName : columnNames) {
149 row.add(datum.get(columnName));
150 }
151 dataVector.add(row);
152 }

Callers 1

checkMakeFileMethod · 0.95

Calls 2

getjTableHeaderMethod · 0.80
adjustColumnWidthsMethod · 0.80

Tested by

no test coverage detected