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

Method addPluginFrame

src/main/java/plugins/CommonTemplate.java:341–412  ·  view source on GitHub ↗
(String pluginJsonPath, String frameName, JTabbedPane tabbedPane)

Source from the content-addressed store, hash-verified

339
340 // 新增插件“运行”功能面板
341 public static void addPluginFrame(String pluginJsonPath, String frameName, JTabbedPane tabbedPane) {
342 // 建立新的窗口Frame
343 JFrame newFrame = new JFrame(frameName);
344 newFrame.setSize(800, 600); // 改变窗口大小,使其能容纳更多文本
345 newFrame.setLocationRelativeTo(null); // 窗口位置居中
346 newFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 关闭窗口时只关闭当前窗口,不影响其他窗口
347
348 // 创建使用BorderLayout的面板
349 JPanel panel = new JPanel(new BorderLayout());
350
351 // 创建结果显示区域,并添加到面板的Center区域
352 JTextArea resultArea = new JTextArea();
353 resultArea.setLineWrap(true); // 设置行包装
354 resultArea.setWrapStyleWord(true); // 设置单词包装
355 panel.add(new JScrollPane(resultArea), BorderLayout.CENTER);
356
357 // 创建新的面板用于放置按钮
358 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 使用FlowLayout并且指定按钮靠左对齐
359 buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // 设置边距为10px
360 // 创建执行按钮,并添加到新面板
361 JButton execButton = new JButton("执行");
362 execButton.setFocusPainted(false); // 取消焦点边框的绘制
363 execButton.setFocusable(false);
364 buttonPanel.add(execButton);
365
366 // 创建“停止”按钮
367 JButton stopButton = new JButton("停止");
368 stopButton.setFocusPainted(false);
369 stopButton.setFocusable(false);
370 buttonPanel.add(stopButton);
371
372 // 把新面板添加到BorderLayout的North区域
373 panel.add(buttonPanel, BorderLayout.NORTH);
374
375 // 把面板添加到窗口中
376 newFrame.add(panel);
377 // 显示窗口
378 newFrame.setVisible(true);
379
380 // 运行按钮添加事件
381 execButton.addActionListener(e -> {
382 // 这里添加按钮动作,实际操作需按需修改
383 String command = constructCommandFromJson(pluginJsonPath);
384 // 清屏
385 resultArea.setText("");
386 if (command != null) {
387 try {
388 // 解析设置文件,运行InputTarget部分
389 parseJsonAndWriteFile(pluginJsonPath);
390 } catch (IOException ex) {
391 throw new RuntimeException(ex);
392 }
393 executeCommand(command, resultArea, tabbedPane, frameName, pluginJsonPath); // 执行命令并显示结果
394
395 } else {
396 JOptionPane.showMessageDialog(null, "无法构造命令", "错误", JOptionPane.ERROR_MESSAGE);
397 }
398 });

Callers 1

addMenuItemsFromFileMethod · 0.95

Calls 3

parseJsonAndWriteFileMethod · 0.95
executeCommandMethod · 0.95

Tested by

no test coverage detected