summaryrefslogtreecommitdiffstats
path: root/src/cppcheckplus/control/MyContorlUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppcheckplus/control/MyContorlUtil.java')
-rw-r--r--src/cppcheckplus/control/MyContorlUtil.java1076
1 files changed, 525 insertions, 551 deletions
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}