diff options
Diffstat (limited to 'src/cppcheckplus/control/MyContorlUtil.java')
-rw-r--r-- | src/cppcheckplus/control/MyContorlUtil.java | 132 |
1 files changed, 77 insertions, 55 deletions
diff --git a/src/cppcheckplus/control/MyContorlUtil.java b/src/cppcheckplus/control/MyContorlUtil.java index a43d570..e7e3d07 100644 --- a/src/cppcheckplus/control/MyContorlUtil.java +++ b/src/cppcheckplus/control/MyContorlUtil.java | |||
@@ -35,6 +35,7 @@ import javax.swing.Icon; | |||
35 | import javax.swing.ImageIcon; | 35 | import javax.swing.ImageIcon; |
36 | import javax.swing.JLabel; | 36 | import javax.swing.JLabel; |
37 | import javax.swing.JMenuItem; | 37 | import javax.swing.JMenuItem; |
38 | import javax.swing.JOptionPane; | ||
38 | import javax.swing.UIManager; | 39 | import javax.swing.UIManager; |
39 | import javax.swing.plaf.FontUIResource; | 40 | import javax.swing.plaf.FontUIResource; |
40 | import javax.xml.parsers.DocumentBuilder; | 41 | import javax.xml.parsers.DocumentBuilder; |
@@ -47,6 +48,7 @@ import org.w3c.dom.Document; | |||
47 | import org.w3c.dom.Element; | 48 | import org.w3c.dom.Element; |
48 | import org.w3c.dom.Node; | 49 | import org.w3c.dom.Node; |
49 | import org.w3c.dom.NodeList; | 50 | import org.w3c.dom.NodeList; |
51 | import toolsconfig.ToolsConfig; | ||
50 | import toolsconfig.ToolsRegistry; | 52 | import toolsconfig.ToolsRegistry; |
51 | 53 | ||
52 | 54 | ||
@@ -270,38 +272,43 @@ public class MyContorlUtil { | |||
270 | public static MyMenuBar loadMenuBar(String xml, ActionListener action) { | 272 | public static MyMenuBar loadMenuBar(String xml, ActionListener action) { |
271 | MyMenuBar menuBar = null; | 273 | MyMenuBar menuBar = null; |
272 | try { | 274 | try { |
275 | // 初始化XML解析器 | ||
273 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | 276 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
274 | DocumentBuilder db = dbf.newDocumentBuilder(); | 277 | DocumentBuilder db = dbf.newDocumentBuilder(); |
278 | // 解析XML文件 | ||
275 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | 279 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); |
276 | Element root = doc.getDocumentElement(); | 280 | Element root = doc.getDocumentElement(); |
277 | NodeList rootMenus = root.getChildNodes(); | 281 | NodeList rootMenus = root.getChildNodes(); |
278 | if (rootMenus != null) { | 282 | if (rootMenus == null) { |
279 | menuBar = new MyMenuBar(); | 283 | return null; |
280 | for (int i = 0; i < rootMenus.getLength(); i++) { | 284 | } |
281 | org.w3c.dom.Node menu = rootMenus.item(i); | 285 | |
282 | if (menu.getNodeType() == Node.ELEMENT_NODE) { | 286 | menuBar = new MyMenuBar(); |
283 | if (menu.getNodeName().equalsIgnoreCase("menu")) { | 287 | // 遍历 |
284 | String text = | 288 | for (int i = 0; i < rootMenus.getLength(); i++) { |
285 | MyContorlUtil.getStringAttribute(menu, "text"); | 289 | org.w3c.dom.Node menu = rootMenus.item(i); |
286 | MyRootMenu rootMenu = new MyRootMenu(); | 290 | if (menu.getNodeType() == Node.ELEMENT_NODE) { |
287 | rootMenu.setText(text); | 291 | if (menu.getNodeName().equalsIgnoreCase("menu")) { |
288 | menuBar.add(rootMenu); | 292 | // 菜单一级节点 |
289 | processMenuItem(menu, rootMenu, action); | 293 | String text = |
290 | } | 294 | MyContorlUtil.getStringAttribute(menu, "text"); |
291 | if (menu.getNodeName().equalsIgnoreCase("logo")) { | 295 | MyRootMenu rootMenu = new MyRootMenu(); |
292 | String tooltip = | 296 | rootMenu.setText(text); // 以text作为菜单名 |
293 | MyContorlUtil.getStringAttribute(menu, | 297 | menuBar.add(rootMenu); |
294 | "tooltip"); | 298 | processMenuItem(menu, rootMenu, action); |
295 | String imageURL = | 299 | } else if (menu.getNodeName().equalsIgnoreCase("logo")) { |
296 | MyContorlUtil.getStringAttribute(menu, "image"); | 300 | // 总菜单栏的logo |
297 | menuBar.add(Box.createGlue()); | 301 | String tooltip = |
298 | JLabel label = new JLabel( | 302 | MyContorlUtil.getStringAttribute(menu, "tooltip"); |
299 | MyContorlUtil.getImageIcon(imageURL)); | 303 | String imageURL = |
300 | label.setBorder( | 304 | MyContorlUtil.getStringAttribute(menu, "image"); |
301 | BorderFactory.createEmptyBorder(0, 5, 0, 5)); | 305 | menuBar.add(Box.createGlue()); |
302 | label.setToolTipText(tooltip); | 306 | JLabel label = |
303 | menuBar.add(label); | 307 | new JLabel(MyContorlUtil.getImageIcon(imageURL)); |
304 | } | 308 | label.setBorder( |
309 | BorderFactory.createEmptyBorder(0, 5, 0, 5)); | ||
310 | label.setToolTipText(tooltip); | ||
311 | menuBar.add(label); | ||
305 | } | 312 | } |
306 | } | 313 | } |
307 | } | 314 | } |
@@ -366,44 +373,59 @@ public class MyContorlUtil { | |||
366 | } catch (Exception ex) { | 373 | } catch (Exception ex) { |
367 | ex.printStackTrace(); | 374 | ex.printStackTrace(); |
368 | } | 375 | } |
369 | |||
370 | } | 376 | } |
371 | 377 | ||
372 | public static void loadToolsRoad(String xml, UIFrame main) { | 378 | public static void loadToolsRoad(String xml, UIFrame ui, |
379 | ActionListener action) { | ||
373 | try { | 380 | try { |
374 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | 381 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
375 | DocumentBuilder db = dbf.newDocumentBuilder(); | 382 | DocumentBuilder db = dbf.newDocumentBuilder(); |
376 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | 383 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); |
377 | Element root = doc.getDocumentElement(); | 384 | Element root = doc.getDocumentElement(); |
378 | NodeList tools = root.getChildNodes(); | 385 | NodeList tools = root.getChildNodes(); |
379 | if (tools != null) { | 386 | |
380 | for (int i = 0; i < tools.getLength(); i++) { | 387 | MyRootMenu checkBar = new MyRootMenu(); |
381 | org.w3c.dom.Node menu = tools.item(i); | 388 | String toolName, filePath, para; |
382 | if (menu.getNodeType() == Node.ELEMENT_NODE) { | 389 | MyMenuItem menuItem; |
383 | if (menu.getNodeName().equalsIgnoreCase("tool")) { | 390 | if (tools == null) { |
384 | String toolName = | 391 | // 弹窗提示 |
385 | MyContorlUtil.getStringAttribute(menu, | 392 | JOptionPane.showMessageDialog(null, "Error: 工具配置文件未找到", |
386 | "toolName"); | 393 | "提示", 2); |
387 | String filePath = | 394 | return; |
388 | MyContorlUtil.getStringAttribute(menu, | 395 | } |
389 | "filePath"); | 396 | for (int i = 0; i < tools.getLength(); i++) { |
390 | String para = | 397 | org.w3c.dom.Node menu = tools.item(i); |
391 | MyContorlUtil.getStringAttribute(menu, "para"); | 398 | if (menu.getNodeType() != Node.ELEMENT_NODE || |
392 | 399 | !menu.getNodeName().equalsIgnoreCase("tool")) { | |
393 | try { | 400 | continue; |
394 | Class<?> clazz = | 401 | } |
395 | Class.forName("toolsconfig." + toolName); | 402 | toolName = MyContorlUtil.getStringAttribute(menu, "toolName"); |
396 | Object obj = clazz.getDeclaredConstructor() | 403 | filePath = MyContorlUtil.getStringAttribute(menu, "filePath"); |
397 | .newInstance(); | 404 | para = MyContorlUtil.getStringAttribute(menu, "para"); |
398 | ToolsRegistry.getTool(toolName) | 405 | |
399 | .init(filePath, para, main); | 406 | ToolsConfig tool = ToolsRegistry.getTool(toolName); |
400 | } catch (Exception e) { | 407 | if (tool != null) { |
401 | e.printStackTrace(); | 408 | tool.init(filePath, para, ui); |
402 | } | 409 | continue; |
403 | } | ||
404 | } | ||
405 | } | 410 | } |
411 | try { | ||
412 | Class<?> clazz = Class.forName("toolsconfig." + toolName); | ||
413 | Object obj = clazz.getDeclaredConstructor().newInstance(); | ||
414 | ToolsRegistry.getTool(toolName).init(filePath, para, ui); | ||
415 | } catch (Exception e) { | ||
416 | e.printStackTrace(); | ||
417 | } | ||
418 | menuItem = new MyMenuItem(); | ||
419 | menuItem.setText(toolName); | ||
420 | menuItem.setToolTipText(toolName); | ||
421 | menuItem.setActionCommand(toolName); | ||
422 | |||
423 | menuItem.addActionListener(action); | ||
424 | checkBar.add(menuItem); | ||
406 | } | 425 | } |
426 | |||
427 | checkBar.setText("检测工具"); | ||
428 | ui.mymenubar.add(checkBar, 1); | ||
407 | } catch (Exception ex) { | 429 | } catch (Exception ex) { |
408 | ex.printStackTrace(); | 430 | ex.printStackTrace(); |
409 | } | 431 | } |