MCPcopy Create free account
hub / github.com/10cks/fofaEX / createTableFromJson

Method createTableFromJson

src/main/java/plugins/CommonTemplate.java:289–338  ·  view source on GitHub ↗
(String configFilePath)

Source from the content-addressed store, hash-verified

287 tabbedPane.addTab(pluginName, mainPanel);
288 }
289 public static JTable createTableFromJson(String configFilePath) {
290 // 创建Gson实例
291 Gson gson = new Gson();
292 String outputFilePath;
293 String[] columnNames;
294
295 // 读取并解析配置文件
296 try {
297 JsonReader configReader = new JsonReader(new FileReader(configFilePath));
298 JsonObject configObject = gson.fromJson(configReader, JsonObject.class);
299 JsonObject runObject = configObject.getAsJsonObject("Run");
300
301 // 解析OutputFile路径以及OutputTarget列名称
302 outputFilePath = runObject.get("OutputFile").getAsString();
303 JsonArray outputTarget = runObject.getAsJsonArray("OutputTarget");
304 columnNames = new String[outputTarget.size()];
305 for (int i = 0; i < outputTarget.size(); i++) {
306 columnNames[i] = outputTarget.get(i).getAsString();
307 }
308 } catch (FileNotFoundException e) {
309 e.printStackTrace();
310 return null;
311 }
312
313 // 从OutputFile文件路径读取内容,并创建表格模型
314 DefaultTableModel model = new DefaultTableModel(columnNames, 0);
315 try {
316 Reader outputReader = new FileReader(outputFilePath);
317 JsonStreamParser parser = new JsonStreamParser(outputReader);
318
319 while (parser.hasNext()) {
320 JsonObject object = parser.next().getAsJsonObject();
321 Vector<String> row = new Vector<String>();
322 for (int i = 0; i < columnNames.length; i++) {
323 if (object.has(columnNames[i])) {
324 JsonElement element = object.get(columnNames[i]);
325 row.add(element.isJsonNull() ? "" : element.getAsString());
326 } else {
327 row.add(""); // 对应的列值为空
328 }
329 }
330 model.addRow(row);
331 }
332 } catch (IOException e) {
333 e.printStackTrace();
334 }
335 // 使用模型创建表格
336 JTable table = new JTable(model);
337 return table;
338 }
339
340 // 新增插件“运行”功能面板
341 public static void addPluginFrame(String pluginJsonPath, String frameName, JTabbedPane tabbedPane) {

Callers 1

addPluginTabMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected