summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-02-21 13:29:09 +0800
committerWe-unite <3205135446@qq.com>2025-02-21 13:29:09 +0800
commit82e3bb8888849e8a47acf5676f5baa63875550c6 (patch)
treebdc64c2b399fe9ba7c1601fc79230708d77a3a10
parent2c3ec51f24394f5f16edafd64998b504eab093f9 (diff)
downloadproject-82e3bb8888849e8a47acf5676f5baa63875550c6.tar.gz
project-82e3bb8888849e8a47acf5676f5baa63875550c6.zip
Clear code of clang-tidy, cppcheck
-rw-r--r--src/cppcheckplus/control/Main.java300
-rw-r--r--src/cppcheckplus/control/MyContorlUtil.java1076
-rw-r--r--src/cppcheckplus/control/settings.xml4
-rw-r--r--src/cppcheckplus/shortcut/MyTree.java6
-rw-r--r--src/cppcheckplus/tab/MyTabPanel1.java154
-rw-r--r--src/cppcheckplus/text/MyTextPanel1.java5
6 files changed, 762 insertions, 783 deletions
diff --git a/src/cppcheckplus/control/Main.java b/src/cppcheckplus/control/Main.java
index 2759e2f..19d33cc 100644
--- a/src/cppcheckplus/control/Main.java
+++ b/src/cppcheckplus/control/Main.java
@@ -65,7 +65,7 @@ public class Main extends JFrame {
65 private final JFileChooser jfc = new JFileChooser();// 文件选择器 65 private final JFileChooser jfc = new JFileChooser();// 文件选择器
66 private final JFileChooser jfsettings = new JFileChooser();// 配置设定 66 private final JFileChooser jfsettings = new JFileChooser();// 配置设定
67 private final String projectPath; 67 private final String projectPath;
68 public MyTabPanel tabPanel; 68 public MyTabPanel centerTabPanel;
69 // 编辑代码的面板 69 // 编辑代码的面板
70 public MyTextPanel testCode; 70 public MyTextPanel testCode;
71 public String src = ""; // 目标源文件或目录的路径 71 public String src = ""; // 目标源文件或目录的路径
@@ -73,9 +73,11 @@ public class Main extends JFrame {
73 public String flawfinderPath = null; 73 public String flawfinderPath = null;
74 public String paracppcheck = null; 74 public String paracppcheck = null;
75 public String paraflawfinder = null; 75 public String paraflawfinder = null;
76 public creatTable ct = new creatTable(); 76 public String clangtidyPath = null;
77 public String paraclangtidy = null;
78 public creatTable ct = new creatTable(); // 生成表格
77 private MyOutlookPanel outlookPanel; 79 private MyOutlookPanel outlookPanel;
78 private MyTabPanel1 tabPanel2; 80 private MyTabPanel1 footTabPanel;
79 private MyShortcutPanel shortcutPanel; 81 private MyShortcutPanel shortcutPanel;
80 private MyTree tree; 82 private MyTree tree;
81 // 标记是否修改了工具路径 83 // 标记是否修改了工具路径
@@ -136,9 +138,9 @@ public class Main extends JFrame {
136 // 读取文件内容并显示到代码区 138 // 读取文件内容并显示到代码区
137 textCode.setText(FileTools.readFile(result)); 139 textCode.setText(FileTools.readFile(result));
138 // 如果代码标签页不存在,则创建一个 140 // 如果代码标签页不存在,则创建一个
139 if (!tabPanel.isSelectTabComponents("代码")) { 141 if (!centerTabPanel.isSelectTabComponents("代码")) {
140 tabPanel.addTab("代码", testCode); 142 centerTabPanel.addTab("代码", testCode);
141 tabPanel.isSelectTabComponents("代码"); 143 centerTabPanel.isSelectTabComponents("代码");
142 } 144 }
143 break; 145 break;
144 case "onMenuLoad": 146 case "onMenuLoad":
@@ -243,10 +245,10 @@ public class Main extends JFrame {
243 // 按类型排序:生成表格并按类型排序 245 // 按类型排序:生成表格并按类型排序
244 ct.makeTable(); 246 ct.makeTable();
245 ct.ord(2); 247 ct.ord(2);
246 if (!tabPanel.isSelectTabComponents("结果")) { 248 if (!centerTabPanel.isSelectTabComponents("结果")) {
247 viewPanel = new ViewPanel(ct.results); 249 viewPanel = new ViewPanel(ct.results);
248 tabPanel.addTab("结果", createPage(viewPanel)); 250 centerTabPanel.addTab("结果", createPage(viewPanel));
249 tabPanel.isSelectTabComponents("结果"); 251 centerTabPanel.isSelectTabComponents("结果");
250 } else { 252 } else {
251 viewPanel.update(ct.results); 253 viewPanel.update(ct.results);
252 } 254 }
@@ -255,10 +257,10 @@ public class Main extends JFrame {
255 // 按级别排序 257 // 按级别排序
256 ct.makeTable(); 258 ct.makeTable();
257 ct.ord(3); 259 ct.ord(3);
258 if (!tabPanel.isSelectTabComponents("结果")) { 260 if (!centerTabPanel.isSelectTabComponents("结果")) {
259 viewPanel = new ViewPanel(ct.results); 261 viewPanel = new ViewPanel(ct.results);
260 tabPanel.addTab("结果", createPage(viewPanel)); 262 centerTabPanel.addTab("结果", createPage(viewPanel));
261 tabPanel.isSelectTabComponents("结果"); 263 centerTabPanel.isSelectTabComponents("结果");
262 } else { 264 } else {
263 viewPanel.update(ct.results); 265 viewPanel.update(ct.results);
264 } 266 }
@@ -267,20 +269,19 @@ public class Main extends JFrame {
267 // 按文件排序 269 // 按文件排序
268 ct.makeTable(); 270 ct.makeTable();
269 ct.ord(1); 271 ct.ord(1);
270 if (!tabPanel.isSelectTabComponents("结果")) { 272 if (!centerTabPanel.isSelectTabComponents("结果")) {
271 viewPanel = new ViewPanel(ct.results); 273 viewPanel = new ViewPanel(ct.results);
272 tabPanel.addTab("结果", createPage(viewPanel)); 274 centerTabPanel.addTab("结果", createPage(viewPanel));
273 tabPanel.isSelectTabComponents("结果"); 275 centerTabPanel.isSelectTabComponents("结果");
274 } else { 276 } else {
275 viewPanel.update(ct.results); 277 viewPanel.update(ct.results);
276 } 278 }
277 break; 279 break;
278 case "onSetCppcheckRoad": 280 case "onSetCppcheckRoad":
279 // cppcheck路径 281 // cppcheck路径
280 jfsettings.setFileSelectionMode(0);// 设定只能选择到文件 282 jfsettings.setFileSelectionMode(JFileChooser.FILES_ONLY);
281// int state = jfsettings.showOpenDialog(null); 283 if (jfsettings.showOpenDialog(null) == JFileChooser.CANCEL_OPTION) {
282 if (jfsettings.showOpenDialog(null) == 1) { 284 return;
283 return; // 撤销则返回
284 } else { 285 } else {
285 File cppcheckFile = jfsettings.getSelectedFile(); 286 File cppcheckFile = jfsettings.getSelectedFile();
286 String cppcheckPathTemp = 287 String cppcheckPathTemp =
@@ -293,8 +294,7 @@ public class Main extends JFrame {
293 case "onSetFlawfinderRoad": 294 case "onSetFlawfinderRoad":
294 // flawfinder路径 295 // flawfinder路径
295 jfsettings.setFileSelectionMode( 296 jfsettings.setFileSelectionMode(
296 JFileChooser.FILES_ONLY);// 设定只能选择到文件 297 JFileChooser.FILES_ONLY);
297// int state = jfsettings.showOpenDialog(null);
298 if (jfsettings.showOpenDialog(null) == 298 if (jfsettings.showOpenDialog(null) ==
299 JFileChooser.CANCEL_OPTION) { 299 JFileChooser.CANCEL_OPTION) {
300 return;// 撤销则返回 300 return;// 撤销则返回
@@ -320,7 +320,6 @@ public class Main extends JFrame {
320 } 320 }
321 321
322 public static void main(String[] args) throws ParserConfigurationException { 322 public static void main(String[] args) throws ParserConfigurationException {
323
324 SwingUtilities.invokeLater(new Runnable() { 323 SwingUtilities.invokeLater(new Runnable() {
325 public void run() { 324 public void run() {
326 MyContorlUtil.setupLookAndFeel(); 325 MyContorlUtil.setupLookAndFeel();
@@ -331,7 +330,7 @@ public class Main extends JFrame {
331 } 330 }
332 331
333 private void execute(String src, String para) { 332 private void execute(String src, String para) {
334 System.out.println("cppcheckPath:" + cppcheckPath); 333 // FIXME:这段代码原因不详,十分令人疑惑
335 if (changedpathcpp) { 334 if (changedpathcpp) {
336 MyContorlUtil.loadToolsRoad(settingsXML, this); 335 MyContorlUtil.loadToolsRoad(settingsXML, this);
337 changedpathcpp = false; 336 changedpathcpp = false;
@@ -342,49 +341,44 @@ public class Main extends JFrame {
342 return; 341 return;
343 } 342 }
344 343
345 Runtime runtime = Runtime.getRuntime(); 344 Runtime[] runtime = {Runtime.getRuntime(), Runtime.getRuntime()};
346 Process p = null; 345 Process[] p = new Process[2];
347 Runtime runtime1 = Runtime.getRuntime();
348 Process p1 = null;
349 try { 346 try {
350 // 指定模板执行cppcheck,格式化输出信息 347 System.out.printf(cppcheckPath + " %s %s%n", para, src);
351 p = runtime.exec(String.format(cppcheckPath + 348 // 指定模板执行cppcheck,用于生成“结果”表格
349 p[0] = runtime[0].exec(String.format(cppcheckPath +
352 " --template=\"cppcheck${file}${line}${severity}${id}${message}${cwe}\" %s %s", 350 " --template=\"cppcheck${file}${line}${severity}${id}${message}${cwe}\" %s %s",
353 para, src)); 351 para, src));
354 final InputStream is1 = p.getInputStream(); 352 // 不使用模板,在底部标签页显示纯文本结果
355 final InputStream is2 = p.getErrorStream(); 353 p[1] = runtime[1].exec(
354 String.format(cppcheckPath + " %s %s", para, src));
356 355
357 // 不使用模板,捕获错误信息 356 final InputStream[] stdout =
358 p1 = 357 {p[0].getInputStream(), p[1].getInputStream()};
359 runtime.exec(String.format(cppcheckPath + " %s %s", para, src)); 358 final InputStream[] stderr =
360 System.out.printf(cppcheckPath + " %s %s%n", para, src); 359 {p[0].getErrorStream(), p[1].getErrorStream()};
361 final InputStream is11 = p1.getInputStream();
362 final InputStream is21 = p1.getErrorStream();
363 360
364 // 处理标准输出 361 // 准输出
365 new Thread() { 362 new Thread() {
366 @SuppressWarnings("resource") 363 @SuppressWarnings("resource")
367 public void run() { 364 public void run() {
368
369 BufferedReader br1 = 365 BufferedReader br1 =
370 new BufferedReader(new InputStreamReader(is1)); 366 new BufferedReader(new InputStreamReader(stdout[0]));
371 //StringBuilder l1 = new StringBuilder(); 367 StringBuilder l1 = new StringBuilder();
372 try { 368 try {
373
374 String line1 = null; 369 String line1 = null;
375 int i = 0; 370 int i = 0;
376 textCheck.setText(""); 371 textCheck.setText("");
377 while ((line1 = br1.readLine()) != null) { 372 while ((line1 = br1.readLine()) != null) {
378 i++;
379 textCheck.append(i + " " + line1 + ENTERWindows); 373 textCheck.append(i + " " + line1 + ENTERWindows);
374 i++;
380 } 375 }
381 } catch (Exception e) { 376 } catch (Exception e) {
382 e.printStackTrace(); 377 e.printStackTrace();
383 System.out.println("inputError"); 378 System.out.println("inputError");
384 } finally { 379 } finally {
385 try { 380 try {
386 //textCheck.setText(new String(l1.toString().getBytes(), "utf-8")); 381 stdout[0].close();
387 is1.close();
388 } catch (IOException e) { 382 } catch (IOException e) {
389 e.printStackTrace(); 383 e.printStackTrace();
390 } 384 }
@@ -392,22 +386,28 @@ public class Main extends JFrame {
392 } 386 }
393 }.start(); 387 }.start();
394 388
395 // 处理错误流 389 // 模板错误流,用于生成结果表格
396 new Thread() { 390 new Thread() {
397 public void run() { 391 public void run() {
398 BufferedReader br2 = 392 BufferedReader br2 =
399 new BufferedReader(new InputStreamReader(is2)); 393 new BufferedReader(new InputStreamReader(stderr[0]));
400 StringBuilder l2 = new StringBuilder(); 394 StringBuilder l2 = new StringBuilder();
401 try { 395 try {
402 String line2 = null; 396 String line2 = null;
397 int i = 0;
403 while ((line2 = br2.readLine()) != null) { 398 while ((line2 = br2.readLine()) != null) {
404 ct.toRowsOfCppcheckResult(line2); 399 ct.toRowsOfCppcheckResult(line2);
400 l2.append(i + " " + line2 + ENTERWindows);
401 i++;
405 } 402 }
406 } catch (Exception e) { 403 } catch (Exception e) {
407 e.printStackTrace(); 404 e.printStackTrace();
408 } finally { 405 } finally {
409 try { 406 try {
410 is2.close(); 407 cppcheckResult.setText(
408 new String(l2.toString().getBytes(),
409 StandardCharsets.UTF_8));
410 stderr[0].close();
411 } catch (IOException e) { 411 } catch (IOException e) {
412 e.printStackTrace(); 412 e.printStackTrace();
413 } 413 }
@@ -415,11 +415,11 @@ public class Main extends JFrame {
415 } 415 }
416 }.start(); 416 }.start();
417 417
418 // 的错误流 418 // 的错误流,用于在底部标签页显示
419 new Thread() { 419 new Thread() {
420 public void run() { 420 public void run() {
421 BufferedReader br2 = 421 BufferedReader br2 =
422 new BufferedReader(new InputStreamReader(is21)); 422 new BufferedReader(new InputStreamReader(stderr[1]));
423 StringBuilder l2 = new StringBuilder(); 423 StringBuilder l2 = new StringBuilder();
424 cppcheckResult.setText(""); 424 cppcheckResult.setText("");
425 try { 425 try {
@@ -436,7 +436,7 @@ public class Main extends JFrame {
436 cppcheckResult.setText( 436 cppcheckResult.setText(
437 new String(l2.toString().getBytes(), 437 new String(l2.toString().getBytes(),
438 StandardCharsets.UTF_8)); 438 StandardCharsets.UTF_8));
439 is21.close(); 439 stderr[1].close();
440 } catch (IOException e) { 440 } catch (IOException e) {
441 e.printStackTrace(); 441 e.printStackTrace();
442 } 442 }
@@ -445,29 +445,29 @@ public class Main extends JFrame {
445 }.start(); 445 }.start();
446 446
447 // 等待两个进程结束 447 // 等待两个进程结束
448 int exitCode = p.waitFor(); 448 int exitCode = p[0].waitFor();
449 int exitCode1 = p1.waitFor(); 449 int exitCode1 = p[1].waitFor();
450 if (exitCode == SUCCESS) { 450 if (exitCode == SUCCESS) {
451 System.out.println(SUCCESS_MESSAGE); 451 System.out.println(SUCCESS_MESSAGE);
452
453 } else { 452 } else {
454 System.err.println(ERROR_MESSAGE + exitCode); 453 System.err.println(ERROR_MESSAGE + exitCode);
455 } 454 }
456 p.destroy(); 455 p[0].destroy();
457 p1.destroy(); 456 p[1].destroy();
458 } catch (Exception e) { 457 } catch (Exception e) {
459 try { 458 try {
460 // 出现异常则关闭相关流 459 // 出现异常则关闭相关流
461 p.getErrorStream().close(); 460 p[0].getErrorStream().close();
462 p.getInputStream().close(); 461 p[0].getInputStream().close();
463 p.getOutputStream().close(); 462 p[0].getOutputStream().close();
464 p1.getErrorStream().close(); 463 p[1].getErrorStream().close();
465 p1.getInputStream().close(); 464 p[1].getInputStream().close();
466 p1.getOutputStream().close(); 465 p[1].getOutputStream().close();
467 } catch (Exception ee) { 466 } catch (Exception ee) {
468 } 467 }
469 } 468 }
470 if (!tabPanel.isSelectTabComponents("结果")) { 469
470 if (!centerTabPanel.isSelectTabComponents("结果")) {
471 try { 471 try {
472 ct.makeTable(); 472 ct.makeTable();
473 viewPanel = new ViewPanel(ct.results); 473 viewPanel = new ViewPanel(ct.results);
@@ -475,8 +475,8 @@ public class Main extends JFrame {
475 e1.printStackTrace(); 475 e1.printStackTrace();
476 System.out.println("图表生成错误"); 476 System.out.println("图表生成错误");
477 } 477 }
478 tabPanel.addTab("结果", createPage(viewPanel)); 478 centerTabPanel.addTab("结果", createPage(viewPanel));
479 tabPanel.isSelectTabComponents("结果"); 479 centerTabPanel.isSelectTabComponents("结果");
480 } else { 480 } else {
481 try { 481 try {
482 ct.makeTable(); 482 ct.makeTable();
@@ -486,59 +486,65 @@ public class Main extends JFrame {
486 System.out.println("图表生成错误"); 486 System.out.println("图表生成错误");
487 } 487 }
488 } 488 }
489
490 // 底部标签页切换到cppcheck
491 if (!footTabPanel.isSelectTabComponents("cppcheck")) {
492 footTabPanel.selectTabByOId("cppcheck");
493 }
489 } 494 }
490 495
491 private void execute2(String src) { 496 private void execute2(String src) {
492 // clamh-tidy 检查 497 // clang-tidy 检查
493 Runtime runtime = Runtime.getRuntime(); 498 Runtime runtime = Runtime.getRuntime();
494 Process p = null; 499 Process p = null;
495 try { 500 try {
496 // 修改为执行 clang-tidy 501 // 修改为执行 clang-tidy
497 String path = "C:\\MinGW\\include"; // FIXME: 需要修改为自己的路径
498 Path srcPath = Paths.get(src); 502 Path srcPath = Paths.get(src);
499 String execable; 503 String execable;
504 // FIXME:
505 // 1.这里没能实现递归检查
506 // 2.如何指定特定的检查规则?
507 // 3.如何指定特定的头文件路径?
508 // 4.是否需要指定代码标准
500 if (Files.isDirectory(srcPath)) { 509 if (Files.isDirectory(srcPath)) {
501 // 是目录,则检查这个目录下所有cpp文件 510 // 是目录,则检查这个目录下所有cpp文件
502 execable = String.format( 511 execable = String.format(
503 "clang-tidy %s\\*.cpp --checks=* --header-filter=%s -- -std=c++17 -I %s", 512 "%s %s\\*.cpp --checks=* --header-filter=%s -- %s",
504 src, src, path); 513 clangtidyPath, src, src, paraclangtidy);
505 } else { 514 } else {
506 // 是文件,直接执行 515 // 是文件,直接执行
507 execable = String.format( 516 execable =
508 "clang-tidy %s --checks=* --header-filter=%s -- -std=c++17 -I %s", 517 String.format("%s %s --checks=* --header-filter=%s -- %s",
509 src, src, path); 518 clangtidyPath, src, src, paraclangtidy);
510 } 519 }
511 //String execable1 = String.format("clang-tidy %s --checks=* --header-filter=%s -- -std=c++17 -I %s", src, src, path);
512 //String execable2 = String.format("clang-tidy %s\\*.cpp --checks=* --header-filter=%s -- -std=c++17 -I %s", src,src, path);
513 //String execable = String.format("clang-tidy %s\\*.cpp --checks='*,misc-no-delete-this,-llvmlibc-restrict-system-libc-headers,-modernize-use-trailing-return-type' -- -std=c++17 -I %s", src, path); 520 //String execable = String.format("clang-tidy %s\\*.cpp --checks='*,misc-no-delete-this,-llvmlibc-restrict-system-libc-headers,-modernize-use-trailing-return-type' -- -std=c++17 -I %s", src, path);
514 System.out.println(execable); 521 System.out.println(execable);
515 522
516 // 执行 523 // 执行
517 p = runtime.exec(execable); // -- 表示之后是源文件 524 p = runtime.exec(execable);
518 final InputStream is1 = p.getInputStream(); // 标准输出流 525 final InputStream stdout = p.getInputStream();
519 final InputStream is2 = p.getErrorStream(); // clang-tidy 的错误流 526 final InputStream stderr = p.getErrorStream();
527
528 clangResult.setText("");
520 529
521 // 处理标准输出 530 // 处理标准输出
522 new Thread() { 531 new Thread() {
523 public void run() { 532 public void run() {
524 BufferedReader br1 = 533 BufferedReader br1 =
525 new BufferedReader(new InputStreamReader(is1)); 534 new BufferedReader(new InputStreamReader(stdout));
526 StringBuilder l1 = new StringBuilder(); 535 StringBuilder l1 = new StringBuilder();
527 try { 536 try {
528 String line1 = null; 537 String line1 = null;
529 while ((line1 = br1.readLine()) != null) { 538 while ((line1 = br1.readLine()) != null) {
530 // 只处理包含源文件路径的行 539 l1.append(line1 + ENTERWindows);
531 if (line1.contains(src)) { 540 ct.toRowsOfClang(line1);
532 l1.append(line1).append(ENTERWindows);
533 // 如果有需要,可以将标准输出进行处理
534 ct.toRowsOfClang(line1);
535 }
536 } 541 }
537 } catch (Exception e) { 542 } catch (Exception e) {
538 e.printStackTrace(); 543 e.printStackTrace();
539 } finally { 544 } finally {
540 try { 545 try {
541 is1.close(); 546 clangResult.append(l1.toString());
547 stdout.close();
542 } catch (IOException e) { 548 } catch (IOException e) {
543 e.printStackTrace(); 549 e.printStackTrace();
544 } 550 }
@@ -546,46 +552,40 @@ public class Main extends JFrame {
546 } 552 }
547 }.start(); 553 }.start();
548 554
549 // FIXME: 这一部分是否必要? 555 new Thread() {
550 //new Thread() { 556 public void run() {
551 // 557 BufferedReader br2 =
552 // 558 new BufferedReader(new InputStreamReader(stderr));
553 // public void run() { 559 StringBuilder l2 = new StringBuilder();
554 // BufferedReader br2 = new BufferedReader(new InputStreamReader(is2)); 560 try {
555 // StringBuilder l2 = new StringBuilder(); 561 String line2 = null;
556 // try { 562 int i = 0;
557 // String line2 = null; 563 l2.append(ENTERWindows + ENTERWindows);
558 // int i = 0; 564 while ((line2 = br2.readLine()) != null) {
559 // clangResult.setText(""); 565 l2.append(line2 + ENTERWindows);
560 // while ((line2 = br2.readLine()) != null) { 566 ct.toRowsOfClang(line2);
561 // l2.append(i + " " + line2 + ENTERWindows); 567 i++;
562 // ct.toRowsOfClang(line2); // 可能需要根据 clang-tidy 的输出格式进行调整 568 }
563 // i++; 569 } catch (Exception e) {
564 // } 570 e.printStackTrace();
565 // } catch (Exception e) { 571 System.out.println("inputError");
566 // e.printStackTrace(); 572 } finally {
567 // System.out.println("inputError"); 573 try {
568 // } finally { 574 clangResult.append(l2.toString());
569 // try { 575 stderr.close();
570 // clangResult.setText(l2.substring(0, l2.length())); 576 } catch (IOException e) {
571 // is2.close(); 577 e.printStackTrace();
572 // } catch (IOException e) { 578 }
573 // e.printStackTrace(); 579 }
574 // } 580 }
575 // } 581 }.start();
576 // }
577 //}.start();
578 582
579 int exitCode = p.waitFor(); 583 int exitCode = p.waitFor();
580 if (exitCode == SUCCESS) { 584 if (exitCode == SUCCESS) {
581 System.out.println(SUCCESS_MESSAGE); 585 System.out.println(SUCCESS_MESSAGE);
582
583 } else { 586 } else {
584 System.err.println(ERROR_MESSAGE + exitCode); 587 System.err.println(ERROR_MESSAGE + exitCode);
585 } 588 }
586
587 // 为什么需要关闭两次?
588 p.destroy();
589 p.destroy(); 589 p.destroy();
590 } catch (Exception e) { 590 } catch (Exception e) {
591 try { 591 try {
@@ -597,7 +597,7 @@ public class Main extends JFrame {
597 } 597 }
598 598
599 // 更新或者创建结果标签页,显示结果 599 // 更新或者创建结果标签页,显示结果
600 if (!tabPanel.isSelectTabComponents("结果")) { 600 if (!centerTabPanel.isSelectTabComponents("结果")) {
601 try { 601 try {
602 ct.makeTable(); 602 ct.makeTable();
603 viewPanel = new ViewPanel(ct.results); 603 viewPanel = new ViewPanel(ct.results);
@@ -605,8 +605,8 @@ public class Main extends JFrame {
605 e1.printStackTrace(); 605 e1.printStackTrace();
606 System.out.println("图表生成错误"); 606 System.out.println("图表生成错误");
607 } 607 }
608 tabPanel.addTab("结果", createPage(viewPanel)); 608 centerTabPanel.addTab("结果", createPage(viewPanel));
609 tabPanel.isSelectTabComponents("结果"); 609 centerTabPanel.isSelectTabComponents("结果");
610 } else { 610 } else {
611 try { 611 try {
612 ct.makeTable(); 612 ct.makeTable();
@@ -616,10 +616,13 @@ public class Main extends JFrame {
616 System.out.println("图表生成错误"); 616 System.out.println("图表生成错误");
617 } 617 }
618 } 618 }
619
620 if (!footTabPanel.isSelectTabComponents("Clang")) {
621 footTabPanel.selectTabByOId("Clang");
622 }
619 } 623 }
620 624
621 private void execute3(String src, String para, String tmpFileName) { 625 private void execute3(String src, String para, String tmpFileName) {
622 System.out.println("flawfinderPath:" + flawfinderPath);
623 // flawfinder 626 // flawfinder
624 if (changedpathflaw) { 627 if (changedpathflaw) {
625 MyContorlUtil.loadToolsRoad(settingsXML, this); 628 MyContorlUtil.loadToolsRoad(settingsXML, this);
@@ -716,7 +719,7 @@ public class Main extends JFrame {
716 } catch (Exception ee) { 719 } catch (Exception ee) {
717 } 720 }
718 } 721 }
719 if (!tabPanel.isSelectTabComponents("结果")) { 722 if (!centerTabPanel.isSelectTabComponents("结果")) {
720 try { 723 try {
721 ct.makeTable(); 724 ct.makeTable();
722 viewPanel = new ViewPanel(ct.results); 725 viewPanel = new ViewPanel(ct.results);
@@ -724,8 +727,8 @@ public class Main extends JFrame {
724 e1.printStackTrace(); 727 e1.printStackTrace();
725 System.out.println("图表生成错误"); 728 System.out.println("图表生成错误");
726 } 729 }
727 tabPanel.addTab("结果", createPage(viewPanel)); 730 centerTabPanel.addTab("结果", createPage(viewPanel));
728 tabPanel.isSelectTabComponents("结果"); 731 centerTabPanel.isSelectTabComponents("结果");
729 } else { 732 } else {
730 try { 733 try {
731 ct.makeTable(); 734 ct.makeTable();
@@ -736,6 +739,9 @@ public class Main extends JFrame {
736 } 739 }
737 } 740 }
738 741
742 if (!footTabPanel.isSelectTabComponents("flawfinder")) {
743 footTabPanel.selectTabByOId("flawfinder");
744 }
739 } 745 }
740 746
741 private void initSwing() throws UnsupportedEncodingException { 747 private void initSwing() throws UnsupportedEncodingException {
@@ -774,11 +780,11 @@ public class Main extends JFrame {
774 780
775 // 面板加入布局 781 // 面板加入布局
776 centerPane.add(outlookPanel, "West"); 782 centerPane.add(outlookPanel, "West");
777 centerPane.add(tabPanel, "Center"); 783 centerPane.add(centerTabPanel, "Center");
778 centerPane.add(shortcutPanel, "East"); 784 centerPane.add(shortcutPanel, "East");
779 785
780 // 底部添加第二个标签页面板,用于显示检查结果 786 // 底部添加第二个标签页面板,用于显示检查结果
781 contentPanel.add(tabPanel2, BorderLayout.SOUTH); 787 contentPanel.add(footTabPanel, BorderLayout.SOUTH);
782 } 788 }
783 789
784 private void initTree() { 790 private void initTree() {
@@ -806,7 +812,7 @@ public class Main extends JFrame {
806 String command = item.getActionCommand(); 812 String command = item.getActionCommand();
807 if (command.equals("Chart2")) { 813 if (command.equals("Chart2")) {
808 // 如果TabPanel不存在就create,否则就切换 814 // 如果TabPanel不存在就create,否则就切换
809 if (!tabPanel.isSelectTabComponents("结果")) { 815 if (!centerTabPanel.isSelectTabComponents("结果")) {
810 try { 816 try {
811 ct.makeTable(); 817 ct.makeTable();
812 viewPanel = new ViewPanel(ct.results); 818 viewPanel = new ViewPanel(ct.results);
@@ -814,20 +820,20 @@ public class Main extends JFrame {
814 e1.printStackTrace(); 820 e1.printStackTrace();
815 System.out.println("图表生成错误"); 821 System.out.println("图表生成错误");
816 } 822 }
817 tabPanel.addTab("结果", createPage(viewPanel)); 823 centerTabPanel.addTab("结果", createPage(viewPanel));
818 tabPanel.isSelectTabComponents("结果"); 824 centerTabPanel.isSelectTabComponents("结果");
819 } 825 }
820 } else if (command.equals("Map")) { 826 } else if (command.equals("Map")) {
821 // 代码标签页 827 // 代码标签页
822 if (!tabPanel.isSelectTabComponents("代码")) { 828 if (!centerTabPanel.isSelectTabComponents("代码")) {
823 tabPanel.addTab("代码", testCode); 829 centerTabPanel.addTab("代码", testCode);
824 tabPanel.isSelectTabComponents("代码"); 830 centerTabPanel.isSelectTabComponents("代码");
825 } 831 }
826 } else if (command.equals("Process")) { 832 } else if (command.equals("Process")) {
827 // 进度 833 // 进度
828 if (!tabPanel.isSelectTabComponents("进度")) { 834 if (!centerTabPanel.isSelectTabComponents("进度")) {
829 tabPanel.addTab("进度", textCheck); 835 centerTabPanel.addTab("进度", textCheck);
830 tabPanel.isSelectTabComponents("进度"); 836 centerTabPanel.isSelectTabComponents("进度");
831 } 837 }
832 } 838 }
833 } 839 }
@@ -839,17 +845,17 @@ public class Main extends JFrame {
839 } 845 }
840 846
841 private void initTab() { 847 private void initTab() {
842 tabPanel = new MyTabPanel(); 848 centerTabPanel = new MyTabPanel();
843 tabPanel.addMouseListener(new MouseAdapter() { 849 centerTabPanel.addMouseListener(new MouseAdapter() {
844 private boolean isMaximized() { 850 private boolean isMaximized() {
845 return outlookPanel.isShrinked(); 851 return outlookPanel.isShrinked();
846 } 852 }
847 853
848 public void mouseClicked(MouseEvent e) { 854 public void mouseClicked(MouseEvent e) {
849 if (e.getClickCount() > 1) { 855 if (e.getClickCount() > 1) {
850 TabbedPaneUI ui = tabPanel.getUI(); 856 TabbedPaneUI ui = centerTabPanel.getUI();
851 int tabIndex = 857 int tabIndex =
852 ui.tabForCoordinate(tabPanel, e.getX(), e.getY()); 858 ui.tabForCoordinate(centerTabPanel, e.getX(), e.getY());
853 if (tabIndex != -1) { 859 if (tabIndex != -1) {
854 boolean maxed = isMaximized(); 860 boolean maxed = isMaximized();
855 outlookPanel.setShrink(!maxed); 861 outlookPanel.setShrink(!maxed);
@@ -867,17 +873,17 @@ public class Main extends JFrame {
867 } 873 }
868 874
869 private void initTab2() { 875 private void initTab2() {
870 tabPanel2 = new MyTabPanel1(); 876 footTabPanel = new MyTabPanel1();
871 tabPanel2.addMouseListener(new MouseAdapter() { 877 footTabPanel.addMouseListener(new MouseAdapter() {
872 private boolean isMaximized() { 878 private boolean isMaximized() {
873 return outlookPanel.isShrinked(); 879 return outlookPanel.isShrinked();
874 } 880 }
875 881
876 public void mouseClicked(MouseEvent e) { 882 public void mouseClicked(MouseEvent e) {
877 if (e.getClickCount() > 1) { 883 if (e.getClickCount() > 1) {
878 TabbedPaneUI ui = tabPanel2.getUI(); 884 TabbedPaneUI ui = footTabPanel.getUI();
879 int tabIndex = 885 int tabIndex =
880 ui.tabForCoordinate(tabPanel2, e.getX(), e.getY()); 886 ui.tabForCoordinate(footTabPanel, e.getX(), e.getY());
881 if (tabIndex != -1) { 887 if (tabIndex != -1) {
882 boolean maxed = isMaximized(); 888 boolean maxed = isMaximized();
883 outlookPanel.setShrink(!maxed); 889 outlookPanel.setShrink(!maxed);
@@ -894,9 +900,9 @@ public class Main extends JFrame {
894 cppcheckResult = cppcheckPanel.getTextArea(); 900 cppcheckResult = cppcheckPanel.getTextArea();
895 clangResult = clangPanel.getTextArea(); 901 clangResult = clangPanel.getTextArea();
896 902
897 tabPanel2.addTab("cppcheck", createPage1(cppcheckPanel)); 903 footTabPanel.addTab("cppcheck", createPage1(cppcheckPanel));
898 tabPanel2.addTab("Clang", createPage1(clangPanel)); 904 footTabPanel.addTab("Clang", createPage1(clangPanel));
899 tabPanel2.addTab("flawfinder", createPage1(flawfinderPanel)); 905 footTabPanel.addTab("flawfinder", createPage1(flawfinderPanel));
900 } 906 }
901 907
902 private MyTabPage1 createPage1(JComponent pageContent) { 908 private MyTabPage1 createPage1(JComponent pageContent) {
diff --git a/src/cppcheckplus/control/MyContorlUtil.java b/src/cppcheckplus/control/MyContorlUtil.java
index 72716de..acdc9ba 100644
--- a/src/cppcheckplus/control/MyContorlUtil.java
+++ b/src/cppcheckplus/control/MyContorlUtil.java
@@ -1,6 +1,15 @@
1
2package cppcheckplus.control; 1package cppcheckplus.control;
3 2
3import com.jgoodies.looks.plastic.PlasticLookAndFeel;
4import com.jgoodies.looks.plastic.theme.ExperienceGreen;
5import cppcheckplus.menu.MyMenu;
6import cppcheckplus.menu.MyMenuBar;
7import cppcheckplus.menu.MyMenuItem;
8import cppcheckplus.menu.MyRootMenu;
9import cppcheckplus.outlookpanel.MyOutlookBar;
10import cppcheckplus.outlookpanel.MyOutlookHeader;
11import cppcheckplus.outlookpanel.MyOutlookPanel;
12import cppcheckplus.outlookpanel.MyOutlookPanelListItem;
4import java.awt.Color; 13import java.awt.Color;
5import java.awt.Component; 14import java.awt.Component;
6import java.awt.Font; 15import java.awt.Font;
@@ -19,7 +28,6 @@ import java.io.IOException;
19import java.io.InputStream; 28import java.io.InputStream;
20import java.util.ArrayList; 29import java.util.ArrayList;
21import java.util.List; 30import java.util.List;
22
23import javax.imageio.ImageIO; 31import javax.imageio.ImageIO;
24import javax.swing.BorderFactory; 32import javax.swing.BorderFactory;
25import javax.swing.Box; 33import javax.swing.Box;
@@ -35,563 +43,529 @@ import javax.xml.transform.Transformer;
35import javax.xml.transform.TransformerFactory; 43import javax.xml.transform.TransformerFactory;
36import javax.xml.transform.dom.DOMSource; 44import javax.xml.transform.dom.DOMSource;
37import javax.xml.transform.stream.StreamResult; 45import javax.xml.transform.stream.StreamResult;
38
39import org.w3c.dom.Document; 46import org.w3c.dom.Document;
40import org.w3c.dom.Element; 47import org.w3c.dom.Element;
41import org.w3c.dom.Node; 48import org.w3c.dom.Node;
42import org.w3c.dom.NodeList; 49import org.w3c.dom.NodeList;
43 50
44import com.jgoodies.looks.plastic.PlasticLookAndFeel;
45import com.jgoodies.looks.plastic.theme.ExperienceGreen;
46
47import cppcheckplus.menu.MyMenu;
48import cppcheckplus.menu.MyMenuBar;
49import cppcheckplus.menu.MyMenuItem;
50import cppcheckplus.menu.MyRootMenu;
51import cppcheckplus.outlookpanel.MyOutlookBar;
52import cppcheckplus.outlookpanel.MyOutlookHeader;
53import cppcheckplus.outlookpanel.MyOutlookPanel;
54import cppcheckplus.outlookpanel.MyOutlookPanelListItem;
55
56 51
57/** 52/**
58 * @ClassName: ContorlUtil 53 * @ClassName: ContorlUtil
59 * @Description: TODO(控件工具,皮肤信息和基本操作) 54 * @Description: TODO(控件工具 , 皮肤信息和基本操作)
60 *
61 */ 55 */
62public class MyContorlUtil 56public class MyContorlUtil {
63{ 57 //文本
64 //文本 58 public static final Color DEFAULT_TEXT_COLOR = new Color(37, 81, 54);
65 public static final Color DEFAULT_TEXT_COLOR = new Color(37, 81, 54); 59 public static final Font FONT_14_BOLD = new Font("微软雅黑", 1, 14);
66 public static final Font FONT_14_BOLD = new Font("微软雅黑", 1, 14); 60 public static final Font FONT_12_BOLD = new Font("微软雅黑", 1, 12);
67 public static final Font FONT_12_BOLD = new Font("微软雅黑", 1, 12); 61 public static final Font FONT_14_PLAIN = new Font("微软雅黑", 0, 14);
68 public static final Font FONT_14_PLAIN = new Font("微软雅黑", 0, 14); 62 public static final Font FONT_12_PLAIN = new Font("微软雅黑", 0, 12);
69 public static final Font FONT_12_PLAIN = new Font("微软雅黑", 0, 12); 63 // public static final Font FONT_12_PLAIN = new Font("Dialog", 0, 12);
70// public static final Font FONT_12_PLAIN = new Font("Dialog", 0, 12);
71//public static final Font FONT_12_PLAIN = new Font("Calibri", 0, 12); 64//public static final Font FONT_12_PLAIN = new Font("Calibri", 0, 12);
72 //菜单 65 //菜单
73 public static final Color MENUITEM_SELECTED_BACKGROUND = new Color(166, 188, 140); 66 public static final Color MENUITEM_SELECTED_BACKGROUND =
74 public static final Color MENUITEM_BACKGROUND = new Color(228, 235, 218); 67 new Color(166, 188, 140);
75 //主面板 68 public static final Color MENUITEM_BACKGROUND = new Color(228, 235, 218);
76 public static final Color CONTENT_PANE_BACKGROUND = new Color(92, 153, 45); 69 //主面板
77 public static final Color CONTENT_PANE_BACKGROUND2 = new Color(78, 238, 148); 70 public static final Color CONTENT_PANE_BACKGROUND = new Color(92, 153, 45);
78 public static final Color CONTENT_PANE_BACKGROUND3 = new Color(238, 220, 130); 71 public static final Color CONTENT_PANE_BACKGROUND2 =
79 //工具栏按钮 72 new Color(78, 238, 148);
80 public static final Color BUTTON_ROVER_COLOR = new Color(196, 196, 197); 73 public static final Color CONTENT_PANE_BACKGROUND3 =
81 //OutLook面板 74 new Color(238, 220, 130);
82 public static final Color OUTLOOK_TEXT_COLOR = new Color(120, 120, 125); 75 //工具栏按钮
83 public static final Color OUTLOOK_SPLIT_COLOR = new Color(174, 171, 162); 76 public static final Color BUTTON_ROVER_COLOR = new Color(196, 196, 197);
84 public static final Color OUTLOOK_CONTAINER_COLOR = new Color(217, 218, 219) ;//容器的背景颜色,灰色 77 //OutLook面板
85 //多视图Tab 78 public static final Color OUTLOOK_TEXT_COLOR = new Color(120, 120, 125);
86 public static final Color TAB_BOTTOM_LINE_COLOR = new Color(167, 173, 175); 79 public static final Color OUTLOOK_SPLIT_COLOR = new Color(174, 171, 162);
87 //快捷菜单面板 80 public static final Color OUTLOOK_CONTAINER_COLOR =
88 public static final Color LIST_SPLIT_COLOR = new Color(105, 113, 120); 81 new Color(217, 218, 219);//容器的背景颜色,灰色
89 public static final Color LIST_BACKGROUND = new Color(175, 174, 176); 82 //多视图Tab
90 public static final Color LIST_TEXT_COLOR = new Color(49, 52, 58); 83 public static final Color TAB_BOTTOM_LINE_COLOR = new Color(167, 173, 175);
91 //图形 84 //快捷菜单面板
92 public static Font CHART_AXIS_FONT = new Font("微软雅黑",Font.PLAIN,12) ;// 坐标轴字体 85 public static final Color LIST_SPLIT_COLOR = new Color(105, 113, 120);
93 public static Font CHART_TITLE_FONT = new Font("微软雅黑",Font.PLAIN,14);//标题字体 86 public static final Color LIST_BACKGROUND = new Color(175, 174, 176);
94 public static Font CHART_LEGEND_FONT = new Font("微软雅黑",Font.PLAIN,12); //图例字体 87 public static final Color LIST_TEXT_COLOR = new Color(49, 52, 58);
95 88 //其他
96 //其他 89 public static final Color NO_COLOR = new Color(0, 0, 0, 0);
97 public static final Color NO_COLOR = new Color(0, 0, 0, 0); 90 public static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0);
98 public static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0); 91 //图形
99 /** 92 public static Font CHART_AXIS_FONT = new Font("微软雅黑", Font.PLAIN, 12);
100 * ClassLoader获得BufferedImage,注意和getClass().getResource()的路径不同 93 //图例字体
101 * 最前面不带/ 94// 坐标轴字体
102 * @param @param imgPath 95 public static Font CHART_TITLE_FONT = new Font("微软雅黑", Font.PLAIN, 14);
103 * @param @return 参数 96 //标题字体
104 * @return Image 返回类型 97 public static Font CHART_LEGEND_FONT = new Font("微软雅黑", Font.PLAIN, 12);
105 * @throws 98
106 */ 99 /**
107 public static Image getImage(String imgPath) 100 * ClassLoader获得BufferedImage,注意和getClass().getResource()的路径不同
108 { 101 * 最前面不带/
109 BufferedImage img = null; 102 *
110 try 103 * @param @param imgPath
111 { 104 * @param @return 参数
112 //System.out.println("图片路径: "+imgPath); 105 * @return Image 返回类型
113 img = ImageIO.read(ClassLoader.getSystemResource(imgPath)); 106 * @throws
114 } catch (IOException e) 107 */
115 { 108 public static Image getImage(String imgPath) {
116 System.out.println("图片路径找不到: "+imgPath); 109 BufferedImage img = null;
117 //e.printStackTrace(); 110 try {
118 } 111 //System.out.println("图片路径: "+imgPath);
119 return img; 112 img = ImageIO.read(ClassLoader.getSystemResource(imgPath));
120 } 113 } catch (IOException e) {
121 public static ImageIcon getImageIcon(String imgPath) 114 System.out.println("图片路径找不到: " + imgPath);
122 { 115 //e.printStackTrace();
123 ImageIcon icon = null; 116 }
124 try 117 return img;
125 { 118 }
126 icon = new ImageIcon(ClassLoader.getSystemResource(imgPath)); 119
127 return icon; 120 public static ImageIcon getImageIcon(String imgPath) {
128 } 121 ImageIcon icon = null;
129 catch (Exception e) 122 try {
130 { 123 icon = new ImageIcon(ClassLoader.getSystemResource(imgPath));
131 System.out.println("找不到图片: " +imgPath ); 124 return icon;
132 } 125 } catch (Exception e) {
133 return icon; 126 System.out.println("找不到图片: " + imgPath);
134 } 127 }
135 public static Image iconToImage(Icon icon) 128 return icon;
136 { 129 }
137 if (icon instanceof ImageIcon) 130
138 { 131 public static Image iconToImage(Icon icon) {
139 return ((ImageIcon) icon).getImage(); 132 if (icon instanceof ImageIcon) {
140 } 133 return ((ImageIcon) icon).getImage();
141 else 134 } else {
142 { 135 int w = icon.getIconWidth();
143 int w = icon.getIconWidth(); 136 int h = icon.getIconHeight();
144 int h = icon.getIconHeight(); 137 BufferedImage image = new BufferedImage(w, h, 2);
145 BufferedImage image = new BufferedImage(w, h, 2); 138 Graphics2D g = image.createGraphics();
146 Graphics2D g = image.createGraphics(); 139 icon.paintIcon(null, g, 0, 0);
147 icon.paintIcon(null, g, 0, 0); 140 g.dispose();
148 g.dispose(); 141 return image;
149 return image; 142 }
150 } 143 }
151 } 144
152 public static ImageIcon createDyedIcon(ImageIcon icon, Color color) 145 public static ImageIcon createDyedIcon(ImageIcon icon, Color color) {
153 { 146 if (color == null) {
154 if (color == null) 147 return icon;
155 { 148 } else {
156 return icon; 149 int iconWidth = icon.getIconWidth();
157 } 150 int iconHeight = icon.getIconHeight();
158 else 151 BufferedImage bi = new BufferedImage(iconWidth, iconHeight, 2);
159 { 152 Graphics2D g2d = bi.createGraphics();
160 int iconWidth = icon.getIconWidth(); 153 icon.paintIcon(null, g2d, 0, 0);
161 int iconHeight = icon.getIconHeight(); 154 g2d.dispose();
162 BufferedImage bi = new BufferedImage(iconWidth, iconHeight, 2); 155 Image dyedImage = createDyedImage(bi, color);
163 Graphics2D g2d = bi.createGraphics(); 156 return new ImageIcon(dyedImage);
164 icon.paintIcon(null, g2d, 0, 0); 157 }
165 g2d.dispose(); 158 }
166 Image dyedImage = createDyedImage(bi, color); 159
167 return new ImageIcon(dyedImage); 160 public static Image createDyedImage(Image image, Color color) {
168 } 161 if (color == null) {
169 } 162 return image;
170 public static Image createDyedImage(Image image, Color color) 163 }
171 { 164 if (image != null) {
172 if (color == null) 165 int w = image.getWidth(null);
173 return image; 166 int h = image.getHeight(null);
174 if (image != null) 167 int[] pixels = new int[w * h];
175 { 168 PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
176 int w = image.getWidth(null); 169 try {
177 int h = image.getHeight(null); 170 pg.grabPixels();
178 int pixels[] = new int[w * h]; 171 } catch (InterruptedException ex) {
179 PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w); 172 ex.printStackTrace();
180 try 173 return null;
181 { 174 }
182 pg.grabPixels(); 175 BufferedImage bi =
183 } 176 new BufferedImage(w <= 1 ? 1 : w, h <= 1 ? 1 : h, 2);
184 catch (InterruptedException ex) 177 for (int i = 0; i < pixels.length; i++) {
185 { 178 int pixel = pixels[i];
186 ex.printStackTrace(); 179 int row = i / w;
187 return null; 180 int col = i % w;
188 } 181 if (color != null && pixel != 0) {
189 BufferedImage bi = new BufferedImage(w <= 1 ? 1 : w, 182 pixel = color.getRGB();
190 h <= 1 ? 1 : h, 2); 183 }
191 for (int i = 0; i < pixels.length; i++) 184 bi.setRGB(col, row, pixel);
192 { 185 }
193 int pixel = pixels[i]; 186 return bi;
194 int row = i / w; 187 } else {
195 int col = i % w; 188 return null;
196 if (color != null && pixel != 0) 189 }
197 pixel = color.getRGB(); 190 }
198 bi.setRGB(col, row, pixel); 191
199 } 192 public static Icon createMovedIcon(Icon icon) {
200 return bi; 193 return createMovedIcon(icon, 1, 1);
201 } 194 }
202 else 195
203 { 196 public static Icon createMovedIcon(final Icon icon, final int offsetX,
204 return null; 197 final int offsetY) {
205 } 198 return new Icon() {
206 } 199 public void paintIcon(Component c, Graphics g, int x, int y) {
207 public static Icon createMovedIcon(Icon icon) 200 icon.paintIcon(c, g, x + offsetX, y + offsetY);
208 { 201 }
209 return createMovedIcon(icon, 1, 1); 202
210 } 203 public int getIconWidth() {
211 public static Icon createMovedIcon(final Icon icon, final int offsetX, 204 return icon.getIconWidth();
212 final int offsetY) 205 }
213 { 206
214 return new Icon() 207 public int getIconHeight() {
215 { 208 return icon.getIconHeight();
216 public void paintIcon(Component c, Graphics g, int x, int y) 209 }
217 { 210 };
218 icon.paintIcon(c, g, x + offsetX, y + offsetY); 211 }
219 } 212
220 public int getIconWidth() 213 public static TexturePaint createTexturePaint(String imgPath) {
221 { 214 ImageIcon icon = getImageIcon(imgPath);
222 return icon.getIconWidth(); 215 int imageWidth = icon.getIconWidth();
223 } 216 int imageHeight = icon.getIconHeight();
224 public int getIconHeight() 217 BufferedImage bi = new BufferedImage(imageWidth, imageHeight, 2);
225 { 218 Graphics2D g2d = bi.createGraphics();
226 return icon.getIconHeight(); 219 g2d.drawImage(icon.getImage(), 0, 0, null);
227 } 220 g2d.dispose();
228 }; 221 return new TexturePaint(bi,
229 } 222 new Rectangle(0, 0, imageWidth, imageHeight));
230 223 }
231 public static TexturePaint createTexturePaint(String imgPath) 224
232 { 225 public static Color getColor(String color) {
233 ImageIcon icon = getImageIcon(imgPath); 226 Color convertedColor = Color.ORANGE;
234 int imageWidth = icon.getIconWidth(); 227 try {
235 int imageHeight = icon.getIconHeight(); 228 convertedColor = new Color(Integer.parseInt(color, 16));
236 BufferedImage bi = new BufferedImage(imageWidth, imageHeight, 2); 229 } catch (NumberFormatException e) {
237 Graphics2D g2d = bi.createGraphics(); 230 String error = String.format("颜色转化出错:s%", color);
238 g2d.drawImage(icon.getImage(), 0, 0, null); 231 System.out.println(error);
239 g2d.dispose(); 232 }
240 return new TexturePaint(bi, 233 return convertedColor;
241 new Rectangle(0, 0, imageWidth, imageHeight)); 234 }
242 } 235
243 236 public static InputStream getXMLFile(String filePath) {
244 public static Color getColor(String color) { 237 return ClassLoader.getSystemResourceAsStream(filePath);
245 Color convertedColor = Color.ORANGE; 238 }
246 try { 239
247 convertedColor = new Color(Integer.parseInt(color, 16)); 240
248 } catch(NumberFormatException e) { 241 public static String getStringAttribute(org.w3c.dom.Node node,
249 String error = String.format("颜色转化出错:s%",color); 242 String name) {
250 System.out.println(error); 243 org.w3c.dom.Node attribute = node.getAttributes().getNamedItem(name);
251 } 244 if (attribute != null) {
252 return convertedColor; 245 return attribute.getNodeValue();
253 } 246 } else {
254 247 return null;
255 public static InputStream getXMLFile(String filePath) 248 }
256 { 249 }
257 return ClassLoader.getSystemResourceAsStream(filePath); 250
258 } 251 private static Icon getIconAttribute(org.w3c.dom.Node node, String name) {
259 252 String iconURL = getStringAttribute(node, name);
260 253 if (iconURL != null && !iconURL.isEmpty()) {
261 public static String getStringAttribute(org.w3c.dom.Node node, String name) 254 return getImageIcon(iconURL);
262 { 255 } else {
263 org.w3c.dom.Node attribute = node.getAttributes().getNamedItem(name); 256 return null;
264 if (attribute != null) 257 }
265 return attribute.getNodeValue(); 258 }
266 else 259
267 return null; 260 private static int getIntAttribute(org.w3c.dom.Node node, String name) {
268 } 261 String value = getStringAttribute(node, name);
269 262 if (value != null && !value.isEmpty()) {
270 private static Icon getIconAttribute(org.w3c.dom.Node node, String name) 263 return Integer.valueOf(value).intValue();
271 { 264 } else {
272 String iconURL = getStringAttribute(node, name); 265 return 0;
273 if (iconURL != null && !iconURL.isEmpty()) 266 }
274 return getImageIcon(iconURL); 267 }
275 else 268
276 return null; 269 public static MyMenuBar loadMenuBar(String xml, ActionListener action) {
277 } 270 MyMenuBar menuBar = null;
278 271 try {
279 private static int getIntAttribute(org.w3c.dom.Node node, String name) 272 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
280 { 273 DocumentBuilder db = dbf.newDocumentBuilder();
281 String value = getStringAttribute(node, name); 274 Document doc = db.parse(MyContorlUtil.getXMLFile(xml));
282 if (value != null && !value.isEmpty()) 275 Element root = doc.getDocumentElement();
283 return Integer.valueOf(value).intValue(); 276 NodeList rootMenus = root.getChildNodes();
284 else 277 if (rootMenus != null) {
285 return 0; 278 menuBar = new MyMenuBar();
286 } 279 for (int i = 0; i < rootMenus.getLength(); i++) {
287 280 org.w3c.dom.Node menu = rootMenus.item(i);
288 public static MyMenuBar loadMenuBar(String xml, ActionListener action) 281 if (menu.getNodeType() == Node.ELEMENT_NODE) {
289 { 282 if (menu.getNodeName().equalsIgnoreCase("menu")) {
290 MyMenuBar menuBar = null; 283 String text =
291 try 284 MyContorlUtil.getStringAttribute(menu, "text");
292 { 285 MyRootMenu rootMenu = new MyRootMenu();
293 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 286 rootMenu.setText(text);
294 DocumentBuilder db = dbf.newDocumentBuilder(); 287 menuBar.add(rootMenu);
295 Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); 288 processMenuItem(menu, rootMenu, action);
296 Element root = doc.getDocumentElement(); 289 }
297 NodeList rootMenus = root.getChildNodes(); 290 if (menu.getNodeName().equalsIgnoreCase("logo")) {
298 if (rootMenus != null) 291 String tooltip =
299 { 292 MyContorlUtil.getStringAttribute(menu,
300 menuBar = new MyMenuBar(); 293 "tooltip");
301 for (int i = 0; i < rootMenus.getLength(); i++) 294 String imageURL =
302 { 295 MyContorlUtil.getStringAttribute(menu, "image");
303 org.w3c.dom.Node menu = rootMenus.item(i); 296 menuBar.add(Box.createGlue());
304 if (menu.getNodeType() == Node.ELEMENT_NODE) 297 JLabel label = new JLabel(
305 { 298 MyContorlUtil.getImageIcon(imageURL));
306 if (menu.getNodeName().equalsIgnoreCase("menu")) 299 label.setBorder(
307 { 300 BorderFactory.createEmptyBorder(0, 5, 0, 5));
308 String text = MyContorlUtil.getStringAttribute(menu, "text"); 301 label.setToolTipText(tooltip);
309 MyRootMenu rootMenu = new MyRootMenu(); 302 menuBar.add(label);
310 rootMenu.setText(text); 303 }
311 menuBar.add(rootMenu); 304 }
312 processMenuItem(menu, rootMenu, action); 305 }
313 } 306 }
314 if (menu.getNodeName().equalsIgnoreCase("logo")) 307 } catch (Exception ex) {
315 { 308 ex.printStackTrace();
316 String tooltip = MyContorlUtil.getStringAttribute(menu, "tooltip"); 309 }
317 String imageURL = MyContorlUtil.getStringAttribute(menu, "image"); 310 return menuBar;
318 menuBar.add(Box.createGlue()); 311 }
319 JLabel label = new JLabel(MyContorlUtil.getImageIcon(imageURL)); 312
320 label.setBorder(BorderFactory.createEmptyBorder(0,5, 0, 5)); 313
321 label.setToolTipText(tooltip); 314 public static void fixSettingPath(String xml, String tool, String newPath) {
322 menuBar.add(label); 315 try {
323 } 316 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
324 } 317 DocumentBuilder db = dbf.newDocumentBuilder();
325 } 318 Document doc = db.parse(MyContorlUtil.getXMLFile(xml));
326 } 319 Element root = doc.getDocumentElement();
327 } 320 NodeList tools = root.getChildNodes();
328 catch (Exception ex) 321 if (tools != null) {
329 { 322 for (int i = 0; i < tools.getLength(); i++) {
330 ex.printStackTrace(); 323 org.w3c.dom.Node menu = tools.item(i);
331 } 324 if (menu.getNodeType() == Node.ELEMENT_NODE) {
332 return menuBar; 325 if (menu.getNodeName().equalsIgnoreCase("tool")) {
333 } 326 org.w3c.dom.Node att =
334 327 menu.getAttributes().getNamedItem("id");
335 328 String toolName =
336 public static void fixSettingPath(String xml, String tool, String newPath) 329 MyContorlUtil.getStringAttribute(menu,
337 { 330 "toolName");
338 try 331 if (tool.equals("cppcheck") &&
339 { 332 toolName.equals("cppcheck")) {
340 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 333 org.w3c.dom.Node attribute =
341 DocumentBuilder db = dbf.newDocumentBuilder(); 334 menu.getAttributes()
342 Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); 335 .getNamedItem("filePath");
343 Element root = doc.getDocumentElement(); 336 if (attribute != null) {
344 NodeList tools = root.getChildNodes(); 337 attribute.setNodeValue(
345 if (tools != null) 338 newPath.replaceAll("\\\\", "\\/"));
346 { 339 }
347 for (int i = 0; i < tools.getLength(); i++) 340 } else if (tool.equals("flawfinder") &&
348 { 341 toolName.equals("flawfinder")) {
349 org.w3c.dom.Node menu = tools.item(i); 342 org.w3c.dom.Node attribute =
350 if (menu.getNodeType() == Node.ELEMENT_NODE) 343 menu.getAttributes()
351 { 344 .getNamedItem("filePath");
352 if (menu.getNodeName().equalsIgnoreCase("tool")) 345 if (attribute != null) {
353 { 346 attribute.setNodeValue(
354 org.w3c.dom.Node att = menu.getAttributes().getNamedItem("id"); 347 newPath.replaceAll("\\\\", "\\/"));
355 String toolName = MyContorlUtil.getStringAttribute(menu, "toolName"); 348 }
356 if(tool.equals("cppcheck") && toolName.equals("cppcheck") ){ 349 }
357 org.w3c.dom.Node attribute = menu.getAttributes().getNamedItem("filePath"); 350 }
358 if (attribute != null) 351 }
359 attribute.setNodeValue(newPath.replaceAll("\\\\","\\/")); 352 }
360 } 353 }
361 else if(tool.equals("flawfinder") && toolName.equals("flawfinder")){ 354
362 org.w3c.dom.Node attribute = menu.getAttributes().getNamedItem("filePath"); 355 Transformer transformer =
363 if (attribute != null) 356 TransformerFactory.newInstance().newTransformer();
364 attribute.setNodeValue(newPath.replaceAll("\\\\","\\/")); 357 DOMSource source = new DOMSource(doc);
365 } 358 File file = new File(ClassLoader.getSystemResource(xml).toURI());
366 } 359 FileOutputStream outstream =
367 } 360 new FileOutputStream("src/cppcheckplus/control/settings.xml");
368 } 361 StreamResult reslut = new StreamResult(outstream);
369 } 362 transformer.transform(source, reslut);
370 363 outstream.close();
371 Transformer transformer=TransformerFactory.newInstance().newTransformer(); 364
372 DOMSource source=new DOMSource(doc); 365 } catch (Exception ex) {
373 File file =new File(ClassLoader.getSystemResource(xml).toURI()); 366 ex.printStackTrace();
374 FileOutputStream outstream =new FileOutputStream("src/cppcheckplus/control/settings.xml"); 367 }
375 StreamResult reslut=new StreamResult(outstream); 368
376 transformer.transform(source, reslut); 369 }
377 outstream.close(); 370
378 371 public static void loadToolsRoad(String xml, Main main) {
379 } 372 try {
380 catch (Exception ex) 373 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
381 { 374 DocumentBuilder db = dbf.newDocumentBuilder();
382 ex.printStackTrace(); 375 Document doc = db.parse(MyContorlUtil.getXMLFile(xml));
383 } 376 Element root = doc.getDocumentElement();
384 377 NodeList tools = root.getChildNodes();
385 } 378 if (tools != null) {
386 379 for (int i = 0; i < tools.getLength(); i++) {
387 public static void loadToolsRoad(String xml, Main main) 380 org.w3c.dom.Node menu = tools.item(i);
388 { 381 if (menu.getNodeType() == Node.ELEMENT_NODE) {
389 try 382 if (menu.getNodeName().equalsIgnoreCase("tool")) {
390 { 383 String toolName =
391 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 384 MyContorlUtil.getStringAttribute(menu,
392 DocumentBuilder db = dbf.newDocumentBuilder(); 385 "toolName");
393 Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); 386 String filePath =
394 Element root = doc.getDocumentElement(); 387 MyContorlUtil.getStringAttribute(menu,
395 NodeList tools = root.getChildNodes(); 388 "filePath");
396 if (tools != null) 389 String para =
397 { 390 MyContorlUtil.getStringAttribute(menu, "para");
398 for (int i = 0; i < tools.getLength(); i++) 391
399 { 392 switch (toolName) {
400 org.w3c.dom.Node menu = tools.item(i); 393 case "cppcheck":
401 if (menu.getNodeType() == Node.ELEMENT_NODE) 394 main.cppcheckPath = filePath;
402 { 395 main.paracppcheck = para;
403 if (menu.getNodeName().equalsIgnoreCase("tool")) 396 break;
404 { 397 case "flawfinder":
405 String toolName = MyContorlUtil.getStringAttribute(menu, "toolName"); 398 main.flawfinderPath = filePath;
406 String filePath = MyContorlUtil.getStringAttribute(menu, "filePath"); 399 main.paraflawfinder = para;
407 String para= MyContorlUtil.getStringAttribute(menu, "para"); 400 break;
408 if(toolName.equals("cppcheck")){ 401 case "clang-tidy":
409 main.cppcheckPath=filePath; 402 main.clangtidyPath = filePath;
410 main.paracppcheck=para; 403 main.paraclangtidy = para;
411 } 404 break;
412 else if(toolName.equals("flawfinder")){ 405 default:
413 main.flawfinderPath=filePath; 406 break;
414 main.paraflawfinder=para; 407 }
415 } 408 }
416 } 409 }
417 } 410 }
418 } 411 }
419 } 412 } catch (Exception ex) {
420 } 413 ex.printStackTrace();
421 catch (Exception ex) 414 }
422 { 415 }
423 ex.printStackTrace(); 416
424 } 417
425 } 418 private static void processMenuItem(org.w3c.dom.Node menu,
426 419 JMenuItem parentMenu,
427 420 ActionListener action) {
428 421 NodeList children = menu.getChildNodes();
429 private static void processMenuItem(org.w3c.dom.Node menu, 422 if (children != null) {
430 JMenuItem parentMenu, ActionListener action) 423 for (int j = 0; j < children.getLength(); j++) {
431 { 424 org.w3c.dom.Node itemNode = children.item(j);
432 NodeList children = menu.getChildNodes(); 425 if (itemNode.getNodeType() != Node.ELEMENT_NODE) {
433 if (children != null) 426 continue;
434 { 427 }
435 for (int j = 0; j < children.getLength(); j++) 428 boolean isMenuItem =
436 { 429 itemNode.getNodeName().equalsIgnoreCase("menuitem");
437 org.w3c.dom.Node itemNode = children.item(j); 430 boolean isMenu =
438 if (itemNode.getNodeType() != Node.ELEMENT_NODE) 431 itemNode.getNodeName().equalsIgnoreCase("menu");
439 continue; 432 if (!isMenuItem && !isMenu) {
440 boolean isMenuItem = itemNode.getNodeName().equalsIgnoreCase( 433 continue;
441 "menuitem"); 434 }
442 boolean isMenu = itemNode.getNodeName() 435 String text = getStringAttribute(itemNode, "text");
443 .equalsIgnoreCase("menu"); 436 String tooltip = getStringAttribute(itemNode, "tooltip");
444 if (!isMenuItem && !isMenu) 437 Icon icon = getIconAttribute(itemNode, "icon");
445 continue; 438 String command = getStringAttribute(itemNode, "action");
446 String text = getStringAttribute(itemNode, "text"); 439 JMenuItem menuItem = null;
447 String tooltip = getStringAttribute(itemNode, "tooltip"); 440 if (isMenu) {
448 Icon icon = getIconAttribute(itemNode, "icon"); 441 menuItem = new MyMenu();
449 String command = getStringAttribute(itemNode, "action"); 442 } else {
450 JMenuItem menuItem = null; 443 menuItem = new MyMenuItem();
451 if (isMenu) 444 menuItem.addActionListener(action);
452 { 445 }
453 menuItem = new MyMenu(); 446 menuItem.setText(text);
454 } 447 menuItem.setToolTipText(tooltip);
455 else 448 menuItem.setActionCommand(command);
456 { 449 menuItem.setIcon(icon);
457 menuItem = new MyMenuItem(); 450 parentMenu.add(menuItem);
458 menuItem.addActionListener(action); 451 if (isMenu) {
459 } 452 processMenuItem(itemNode, menuItem, action);
460 menuItem.setText(text); 453 }
461 menuItem.setToolTipText(tooltip); 454 }
462 menuItem.setActionCommand(command); 455 }
463 menuItem.setIcon(icon); 456 }
464 parentMenu.add(menuItem); 457
465 if (isMenu) 458 //加载OutloolPanel上的最上面的快捷工具栏OutlookHeader
466 processMenuItem(itemNode, menuItem, action); 459 public static void loadOutlookToolBar(String xml, MyOutlookHeader header,
467 } 460 ActionListener action) {
468 } 461 try {
469 } 462 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
470 463 DocumentBuilder db = dbf.newDocumentBuilder();
471 //加载OutloolPanel上的最上面的快捷工具栏OutlookHeader 464 Document doc = db.parse(getXMLFile(xml));
472 public static void loadOutlookToolBar(String xml, MyOutlookHeader header, 465 Element root = doc.getDocumentElement();
473 ActionListener action) 466 NodeList buttons = root.getChildNodes();
474 { 467 if (buttons != null) {
475 try 468 for (int i = 0; i < buttons.getLength(); i++) {
476 { 469 org.w3c.dom.Node buttonNode = buttons.item(i);
477 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 470 if (buttonNode.getNodeType() == Node.ELEMENT_NODE) {
478 DocumentBuilder db = dbf.newDocumentBuilder(); 471 if (buttonNode.getNodeName()
479 Document doc = db.parse(getXMLFile(xml)); 472 .equalsIgnoreCase("button")) {
480 Element root = doc.getDocumentElement(); 473 String tooltip =
481 NodeList buttons = root.getChildNodes(); 474 getStringAttribute(buttonNode, "tooltip");
482 if (buttons != null) 475 Icon icon = getIconAttribute(buttonNode, "icon");
483 { 476 String command =
484 for (int i = 0; i < buttons.getLength(); i++) 477 getStringAttribute(buttonNode, "action");
485 { 478 header.addButton(icon, tooltip, action, command);
486 org.w3c.dom.Node buttonNode = buttons.item(i); 479 }
487 if (buttonNode.getNodeType() == Node.ELEMENT_NODE) 480 if (buttonNode.getNodeName()
488 { 481 .equalsIgnoreCase("separator")) {
489 if (buttonNode.getNodeName().equalsIgnoreCase("button")) 482 header.addSeparator();
490 { 483 }
491 String tooltip = getStringAttribute(buttonNode, 484 }
492 "tooltip"); 485 }
493 Icon icon = getIconAttribute(buttonNode, "icon"); 486 }
494 String command = getStringAttribute(buttonNode, 487 } catch (Exception ex) {
495 "action"); 488 ex.printStackTrace();
496 header.addButton(icon, tooltip, action, command); 489 }
497 } 490 }
498 if (buttonNode.getNodeName().equalsIgnoreCase( 491
499 "separator")) 492 public static void loadOutlookPanel(String xml,
500 header.addSeparator(); 493 MyOutlookPanel outlookPane) {
501 } 494 try {
502 } 495 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
503 } 496 DocumentBuilder db = dbf.newDocumentBuilder();
504 } 497 Document doc = db.parse(getXMLFile(xml));
505 catch (Exception ex) 498 Element root = doc.getDocumentElement();
506 { 499 NodeList modules = root.getChildNodes();
507 ex.printStackTrace(); 500 if (modules != null) {
508 } 501 for (int i = 0; i < modules.getLength(); i++) {
509 } 502 org.w3c.dom.Node moduleNode = modules.item(i);
510 503 if (moduleNode.getNodeType() == Node.ELEMENT_NODE &&
511 public static void loadOutlookPanel(String xml, MyOutlookPanel outlookPane) 504 moduleNode.getNodeName().equalsIgnoreCase("module")) {
512 { 505 String text = getStringAttribute(moduleNode, "text");
513 try 506 Icon icon = getIconAttribute(moduleNode, "icon");
514 { 507 Icon iconSelected =
515 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 508 getIconAttribute(moduleNode, "selected_icon");
516 DocumentBuilder db = dbf.newDocumentBuilder(); 509 MyOutlookBar bar =
517 Document doc = db.parse(getXMLFile(xml)); 510 outlookPane.addBar(text, icon, iconSelected,
518 Element root = doc.getDocumentElement(); 511 getOutlookPanelSubModules(moduleNode));
519 NodeList modules = root.getChildNodes(); 512 }
520 if (modules != null) 513 }
521 { 514 }
522 for (int i = 0; i < modules.getLength(); i++) 515 } catch (Exception ex) {
523 { 516 ex.printStackTrace();
524 org.w3c.dom.Node moduleNode = modules.item(i); 517 }
525 if (moduleNode.getNodeType() == Node.ELEMENT_NODE 518 }
526 && moduleNode.getNodeName().equalsIgnoreCase( 519
527 "module")) 520 private static MyOutlookPanelListItem[] getOutlookPanelSubModules(
528 { 521 Node moduleNode) {
529 String text = getStringAttribute(moduleNode, "text"); 522 List<MyOutlookPanelListItem> listItemList =
530 Icon icon = getIconAttribute(moduleNode, "icon"); 523 new ArrayList<MyOutlookPanelListItem>();
531 Icon iconSelected = getIconAttribute(moduleNode, 524 if (moduleNode != null) {
532 "selected_icon"); 525 NodeList subModules = moduleNode.getChildNodes();
533 MyOutlookBar bar = outlookPane.addBar(text, icon, 526 for (int i = 0; i < subModules.getLength(); i++) {
534 iconSelected,getOutlookPanelSubModules(moduleNode)); 527 Node subNode = subModules.item(i);
535 } 528 if ((subNode.getNodeType() == Node.ELEMENT_NODE) &&
536 } 529 (subNode.getNodeName().equalsIgnoreCase("submodule"))) {
537 } 530 MyOutlookPanelListItem item = new MyOutlookPanelListItem();
538 } 531 item.setIcon(getIconAttribute(subNode, "icon"));
539 catch (Exception ex) 532 item.setText(getStringAttribute(subNode, "text"));
540 { 533 item.setToolTip(getStringAttribute(subNode, "tooltip"));
541 ex.printStackTrace(); 534 item.setActionCommand(
542 } 535 getStringAttribute(subNode, "action"));
543 } 536 listItemList.add(item);
544 537 }
545 private static MyOutlookPanelListItem[] getOutlookPanelSubModules(Node moduleNode) 538 }
546 { 539 }
547 List<MyOutlookPanelListItem> listItemList = new ArrayList<MyOutlookPanelListItem>(); 540 MyOutlookPanelListItem[] items =
548 if(moduleNode != null) 541 new MyOutlookPanelListItem[listItemList.size()];
549 { 542 return listItemList.toArray(items);
550 NodeList subModules = moduleNode.getChildNodes(); 543 }
551 for (int i = 0; i < subModules.getLength(); i++) 544
552 { 545 public static void setupLookAndFeel() {
553 Node subNode = subModules.item(i); 546 //Locale.setDefault(new Locale("EN_US"));
554 if( (subNode.getNodeType() == Node.ELEMENT_NODE) && (subNode.getNodeName().equalsIgnoreCase("submodule")) ) 547 com.jgoodies.looks.plastic.PlasticTheme theme = new ExperienceGreen() {
555 { 548 public FontUIResource getControlTextFont() {
556 MyOutlookPanelListItem item = new MyOutlookPanelListItem(); 549 return new FontUIResource(new Font("微软雅黑", 0, 11));
557 item.setIcon(getIconAttribute(subNode, "icon")); 550 }
558 item.setText(getStringAttribute(subNode,"text")); 551 };
559 item.setToolTip(getStringAttribute(subNode, "tooltip")); 552 PlasticLookAndFeel.setPlasticTheme(theme);
560 item.setActionCommand(getStringAttribute(subNode, "action")); 553 try {
561 listItemList.add(item); 554 UIManager.setLookAndFeel(
562 } 555 "com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
563 } 556 } catch (Exception ex) {
564 } 557 ex.printStackTrace();
565 MyOutlookPanelListItem[] items = new MyOutlookPanelListItem[listItemList.size()]; 558 }
566 return listItemList.toArray(items); 559 UIManager.put("Menu.selectionBackground", MyContorlUtil.NO_COLOR);
567 } 560 UIManager.put("MenuItem.selectionBackground",
568 561 MyContorlUtil.MENUITEM_SELECTED_BACKGROUND);
569 public static void setupLookAndFeel() 562 // UIManager.put("PopupMenu.border", new FreePopupMenuBorder());
570 { 563 UIManager.put("ToolTip.font", MyContorlUtil.FONT_14_BOLD);
571 //Locale.setDefault(new Locale("EN_US")); 564 UIManager.put("TabbedPane.contentBorderInsets",
572 com.jgoodies.looks.plastic.PlasticTheme theme = new ExperienceGreen() 565 MyContorlUtil.ZERO_INSETS);
573 { 566 UIManager.put("TabbedPane.tabInsets", MyContorlUtil.ZERO_INSETS);
574 public FontUIResource getControlTextFont() 567 UIManager.put("TabbedPane.selectedTabPadInsets",
575 { 568 MyContorlUtil.ZERO_INSETS);
576 return new FontUIResource(new Font("微软雅黑", 0, 11)); 569 UIManager.put("TabbedPane.tabAreaInsets", MyContorlUtil.ZERO_INSETS);
577 } 570 }
578 };
579 PlasticLookAndFeel.setPlasticTheme(theme);
580 try
581 {
582 UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
583 }
584 catch (Exception ex)
585 {
586 ex.printStackTrace();
587 }
588 UIManager.put("Menu.selectionBackground", MyContorlUtil.NO_COLOR);
589 UIManager.put("MenuItem.selectionBackground",MyContorlUtil.MENUITEM_SELECTED_BACKGROUND);
590 // UIManager.put("PopupMenu.border", new FreePopupMenuBorder());
591 UIManager.put("ToolTip.font", MyContorlUtil.FONT_14_BOLD);
592 UIManager.put("TabbedPane.contentBorderInsets", MyContorlUtil.ZERO_INSETS);
593 UIManager.put("TabbedPane.tabInsets", MyContorlUtil.ZERO_INSETS);
594 UIManager.put("TabbedPane.selectedTabPadInsets", MyContorlUtil.ZERO_INSETS);
595 UIManager.put("TabbedPane.tabAreaInsets", MyContorlUtil.ZERO_INSETS);
596 }
597} 571}
diff --git a/src/cppcheckplus/control/settings.xml b/src/cppcheckplus/control/settings.xml
index 43efee0..078103a 100644
--- a/src/cppcheckplus/control/settings.xml
+++ b/src/cppcheckplus/control/settings.xml
@@ -1,6 +1,8 @@
1<?xml version="1.0" encoding="UTF-8" standalone="no"?><settings> 1<?xml version="1.0" encoding="UTF-8" standalone="no"?><settings>
2 <tool filePath="C:/Users/HP/Desktop/智能软件中心/软件测试小组/工具/苏佳/苏佳的代码-代码缺陷检测工具/cppcheck/bin/debug/cppcheck.exe" para="--enable=all" toolName="cppcheck"> 2 <tool filePath="C:/Users/we-unite/Desktop/Project/Project/code/cppcheck/bin/debug/cppcheck.exe" para="--enable=all" toolName="cppcheck">
3 </tool> 3 </tool>
4 <tool filePath="C:/Users/we-unite/Desktop/Project/Project/code/flawfinder-2.0.19/flawfinder-2.0.19/flawfinder.py" para="" toolName="flawfinder"> 4 <tool filePath="C:/Users/we-unite/Desktop/Project/Project/code/flawfinder-2.0.19/flawfinder-2.0.19/flawfinder.py" para="" toolName="flawfinder">
5 </tool> 5 </tool>
6 <tool filePath="clang-tidy.exe" para="-I C:\\Program Files\\LLVM\\lib\\clang\\17" toolName="clang-tidy">
7 </tool>
6</settings> \ No newline at end of file 8</settings> \ No newline at end of file
diff --git a/src/cppcheckplus/shortcut/MyTree.java b/src/cppcheckplus/shortcut/MyTree.java
index 74485b3..775e3a2 100644
--- a/src/cppcheckplus/shortcut/MyTree.java
+++ b/src/cppcheckplus/shortcut/MyTree.java
@@ -71,9 +71,9 @@ public class MyTree extends JPanel {
71 if(selectedNode!=null && selectedNode.isLeaf()){ 71 if(selectedNode!=null && selectedNode.isLeaf()){
72 result = ((FileObject) selectedNode.getUserObject()).file; 72 result = ((FileObject) selectedNode.getUserObject()).file;
73 jf.src = result.getAbsolutePath(); 73 jf.src = result.getAbsolutePath();
74 if (!jf.tabPanel.isSelectTabComponents("代码")) { 74 if (!jf.centerTabPanel.isSelectTabComponents("代码")) {
75 jf.tabPanel.addTab("代码", jf.testCode); 75 jf.centerTabPanel.addTab("代码", jf.testCode);
76 jf.tabPanel.isSelectTabComponents("代码"); 76 jf.centerTabPanel.isSelectTabComponents("代码");
77 } 77 }
78 textCode.setText(FileTools.readFile(result)); 78 textCode.setText(FileTools.readFile(result));
79 } 79 }
diff --git a/src/cppcheckplus/tab/MyTabPanel1.java b/src/cppcheckplus/tab/MyTabPanel1.java
index ace4d72..df3da4d 100644
--- a/src/cppcheckplus/tab/MyTabPanel1.java
+++ b/src/cppcheckplus/tab/MyTabPanel1.java
@@ -1,96 +1,92 @@
1package cppcheckplus.tab; 1package cppcheckplus.tab;
2 2
3import cppcheckplus.control.MyContorlUtil;
3import java.awt.Component; 4import java.awt.Component;
4import javax.swing.JTabbedPane; 5import javax.swing.JTabbedPane;
5import javax.swing.event.ChangeEvent; 6import javax.swing.event.ChangeEvent;
6import javax.swing.event.ChangeListener; 7import javax.swing.event.ChangeListener;
7 8
8import cppcheckplus.control.MyContorlUtil; 9public class MyTabPanel1 extends JTabbedPane {
10 private final int preferredUnselectedTabWidth;
11 private final int preferredTabHeight;
12
13 public MyTabPanel1() {
14 preferredUnselectedTabWidth = 80;
15 preferredTabHeight = MyContorlUtil.getImageIcon(
16 "control/images/tab_header_background.png").getIconHeight();
17 init();
18 }
9 19
10public class MyTabPanel1 extends JTabbedPane 20 private void init() {
11{ 21 setFont(MyContorlUtil.FONT_12_BOLD);
12 private int preferredUnselectedTabWidth; 22 setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR);
13 private int preferredTabHeight; 23 setBorder(null);
24 setFocusable(false);
25 setTabLayoutPolicy(1);
26 setOpaque(false);
27 setUI(new MyTabPanelUI1(this));
28 addChangeListener(new ChangeListener() {
29 public void stateChanged(ChangeEvent e) {
30 updateTabComponents();
31 }
32 });
33 }
14 34
15 public MyTabPanel1()
16 {
17 preferredUnselectedTabWidth = 80;
18 preferredTabHeight = MyContorlUtil.getImageIcon("control/images/tab_header_background.png").getIconHeight();
19 init();
20 }
21 35
22 private void init() 36 @Override
23 { 37 public void addTab(String title, Component component) {
24 setFont(MyContorlUtil.FONT_12_BOLD); 38 super.addTab(title, component);
25 setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); 39 int index = getTabCount() - 1;
26 setBorder(null); 40 MyTabComponent1 tabComponent = new MyTabComponent1(title, this);
27 setFocusable(false); 41 tabComponent.setTitle(title);
28 setTabLayoutPolicy(1); 42 setTabComponentAt(index, tabComponent);
29 setOpaque(false); 43 setToolTipTextAt(index, title);
30 setUI(new MyTabPanelUI1(this)); 44 updateTabComponents();
31 addChangeListener(new ChangeListener() { 45 }
32 public void stateChanged(ChangeEvent e)
33 {
34 updateTabComponents();
35 }
36 });
37 }
38 46
39 47 public boolean isSelectTabComponents(String oId) {
40 @Override 48 for (int i = 0; i < getTabCount(); i++) {
41 public void addTab(String title, Component component) 49 Component c = getTabComponentAt(i);
42 { 50 if (c instanceof MyTabComponent) {
43 super.addTab(title, component); 51 if (((MyTabComponent) c).getOId().equals(oId)) {
44 int index = getTabCount() - 1; 52 setSelectedIndex(i);
45 MyTabComponent1 tabComponent = new MyTabComponent1(title, this); 53 updateTabComponents();
46 tabComponent.setTitle(title); 54 return true;
47 setTabComponentAt(index, tabComponent); 55 }
48 setToolTipTextAt(index, title); 56 }
49 updateTabComponents(); 57 }
50 } 58 return false;
51 59 }
52 public boolean isSelectTabComponents(String oId)
53 {
54 for(int i=0;i<getTabCount();i++)
55 {
56 Component c = getTabComponentAt(i);
57 if (c instanceof MyTabComponent)
58 {
59 if(((MyTabComponent) c).getOId().equals(oId))
60 {
61 setSelectedIndex(i);
62 updateTabComponents();
63 return true;
64 }
65 }
66 }
67 return false;
68 }
69 60
70 public int getPreferredTabHeight() 61 public int getPreferredTabHeight() {
71 { 62 return preferredTabHeight;
72 return preferredTabHeight; 63 }
73 }
74 64
75 private void updateTabComponents() 65 private void updateTabComponents() {
76 { 66 int selectedIndex = getSelectedIndex();
77 int selectedIndex = getSelectedIndex(); 67 for (int i = 0; i < getTabCount(); i++) {
78 for (int i = 0; i < getTabCount(); i++) 68 Component c = getTabComponentAt(i);
79 { 69 if (c instanceof MyTabComponent) {
80 Component c = getTabComponentAt(i); 70 MyTabComponent component = (MyTabComponent) c;
81 if (c instanceof MyTabComponent) 71 boolean selected = selectedIndex == i;
82 { 72 component.updateSelection(selected);
83 MyTabComponent component = (MyTabComponent)c; 73 }
84 boolean selected = selectedIndex == i; 74 }
85 component.updateSelection(selected);
86 }
87 }
88 75
89 } 76 }
90 77
91 public int getPreferredUnselectedTabWidth() 78 public int getPreferredUnselectedTabWidth() {
92 { 79 return preferredUnselectedTabWidth;
93 return preferredUnselectedTabWidth; 80 }
94 }
95 81
82 public boolean selectTabByOId(String oId) {
83 for (int i = 0; i < getTabCount(); i++) {
84 if (getTitleAt(i).equals(oId)) {
85 setSelectedIndex(i);
86 updateTabComponents();
87 return true;
88 }
89 }
90 return false;
91 }
96} 92}
diff --git a/src/cppcheckplus/text/MyTextPanel1.java b/src/cppcheckplus/text/MyTextPanel1.java
index 4a70ce5..fb07c7d 100644
--- a/src/cppcheckplus/text/MyTextPanel1.java
+++ b/src/cppcheckplus/text/MyTextPanel1.java
@@ -2,7 +2,7 @@ package cppcheckplus.text;
2 2
3import java.awt.BorderLayout; 3import java.awt.BorderLayout;
4import java.awt.TextArea; 4import java.awt.TextArea;
5 5import java.awt.Font;
6import javax.swing.JPanel; 6import javax.swing.JPanel;
7 7
8import cppcheckplus.control.XChartletFullScreenListenter; 8import cppcheckplus.control.XChartletFullScreenListenter;
@@ -26,7 +26,8 @@ public class MyTextPanel1 extends JPanel implements XChartletFullScreenListenter
26 { 26 {
27 layout = new BorderLayout(); 27 layout = new BorderLayout();
28 setLayout(layout); 28 setLayout(layout);
29 textArea=new TextArea(""); 29 textArea=new TextArea("");
30 textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
30 31
31 add(textArea); 32 add(textArea);
32 } 33 }