diff options
author | 2025-02-19 13:45:27 +0800 | |
---|---|---|
committer | 2025-02-19 13:45:27 +0800 | |
commit | eaba1ffa193104f90751371bfa9814552a2a6243 (patch) | |
tree | 07fbb22993b79dcbf8e1dd4521918e50523e1315 | |
download | project-eaba1ffa193104f90751371bfa9814552a2a6243.tar.gz project-eaba1ffa193104f90751371bfa9814552a2a6243.zip |
Init
175 files changed, 6966 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6b8a8b --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,8 @@ | |||
1 | .idea/* | ||
2 | bin/ | ||
3 | web/ | ||
4 | .classpath | ||
5 | .project | ||
6 | .settings/ | ||
7 | target/ | ||
8 | *.iml | ||
diff --git a/lib/TableLayout.jar b/lib/TableLayout.jar new file mode 100644 index 0000000..23519b0 --- /dev/null +++ b/lib/TableLayout.jar | |||
Binary files differ | |||
diff --git a/lib/dom4j-2.0.3.jar b/lib/dom4j-2.0.3.jar new file mode 100644 index 0000000..1ef5c52 --- /dev/null +++ b/lib/dom4j-2.0.3.jar | |||
Binary files differ | |||
diff --git a/lib/example/GridBagVersusTable$1.class b/lib/example/GridBagVersusTable$1.class new file mode 100644 index 0000000..78bc1c2 --- /dev/null +++ b/lib/example/GridBagVersusTable$1.class | |||
Binary files differ | |||
diff --git a/lib/example/GridBagVersusTable.class b/lib/example/GridBagVersusTable.class new file mode 100644 index 0000000..52ee8f7 --- /dev/null +++ b/lib/example/GridBagVersusTable.class | |||
Binary files differ | |||
diff --git a/lib/example/GridBagVersusTable.java b/lib/example/GridBagVersusTable.java new file mode 100644 index 0000000..53e45d6 --- /dev/null +++ b/lib/example/GridBagVersusTable.java | |||
@@ -0,0 +1,140 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import javax.swing.JButton; | ||
8 | import layout.TableLayout; | ||
9 | import layout.TableLayoutConstraints; | ||
10 | |||
11 | |||
12 | |||
13 | public class GridBagVersusTable | ||
14 | { | ||
15 | |||
16 | |||
17 | |||
18 | protected static void makeButton | ||
19 | (Frame frame, String name, GridBagLayout gridbag, GridBagConstraints c) | ||
20 | { | ||
21 | JButton button = new JButton(name); | ||
22 | gridbag.setConstraints(button, c); | ||
23 | frame.add(button); | ||
24 | } | ||
25 | |||
26 | |||
27 | |||
28 | protected static Frame showGridBagWindow () | ||
29 | { | ||
30 | // Create layout and contraints object | ||
31 | GridBagLayout gridbag = new GridBagLayout(); | ||
32 | GridBagConstraints c = new GridBagConstraints(); | ||
33 | |||
34 | // Create frame | ||
35 | Frame frame = new Frame("GridBagLayout"); | ||
36 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | ||
37 | frame.setLayout (gridbag); | ||
38 | |||
39 | // Create buttons, add buttons, and apply constraints | ||
40 | c.fill = GridBagConstraints.BOTH; | ||
41 | c.weightx = 1.0; | ||
42 | makeButton (frame, "Button1", gridbag, c); | ||
43 | makeButton (frame, "Button2", gridbag, c); | ||
44 | makeButton (frame, "Button3", gridbag, c); | ||
45 | |||
46 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row | ||
47 | makeButton (frame, "Button4", gridbag, c); | ||
48 | |||
49 | c.weightx = 0.0; //reset to the default | ||
50 | makeButton (frame, "Button5", gridbag, c); //another row | ||
51 | |||
52 | c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row | ||
53 | makeButton (frame, "Button6", gridbag, c); | ||
54 | |||
55 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row | ||
56 | makeButton (frame, "Button7", gridbag, c); | ||
57 | |||
58 | c.gridwidth = 1; //reset to the default | ||
59 | c.gridheight = 2; | ||
60 | c.weighty = 1.0; | ||
61 | makeButton (frame, "Button8", gridbag, c); | ||
62 | |||
63 | c.weighty = 0.0; //reset to the default | ||
64 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row | ||
65 | c.gridheight = 1; //reset to the default | ||
66 | makeButton (frame, "Button9", gridbag, c); | ||
67 | makeButton (frame, "Button10", gridbag, c); | ||
68 | |||
69 | // Show frame | ||
70 | frame.pack(); | ||
71 | frame.setLocation (0, 10); | ||
72 | frame.show(); | ||
73 | |||
74 | return frame; | ||
75 | } | ||
76 | |||
77 | |||
78 | |||
79 | protected static Frame showTableWindow () | ||
80 | { | ||
81 | // Create frame | ||
82 | Frame frame = new Frame("TableLayout"); | ||
83 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); | ||
84 | |||
85 | // Set layout | ||
86 | double f = TableLayout.FILL; | ||
87 | double p = TableLayout.PREFERRED; | ||
88 | double size[][] = {{f, f, f, f}, {p, p, p, p, f}}; | ||
89 | |||
90 | TableLayout layout = new TableLayout(size); | ||
91 | frame.setLayout (layout); | ||
92 | |||
93 | // Create buttons labeled Button1 to Button10 | ||
94 | int numButton = 10; | ||
95 | JButton button[] = new JButton[numButton + 1]; | ||
96 | |||
97 | for (int i = 1; i <= numButton; i++) | ||
98 | button[i] = new JButton("Button" + i); | ||
99 | |||
100 | // Add buttons | ||
101 | frame.add (button[1], "0, 0"); | ||
102 | frame.add (button[2], "1, 0"); | ||
103 | frame.add (button[3], "2, 0"); | ||
104 | frame.add (button[4], "3, 0"); | ||
105 | frame.add (button[5], "0, 1, 3, 1"); | ||
106 | frame.add (button[6], "0, 2, 2, 2"); | ||
107 | frame.add (button[7], "3, 2, 3, 2"); | ||
108 | frame.add (button[8], "0, 3, 0, 4"); | ||
109 | frame.add (button[9], "1, 3, 3, 3"); | ||
110 | frame.add (button[10], "1, 4, 3, 4"); | ||
111 | |||
112 | // Show frame | ||
113 | frame.pack(); | ||
114 | frame.setLocation (400, 10); | ||
115 | frame.show(); | ||
116 | |||
117 | return frame; | ||
118 | } | ||
119 | |||
120 | |||
121 | |||
122 | public static void main (String args[]) | ||
123 | { | ||
124 | WindowListener listener = | ||
125 | (new WindowAdapter() | ||
126 | { | ||
127 | public void windowClosing (WindowEvent e) | ||
128 | { | ||
129 | System.exit (0); | ||
130 | } | ||
131 | } | ||
132 | ); | ||
133 | |||
134 | Frame frame = showGridBagWindow(); | ||
135 | frame.addWindowListener (listener); | ||
136 | |||
137 | frame = showTableWindow(); | ||
138 | frame.addWindowListener (listener); | ||
139 | } | ||
140 | } | ||
diff --git a/lib/example/GridVersusTable$1.class b/lib/example/GridVersusTable$1.class new file mode 100644 index 0000000..0acce1a --- /dev/null +++ b/lib/example/GridVersusTable$1.class | |||
Binary files differ | |||
diff --git a/lib/example/GridVersusTable.class b/lib/example/GridVersusTable.class new file mode 100644 index 0000000..ea2dbbe --- /dev/null +++ b/lib/example/GridVersusTable.class | |||
Binary files differ | |||
diff --git a/lib/example/GridVersusTable.java b/lib/example/GridVersusTable.java new file mode 100644 index 0000000..c5746c4 --- /dev/null +++ b/lib/example/GridVersusTable.java | |||
@@ -0,0 +1,112 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import javax.swing.JButton; | ||
8 | import layout.TableLayout; | ||
9 | |||
10 | |||
11 | |||
12 | public class GridVersusTable { | ||
13 | |||
14 | |||
15 | |||
16 | protected static Frame showGridWindow () | ||
17 | { | ||
18 | // Create frame | ||
19 | Frame frame = new Frame("GridLayout"); | ||
20 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | ||
21 | frame.setLayout (new GridLayout(2, 0)); | ||
22 | |||
23 | // Create and add buttons | ||
24 | frame.add (new JButton("One")); | ||
25 | frame.add (new JButton("Two")); | ||
26 | frame.add (new JButton("Three")); | ||
27 | frame.add (new JButton("Four")); | ||
28 | |||
29 | // Show frame | ||
30 | frame.pack(); | ||
31 | frame.setLocation (0, 10); | ||
32 | frame.show(); | ||
33 | |||
34 | return frame; | ||
35 | } | ||
36 | |||
37 | |||
38 | |||
39 | protected static Frame showTableWindow () | ||
40 | { | ||
41 | // Create frame | ||
42 | Frame frame = new Frame("TableLayout"); | ||
43 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | ||
44 | |||
45 | // Set layout | ||
46 | double f = TableLayout.FILL; | ||
47 | double size[][] = {{f, f}, {f, f}}; | ||
48 | frame.setLayout (new TableLayout(size)); | ||
49 | |||
50 | // Create and add buttons | ||
51 | frame.add (new JButton("One"), "0, 0"); | ||
52 | frame.add (new JButton("Two"), "1, 0"); | ||
53 | frame.add (new JButton("Three"), "0, 1"); | ||
54 | frame.add (new JButton("Four"), "1, 1"); | ||
55 | |||
56 | // Show frame | ||
57 | frame.pack(); | ||
58 | frame.setLocation (200, 10); | ||
59 | frame.show(); | ||
60 | |||
61 | return frame; | ||
62 | } | ||
63 | |||
64 | |||
65 | |||
66 | protected static Frame showTableWindow2 () | ||
67 | { | ||
68 | // Create frame | ||
69 | Frame frame = new Frame("TableLayout"); | ||
70 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | ||
71 | |||
72 | // Set layout | ||
73 | double f = TableLayout.FILL; | ||
74 | double size[][] = {{f, f}, {f, f}}; | ||
75 | frame.setLayout (new TableLayout(size)); | ||
76 | |||
77 | // Create and add buttons | ||
78 | frame.add (new JButton("One"), "0, 0"); | ||
79 | frame.add (new JButton("Two"), "1, 1"); | ||
80 | |||
81 | // Show frame | ||
82 | frame.pack(); | ||
83 | frame.setLocation (400, 10); | ||
84 | frame.show(); | ||
85 | |||
86 | return frame; | ||
87 | } | ||
88 | |||
89 | |||
90 | |||
91 | public static void main (String args[]) | ||
92 | { | ||
93 | WindowListener listener = | ||
94 | (new WindowAdapter() | ||
95 | { | ||
96 | public void windowClosing (WindowEvent e) | ||
97 | { | ||
98 | System.exit (0); | ||
99 | } | ||
100 | } | ||
101 | ); | ||
102 | |||
103 | Frame frame = showGridWindow(); | ||
104 | frame.addWindowListener(listener); | ||
105 | |||
106 | frame = showTableWindow(); | ||
107 | frame.addWindowListener(listener); | ||
108 | |||
109 | frame = showTableWindow2(); | ||
110 | frame.addWindowListener(listener); | ||
111 | } | ||
112 | } | ||
diff --git a/lib/example/MyClass$1.class b/lib/example/MyClass$1.class new file mode 100644 index 0000000..d221d3f --- /dev/null +++ b/lib/example/MyClass$1.class | |||
Binary files differ | |||
diff --git a/lib/example/MyClass.class b/lib/example/MyClass.class new file mode 100644 index 0000000..0ff16c4 --- /dev/null +++ b/lib/example/MyClass.class | |||
Binary files differ | |||
diff --git a/lib/example/MyClass.java b/lib/example/MyClass.java new file mode 100644 index 0000000..632e99a --- /dev/null +++ b/lib/example/MyClass.java | |||
@@ -0,0 +1,49 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import layout.TableLayout; | ||
8 | |||
9 | public class MyClass | ||
10 | { | ||
11 | |||
12 | public static void main (String args[]) | ||
13 | { | ||
14 | Frame frame = new Frame("MyTitle"); | ||
15 | frame.setBounds (100, 100, 300, 300); | ||
16 | |||
17 | double size[][] = | ||
18 | {{-2.0, 10.0, 50.0, -1.0, 10.0}, // Columns | ||
19 | {-2.0, 10.0, 0.25, -1.0, 10.0}}; // Rows | ||
20 | |||
21 | frame.setLayout (new TableLayout(size)); | ||
22 | |||
23 | Button button; | ||
24 | button = new Button("3, 3, R, C"); | ||
25 | frame.add (button, "3, 3, R, C"); | ||
26 | button = new Button("3, 3, L, T"); | ||
27 | frame.add (button, "3, 3, L, T"); | ||
28 | button = new Button("2, 3, C, T"); | ||
29 | frame.add (button, "2, 3, C, T"); | ||
30 | button = new Button("3, 2, L, C"); | ||
31 | frame.add (button, "3, 2, L, C"); | ||
32 | button = new Button("2, 2, F, F"); | ||
33 | frame.add (button, "2, 2, F, F"); | ||
34 | button = new Button("3, 3, C, C"); | ||
35 | frame.add (button, "3, 3, C, C"); | ||
36 | |||
37 | frame.addWindowListener | ||
38 | (new WindowAdapter() | ||
39 | { | ||
40 | public void windowClosing (WindowEvent e) | ||
41 | { | ||
42 | System.exit (0); | ||
43 | } | ||
44 | } | ||
45 | ); | ||
46 | |||
47 | frame.show(); | ||
48 | } | ||
49 | } | ||
diff --git a/lib/example/Preferred$1.class b/lib/example/Preferred$1.class new file mode 100644 index 0000000..2501341 --- /dev/null +++ b/lib/example/Preferred$1.class | |||
Binary files differ | |||
diff --git a/lib/example/Preferred.class b/lib/example/Preferred.class new file mode 100644 index 0000000..221d384 --- /dev/null +++ b/lib/example/Preferred.class | |||
Binary files differ | |||
diff --git a/lib/example/Preferred.java b/lib/example/Preferred.java new file mode 100644 index 0000000..aa1e8a6 --- /dev/null +++ b/lib/example/Preferred.java | |||
@@ -0,0 +1,106 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import javax.swing.*; | ||
8 | import layout.TableLayout; | ||
9 | |||
10 | |||
11 | |||
12 | public class Preferred extends JFrame | ||
13 | { | ||
14 | |||
15 | |||
16 | |||
17 | public static void main (String args[]) | ||
18 | { | ||
19 | new Preferred(); | ||
20 | } | ||
21 | |||
22 | |||
23 | |||
24 | public Preferred () | ||
25 | { | ||
26 | super ("The Power of Preferred Sizes"); | ||
27 | |||
28 | Container pane = getContentPane(); | ||
29 | |||
30 | // b - border | ||
31 | // f - FILL | ||
32 | // p - PREFERRED | ||
33 | // vs - vertical space between labels and text fields | ||
34 | // vg - vertical gap between form elements | ||
35 | // hg - horizontal gap between form elements | ||
36 | |||
37 | double b = 10; | ||
38 | double f = TableLayout.FILL; | ||
39 | double p = TableLayout.PREFERRED; | ||
40 | double vs = 5; | ||
41 | double vg = 10; | ||
42 | double hg = 10; | ||
43 | |||
44 | double size[][] = | ||
45 | {{b, f, hg, p, hg, p, b}, | ||
46 | {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; | ||
47 | |||
48 | TableLayout layout = new TableLayout(size); | ||
49 | pane.setLayout (layout); | ||
50 | |||
51 | // Create all controls | ||
52 | JLabel labelName = new JLabel("Name"); | ||
53 | JLabel labelAddress = new JLabel("Address"); | ||
54 | JLabel labelCity = new JLabel("City"); | ||
55 | JLabel labelState = new JLabel("State"); | ||
56 | JLabel labelZip = new JLabel("Zip"); | ||
57 | |||
58 | JTextField textfieldName = new JTextField(10); | ||
59 | JTextField textfieldAddress = new JTextField(20); | ||
60 | JTextField textfieldCity = new JTextField(10); | ||
61 | JTextField textfieldState = new JTextField(2); | ||
62 | JTextField textfieldZip = new JTextField(5); | ||
63 | |||
64 | JButton buttonOk = new JButton("OK"); | ||
65 | JButton buttonCancel = new JButton("Cancel"); | ||
66 | JPanel panelButton = new JPanel(); | ||
67 | panelButton.add (buttonOk); | ||
68 | panelButton.add (buttonCancel); | ||
69 | |||
70 | // Add all controls | ||
71 | pane.add (labelName, "1, 1, 5, 1"); | ||
72 | pane.add (textfieldName, "1, 3, 5, 3"); | ||
73 | pane.add (labelAddress, "1, 5, 5, 5"); | ||
74 | pane.add (textfieldAddress, "1, 7, 5, 7"); | ||
75 | pane.add (labelCity, "1, 9"); | ||
76 | pane.add (textfieldCity, "1, 11"); | ||
77 | pane.add (labelState, "3, 9"); | ||
78 | pane.add (textfieldState, "3, 11"); | ||
79 | pane.add (labelZip, "5, 9"); | ||
80 | pane.add (textfieldZip, "5, 11"); | ||
81 | pane.add (panelButton, "1, 13, 5, 13"); | ||
82 | |||
83 | allowClosing(); | ||
84 | pack(); | ||
85 | setResizable (false); | ||
86 | show(); | ||
87 | } | ||
88 | |||
89 | |||
90 | |||
91 | public void allowClosing () | ||
92 | { | ||
93 | addWindowListener | ||
94 | (new WindowAdapter() | ||
95 | { | ||
96 | public void windowClosing (WindowEvent e) | ||
97 | { | ||
98 | System.exit (0); | ||
99 | } | ||
100 | } | ||
101 | ); | ||
102 | } | ||
103 | |||
104 | |||
105 | |||
106 | } | ||
diff --git a/lib/example/RadTool$1.class b/lib/example/RadTool$1.class new file mode 100644 index 0000000..5701874 --- /dev/null +++ b/lib/example/RadTool$1.class | |||
Binary files differ | |||
diff --git a/lib/example/RadTool$Box.class b/lib/example/RadTool$Box.class new file mode 100644 index 0000000..4ca3197 --- /dev/null +++ b/lib/example/RadTool$Box.class | |||
Binary files differ | |||
diff --git a/lib/example/RadTool$Smiley.class b/lib/example/RadTool$Smiley.class new file mode 100644 index 0000000..2796ed6 --- /dev/null +++ b/lib/example/RadTool$Smiley.class | |||
Binary files differ | |||
diff --git a/lib/example/RadTool.class b/lib/example/RadTool.class new file mode 100644 index 0000000..cc59d1f --- /dev/null +++ b/lib/example/RadTool.class | |||
Binary files differ | |||
diff --git a/lib/example/RadTool.java b/lib/example/RadTool.java new file mode 100644 index 0000000..8ef0c55 --- /dev/null +++ b/lib/example/RadTool.java | |||
@@ -0,0 +1,647 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import java.util.*; | ||
8 | import javax.swing.*; | ||
9 | import layout.TableLayout; | ||
10 | import layout.TableLayoutConstraints; | ||
11 | import support.GeneralDialog; | ||
12 | |||
13 | |||
14 | |||
15 | public class RadTool extends Frame implements ActionListener | ||
16 | { | ||
17 | |||
18 | |||
19 | |||
20 | private JTextField textfieldColumnNumber; | ||
21 | private JTextField textfieldColumnSize; | ||
22 | private JTextField textfieldRowNumber; | ||
23 | private JTextField textfieldRowSize; | ||
24 | private JButton buttonAddColumn; | ||
25 | private JButton buttonRemoveColumn; | ||
26 | private JButton buttonResizeColumn; | ||
27 | private JButton buttonAddRow; | ||
28 | private JButton buttonRemoveRow; | ||
29 | private JButton buttonResizeRow; | ||
30 | private JButton buttonShowLayout; | ||
31 | private JButton buttonGenerateCode; | ||
32 | private TextArea textArea; | ||
33 | private JPanel panel; | ||
34 | private TableLayout layout; | ||
35 | private ArrayList columnHeader; | ||
36 | private ArrayList rowHeader; | ||
37 | private ArrayList boxList; | ||
38 | |||
39 | |||
40 | |||
41 | public static void main (String args[]) | ||
42 | { | ||
43 | new RadTool(); | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /** | ||
49 | * Constructs the user interface. | ||
50 | */ | ||
51 | |||
52 | public RadTool() | ||
53 | { | ||
54 | // Create frame | ||
55 | super("Example of Dynamic Rows and Columns"); | ||
56 | |||
57 | // Create a TableLayout for the frame | ||
58 | double b = 10; | ||
59 | double s = 5; | ||
60 | double f = TableLayout.FILL; | ||
61 | double p = TableLayout.PREFERRED; | ||
62 | double size[][] = | ||
63 | {{b, p, s, p, s, p, s, p, s, p, s, p, s, p, f, b}, | ||
64 | {f, s, p, s, p, s, 100, s, p, b}}; | ||
65 | |||
66 | setLayout (new TableLayout(size)); | ||
67 | |||
68 | // Create static controls | ||
69 | JLabel labelColumn = new JLabel("Column"); | ||
70 | JLabel labelColumnSize = new JLabel("Size"); | ||
71 | textfieldColumnNumber = new JTextField(2); | ||
72 | textfieldColumnSize = new JTextField(2); | ||
73 | buttonAddColumn = new JButton("Add"); | ||
74 | buttonRemoveColumn = new JButton("Remove"); | ||
75 | buttonResizeColumn = new JButton("Resize"); | ||
76 | |||
77 | JLabel labelRow = new JLabel("Row"); | ||
78 | JLabel labelRowSize = new JLabel("Size"); | ||
79 | textfieldRowNumber = new JTextField(2); | ||
80 | textfieldRowSize = new JTextField(5); | ||
81 | buttonAddRow = new JButton("Add"); | ||
82 | buttonRemoveRow = new JButton("Remove"); | ||
83 | buttonResizeRow = new JButton("Resize"); | ||
84 | |||
85 | textArea = new TextArea(); | ||
86 | columnHeader = new ArrayList(); | ||
87 | rowHeader = new ArrayList(); | ||
88 | boxList = new ArrayList(); | ||
89 | buttonShowLayout = new JButton("Show Layout"); | ||
90 | buttonGenerateCode = new JButton("Generate Code"); | ||
91 | |||
92 | // Add static controls | ||
93 | add (labelColumn, " 1, 2"); | ||
94 | add (textfieldColumnNumber, " 3, 2"); | ||
95 | add (labelColumnSize, " 5, 2"); | ||
96 | add (textfieldColumnSize, " 7, 2"); | ||
97 | add (buttonAddColumn, " 9, 2"); | ||
98 | add (buttonRemoveColumn, "11, 2"); | ||
99 | add (buttonResizeColumn, "13, 2"); | ||
100 | |||
101 | add (labelRow, " 1, 4"); | ||
102 | add (textfieldRowNumber, " 3, 4"); | ||
103 | add (labelRowSize, " 5, 4"); | ||
104 | add (textfieldRowSize, " 7, 4"); | ||
105 | add (buttonAddRow, " 9, 4"); | ||
106 | add (buttonRemoveRow, "11, 4"); | ||
107 | add (buttonResizeRow, "13, 4"); | ||
108 | |||
109 | add (textArea, "1, 6, 14, 6"); | ||
110 | add (buttonShowLayout, "1, 8, 7, 6"); | ||
111 | add (buttonGenerateCode, "9, 8, 12, 8"); | ||
112 | |||
113 | // Listen for button events | ||
114 | buttonAddColumn.addActionListener (this); | ||
115 | buttonRemoveColumn.addActionListener (this); | ||
116 | buttonResizeColumn.addActionListener (this); | ||
117 | buttonAddRow.addActionListener (this); | ||
118 | buttonRemoveRow.addActionListener (this); | ||
119 | buttonResizeRow.addActionListener (this); | ||
120 | buttonShowLayout.addActionListener (this); | ||
121 | buttonGenerateCode.addActionListener (this); | ||
122 | |||
123 | // Add a panel for RadTool controls | ||
124 | panel = new JPanel(); | ||
125 | panel.setBackground (Color.white); | ||
126 | add (panel, "0, 0, 15, 0"); | ||
127 | |||
128 | // Create the layout manager for the panel | ||
129 | double size2[][] = {{p, -1}, {p, -1}}; | ||
130 | layout = new TableLayout(size2); | ||
131 | panel.setLayout (layout); | ||
132 | updateHeader(); | ||
133 | updateBox(); | ||
134 | |||
135 | // Allow user to close the window to terminate the program | ||
136 | addWindowListener | ||
137 | (new WindowAdapter() | ||
138 | { | ||
139 | public void windowClosing (WindowEvent e) | ||
140 | { | ||
141 | System.exit (0); | ||
142 | } | ||
143 | } | ||
144 | ); | ||
145 | |||
146 | // Show frame | ||
147 | setBackground (Color.lightGray); | ||
148 | setBounds (100, 100, 500, 400); | ||
149 | show(); | ||
150 | } | ||
151 | |||
152 | |||
153 | |||
154 | /** | ||
155 | * Handles all action events. | ||
156 | */ | ||
157 | |||
158 | public void actionPerformed (ActionEvent e) | ||
159 | { | ||
160 | // Get row and column information from text fields | ||
161 | int row = getInt(textfieldRowNumber); | ||
162 | int col = getInt(textfieldColumnNumber); | ||
163 | double rowSize = getDouble(textfieldRowSize); | ||
164 | double colSize = getDouble(textfieldColumnSize); | ||
165 | |||
166 | // Get source of the event | ||
167 | Object source = e.getSource(); | ||
168 | |||
169 | try | ||
170 | { | ||
171 | // Update layout | ||
172 | if (source == buttonAddColumn) | ||
173 | layout.insertColumn (col, colSize); | ||
174 | else if (source == buttonRemoveColumn) | ||
175 | layout.deleteColumn (col); | ||
176 | else if (source == buttonResizeColumn) | ||
177 | layout.setColumn (col, colSize); | ||
178 | else if (source == buttonAddRow) | ||
179 | layout.insertRow (row, rowSize); | ||
180 | else if (source == buttonRemoveRow) | ||
181 | layout.deleteRow (row); | ||
182 | else if (source == buttonResizeRow) | ||
183 | layout.setRow (row, rowSize); | ||
184 | |||
185 | // Update headers, etc. to reflect layout's change | ||
186 | updateHeader(); | ||
187 | updateBox(); | ||
188 | |||
189 | // Layout and repaint panel since the layout has changed | ||
190 | panel.doLayout(); | ||
191 | panel.repaint(); | ||
192 | |||
193 | // Update layout's description | ||
194 | textArea.setText(layout.toString()); | ||
195 | |||
196 | // Generate code if desired | ||
197 | if (source == buttonGenerateCode) | ||
198 | generateCode(); | ||
199 | } | ||
200 | catch (Throwable error) | ||
201 | { | ||
202 | error.printStackTrace(); | ||
203 | textArea.setText (error.toString()); | ||
204 | } | ||
205 | } | ||
206 | |||
207 | |||
208 | |||
209 | /** | ||
210 | * Converts the text in a text field to an integer. | ||
211 | */ | ||
212 | |||
213 | private int getInt (JTextField field) | ||
214 | { | ||
215 | int value = 0; | ||
216 | |||
217 | try | ||
218 | { | ||
219 | value = Integer.parseInt(field.getText()); | ||
220 | } | ||
221 | catch (NumberFormatException e) {} | ||
222 | |||
223 | return value; | ||
224 | } | ||
225 | |||
226 | |||
227 | |||
228 | /** | ||
229 | * Converts the text in a text field to a double. | ||
230 | */ | ||
231 | |||
232 | private double getDouble (JTextField field) | ||
233 | { | ||
234 | double value = -1.0; | ||
235 | |||
236 | try | ||
237 | { | ||
238 | value = Double.parseDouble(field.getText()); | ||
239 | } | ||
240 | catch (NumberFormatException e) {} | ||
241 | |||
242 | return value; | ||
243 | } | ||
244 | |||
245 | |||
246 | |||
247 | /** | ||
248 | * Updates all the row and columns headers by bruce force. The headers | ||
249 | * are removed and then recreated based on the current layout configuration. | ||
250 | */ | ||
251 | |||
252 | private void updateHeader () | ||
253 | { | ||
254 | TableLayoutConstraints c = new TableLayoutConstraints | ||
255 | (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); | ||
256 | |||
257 | double size[] = layout.getColumn(); | ||
258 | |||
259 | for (int i = columnHeader.size() - 1; i >= 0; i--) | ||
260 | { | ||
261 | JButton header = (JButton) columnHeader.remove(i); | ||
262 | panel.remove(header); | ||
263 | } | ||
264 | |||
265 | for (int i = 0; i < size.length; i++) | ||
266 | { | ||
267 | c.col1 = c.col2 = i; | ||
268 | JButton header = new JButton("" + i + ": " + size[i]); | ||
269 | columnHeader.add(i, header); | ||
270 | panel.add (header, c); | ||
271 | } | ||
272 | |||
273 | c.col1 = c.col2 = 0; | ||
274 | size = layout.getRow(); | ||
275 | |||
276 | for (int i = rowHeader.size() - 1; i >= 0; i--) | ||
277 | { | ||
278 | JButton header = (JButton) rowHeader.remove(i); | ||
279 | panel.remove(header); | ||
280 | } | ||
281 | |||
282 | for (int i = 0; i < size.length; i++) | ||
283 | { | ||
284 | c.row1 = c.row2 = i; | ||
285 | JButton header = new JButton("" + i + ": " + size[i]); | ||
286 | rowHeader.add(i, header); | ||
287 | panel.add (header, c); | ||
288 | } | ||
289 | } | ||
290 | |||
291 | |||
292 | |||
293 | /** | ||
294 | * Updates the boxes used to illustrate cells. This is a brute force, | ||
295 | * unoptimized method. | ||
296 | */ | ||
297 | |||
298 | private void updateBox () | ||
299 | { | ||
300 | for (int i = boxList.size() - 1; i >= 0; i--) | ||
301 | { | ||
302 | Box box = (Box) boxList.remove(i); | ||
303 | panel.remove(box); | ||
304 | } | ||
305 | |||
306 | TableLayoutConstraints constraint = new TableLayoutConstraints | ||
307 | (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); | ||
308 | |||
309 | double col[] = layout.getColumn(); | ||
310 | double row[] = layout.getRow(); | ||
311 | |||
312 | for (int c = 1; c < col.length; c++) | ||
313 | for (int r = 1; r < row.length; r++) | ||
314 | { | ||
315 | constraint.col1 = constraint.col2 = c; | ||
316 | constraint.row1 = constraint.row2 = r; | ||
317 | Box box = new Box(); | ||
318 | panel.add (box, constraint); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | |||
323 | |||
324 | /** | ||
325 | * Generates code based on the current layout and Smiley controls. | ||
326 | */ | ||
327 | |||
328 | private void generateCode () | ||
329 | { | ||
330 | String code = | ||
331 | "import java.awt.*;\n" + | ||
332 | "import java.awt.event.*;\n" + | ||
333 | "import layout.TableLayout;\n\n" + | ||
334 | |||
335 | "public class MyClass\n" + | ||
336 | "{\n\n" + | ||
337 | |||
338 | " public static void main (String args[])\n" + | ||
339 | " {\n" + | ||
340 | " Frame frame = new Frame(\"MyTitle\");\n" + | ||
341 | " frame.setBounds (100, 100, 300, 300);\n\n" + | ||
342 | |||
343 | " double size[][] =\n" + | ||
344 | " {{"; | ||
345 | |||
346 | double size[] = layout.getColumn(); | ||
347 | |||
348 | if (size.length > 0) | ||
349 | code += size[0]; | ||
350 | |||
351 | for (int i = 1; i < size.length; i++) | ||
352 | code += ", " + size[i]; | ||
353 | |||
354 | code += "}, // Columns\n" + | ||
355 | " {"; | ||
356 | |||
357 | size = layout.getRow(); | ||
358 | |||
359 | if (size.length > 0) | ||
360 | code += size[0]; | ||
361 | |||
362 | for (int i = 1; i < size.length; i++) | ||
363 | code += ", " + size[i]; | ||
364 | |||
365 | code += "}}; // Rows\n\n" + | ||
366 | " frame.setLayout (new TableLayout(size));\n\n" + | ||
367 | " Button button;\n"; | ||
368 | |||
369 | Component component[] = panel.getComponents(); | ||
370 | |||
371 | for (int i = 0; i < component.length; i++) | ||
372 | { | ||
373 | if (component[i] instanceof Smiley) | ||
374 | { | ||
375 | TableLayoutConstraints c = layout.getConstraints(component[i]); | ||
376 | String constraint = "" + c.col1 + ", " + c.row1 + ", "; | ||
377 | |||
378 | if ((c.col1 == c.col2) && (c.row1 == c.row2)) | ||
379 | { | ||
380 | String h[] = {"L", "C", "F", "R"}; | ||
381 | String v[] = {"T", "C", "F", "B"}; | ||
382 | constraint += h[c.hAlign] + ", " + v[c.vAlign]; | ||
383 | } | ||
384 | else | ||
385 | constraint += c.col2 + ", " + c.row2; | ||
386 | |||
387 | code += | ||
388 | " button = new Button(\"" + constraint + "\");\n" + | ||
389 | " frame.add (button, \"" + constraint + "\");\n"; | ||
390 | } | ||
391 | } | ||
392 | |||
393 | code += | ||
394 | "\n" + | ||
395 | " frame.addWindowListener\n" + | ||
396 | " (new WindowAdapter()\n" + | ||
397 | " {\n" + | ||
398 | " public void windowClosing (WindowEvent e)\n" + | ||
399 | " {\n" + | ||
400 | " System.exit (0);\n" + | ||
401 | " }\n" + | ||
402 | " }\n" + | ||
403 | " );\n\n" + | ||
404 | " frame.show();\n" + | ||
405 | " }\n" + | ||
406 | "}\n"; | ||
407 | |||
408 | textArea.setText (code); | ||
409 | } | ||
410 | |||
411 | |||
412 | |||
413 | /** | ||
414 | * This inner class is a component that looks like a box. | ||
415 | */ | ||
416 | |||
417 | public class Box extends Component implements MouseListener | ||
418 | { | ||
419 | public Box () | ||
420 | { | ||
421 | super(); | ||
422 | addMouseListener(this); | ||
423 | } | ||
424 | |||
425 | public void update (Graphics g) | ||
426 | { | ||
427 | paint (g); | ||
428 | } | ||
429 | |||
430 | public void paint (Graphics g) | ||
431 | { | ||
432 | Dimension d = getSize(); | ||
433 | g.setColor (Color.black); | ||
434 | g.drawRect (0, 0, d.width - 1, d.height - 1); | ||
435 | } | ||
436 | |||
437 | public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} | ||
438 | public void mousePressed(java.awt.event.MouseEvent mouseEvent) {} | ||
439 | public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {} | ||
440 | public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {} | ||
441 | |||
442 | public void mouseReleased(java.awt.event.MouseEvent mouseEvent) | ||
443 | { | ||
444 | TableLayoutConstraints c = layout.getConstraints(this); | ||
445 | Smiley smiley = new Smiley(); | ||
446 | Container container = getParent(); | ||
447 | container.add(smiley, c, 0); | ||
448 | container.doLayout(); | ||
449 | } | ||
450 | } | ||
451 | |||
452 | |||
453 | |||
454 | /** | ||
455 | * This inner class is a component that looks like a smiley face. | ||
456 | */ | ||
457 | |||
458 | public class Smiley extends Component implements MouseListener | ||
459 | { | ||
460 | public Smiley () | ||
461 | { | ||
462 | super(); | ||
463 | addMouseListener (this); | ||
464 | } | ||
465 | |||
466 | public Dimension getPreferredSize () | ||
467 | { | ||
468 | return new Dimension(64, 64); | ||
469 | } | ||
470 | |||
471 | public void update (Graphics g) | ||
472 | { | ||
473 | paint (g); | ||
474 | } | ||
475 | |||
476 | public void paint (Graphics g) | ||
477 | { | ||
478 | Dimension d = getSize(); | ||
479 | int width_1_8 = d.width >> 3; | ||
480 | int width_7_8 = d.width - width_1_8; | ||
481 | int width_1_4 = d.width >> 2; | ||
482 | int width_3_4 = d.width - width_1_4; | ||
483 | int width_5_8 = width_3_4 - width_1_8; | ||
484 | int width_1_2 = d.width >> 1; | ||
485 | int height_1_8 = d.height >> 3; | ||
486 | int height_7_8 = d.height - height_1_8; | ||
487 | int height_1_4 = d.height >> 2; | ||
488 | int height_3_4 = d.height - height_1_4; | ||
489 | int height_5_8 = height_7_8 - height_1_4; | ||
490 | |||
491 | g.setColor (Color.yellow); | ||
492 | g.fillArc (0, 0, d.width - 1, d.height - 1, 0, 360); | ||
493 | g.setColor (Color.blue); | ||
494 | g.fillArc (width_1_4, height_1_4, width_1_8, height_1_8, 0, 360); | ||
495 | g.fillArc (width_5_8, height_1_4, width_1_8, height_1_8, 0, 360); | ||
496 | g.setColor (Color.red); | ||
497 | g.fillArc (width_1_4, height_5_8, width_1_2, height_1_4, 180, 180); | ||
498 | } | ||
499 | |||
500 | public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} | ||
501 | public void mousePressed(java.awt.event.MouseEvent mouseEvent) {} | ||
502 | public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {} | ||
503 | public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {} | ||
504 | |||
505 | public void mouseReleased(java.awt.event.MouseEvent mouseEvent) | ||
506 | { | ||
507 | // Get constraints applied to this Smiley | ||
508 | TableLayoutConstraints c = layout.getConstraints(this); | ||
509 | |||
510 | // Create controls | ||
511 | Panel panel = new Panel(); | ||
512 | |||
513 | int numRow = layout.getNumRow(); | ||
514 | int numColumn = layout.getNumColumn(); | ||
515 | |||
516 | Choice choiceCol1 = new Choice(); | ||
517 | Choice choiceCol2 = new Choice(); | ||
518 | Choice choiceRow1 = new Choice(); | ||
519 | Choice choiceRow2 = new Choice(); | ||
520 | |||
521 | for (int i = 1; i < numColumn; i++) | ||
522 | { | ||
523 | choiceCol1.add ("" + i); | ||
524 | choiceCol2.add ("" + i); | ||
525 | } | ||
526 | |||
527 | for (int i = 1; i < numRow; i++) | ||
528 | { | ||
529 | choiceRow1.add ("" + i); | ||
530 | choiceRow2.add ("" + i); | ||
531 | } | ||
532 | |||
533 | choiceCol1.select (c.col1 - 1); | ||
534 | choiceCol2.select (c.col2 - 1); | ||
535 | choiceRow1.select (c.row1 - 1); | ||
536 | choiceRow2.select (c.row2 - 1); | ||
537 | |||
538 | Choice choiceAlignH = new Choice(); | ||
539 | choiceAlignH.add ("Left"); | ||
540 | choiceAlignH.add ("Center"); | ||
541 | choiceAlignH.add ("Full"); | ||
542 | choiceAlignH.add ("Right"); | ||
543 | choiceAlignH.select (c.hAlign); | ||
544 | |||
545 | Choice choiceAlignV = new Choice(); | ||
546 | choiceAlignV.add ("Top"); | ||
547 | choiceAlignV.add ("Center"); | ||
548 | choiceAlignV.add ("Full"); | ||
549 | choiceAlignV.add ("Bottom"); | ||
550 | choiceAlignV.select (c.vAlign); | ||
551 | |||
552 | JLabel labelCol1 = new JLabel("Column 1"); | ||
553 | JLabel labelCol2 = new JLabel("Column 2"); | ||
554 | JLabel labelRow1 = new JLabel("Row 1"); | ||
555 | JLabel labelRow2 = new JLabel("Row 2"); | ||
556 | JLabel labelAlignH = new JLabel("Horizontal Justification"); | ||
557 | JLabel labelAlignV = new JLabel("Vertical Justification"); | ||
558 | labelAlignH.setHorizontalAlignment (JLabel.RIGHT); | ||
559 | labelAlignV.setHorizontalAlignment (JLabel.RIGHT); | ||
560 | |||
561 | // Create layout | ||
562 | double f = TableLayout.FILL; | ||
563 | double p = TableLayout.PREFERRED; | ||
564 | double s = 10; | ||
565 | |||
566 | double size[][] = | ||
567 | {{f, p, s, p, s, p, s, p, f}, | ||
568 | {p, s, p, s, p, s, p, s, p, s, p}}; | ||
569 | |||
570 | TableLayout panelLayout = new TableLayout(size); | ||
571 | panel.setLayout (panelLayout); | ||
572 | |||
573 | // Add controls | ||
574 | panel.add (labelCol1, "1, 0, R, B"); | ||
575 | panel.add (choiceCol1, "3, 0, L, B"); | ||
576 | panel.add (labelRow1, "5, 0, R, B"); | ||
577 | panel.add (choiceRow1, "7, 0, L, B"); | ||
578 | panel.add (labelCol2, "1, 2, R, B"); | ||
579 | panel.add (choiceCol2, "3, 2, L, B"); | ||
580 | panel.add (labelRow2, "5, 2, R, B"); | ||
581 | panel.add (choiceRow2, "7, 2, L, B"); | ||
582 | panel.add (labelAlignH, "0, 4, 3, 4"); | ||
583 | panel.add (choiceAlignH, "5, 4, 7, 4"); | ||
584 | panel.add (labelAlignV, "0, 6, 3, 6"); | ||
585 | panel.add (choiceAlignV, "5, 6, 7, 6"); | ||
586 | |||
587 | // Prompt user | ||
588 | String button[] = {"Update Smiley", "Remove Smiley", "Cancel"}; | ||
589 | |||
590 | GeneralDialog dialog = new GeneralDialog | ||
591 | (RadTool.this, "Update Smiley", "", button, null, panel); | ||
592 | |||
593 | String answer = dialog.promptUser(); | ||
594 | |||
595 | // Update constraints applied to this Smiley | ||
596 | if (answer.equals("Update Smiley")) | ||
597 | { | ||
598 | // Get columns | ||
599 | int col1 = choiceCol1.getSelectedIndex() + 1; | ||
600 | int col2 = choiceCol2.getSelectedIndex() + 1; | ||
601 | int row1 = choiceRow1.getSelectedIndex() + 1; | ||
602 | int row2 = choiceRow2.getSelectedIndex() + 1; | ||
603 | |||
604 | // Make sure col1 < col2 | ||
605 | if (col1 > col2) | ||
606 | { | ||
607 | int temp = col1; | ||
608 | col1 = col2; | ||
609 | col2 = temp; | ||
610 | } | ||
611 | |||
612 | // Make sure row1 < row2 | ||
613 | if (row1 > row2) | ||
614 | { | ||
615 | int temp = row1; | ||
616 | row1 = row2; | ||
617 | row2 = temp; | ||
618 | } | ||
619 | |||
620 | // Apply new constraints | ||
621 | c.col1 = col1; | ||
622 | c.col2 = col2; | ||
623 | c.row1 = row1; | ||
624 | c.row2 = row2; | ||
625 | c.hAlign = choiceAlignH.getSelectedIndex(); | ||
626 | c.vAlign = choiceAlignV.getSelectedIndex(); | ||
627 | layout.setConstraints (this, c); | ||
628 | |||
629 | // Repaint and layout container since layout has changed | ||
630 | Container container = getParent(); | ||
631 | container.doLayout(); | ||
632 | container.repaint(); | ||
633 | } | ||
634 | // Remove Smiley | ||
635 | else if (answer.equals("Remove Smiley")) | ||
636 | { | ||
637 | Container container = getParent(); | ||
638 | container.remove (this); | ||
639 | container.doLayout(); | ||
640 | container.repaint(); | ||
641 | } | ||
642 | } | ||
643 | } | ||
644 | |||
645 | |||
646 | |||
647 | } | ||
diff --git a/lib/example/Simple$1.class b/lib/example/Simple$1.class new file mode 100644 index 0000000..d8ad138 --- /dev/null +++ b/lib/example/Simple$1.class | |||
Binary files differ | |||
diff --git a/lib/example/Simple.class b/lib/example/Simple.class new file mode 100644 index 0000000..8fc8404 --- /dev/null +++ b/lib/example/Simple.class | |||
Binary files differ | |||
diff --git a/lib/example/Simple.java b/lib/example/Simple.java new file mode 100644 index 0000000..3ff9fb9 --- /dev/null +++ b/lib/example/Simple.java | |||
@@ -0,0 +1,62 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import layout.TableLayout; | ||
8 | |||
9 | |||
10 | |||
11 | public class Simple | ||
12 | { | ||
13 | |||
14 | |||
15 | |||
16 | public static void main (String args[]) | ||
17 | { | ||
18 | // Create a frame | ||
19 | Frame frame = new Frame("Example of TableLayout"); | ||
20 | frame.setBounds (100, 100, 300, 300); | ||
21 | |||
22 | // Create a TableLayout for the frame | ||
23 | double border = 10; | ||
24 | double size[][] = | ||
25 | {{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns | ||
26 | {border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows | ||
27 | |||
28 | frame.setLayout (new TableLayout(size)); | ||
29 | |||
30 | // Create some buttons | ||
31 | String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"}; | ||
32 | Button button[] = new Button[label.length]; | ||
33 | |||
34 | for (int i = 0; i < label.length; i++) | ||
35 | button[i] = new Button(label[i]); | ||
36 | |||
37 | // Add buttons | ||
38 | frame.add (button[0], "1, 1, 5, 1"); // Top | ||
39 | frame.add (button[1], "1, 5, 5, 5"); // Bottom | ||
40 | frame.add (button[2], "1, 3 "); // Left | ||
41 | frame.add (button[3], "5, 3 "); // Right | ||
42 | frame.add (button[4], "3, 3, c, c"); // Center | ||
43 | frame.add (button[5], "3, 3, 3, 5"); // Overlap | ||
44 | |||
45 | // Allow user to close the window to terminate the program | ||
46 | frame.addWindowListener | ||
47 | (new WindowAdapter() | ||
48 | { | ||
49 | public void windowClosing (WindowEvent e) | ||
50 | { | ||
51 | System.exit (0); | ||
52 | } | ||
53 | } | ||
54 | ); | ||
55 | |||
56 | // Show frame | ||
57 | frame.show(); | ||
58 | } | ||
59 | |||
60 | |||
61 | |||
62 | } \ No newline at end of file | ||
diff --git a/lib/example/TypicalGui$1.class b/lib/example/TypicalGui$1.class new file mode 100644 index 0000000..571f3ee --- /dev/null +++ b/lib/example/TypicalGui$1.class | |||
Binary files differ | |||
diff --git a/lib/example/TypicalGui$ColorBox.class b/lib/example/TypicalGui$ColorBox.class new file mode 100644 index 0000000..9c6555d --- /dev/null +++ b/lib/example/TypicalGui$ColorBox.class | |||
Binary files differ | |||
diff --git a/lib/example/TypicalGui.class b/lib/example/TypicalGui.class new file mode 100644 index 0000000..cc6dfb5 --- /dev/null +++ b/lib/example/TypicalGui.class | |||
Binary files differ | |||
diff --git a/lib/example/TypicalGui.java b/lib/example/TypicalGui.java new file mode 100644 index 0000000..ab80ff1 --- /dev/null +++ b/lib/example/TypicalGui.java | |||
@@ -0,0 +1,179 @@ | |||
1 | package example; | ||
2 | |||
3 | |||
4 | |||
5 | import java.awt.*; | ||
6 | import java.awt.event.*; | ||
7 | import javax.swing.*; | ||
8 | import layout.TableLayout; | ||
9 | |||
10 | |||
11 | |||
12 | public class TypicalGui extends JFrame | ||
13 | { | ||
14 | |||
15 | |||
16 | |||
17 | public static void main (String args[]) | ||
18 | { | ||
19 | new TypicalGui(); | ||
20 | } | ||
21 | |||
22 | |||
23 | |||
24 | public TypicalGui () | ||
25 | { | ||
26 | super ("A Typical GUI"); | ||
27 | |||
28 | Container pane = getContentPane(); | ||
29 | |||
30 | double b = 10; | ||
31 | double f = TableLayout.FILL; | ||
32 | double p = TableLayout.PREFERRED; | ||
33 | double size[][] = {{b, f, 5, p, 5, p, b}, {p, b, f, 10, p, b}}; | ||
34 | TableLayout layout = new TableLayout(size); | ||
35 | pane.setLayout (layout); | ||
36 | |||
37 | addMenu(pane); | ||
38 | addCommandButtons(pane, layout); | ||
39 | addColorBoxes(pane, layout); | ||
40 | addTextArea(pane, layout); | ||
41 | |||
42 | allowClosing(); | ||
43 | setSize (640, 480); | ||
44 | show(); | ||
45 | } | ||
46 | |||
47 | |||
48 | |||
49 | public void addMenu (Container pane) | ||
50 | { | ||
51 | JMenuBar menuBar = new JMenuBar(); | ||
52 | |||
53 | String menuText[] = {"File", "Edit", "View", "Help"}; | ||
54 | String itemText[][] = | ||
55 | {{"New", "Open", "Save", "Print", "Exit"}, | ||
56 | {"Cut", "Copy", "Paste"}, | ||
57 | {"Zoom in", "Zoom out"}, | ||
58 | {"About", "Index", "Search"}}; | ||
59 | |||
60 | for (int i = 0; i < menuText.length; i++) | ||
61 | { | ||
62 | JMenu menu = new JMenu(menuText[i]); | ||
63 | menuBar.add (menu); | ||
64 | |||
65 | for (int j = 0; j < itemText[i].length; j++) | ||
66 | { | ||
67 | JMenuItem item = new JMenuItem(itemText[i][j]); | ||
68 | menu.add (item); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | pane.add (menuBar, "0, 0, 6, 0"); | ||
73 | } | ||
74 | |||
75 | |||
76 | |||
77 | public void addCommandButtons (Container pane, TableLayout layout) | ||
78 | { | ||
79 | JPanel buttonPanel = new JPanel(); | ||
80 | pane.add (buttonPanel, "1, 4, 5, 4"); | ||
81 | |||
82 | for (int i = 1; i <= 5; i++) | ||
83 | { | ||
84 | JButton button = new JButton("Button " + i); | ||
85 | buttonPanel.add (button); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | |||
90 | |||
91 | public void addColorBoxes (Container pane, TableLayout layout) | ||
92 | { | ||
93 | Color color[][] = | ||
94 | {{Color.white, Color.black}, | ||
95 | {Color.green, Color.blue}, | ||
96 | {Color.red, Color.yellow}, | ||
97 | {Color.pink, Color.orange}, | ||
98 | {Color.magenta, Color.cyan}}; | ||
99 | |||
100 | for (int i = 0; i < color.length; i++) | ||
101 | { | ||
102 | // Add a row for spacing and a row for the color boxes | ||
103 | layout.insertRow (2, TableLayout.PREFERRED); | ||
104 | layout.insertRow (2, 5); | ||
105 | |||
106 | // Add color boxes | ||
107 | pane.add (new ColorBox(color[i][0]), "3, 3"); | ||
108 | pane.add (new ColorBox(color[i][1]), "5, 3"); | ||
109 | } | ||
110 | |||
111 | // Remove the unnecessary leading space | ||
112 | layout.deleteRow (2); | ||
113 | } | ||
114 | |||
115 | |||
116 | |||
117 | public void addTextArea (Container pane, TableLayout layout) | ||
118 | { | ||
119 | int numRow = layout.getRow().length; | ||
120 | JTextPane textArea = new JTextPane(); | ||
121 | pane.add (textArea, "1, 2, 1, " + (numRow - 4)); | ||
122 | } | ||
123 | |||
124 | |||
125 | |||
126 | public void allowClosing () | ||
127 | { | ||
128 | addWindowListener | ||
129 | (new WindowAdapter() | ||
130 | { | ||
131 | public void windowClosing (WindowEvent e) | ||
132 | { | ||
133 | System.exit (0); | ||
134 | } | ||
135 | } | ||
136 | ); | ||
137 | } | ||
138 | |||
139 | |||
140 | |||
141 | //************************************************************************** | ||
142 | //*** Inner classes *** | ||
143 | //************************************************************************** | ||
144 | |||
145 | |||
146 | |||
147 | protected class ColorBox extends Component | ||
148 | { | ||
149 | protected Color color; | ||
150 | |||
151 | protected ColorBox (Color color) | ||
152 | { | ||
153 | this.color = color; | ||
154 | } | ||
155 | |||
156 | public void update (Graphics g) | ||
157 | { | ||
158 | paint (g); | ||
159 | } | ||
160 | |||
161 | public void paint (Graphics g) | ||
162 | { | ||
163 | Dimension d = getSize(); | ||
164 | g.setColor (Color.black); | ||
165 | g.drawRect (0, 0, d.width - 1, d.height - 1); | ||
166 | |||
167 | g.setColor (color); | ||
168 | g.fillRect (1, 1, d.width - 1, d.height - 1); | ||
169 | } | ||
170 | |||
171 | public Dimension getPreferredSize () | ||
172 | { | ||
173 | return new Dimension(40, 20);; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | |||
178 | |||
179 | } | ||
diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 --- /dev/null +++ b/lib/hamcrest-core-1.3.jar | |||
Binary files differ | |||
diff --git a/lib/jcommon-1.0.16.jar b/lib/jcommon-1.0.16.jar new file mode 100644 index 0000000..4cd6807 --- /dev/null +++ b/lib/jcommon-1.0.16.jar | |||
Binary files differ | |||
diff --git a/lib/jfreechart-1.0.13.jar b/lib/jfreechart-1.0.13.jar new file mode 100644 index 0000000..83c6993 --- /dev/null +++ b/lib/jfreechart-1.0.13.jar | |||
Binary files differ | |||
diff --git a/lib/junit-4.13.jar b/lib/junit-4.13.jar new file mode 100644 index 0000000..acc3c43 --- /dev/null +++ b/lib/junit-4.13.jar | |||
Binary files differ | |||
diff --git a/lib/looks-2.1.4.jar b/lib/looks-2.1.4.jar new file mode 100644 index 0000000..d2c47c7 --- /dev/null +++ b/lib/looks-2.1.4.jar | |||
Binary files differ | |||
diff --git a/src/control/images/Manual_confirmation_no.png b/src/control/images/Manual_confirmation_no.png new file mode 100644 index 0000000..08ffcf0 --- /dev/null +++ b/src/control/images/Manual_confirmation_no.png | |||
Binary files differ | |||
diff --git a/src/control/images/Manual_confirmation_unknown.png b/src/control/images/Manual_confirmation_unknown.png new file mode 100644 index 0000000..d53ad68 --- /dev/null +++ b/src/control/images/Manual_confirmation_unknown.png | |||
Binary files differ | |||
diff --git a/src/control/images/Manual_confirmation_yes.png b/src/control/images/Manual_confirmation_yes.png new file mode 100644 index 0000000..3915fb6 --- /dev/null +++ b/src/control/images/Manual_confirmation_yes.png | |||
Binary files differ | |||
diff --git a/src/control/images/agree_no.gif b/src/control/images/agree_no.gif new file mode 100644 index 0000000..5bf7e2c --- /dev/null +++ b/src/control/images/agree_no.gif | |||
Binary files differ | |||
diff --git a/src/control/images/agree_ok.gif b/src/control/images/agree_ok.gif new file mode 100644 index 0000000..68d734c --- /dev/null +++ b/src/control/images/agree_ok.gif | |||
Binary files differ | |||
diff --git a/src/control/images/arrow_down.png b/src/control/images/arrow_down.png new file mode 100644 index 0000000..a9eb825 --- /dev/null +++ b/src/control/images/arrow_down.png | |||
Binary files differ | |||
diff --git a/src/control/images/arrow_left.png b/src/control/images/arrow_left.png new file mode 100644 index 0000000..b8578da --- /dev/null +++ b/src/control/images/arrow_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/arrow_left_down.png b/src/control/images/arrow_left_down.png new file mode 100644 index 0000000..344bab2 --- /dev/null +++ b/src/control/images/arrow_left_down.png | |||
Binary files differ | |||
diff --git a/src/control/images/arrow_left_up.png b/src/control/images/arrow_left_up.png new file mode 100644 index 0000000..075f0d9 --- /dev/null +++ b/src/control/images/arrow_left_up.png | |||
Binary files differ | |||
diff --git a/src/control/images/back1.jpg b/src/control/images/back1.jpg new file mode 100644 index 0000000..f85fa1a --- /dev/null +++ b/src/control/images/back1.jpg | |||
Binary files differ | |||
diff --git a/src/control/images/back2.jpg b/src/control/images/back2.jpg new file mode 100644 index 0000000..e4f722c --- /dev/null +++ b/src/control/images/back2.jpg | |||
Binary files differ | |||
diff --git a/src/control/images/chartpanel/exportToImage.png b/src/control/images/chartpanel/exportToImage.png new file mode 100644 index 0000000..94198be --- /dev/null +++ b/src/control/images/chartpanel/exportToImage.png | |||
Binary files differ | |||
diff --git a/src/control/images/chartpanel/pan.png b/src/control/images/chartpanel/pan.png new file mode 100644 index 0000000..a367b39 --- /dev/null +++ b/src/control/images/chartpanel/pan.png | |||
Binary files differ | |||
diff --git a/src/control/images/chartpanel/zoomIn.png b/src/control/images/chartpanel/zoomIn.png new file mode 100644 index 0000000..5ca924b --- /dev/null +++ b/src/control/images/chartpanel/zoomIn.png | |||
Binary files differ | |||
diff --git a/src/control/images/chartpanel/zoomOut.png b/src/control/images/chartpanel/zoomOut.png new file mode 100644 index 0000000..34ea7be --- /dev/null +++ b/src/control/images/chartpanel/zoomOut.png | |||
Binary files differ | |||
diff --git a/src/control/images/chartpanel/zoomReset.png b/src/control/images/chartpanel/zoomReset.png new file mode 100644 index 0000000..52e005c --- /dev/null +++ b/src/control/images/chartpanel/zoomReset.png | |||
Binary files differ | |||
diff --git a/src/control/images/chartpanel/zoomToOverview.png b/src/control/images/chartpanel/zoomToOverview.png new file mode 100644 index 0000000..0566e8e --- /dev/null +++ b/src/control/images/chartpanel/zoomToOverview.png | |||
Binary files differ | |||
diff --git a/src/control/images/email.png b/src/control/images/email.png new file mode 100644 index 0000000..94e0869 --- /dev/null +++ b/src/control/images/email.png | |||
Binary files differ | |||
diff --git a/src/control/images/exit.gif b/src/control/images/exit.gif new file mode 100644 index 0000000..9846fa6 --- /dev/null +++ b/src/control/images/exit.gif | |||
Binary files differ | |||
diff --git a/src/control/images/gc.png b/src/control/images/gc.png new file mode 100644 index 0000000..d1e300b --- /dev/null +++ b/src/control/images/gc.png | |||
Binary files differ | |||
diff --git a/src/control/images/header_background.png b/src/control/images/header_background.png new file mode 100644 index 0000000..99b4ea4 --- /dev/null +++ b/src/control/images/header_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/header_background_left.png b/src/control/images/header_background_left.png new file mode 100644 index 0000000..6304e77 --- /dev/null +++ b/src/control/images/header_background_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/header_background_right.png b/src/control/images/header_background_right.png new file mode 100644 index 0000000..3fe3364 --- /dev/null +++ b/src/control/images/header_background_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/list_item_default_icon.png b/src/control/images/list_item_default_icon.png new file mode 100644 index 0000000..d259489 --- /dev/null +++ b/src/control/images/list_item_default_icon.png | |||
Binary files differ | |||
diff --git a/src/control/images/logo.png b/src/control/images/logo.png new file mode 100644 index 0000000..f39bbb7 --- /dev/null +++ b/src/control/images/logo.png | |||
Binary files differ | |||
diff --git a/src/control/images/logo1.png b/src/control/images/logo1.png new file mode 100644 index 0000000..b983eba --- /dev/null +++ b/src/control/images/logo1.png | |||
Binary files differ | |||
diff --git a/src/control/images/logo2.png b/src/control/images/logo2.png new file mode 100644 index 0000000..4d1a092 --- /dev/null +++ b/src/control/images/logo2.png | |||
Binary files differ | |||
diff --git a/src/control/images/menu_arrow.png b/src/control/images/menu_arrow.png new file mode 100644 index 0000000..399f188 --- /dev/null +++ b/src/control/images/menu_arrow.png | |||
Binary files differ | |||
diff --git a/src/control/images/menubar_background.png b/src/control/images/menubar_background.png new file mode 100644 index 0000000..da7fa0e --- /dev/null +++ b/src/control/images/menubar_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/menubar_background_left.png b/src/control/images/menubar_background_left.png new file mode 100644 index 0000000..ff0a871 --- /dev/null +++ b/src/control/images/menubar_background_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/menubar_background_right.png b/src/control/images/menubar_background_right.png new file mode 100644 index 0000000..c7d8c5f --- /dev/null +++ b/src/control/images/menubar_background_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/menubar_background_selected.png b/src/control/images/menubar_background_selected.png new file mode 100644 index 0000000..0250723 --- /dev/null +++ b/src/control/images/menubar_background_selected.png | |||
Binary files differ | |||
diff --git a/src/control/images/module_node.png b/src/control/images/module_node.png new file mode 100644 index 0000000..0b22eb8 --- /dev/null +++ b/src/control/images/module_node.png | |||
Binary files differ | |||
diff --git a/src/control/images/module_node_selected.png b/src/control/images/module_node_selected.png new file mode 100644 index 0000000..9caf91b --- /dev/null +++ b/src/control/images/module_node_selected.png | |||
Binary files differ | |||
diff --git a/src/control/images/onError.gif b/src/control/images/onError.gif new file mode 100644 index 0000000..e1b6bdb --- /dev/null +++ b/src/control/images/onError.gif | |||
Binary files differ | |||
diff --git a/src/control/images/outlookPanel/module_selected.png b/src/control/images/outlookPanel/module_selected.png new file mode 100644 index 0000000..fd70582 --- /dev/null +++ b/src/control/images/outlookPanel/module_selected.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlookPanel/module_unselected.png b/src/control/images/outlookPanel/module_unselected.png new file mode 100644 index 0000000..1fe6f7a --- /dev/null +++ b/src/control/images/outlookPanel/module_unselected.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlook_bar_background.png b/src/control/images/outlook_bar_background.png new file mode 100644 index 0000000..ab8c9f7 --- /dev/null +++ b/src/control/images/outlook_bar_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlook_bar_background_selected.png b/src/control/images/outlook_bar_background_selected.png new file mode 100644 index 0000000..553624b --- /dev/null +++ b/src/control/images/outlook_bar_background_selected.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlook_bar_background_selected_left.png b/src/control/images/outlook_bar_background_selected_left.png new file mode 100644 index 0000000..d391a24 --- /dev/null +++ b/src/control/images/outlook_bar_background_selected_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlook_bar_background_selected_right.png b/src/control/images/outlook_bar_background_selected_right.png new file mode 100644 index 0000000..a7daf4c --- /dev/null +++ b/src/control/images/outlook_bar_background_selected_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlook_bar_handler.png b/src/control/images/outlook_bar_handler.png new file mode 100644 index 0000000..b727e8b --- /dev/null +++ b/src/control/images/outlook_bar_handler.png | |||
Binary files differ | |||
diff --git a/src/control/images/outlook_bar_handler_selected.png b/src/control/images/outlook_bar_handler_selected.png new file mode 100644 index 0000000..b317475 --- /dev/null +++ b/src/control/images/outlook_bar_handler_selected.png | |||
Binary files differ | |||
diff --git a/src/control/images/progress_select_background.png b/src/control/images/progress_select_background.png new file mode 100644 index 0000000..e46c3bb --- /dev/null +++ b/src/control/images/progress_select_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/progress_selected_left.png b/src/control/images/progress_selected_left.png new file mode 100644 index 0000000..60e4fd9 --- /dev/null +++ b/src/control/images/progress_selected_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/progress_selected_right.png b/src/control/images/progress_selected_right.png new file mode 100644 index 0000000..fc21624 --- /dev/null +++ b/src/control/images/progress_selected_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/progress_unselect_background.png b/src/control/images/progress_unselect_background.png new file mode 100644 index 0000000..b1e90de --- /dev/null +++ b/src/control/images/progress_unselect_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/resize_handler.png b/src/control/images/resize_handler.png new file mode 100644 index 0000000..6e892c6 --- /dev/null +++ b/src/control/images/resize_handler.png | |||
Binary files differ | |||
diff --git a/src/control/images/separator_background.png b/src/control/images/separator_background.png new file mode 100644 index 0000000..007c518 --- /dev/null +++ b/src/control/images/separator_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/server.png b/src/control/images/server.png new file mode 100644 index 0000000..49d9bd0 --- /dev/null +++ b/src/control/images/server.png | |||
Binary files differ | |||
diff --git a/src/control/images/shrink_handler_left.png b/src/control/images/shrink_handler_left.png new file mode 100644 index 0000000..c52b66c --- /dev/null +++ b/src/control/images/shrink_handler_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/shrink_handler_right.png b/src/control/images/shrink_handler_right.png new file mode 100644 index 0000000..99ef162 --- /dev/null +++ b/src/control/images/shrink_handler_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_background.png b/src/control/images/statusbar_background.png new file mode 100644 index 0000000..71bbac2 --- /dev/null +++ b/src/control/images/statusbar_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_background_left.png b/src/control/images/statusbar_background_left.png new file mode 100644 index 0000000..4c3bb0f --- /dev/null +++ b/src/control/images/statusbar_background_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_background_right.png b/src/control/images/statusbar_background_right.png new file mode 100644 index 0000000..7433e88 --- /dev/null +++ b/src/control/images/statusbar_background_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_message_light_green.png b/src/control/images/statusbar_message_light_green.png new file mode 100644 index 0000000..4999e77 --- /dev/null +++ b/src/control/images/statusbar_message_light_green.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_message_light_orange.png b/src/control/images/statusbar_message_light_orange.png new file mode 100644 index 0000000..63e7de4 --- /dev/null +++ b/src/control/images/statusbar_message_light_orange.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_message_light_red.png b/src/control/images/statusbar_message_light_red.png new file mode 100644 index 0000000..c22f7a2 --- /dev/null +++ b/src/control/images/statusbar_message_light_red.png | |||
Binary files differ | |||
diff --git a/src/control/images/statusbar_separator.png b/src/control/images/statusbar_separator.png new file mode 100644 index 0000000..bab1de5 --- /dev/null +++ b/src/control/images/statusbar_separator.png | |||
Binary files differ | |||
diff --git a/src/control/images/submodule.png b/src/control/images/submodule.png new file mode 100644 index 0000000..207289a --- /dev/null +++ b/src/control/images/submodule.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_close.png b/src/control/images/tab_close.png new file mode 100644 index 0000000..3c08ef8 --- /dev/null +++ b/src/control/images/tab_close.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_close_pressed.png b/src/control/images/tab_close_pressed.png new file mode 100644 index 0000000..76b2d21 --- /dev/null +++ b/src/control/images/tab_close_pressed.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_header_background.png b/src/control/images/tab_header_background.png new file mode 100644 index 0000000..3555855 --- /dev/null +++ b/src/control/images/tab_header_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_header_selected_background_left.png b/src/control/images/tab_header_selected_background_left.png new file mode 100644 index 0000000..7624a75 --- /dev/null +++ b/src/control/images/tab_header_selected_background_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_header_selected_background_right.png b/src/control/images/tab_header_selected_background_right.png new file mode 100644 index 0000000..f105cb6 --- /dev/null +++ b/src/control/images/tab_header_selected_background_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_header_unselected_background.png b/src/control/images/tab_header_unselected_background.png new file mode 100644 index 0000000..888db7a --- /dev/null +++ b/src/control/images/tab_header_unselected_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_header_unselected_background_left.png b/src/control/images/tab_header_unselected_background_left.png new file mode 100644 index 0000000..ee3eb6b --- /dev/null +++ b/src/control/images/tab_header_unselected_background_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/tab_header_unselected_background_right.png b/src/control/images/tab_header_unselected_background_right.png new file mode 100644 index 0000000..10daac8 --- /dev/null +++ b/src/control/images/tab_header_unselected_background_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/textfield_background.png b/src/control/images/textfield_background.png new file mode 100644 index 0000000..02c004f --- /dev/null +++ b/src/control/images/textfield_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/textfield_background_left.png b/src/control/images/textfield_background_left.png new file mode 100644 index 0000000..741acbc --- /dev/null +++ b/src/control/images/textfield_background_left.png | |||
Binary files differ | |||
diff --git a/src/control/images/textfield_background_right.png b/src/control/images/textfield_background_right.png new file mode 100644 index 0000000..b312518 --- /dev/null +++ b/src/control/images/textfield_background_right.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/add.png b/src/control/images/toolbar/add.png new file mode 100644 index 0000000..0374b7c --- /dev/null +++ b/src/control/images/toolbar/add.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/capture.png b/src/control/images/toolbar/capture.png new file mode 100644 index 0000000..4121be9 --- /dev/null +++ b/src/control/images/toolbar/capture.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/chart.png b/src/control/images/toolbar/chart.png new file mode 100644 index 0000000..dc94e72 --- /dev/null +++ b/src/control/images/toolbar/chart.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/email.png b/src/control/images/toolbar/email.png new file mode 100644 index 0000000..94e0869 --- /dev/null +++ b/src/control/images/toolbar/email.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/home.png b/src/control/images/toolbar/home.png new file mode 100644 index 0000000..28c7279 --- /dev/null +++ b/src/control/images/toolbar/home.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/image_edit.png b/src/control/images/toolbar/image_edit.png new file mode 100644 index 0000000..5d8fa5b --- /dev/null +++ b/src/control/images/toolbar/image_edit.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/left.png b/src/control/images/toolbar/left.png new file mode 100644 index 0000000..302ed19 --- /dev/null +++ b/src/control/images/toolbar/left.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/message.png b/src/control/images/toolbar/message.png new file mode 100644 index 0000000..c0ef149 --- /dev/null +++ b/src/control/images/toolbar/message.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/print.png b/src/control/images/toolbar/print.png new file mode 100644 index 0000000..e5aca4c --- /dev/null +++ b/src/control/images/toolbar/print.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/refresh.png b/src/control/images/toolbar/refresh.png new file mode 100644 index 0000000..19b79ed --- /dev/null +++ b/src/control/images/toolbar/refresh.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/right.png b/src/control/images/toolbar/right.png new file mode 100644 index 0000000..7f15cd6 --- /dev/null +++ b/src/control/images/toolbar/right.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/update.png b/src/control/images/toolbar/update.png new file mode 100644 index 0000000..b02465f --- /dev/null +++ b/src/control/images/toolbar/update.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/user.png b/src/control/images/toolbar/user.png new file mode 100644 index 0000000..d25bce2 --- /dev/null +++ b/src/control/images/toolbar/user.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar/viewer.png b/src/control/images/toolbar/viewer.png new file mode 100644 index 0000000..638d70c --- /dev/null +++ b/src/control/images/toolbar/viewer.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar_background.png b/src/control/images/toolbar_background.png new file mode 100644 index 0000000..3f4329a --- /dev/null +++ b/src/control/images/toolbar_background.png | |||
Binary files differ | |||
diff --git a/src/control/images/toolbar_separator.png b/src/control/images/toolbar_separator.png new file mode 100644 index 0000000..50d92b6 --- /dev/null +++ b/src/control/images/toolbar_separator.png | |||
Binary files differ | |||
diff --git a/src/cppcheckplus/control/Main.java b/src/cppcheckplus/control/Main.java new file mode 100644 index 0000000..4c84eac --- /dev/null +++ b/src/cppcheckplus/control/Main.java | |||
@@ -0,0 +1,917 @@ | |||
1 | package cppcheckplus.control; | ||
2 | |||
3 | import cppcheckplus.menu.MyMenuBar; | ||
4 | import cppcheckplus.outlookpanel.MyOutlookPanel; | ||
5 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; | ||
6 | import cppcheckplus.shortcut.MyShortcutPanel; | ||
7 | import cppcheckplus.shortcut.MyTree; | ||
8 | import cppcheckplus.tab.MyTabPage; | ||
9 | import cppcheckplus.tab.MyTabPage1; | ||
10 | import cppcheckplus.tab.MyTabPanel; | ||
11 | import cppcheckplus.tab.MyTabPanel1; | ||
12 | import cppcheckplus.text.FileTools; | ||
13 | import cppcheckplus.text.MyPanel; | ||
14 | import cppcheckplus.text.MyTextPanel; | ||
15 | import cppcheckplus.text.MyTextPanel1; | ||
16 | import cppcheckplus.text.ViewPanel; | ||
17 | import cppcheckplus.text.creatTable; | ||
18 | import java.awt.BorderLayout; | ||
19 | import java.awt.TextArea; | ||
20 | import java.awt.event.ActionEvent; | ||
21 | import java.awt.event.ActionListener; | ||
22 | import java.awt.event.MouseAdapter; | ||
23 | import java.awt.event.MouseEvent; | ||
24 | import java.io.BufferedReader; | ||
25 | import java.io.File; | ||
26 | import java.io.IOException; | ||
27 | import java.io.InputStream; | ||
28 | import java.io.InputStreamReader; | ||
29 | import java.io.UnsupportedEncodingException; | ||
30 | import java.nio.charset.StandardCharsets; | ||
31 | import java.nio.file.Files; | ||
32 | import java.nio.file.Path; | ||
33 | import java.nio.file.Paths; | ||
34 | import javax.swing.BorderFactory; | ||
35 | import javax.swing.JComponent; | ||
36 | import javax.swing.JFileChooser; | ||
37 | import javax.swing.JFrame; | ||
38 | import javax.swing.JList; | ||
39 | import javax.swing.JOptionPane; | ||
40 | import javax.swing.JTextArea; | ||
41 | import javax.swing.SwingUtilities; | ||
42 | import javax.swing.event.ListSelectionEvent; | ||
43 | import javax.swing.event.ListSelectionListener; | ||
44 | import javax.swing.plaf.TabbedPaneUI; | ||
45 | import javax.xml.parsers.ParserConfigurationException; | ||
46 | |||
47 | |||
48 | // 构造界面和各个工具的调用逻辑 | ||
49 | public class Main extends JFrame { | ||
50 | //private String target = "";// dump文件路径 | ||
51 | public static final int SUCCESS = 0; // 表示程序执行成功 | ||
52 | public static final String COMMAND = "java.exe -version"; // 要执行的语句 | ||
53 | public static final String SUCCESS_MESSAGE = "程序执行成功!"; | ||
54 | public static final String ERROR_MESSAGE = "程序执行出错:"; | ||
55 | public static final String ENTERWindows = "\r\n"; | ||
56 | public static final String ENTERLinux = "\n"; | ||
57 | // XML配置文件路径 | ||
58 | private final String menuBarXML; | ||
59 | private final String outlookPanelXML; | ||
60 | private final String settingsXML; | ||
61 | private final String stdclangXML; | ||
62 | // 界面组件 | ||
63 | private final MyContentPanel contentPanel; | ||
64 | private final MyMenuBar menubar; | ||
65 | private final JFileChooser jfc = new JFileChooser();// 文件选择器 | ||
66 | private final JFileChooser jfsettings = new JFileChooser();// 配置设定 | ||
67 | public MyTabPanel tabPanel; | ||
68 | // 编辑代码的面板 | ||
69 | public MyTextPanel testCode; | ||
70 | public String src = ""; // 目标源文件或目录的路径 | ||
71 | public String cppcheckPath = null; | ||
72 | public String flawfinderPath = null; | ||
73 | public String paracppcheck = null; | ||
74 | public String paraflawfinder = null; | ||
75 | public creatTable ct = new creatTable(); | ||
76 | private MyOutlookPanel outlookPanel; | ||
77 | private MyTabPanel1 tabPanel2; | ||
78 | private MyShortcutPanel shortcutPanel; | ||
79 | private MyTree tree; | ||
80 | // 标记是否修改了工具路径 | ||
81 | private boolean changedpathcpp = false; | ||
82 | private boolean changedpathflaw = false; | ||
83 | private MyTextPanel1 testPanel; | ||
84 | private ViewPanel viewPanel; | ||
85 | // 显示代码和检查进程的文本区域 | ||
86 | private JTextArea textCode;// 显示代码内容 | ||
87 | private TextArea textCheck;// 显示检查进度输出 | ||
88 | // 各工具的面板 | ||
89 | private MyTextPanel1 flawfinderPanel; | ||
90 | private MyTextPanel1 cppcheckPanel; | ||
91 | private MyTextPanel1 clangPanel; | ||
92 | // 各工具的检测结果 | ||
93 | private TextArea flawfinderResult;//flawfinder检测结果 | ||
94 | private TextArea cppcheckResult;//cppcheck检测结果 | ||
95 | private TextArea clangResult;//clang检测结果 | ||
96 | // 文件操作相关 | ||
97 | private File result; // 存储打开的文件 | ||
98 | private File report; // 导出报告时选择的文件 | ||
99 | private File direct; // 存储打开的目录 | ||
100 | private String tmpFileName = "";//tmp文件名 | ||
101 | //private static String inputResult = "inputResult.txt"; | ||
102 | //private static String errorResult = "errorResult.txt"; | ||
103 | private Main ui; | ||
104 | private final String projectPath; | ||
105 | |||
106 | // 构造函数:初始化各个组件,加载配置文件,建立界面布局 | ||
107 | public Main() { | ||
108 | projectPath = System.getProperty("user.dir"); | ||
109 | // 文件选择器初始目录 | ||
110 | jfc.setCurrentDirectory(new File("d://")); | ||
111 | jfsettings.setCurrentDirectory(new File("d://")); | ||
112 | |||
113 | // 配置文件路径 | ||
114 | menuBarXML = "cppcheckplus/control/menubar.xml"; | ||
115 | outlookPanelXML = "cppcheckplus/control/outlook.xml"; | ||
116 | settingsXML = "cppcheckplus/control/settings.xml"; | ||
117 | stdclangXML = "cppcheckplus/control/stdclang.xml"; | ||
118 | |||
119 | MyContorlUtil.loadToolsRoad(settingsXML, this);// 加载工具路径设置到当前对象中 | ||
120 | ct.initSTDClang(stdclangXML);// 设置clang配置 | ||
121 | |||
122 | // 加载菜单栏,注册事件监听 | ||
123 | menubar = MyContorlUtil.loadMenuBar(menuBarXML, new ActionListener() { | ||
124 | public void actionPerformed(ActionEvent e) { | ||
125 | String command = e.getActionCommand(); | ||
126 | switch (command) { | ||
127 | case "OnMenuOpen": | ||
128 | // 打开文件 | ||
129 | jfc.setFileSelectionMode(0);// 设定只能选择到文件 | ||
130 | int state = jfc.showOpenDialog(null); | ||
131 | if (state == 1) { | ||
132 | return; // 撤销选择则返回 | ||
133 | } else { | ||
134 | result = jfc.getSelectedFile();// result为选择到的文件 | ||
135 | src = result.getAbsolutePath(); | ||
136 | // 读取文件内容并显示到代码区 | ||
137 | textCode.setText(FileTools.readFile(result)); | ||
138 | // 如果代码标签页不存在,则创建一个 | ||
139 | if (!tabPanel.isSelectTabComponents("代码")) { | ||
140 | tabPanel.addTab("代码", testCode); | ||
141 | tabPanel.isSelectTabComponents("代码"); | ||
142 | } | ||
143 | } | ||
144 | break; | ||
145 | case "onMenuLoad": | ||
146 | // 加载目录:选择目录并更新目录树 | ||
147 | jfc.setFileSelectionMode(1);// 只能选择到文件夹 | ||
148 | // int state = jfc.showOpenDialog(null); | ||
149 | if (jfc.showOpenDialog(null) == 1) { | ||
150 | return; | ||
151 | } | ||
152 | direct = jfc.getSelectedFile();// 选择到的目录 | ||
153 | src = direct.getAbsolutePath(); | ||
154 | tree.setRootDir(direct);// 更新目录树 | ||
155 | break; | ||
156 | case "onMenuSave": | ||
157 | // 保存文件 | ||
158 | if (result != null) { | ||
159 | FileTools.writeFile(result, textCode.getText()); | ||
160 | } | ||
161 | break; | ||
162 | case "onMenuClose": | ||
163 | // 关闭程序 | ||
164 | System.exit(0); | ||
165 | break; | ||
166 | case "onMenuClean": | ||
167 | // 清空:清空代码、检查结果、进度信息,重置参数 | ||
168 | textCode.setText(""); | ||
169 | flawfinderResult.setText(""); | ||
170 | cppcheckResult.setText(""); | ||
171 | clangResult.setText(""); | ||
172 | viewPanel.clearTable(); | ||
173 | ct.clearall(); | ||
174 | textCheck.setText(""); | ||
175 | paracppcheck = "--enable=all"; | ||
176 | break; | ||
177 | case "onMenuExport": | ||
178 | // 导出:将检查结果导出到xml文件 | ||
179 | JFileChooser dialog = new JFileChooser(); | ||
180 | dialog.setDialogTitle("另存为"); | ||
181 | dialog.setFileSelectionMode(JFileChooser.FILES_ONLY); | ||
182 | dialog.setDialogType(JFileChooser.SAVE_DIALOG); | ||
183 | int r = dialog.showSaveDialog(ui); | ||
184 | if (r == JFileChooser.APPROVE_OPTION) { | ||
185 | report = dialog.getSelectedFile(); | ||
186 | FileTools.writeFile(report, ct.results); | ||
187 | } else { | ||
188 | JOptionPane.showMessageDialog(null, "路径错误", | ||
189 | "提示", 2); | ||
190 | } | ||
191 | break; | ||
192 | case "onCppcheck": | ||
193 | // cppcheck检查 | ||
194 | if (src != null && src.length() != 0) { | ||
195 | if (paracppcheck != null && | ||
196 | paracppcheck.length() != 0) { | ||
197 | new Thread() { | ||
198 | public void run() { | ||
199 | execute(src, paracppcheck); | ||
200 | } | ||
201 | }.start(); | ||
202 | } else { | ||
203 | JOptionPane.showMessageDialog(null, "参数错误", | ||
204 | "提示", 2); | ||
205 | } | ||
206 | } else { | ||
207 | JOptionPane.showMessageDialog(null, "目标路径错误", | ||
208 | "提示", 2); | ||
209 | } | ||
210 | break; | ||
211 | case "onClang": | ||
212 | // clang/clang-tidy检查 | ||
213 | if (src != null && src.length() != 0) { | ||
214 | new Thread() { | ||
215 | public void run() { | ||
216 | execute2(src); | ||
217 | } | ||
218 | }.start(); | ||
219 | } else { | ||
220 | JOptionPane.showMessageDialog(null, "目标路径错误", | ||
221 | "提示", 2); | ||
222 | } | ||
223 | break; | ||
224 | case "onFlawfinder": | ||
225 | // flawfinder检查 | ||
226 | if (src != null && src.length() != 0) { | ||
227 | new Thread() { | ||
228 | public void run() { | ||
229 | tmpFileName = "tmp" + "src" + ".csv"; | ||
230 | execute3(src, paraflawfinder, tmpFileName); | ||
231 | } | ||
232 | }.start(); | ||
233 | } else { | ||
234 | JOptionPane.showMessageDialog(null, "目标路径错误", | ||
235 | "提示", 2); | ||
236 | } | ||
237 | break; | ||
238 | case "onMenuAbout": | ||
239 | // 关于:显示软件信息 | ||
240 | JOptionPane.showMessageDialog(null, "cppcheckplus", | ||
241 | "提示", 2); | ||
242 | break; | ||
243 | case "onOrderType": | ||
244 | // 按类型排序:生成表格并按类型排序 | ||
245 | ct.makeTable(); | ||
246 | ct.ord(2); | ||
247 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
248 | viewPanel = new ViewPanel(ct.results); | ||
249 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
250 | tabPanel.isSelectTabComponents("结果"); | ||
251 | } else { | ||
252 | viewPanel.update(ct.results); | ||
253 | } | ||
254 | break; | ||
255 | case "onOrderLevel": | ||
256 | // 按级别排序 | ||
257 | ct.makeTable(); | ||
258 | ct.ord(3); | ||
259 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
260 | viewPanel = new ViewPanel(ct.results); | ||
261 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
262 | tabPanel.isSelectTabComponents("结果"); | ||
263 | } else { | ||
264 | viewPanel.update(ct.results); | ||
265 | } | ||
266 | break; | ||
267 | case "onOrderFile": | ||
268 | // 按文件排序 | ||
269 | ct.makeTable(); | ||
270 | ct.ord(1); | ||
271 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
272 | viewPanel = new ViewPanel(ct.results); | ||
273 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
274 | tabPanel.isSelectTabComponents("结果"); | ||
275 | } else { | ||
276 | viewPanel.update(ct.results); | ||
277 | } | ||
278 | break; | ||
279 | case "onSetCppcheckRoad": | ||
280 | // cppcheck路径 | ||
281 | jfsettings.setFileSelectionMode(0);// 设定只能选择到文件 | ||
282 | // int state = jfsettings.showOpenDialog(null); | ||
283 | if (jfsettings.showOpenDialog(null) == 1) { | ||
284 | return; // 撤销则返回 | ||
285 | } else { | ||
286 | File cppcheckFile = jfsettings.getSelectedFile(); | ||
287 | String cppcheckPathTemp = | ||
288 | cppcheckFile.getAbsolutePath(); | ||
289 | MyContorlUtil.fixSettingPath(settingsXML, | ||
290 | "cppcheck", cppcheckPathTemp); | ||
291 | changedpathcpp = true; | ||
292 | } | ||
293 | break; | ||
294 | case "onSetFlawfinderRoad": | ||
295 | // flawfinder路径 | ||
296 | jfsettings.setFileSelectionMode(0);// 设定只能选择到文件 | ||
297 | // int state = jfsettings.showOpenDialog(null); | ||
298 | if (jfsettings.showOpenDialog(null) == 1) { | ||
299 | return;// 撤销则返回 | ||
300 | } else { | ||
301 | File flawfinderFile = jfsettings.getSelectedFile(); | ||
302 | String flawfinderPathTemp = | ||
303 | flawfinderFile.getAbsolutePath(); | ||
304 | MyContorlUtil.fixSettingPath(settingsXML, | ||
305 | "flawfinder", flawfinderPathTemp); | ||
306 | changedpathflaw = true; | ||
307 | } | ||
308 | break; | ||
309 | } | ||
310 | } | ||
311 | }); | ||
312 | |||
313 | // 初始化主内容面板 | ||
314 | contentPanel = new MyContentPanel(); | ||
315 | try { | ||
316 | initSwing(); | ||
317 | } catch (UnsupportedEncodingException e1) { | ||
318 | e1.printStackTrace(); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | public static void main(String[] args) throws ParserConfigurationException { | ||
323 | |||
324 | SwingUtilities.invokeLater(new Runnable() { | ||
325 | public void run() { | ||
326 | MyContorlUtil.setupLookAndFeel(); | ||
327 | Main ui = new Main(); | ||
328 | ui.setVisible(true); | ||
329 | } | ||
330 | }); | ||
331 | } | ||
332 | |||
333 | private void execute(String src, String para) { | ||
334 | if (changedpathcpp) { | ||
335 | MyContorlUtil.loadToolsRoad(settingsXML, this); | ||
336 | changedpathcpp = false; | ||
337 | } | ||
338 | |||
339 | // 路径未配置,直接返回 | ||
340 | if (cppcheckPath == null) { | ||
341 | return; | ||
342 | } | ||
343 | |||
344 | Runtime runtime = Runtime.getRuntime(); | ||
345 | Process p = null; | ||
346 | Runtime runtime1 = Runtime.getRuntime(); | ||
347 | Process p1 = null; | ||
348 | try { | ||
349 | // 指定模板执行cppcheck,格式化输出信息 | ||
350 | p = runtime.exec(String.format(cppcheckPath + | ||
351 | " --template=\"cppcheck${file}${line}${severity}${id}${message}${cwe}\" %s %s", | ||
352 | para, src)); | ||
353 | final InputStream is1 = p.getInputStream(); | ||
354 | final InputStream is2 = p.getErrorStream(); | ||
355 | |||
356 | // 不使用模板,捕获错误信息 | ||
357 | p1 = | ||
358 | runtime.exec(String.format(cppcheckPath + " %s %s", para, src)); | ||
359 | System.out.printf(cppcheckPath + " %s %s%n", para, src); | ||
360 | final InputStream is11 = p1.getInputStream(); | ||
361 | final InputStream is21 = p1.getErrorStream(); | ||
362 | |||
363 | // 处理标准输出 | ||
364 | new Thread() { | ||
365 | @SuppressWarnings("resource") | ||
366 | public void run() { | ||
367 | |||
368 | BufferedReader br1 = | ||
369 | new BufferedReader(new InputStreamReader(is1)); | ||
370 | //StringBuilder l1 = new StringBuilder(); | ||
371 | try { | ||
372 | |||
373 | String line1 = null; | ||
374 | int i = 0; | ||
375 | textCheck.setText(""); | ||
376 | while ((line1 = br1.readLine()) != null) { | ||
377 | i++; | ||
378 | textCheck.append(i + " " + line1 + ENTERWindows); | ||
379 | } | ||
380 | } catch (Exception e) { | ||
381 | e.printStackTrace(); | ||
382 | System.out.println("inputError"); | ||
383 | } finally { | ||
384 | try { | ||
385 | //textCheck.setText(new String(l1.toString().getBytes(), "utf-8")); | ||
386 | is1.close(); | ||
387 | } catch (IOException e) { | ||
388 | e.printStackTrace(); | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | }.start(); | ||
393 | |||
394 | // 处理错误流 | ||
395 | new Thread() { | ||
396 | public void run() { | ||
397 | BufferedReader br2 = | ||
398 | new BufferedReader(new InputStreamReader(is2)); | ||
399 | StringBuilder l2 = new StringBuilder(); | ||
400 | try { | ||
401 | String line2 = null; | ||
402 | while ((line2 = br2.readLine()) != null) { | ||
403 | ct.toRowsOfCppcheckResult(line2); | ||
404 | } | ||
405 | } catch (Exception e) { | ||
406 | e.printStackTrace(); | ||
407 | } finally { | ||
408 | try { | ||
409 | is2.close(); | ||
410 | } catch (IOException e) { | ||
411 | e.printStackTrace(); | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | }.start(); | ||
416 | |||
417 | // 第二次的错误流 | ||
418 | new Thread() { | ||
419 | public void run() { | ||
420 | BufferedReader br2 = | ||
421 | new BufferedReader(new InputStreamReader(is21)); | ||
422 | StringBuilder l2 = new StringBuilder(); | ||
423 | cppcheckResult.setText(""); | ||
424 | try { | ||
425 | String line2 = null; | ||
426 | int i = 0; | ||
427 | while ((line2 = br2.readLine()) != null) { | ||
428 | l2.append(i + " " + line2 + ENTERWindows); | ||
429 | i++; | ||
430 | } | ||
431 | } catch (Exception e) { | ||
432 | e.printStackTrace(); | ||
433 | } finally { | ||
434 | try { | ||
435 | cppcheckResult.setText( | ||
436 | new String(l2.toString().getBytes(), | ||
437 | StandardCharsets.UTF_8)); | ||
438 | is21.close(); | ||
439 | } catch (IOException e) { | ||
440 | e.printStackTrace(); | ||
441 | } | ||
442 | } | ||
443 | } | ||
444 | }.start(); | ||
445 | |||
446 | // 等待两个进程结束 | ||
447 | int exitCode = p.waitFor(); | ||
448 | int exitCode1 = p1.waitFor(); | ||
449 | if (exitCode == SUCCESS) { | ||
450 | System.out.println(SUCCESS_MESSAGE); | ||
451 | |||
452 | } else { | ||
453 | System.err.println(ERROR_MESSAGE + exitCode); | ||
454 | } | ||
455 | p.destroy(); | ||
456 | p1.destroy(); | ||
457 | } catch (Exception e) { | ||
458 | try { | ||
459 | // 出现异常则关闭相关流 | ||
460 | p.getErrorStream().close(); | ||
461 | p.getInputStream().close(); | ||
462 | p.getOutputStream().close(); | ||
463 | p1.getErrorStream().close(); | ||
464 | p1.getInputStream().close(); | ||
465 | p1.getOutputStream().close(); | ||
466 | } catch (Exception ee) { | ||
467 | } | ||
468 | } | ||
469 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
470 | try { | ||
471 | ct.makeTable(); | ||
472 | viewPanel = new ViewPanel(ct.results); | ||
473 | } catch (Exception e1) { | ||
474 | e1.printStackTrace(); | ||
475 | System.out.println("图表生成错误"); | ||
476 | } | ||
477 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
478 | tabPanel.isSelectTabComponents("结果"); | ||
479 | } else { | ||
480 | try { | ||
481 | ct.makeTable(); | ||
482 | viewPanel.update(ct.results); | ||
483 | } catch (Exception e1) { | ||
484 | e1.printStackTrace(); | ||
485 | System.out.println("图表生成错误"); | ||
486 | } | ||
487 | } | ||
488 | } | ||
489 | |||
490 | private void execute2(String src) { | ||
491 | // clamh-tidy 检查 | ||
492 | Runtime runtime = Runtime.getRuntime(); | ||
493 | Process p = null; | ||
494 | try { | ||
495 | // 修改为执行 clang-tidy | ||
496 | String path = "C:\\MinGW\\include"; // FIXME: 需要修改为自己的路径 | ||
497 | Path srcPath = Paths.get(src); | ||
498 | String execable; | ||
499 | if (Files.isDirectory(srcPath)) { | ||
500 | // 是目录,则检查这个目录下所有cpp文件 | ||
501 | execable = String.format( | ||
502 | "clang-tidy %s\\*.cpp --checks=* --header-filter=%s -- -std=c++17 -I %s", | ||
503 | src, src, path); | ||
504 | } else { | ||
505 | // 是文件,直接执行 | ||
506 | execable = String.format( | ||
507 | "clang-tidy %s --checks=* --header-filter=%s -- -std=c++17 -I %s", | ||
508 | src, src, path); | ||
509 | } | ||
510 | //String execable1 = String.format("clang-tidy %s --checks=* --header-filter=%s -- -std=c++17 -I %s", src, src, path); | ||
511 | //String execable2 = String.format("clang-tidy %s\\*.cpp --checks=* --header-filter=%s -- -std=c++17 -I %s", src,src, path); | ||
512 | //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); | ||
513 | System.out.println(execable); | ||
514 | |||
515 | // 执行 | ||
516 | p = runtime.exec(execable); // -- 表示之后是源文件 | ||
517 | final InputStream is1 = p.getInputStream(); // 标准输出流 | ||
518 | final InputStream is2 = p.getErrorStream(); // clang-tidy 的错误流 | ||
519 | |||
520 | // 处理标准输出 | ||
521 | new Thread() { | ||
522 | public void run() { | ||
523 | BufferedReader br1 = | ||
524 | new BufferedReader(new InputStreamReader(is1)); | ||
525 | StringBuilder l1 = new StringBuilder(); | ||
526 | try { | ||
527 | String line1 = null; | ||
528 | while ((line1 = br1.readLine()) != null) { | ||
529 | // 只处理包含源文件路径的行 | ||
530 | if (line1.contains(src)) { | ||
531 | l1.append(line1).append(ENTERWindows); | ||
532 | // 如果有需要,可以将标准输出进行处理 | ||
533 | ct.toRowsOfClang(line1); | ||
534 | } | ||
535 | } | ||
536 | } catch (Exception e) { | ||
537 | e.printStackTrace(); | ||
538 | } finally { | ||
539 | try { | ||
540 | is1.close(); | ||
541 | } catch (IOException e) { | ||
542 | e.printStackTrace(); | ||
543 | } | ||
544 | } | ||
545 | } | ||
546 | }.start(); | ||
547 | |||
548 | // FIXME: 这一部分是否必要? | ||
549 | //new Thread() { | ||
550 | // | ||
551 | // | ||
552 | // public void run() { | ||
553 | // BufferedReader br2 = new BufferedReader(new InputStreamReader(is2)); | ||
554 | // StringBuilder l2 = new StringBuilder(); | ||
555 | // try { | ||
556 | // String line2 = null; | ||
557 | // int i = 0; | ||
558 | // clangResult.setText(""); | ||
559 | // while ((line2 = br2.readLine()) != null) { | ||
560 | // l2.append(i + " " + line2 + ENTERWindows); | ||
561 | // ct.toRowsOfClang(line2); // 可能需要根据 clang-tidy 的输出格式进行调整 | ||
562 | // i++; | ||
563 | // } | ||
564 | // } catch (Exception e) { | ||
565 | // e.printStackTrace(); | ||
566 | // System.out.println("inputError"); | ||
567 | // } finally { | ||
568 | // try { | ||
569 | // clangResult.setText(l2.substring(0, l2.length())); | ||
570 | // is2.close(); | ||
571 | // } catch (IOException e) { | ||
572 | // e.printStackTrace(); | ||
573 | // } | ||
574 | // } | ||
575 | // } | ||
576 | //}.start(); | ||
577 | |||
578 | int exitCode = p.waitFor(); | ||
579 | if (exitCode == SUCCESS) { | ||
580 | System.out.println(SUCCESS_MESSAGE); | ||
581 | |||
582 | } else { | ||
583 | System.err.println(ERROR_MESSAGE + exitCode); | ||
584 | } | ||
585 | |||
586 | // 为什么需要关闭两次? | ||
587 | p.destroy(); | ||
588 | p.destroy(); | ||
589 | } catch (Exception e) { | ||
590 | try { | ||
591 | p.getInputStream().close(); | ||
592 | p.getOutputStream().close(); | ||
593 | p.getErrorStream().close(); | ||
594 | } catch (Exception ee) { | ||
595 | } | ||
596 | } | ||
597 | |||
598 | // 更新或者创建结果标签页,显示结果 | ||
599 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
600 | try { | ||
601 | ct.makeTable(); | ||
602 | viewPanel = new ViewPanel(ct.results); | ||
603 | } catch (Exception e1) { | ||
604 | e1.printStackTrace(); | ||
605 | System.out.println("图表生成错误"); | ||
606 | } | ||
607 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
608 | tabPanel.isSelectTabComponents("结果"); | ||
609 | } else { | ||
610 | try { | ||
611 | ct.makeTable(); | ||
612 | viewPanel.update(ct.results); | ||
613 | } catch (Exception e1) { | ||
614 | e1.printStackTrace(); | ||
615 | System.out.println("图表生成错误"); | ||
616 | } | ||
617 | } | ||
618 | } | ||
619 | |||
620 | private void execute3(String src, String para, String tmpFileName) { | ||
621 | // flawfinder | ||
622 | if (changedpathflaw) { | ||
623 | MyContorlUtil.loadToolsRoad(settingsXML, this); | ||
624 | changedpathflaw = false; | ||
625 | } | ||
626 | |||
627 | if (flawfinderPath == null) { | ||
628 | return; | ||
629 | } | ||
630 | Runtime runtime = Runtime.getRuntime(); | ||
631 | Process p = null; | ||
632 | Runtime runtime2 = Runtime.getRuntime(); | ||
633 | Process p2 = null; | ||
634 | try { | ||
635 | |||
636 | // 两个参数数组,一个是csv格式,一个是传入的参数 | ||
637 | String[] arguments = | ||
638 | new String[] {"python", flawfinderPath, "--csv", src}; | ||
639 | String[] arguments2 = | ||
640 | new String[] {"python", flawfinderPath, para, src}; | ||
641 | |||
642 | p = runtime.exec(arguments); | ||
643 | p2 = runtime.exec(arguments2); | ||
644 | final InputStream is1 = p.getInputStream(); | ||
645 | final InputStream is2 = p2.getInputStream(); | ||
646 | System.out.println(arguments2[1]); | ||
647 | |||
648 | // csv结果添加到表格 | ||
649 | new Thread() { | ||
650 | public void run() { | ||
651 | BufferedReader br1 = | ||
652 | new BufferedReader(new InputStreamReader(is1)); | ||
653 | try { | ||
654 | String line1 = null; | ||
655 | while ((line1 = br1.readLine()) != null) { | ||
656 | ct.toRowsOfflawfinder(line1); | ||
657 | } | ||
658 | } catch (Exception e) { | ||
659 | e.printStackTrace(); | ||
660 | } finally { | ||
661 | try { | ||
662 | is1.close(); | ||
663 | } catch (IOException e) { | ||
664 | e.printStackTrace(); | ||
665 | } | ||
666 | } | ||
667 | } | ||
668 | }.start(); | ||
669 | |||
670 | // 普通结果显示在文本框 | ||
671 | new Thread() { | ||
672 | public void run() { | ||
673 | //flawfinder result | ||
674 | BufferedReader br1 = | ||
675 | new BufferedReader(new InputStreamReader(is2)); | ||
676 | StringBuilder l1 = new StringBuilder(); | ||
677 | flawfinderResult.setText(""); | ||
678 | try { | ||
679 | String line1 = null; | ||
680 | while ((line1 = br1.readLine()) != null) { | ||
681 | l1.append(line1 + ENTERWindows); | ||
682 | } | ||
683 | } catch (Exception e) { | ||
684 | e.printStackTrace(); | ||
685 | } finally { | ||
686 | try { | ||
687 | flawfinderResult.setText( | ||
688 | l1.substring(0, l1.length())); | ||
689 | is2.close(); | ||
690 | } catch (IOException e) { | ||
691 | e.printStackTrace(); | ||
692 | } | ||
693 | } | ||
694 | } | ||
695 | }.start(); | ||
696 | |||
697 | int exitCode = p.waitFor(); | ||
698 | int exitCode2 = p2.waitFor(); | ||
699 | if (exitCode == SUCCESS) { | ||
700 | System.out.println(SUCCESS_MESSAGE); | ||
701 | } else { | ||
702 | System.err.println(ERROR_MESSAGE + exitCode); | ||
703 | } | ||
704 | p.destroy(); | ||
705 | p2.destroy(); | ||
706 | } catch (Exception e) { | ||
707 | try { | ||
708 | p.getErrorStream().close(); | ||
709 | p.getInputStream().close(); | ||
710 | p.getOutputStream().close(); | ||
711 | p2.getErrorStream().close(); | ||
712 | p2.getInputStream().close(); | ||
713 | p2.getOutputStream().close(); | ||
714 | } catch (Exception ee) { | ||
715 | } | ||
716 | } | ||
717 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
718 | try { | ||
719 | ct.makeTable(); | ||
720 | viewPanel = new ViewPanel(ct.results); | ||
721 | } catch (Exception e1) { | ||
722 | e1.printStackTrace(); | ||
723 | System.out.println("图表生成错误"); | ||
724 | } | ||
725 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
726 | tabPanel.isSelectTabComponents("结果"); | ||
727 | } else { | ||
728 | try { | ||
729 | ct.makeTable(); | ||
730 | viewPanel.update(ct.results); | ||
731 | } catch (Exception e1) { | ||
732 | e1.printStackTrace(); | ||
733 | System.out.println("图表生成错误"); | ||
734 | } | ||
735 | } | ||
736 | |||
737 | } | ||
738 | |||
739 | private void initSwing() throws UnsupportedEncodingException { | ||
740 | setTitle("Cppcheckplus"); | ||
741 | setDefaultCloseOperation(3); // 关闭窗口时退出程序 | ||
742 | setSize(1024, 768); | ||
743 | |||
744 | // 设置窗口图标 | ||
745 | setIconImage(MyContorlUtil.getImage("control/images/logo2.png")); | ||
746 | setContentPane(contentPanel); | ||
747 | // 菜单栏在最上方 | ||
748 | contentPanel.add(menubar, "North"); | ||
749 | |||
750 | // 除却菜单栏之外的面板 | ||
751 | //JPanel centerPane = new JPanel(new BorderLayout()); | ||
752 | |||
753 | // 中间区域,除了菜单栏之外的所有内容 | ||
754 | MyPanel centerPane = new MyPanel(new BorderLayout()); | ||
755 | centerPane.setOpaque(true); | ||
756 | //centerPane.setBackground(MyContorlUtil.CONTENT_PANE_BACKGROUND3); | ||
757 | //centerPane.setBackground(MyContorlUtil.getImage("control/images/logo2.png")); | ||
758 | centerPane.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); | ||
759 | contentPanel.add(centerPane, "Center"); | ||
760 | |||
761 | // 初始化各个标签页、侧边栏、目录树 | ||
762 | initTab(); | ||
763 | initTab2(); | ||
764 | initOutlookPanel(); | ||
765 | try { | ||
766 | initShortcutPanel(); | ||
767 | } catch (UnsupportedEncodingException e) { | ||
768 | // TODO Auto-generated catch block | ||
769 | e.printStackTrace(); | ||
770 | } | ||
771 | initTree(); | ||
772 | |||
773 | // 面板加入布局 | ||
774 | centerPane.add(outlookPanel, "West"); | ||
775 | centerPane.add(tabPanel, "Center"); | ||
776 | centerPane.add(shortcutPanel, "East"); | ||
777 | |||
778 | // 底部添加第二个标签页面板,用于显示检查结果 | ||
779 | contentPanel.add(tabPanel2, BorderLayout.SOUTH); | ||
780 | } | ||
781 | |||
782 | private void initTree() { | ||
783 | tree = shortcutPanel.mytree; | ||
784 | // 点击目录树节点,显示对应文件内容 | ||
785 | tree.setCode(textCode, this); | ||
786 | } | ||
787 | |||
788 | private void initOutlookPanel() { | ||
789 | outlookPanel = new MyOutlookPanel(new ActionListener() { | ||
790 | @Override | ||
791 | public void actionPerformed(ActionEvent e) { | ||
792 | String command = e.getActionCommand(); | ||
793 | System.out.println("Head:" + command); | ||
794 | } | ||
795 | |||
796 | }, new ListSelectionListener() { | ||
797 | @Override | ||
798 | public void valueChanged(ListSelectionEvent e) { | ||
799 | boolean adjust = e.getValueIsAdjusting(); | ||
800 | if (!adjust) { | ||
801 | JList list = (JList) e.getSource(); | ||
802 | Object[] selectionValues = list.getSelectedValues(); | ||
803 | MyOutlookPanelListItem item = | ||
804 | (MyOutlookPanelListItem) selectionValues[0]; | ||
805 | String command = item.getActionCommand(); | ||
806 | if (command.equals("Chart2")) { | ||
807 | // 如果TabPanel不存在就create,否则就切换 | ||
808 | if (!tabPanel.isSelectTabComponents("结果")) { | ||
809 | try { | ||
810 | ct.makeTable(); | ||
811 | viewPanel = new ViewPanel(ct.results); | ||
812 | } catch (Exception e1) { | ||
813 | e1.printStackTrace(); | ||
814 | System.out.println("图表生成错误"); | ||
815 | } | ||
816 | tabPanel.addTab("结果", createPage(viewPanel)); | ||
817 | tabPanel.isSelectTabComponents("结果"); | ||
818 | } | ||
819 | } else if (command.equals("Map")) { | ||
820 | // 代码标签页 | ||
821 | if (!tabPanel.isSelectTabComponents("代码")) { | ||
822 | tabPanel.addTab("代码", testCode); | ||
823 | tabPanel.isSelectTabComponents("代码"); | ||
824 | } | ||
825 | } else if (command.equals("Process")) { | ||
826 | // 进度 | ||
827 | if (!tabPanel.isSelectTabComponents("进度")) { | ||
828 | tabPanel.addTab("进度", textCheck); | ||
829 | tabPanel.isSelectTabComponents("进度"); | ||
830 | } | ||
831 | } | ||
832 | } | ||
833 | } | ||
834 | |||
835 | }); | ||
836 | // 根据XML配置文件加载Outlook面板内容 | ||
837 | MyContorlUtil.loadOutlookPanel(outlookPanelXML, outlookPanel); | ||
838 | } | ||
839 | |||
840 | private void initTab() { | ||
841 | tabPanel = new MyTabPanel(); | ||
842 | tabPanel.addMouseListener(new MouseAdapter() { | ||
843 | private boolean isMaximized() { | ||
844 | return outlookPanel.isShrinked(); | ||
845 | } | ||
846 | |||
847 | public void mouseClicked(MouseEvent e) { | ||
848 | if (e.getClickCount() > 1) { | ||
849 | TabbedPaneUI ui = tabPanel.getUI(); | ||
850 | int tabIndex = | ||
851 | ui.tabForCoordinate(tabPanel, e.getX(), e.getY()); | ||
852 | if (tabIndex != -1) { | ||
853 | boolean maxed = isMaximized(); | ||
854 | outlookPanel.setShrink(!maxed); | ||
855 | shortcutPanel.setShrink(!maxed); | ||
856 | } | ||
857 | } | ||
858 | } | ||
859 | }); | ||
860 | |||
861 | testCode = new MyTextPanel(); | ||
862 | testPanel = new MyTextPanel1(); | ||
863 | viewPanel = new ViewPanel(); | ||
864 | textCode = testCode.getTextArea(); | ||
865 | textCheck = testPanel.getTextArea(); | ||
866 | } | ||
867 | |||
868 | private void initTab2() { | ||
869 | tabPanel2 = new MyTabPanel1(); | ||
870 | tabPanel2.addMouseListener(new MouseAdapter() { | ||
871 | private boolean isMaximized() { | ||
872 | return outlookPanel.isShrinked(); | ||
873 | } | ||
874 | |||
875 | public void mouseClicked(MouseEvent e) { | ||
876 | if (e.getClickCount() > 1) { | ||
877 | TabbedPaneUI ui = tabPanel2.getUI(); | ||
878 | int tabIndex = | ||
879 | ui.tabForCoordinate(tabPanel2, e.getX(), e.getY()); | ||
880 | if (tabIndex != -1) { | ||
881 | boolean maxed = isMaximized(); | ||
882 | outlookPanel.setShrink(!maxed); | ||
883 | shortcutPanel.setShrink(!maxed); | ||
884 | } | ||
885 | } | ||
886 | } | ||
887 | }); | ||
888 | |||
889 | flawfinderPanel = new MyTextPanel1(); | ||
890 | cppcheckPanel = new MyTextPanel1(); | ||
891 | clangPanel = new MyTextPanel1(); | ||
892 | flawfinderResult = flawfinderPanel.getTextArea(); | ||
893 | cppcheckResult = cppcheckPanel.getTextArea(); | ||
894 | clangResult = clangPanel.getTextArea(); | ||
895 | |||
896 | tabPanel2.addTab("cppcheck", createPage1(cppcheckPanel)); | ||
897 | tabPanel2.addTab("Clang", createPage1(clangPanel)); | ||
898 | tabPanel2.addTab("flawfinder", createPage1(flawfinderPanel)); | ||
899 | } | ||
900 | |||
901 | private MyTabPage1 createPage1(JComponent pageContent) { | ||
902 | MyTabPage1 page = new MyTabPage1(pageContent); | ||
903 | return page; | ||
904 | } | ||
905 | |||
906 | private MyTabPage createPage(JComponent pageContent) { | ||
907 | MyTabPage page = new MyTabPage(pageContent); | ||
908 | return page; | ||
909 | } | ||
910 | |||
911 | //改造成目录树 | ||
912 | private void initShortcutPanel() throws UnsupportedEncodingException { | ||
913 | shortcutPanel = new MyShortcutPanel(); | ||
914 | shortcutPanel.setTitle( | ||
915 | new String("项目".getBytes(), StandardCharsets.UTF_8)); | ||
916 | } | ||
917 | } | ||
diff --git a/src/cppcheckplus/control/MyContentPanel.java b/src/cppcheckplus/control/MyContentPanel.java new file mode 100644 index 0000000..63d792a --- /dev/null +++ b/src/cppcheckplus/control/MyContentPanel.java | |||
@@ -0,0 +1,16 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | |||
6 | import javax.swing.JPanel; | ||
7 | |||
8 | public class MyContentPanel extends JPanel | ||
9 | { | ||
10 | public MyContentPanel() | ||
11 | { | ||
12 | super(); | ||
13 | setLayout(new BorderLayout()); | ||
14 | setBackground(MyContorlUtil.CONTENT_PANE_BACKGROUND); | ||
15 | } | ||
16 | } | ||
diff --git a/src/cppcheckplus/control/MyContorlUtil.java b/src/cppcheckplus/control/MyContorlUtil.java new file mode 100644 index 0000000..72716de --- /dev/null +++ b/src/cppcheckplus/control/MyContorlUtil.java | |||
@@ -0,0 +1,597 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Component; | ||
6 | import java.awt.Font; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Graphics2D; | ||
9 | import java.awt.Image; | ||
10 | import java.awt.Insets; | ||
11 | import java.awt.Rectangle; | ||
12 | import java.awt.TexturePaint; | ||
13 | import java.awt.event.ActionListener; | ||
14 | import java.awt.image.BufferedImage; | ||
15 | import java.awt.image.PixelGrabber; | ||
16 | import java.io.File; | ||
17 | import java.io.FileOutputStream; | ||
18 | import java.io.IOException; | ||
19 | import java.io.InputStream; | ||
20 | import java.util.ArrayList; | ||
21 | import java.util.List; | ||
22 | |||
23 | import javax.imageio.ImageIO; | ||
24 | import javax.swing.BorderFactory; | ||
25 | import javax.swing.Box; | ||
26 | import javax.swing.Icon; | ||
27 | import javax.swing.ImageIcon; | ||
28 | import javax.swing.JLabel; | ||
29 | import javax.swing.JMenuItem; | ||
30 | import javax.swing.UIManager; | ||
31 | import javax.swing.plaf.FontUIResource; | ||
32 | import javax.xml.parsers.DocumentBuilder; | ||
33 | import javax.xml.parsers.DocumentBuilderFactory; | ||
34 | import javax.xml.transform.Transformer; | ||
35 | import javax.xml.transform.TransformerFactory; | ||
36 | import javax.xml.transform.dom.DOMSource; | ||
37 | import javax.xml.transform.stream.StreamResult; | ||
38 | |||
39 | import org.w3c.dom.Document; | ||
40 | import org.w3c.dom.Element; | ||
41 | import org.w3c.dom.Node; | ||
42 | import org.w3c.dom.NodeList; | ||
43 | |||
44 | import com.jgoodies.looks.plastic.PlasticLookAndFeel; | ||
45 | import com.jgoodies.looks.plastic.theme.ExperienceGreen; | ||
46 | |||
47 | import cppcheckplus.menu.MyMenu; | ||
48 | import cppcheckplus.menu.MyMenuBar; | ||
49 | import cppcheckplus.menu.MyMenuItem; | ||
50 | import cppcheckplus.menu.MyRootMenu; | ||
51 | import cppcheckplus.outlookpanel.MyOutlookBar; | ||
52 | import cppcheckplus.outlookpanel.MyOutlookHeader; | ||
53 | import cppcheckplus.outlookpanel.MyOutlookPanel; | ||
54 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * @ClassName: ContorlUtil | ||
59 | * @Description: TODO(控件工具,皮肤信息和基本操作) | ||
60 | * | ||
61 | */ | ||
62 | public class MyContorlUtil | ||
63 | { | ||
64 | //文本 | ||
65 | public static final Color DEFAULT_TEXT_COLOR = new Color(37, 81, 54); | ||
66 | public static final Font FONT_14_BOLD = new Font("微软雅黑", 1, 14); | ||
67 | public static final Font FONT_12_BOLD = new Font("微软雅黑", 1, 12); | ||
68 | public static final Font FONT_14_PLAIN = new Font("微软雅黑", 0, 14); | ||
69 | public static final Font FONT_12_PLAIN = new Font("微软雅黑", 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); | ||
72 | //菜单 | ||
73 | public static final Color MENUITEM_SELECTED_BACKGROUND = new Color(166, 188, 140); | ||
74 | public static final Color MENUITEM_BACKGROUND = new Color(228, 235, 218); | ||
75 | //主面板 | ||
76 | public static final Color CONTENT_PANE_BACKGROUND = new Color(92, 153, 45); | ||
77 | public static final Color CONTENT_PANE_BACKGROUND2 = new Color(78, 238, 148); | ||
78 | public static final Color CONTENT_PANE_BACKGROUND3 = new Color(238, 220, 130); | ||
79 | //工具栏按钮 | ||
80 | public static final Color BUTTON_ROVER_COLOR = new Color(196, 196, 197); | ||
81 | //OutLook面板 | ||
82 | public static final Color OUTLOOK_TEXT_COLOR = new Color(120, 120, 125); | ||
83 | public static final Color OUTLOOK_SPLIT_COLOR = new Color(174, 171, 162); | ||
84 | public static final Color OUTLOOK_CONTAINER_COLOR = new Color(217, 218, 219) ;//容器的背景颜色,灰色 | ||
85 | //多视图Tab | ||
86 | public static final Color TAB_BOTTOM_LINE_COLOR = new Color(167, 173, 175); | ||
87 | //快捷菜单面板 | ||
88 | public static final Color LIST_SPLIT_COLOR = new Color(105, 113, 120); | ||
89 | public static final Color LIST_BACKGROUND = new Color(175, 174, 176); | ||
90 | public static final Color LIST_TEXT_COLOR = new Color(49, 52, 58); | ||
91 | //图形 | ||
92 | public static Font CHART_AXIS_FONT = new Font("微软雅黑",Font.PLAIN,12) ;// 坐标轴字体 | ||
93 | public static Font CHART_TITLE_FONT = new Font("微软雅黑",Font.PLAIN,14);//标题字体 | ||
94 | public static Font CHART_LEGEND_FONT = new Font("微软雅黑",Font.PLAIN,12); //图例字体 | ||
95 | |||
96 | //其他 | ||
97 | public static final Color NO_COLOR = new Color(0, 0, 0, 0); | ||
98 | public static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0); | ||
99 | /** | ||
100 | * ClassLoader获得BufferedImage,注意和getClass().getResource()的路径不同 | ||
101 | * 最前面不带/ | ||
102 | * @param @param imgPath | ||
103 | * @param @return 参数 | ||
104 | * @return Image 返回类型 | ||
105 | * @throws | ||
106 | */ | ||
107 | public static Image getImage(String imgPath) | ||
108 | { | ||
109 | BufferedImage img = null; | ||
110 | try | ||
111 | { | ||
112 | //System.out.println("图片路径: "+imgPath); | ||
113 | img = ImageIO.read(ClassLoader.getSystemResource(imgPath)); | ||
114 | } catch (IOException e) | ||
115 | { | ||
116 | System.out.println("图片路径找不到: "+imgPath); | ||
117 | //e.printStackTrace(); | ||
118 | } | ||
119 | return img; | ||
120 | } | ||
121 | public static ImageIcon getImageIcon(String imgPath) | ||
122 | { | ||
123 | ImageIcon icon = null; | ||
124 | try | ||
125 | { | ||
126 | icon = new ImageIcon(ClassLoader.getSystemResource(imgPath)); | ||
127 | return icon; | ||
128 | } | ||
129 | catch (Exception e) | ||
130 | { | ||
131 | System.out.println("找不到图片: " +imgPath ); | ||
132 | } | ||
133 | return icon; | ||
134 | } | ||
135 | public static Image iconToImage(Icon icon) | ||
136 | { | ||
137 | if (icon instanceof ImageIcon) | ||
138 | { | ||
139 | return ((ImageIcon) icon).getImage(); | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | int w = icon.getIconWidth(); | ||
144 | int h = icon.getIconHeight(); | ||
145 | BufferedImage image = new BufferedImage(w, h, 2); | ||
146 | Graphics2D g = image.createGraphics(); | ||
147 | icon.paintIcon(null, g, 0, 0); | ||
148 | g.dispose(); | ||
149 | return image; | ||
150 | } | ||
151 | } | ||
152 | public static ImageIcon createDyedIcon(ImageIcon icon, Color color) | ||
153 | { | ||
154 | if (color == null) | ||
155 | { | ||
156 | return icon; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | int iconWidth = icon.getIconWidth(); | ||
161 | int iconHeight = icon.getIconHeight(); | ||
162 | BufferedImage bi = new BufferedImage(iconWidth, iconHeight, 2); | ||
163 | Graphics2D g2d = bi.createGraphics(); | ||
164 | icon.paintIcon(null, g2d, 0, 0); | ||
165 | g2d.dispose(); | ||
166 | Image dyedImage = createDyedImage(bi, color); | ||
167 | return new ImageIcon(dyedImage); | ||
168 | } | ||
169 | } | ||
170 | public static Image createDyedImage(Image image, Color color) | ||
171 | { | ||
172 | if (color == null) | ||
173 | return image; | ||
174 | if (image != null) | ||
175 | { | ||
176 | int w = image.getWidth(null); | ||
177 | int h = image.getHeight(null); | ||
178 | int pixels[] = new int[w * h]; | ||
179 | PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w); | ||
180 | try | ||
181 | { | ||
182 | pg.grabPixels(); | ||
183 | } | ||
184 | catch (InterruptedException ex) | ||
185 | { | ||
186 | ex.printStackTrace(); | ||
187 | return null; | ||
188 | } | ||
189 | BufferedImage bi = new BufferedImage(w <= 1 ? 1 : w, | ||
190 | h <= 1 ? 1 : h, 2); | ||
191 | for (int i = 0; i < pixels.length; i++) | ||
192 | { | ||
193 | int pixel = pixels[i]; | ||
194 | int row = i / w; | ||
195 | int col = i % w; | ||
196 | if (color != null && pixel != 0) | ||
197 | pixel = color.getRGB(); | ||
198 | bi.setRGB(col, row, pixel); | ||
199 | } | ||
200 | return bi; | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | return null; | ||
205 | } | ||
206 | } | ||
207 | public static Icon createMovedIcon(Icon icon) | ||
208 | { | ||
209 | return createMovedIcon(icon, 1, 1); | ||
210 | } | ||
211 | public static Icon createMovedIcon(final Icon icon, final int offsetX, | ||
212 | final int offsetY) | ||
213 | { | ||
214 | return new Icon() | ||
215 | { | ||
216 | public void paintIcon(Component c, Graphics g, int x, int y) | ||
217 | { | ||
218 | icon.paintIcon(c, g, x + offsetX, y + offsetY); | ||
219 | } | ||
220 | public int getIconWidth() | ||
221 | { | ||
222 | return icon.getIconWidth(); | ||
223 | } | ||
224 | public int getIconHeight() | ||
225 | { | ||
226 | return icon.getIconHeight(); | ||
227 | } | ||
228 | }; | ||
229 | } | ||
230 | |||
231 | public static TexturePaint createTexturePaint(String imgPath) | ||
232 | { | ||
233 | ImageIcon icon = getImageIcon(imgPath); | ||
234 | int imageWidth = icon.getIconWidth(); | ||
235 | int imageHeight = icon.getIconHeight(); | ||
236 | BufferedImage bi = new BufferedImage(imageWidth, imageHeight, 2); | ||
237 | Graphics2D g2d = bi.createGraphics(); | ||
238 | g2d.drawImage(icon.getImage(), 0, 0, null); | ||
239 | g2d.dispose(); | ||
240 | return new TexturePaint(bi, | ||
241 | new Rectangle(0, 0, imageWidth, imageHeight)); | ||
242 | } | ||
243 | |||
244 | public static Color getColor(String color) { | ||
245 | Color convertedColor = Color.ORANGE; | ||
246 | try { | ||
247 | convertedColor = new Color(Integer.parseInt(color, 16)); | ||
248 | } catch(NumberFormatException e) { | ||
249 | String error = String.format("颜色转化出错:s%",color); | ||
250 | System.out.println(error); | ||
251 | } | ||
252 | return convertedColor; | ||
253 | } | ||
254 | |||
255 | public static InputStream getXMLFile(String filePath) | ||
256 | { | ||
257 | return ClassLoader.getSystemResourceAsStream(filePath); | ||
258 | } | ||
259 | |||
260 | |||
261 | public static String getStringAttribute(org.w3c.dom.Node node, String name) | ||
262 | { | ||
263 | org.w3c.dom.Node attribute = node.getAttributes().getNamedItem(name); | ||
264 | if (attribute != null) | ||
265 | return attribute.getNodeValue(); | ||
266 | else | ||
267 | return null; | ||
268 | } | ||
269 | |||
270 | private static Icon getIconAttribute(org.w3c.dom.Node node, String name) | ||
271 | { | ||
272 | String iconURL = getStringAttribute(node, name); | ||
273 | if (iconURL != null && !iconURL.isEmpty()) | ||
274 | return getImageIcon(iconURL); | ||
275 | else | ||
276 | return null; | ||
277 | } | ||
278 | |||
279 | private static int getIntAttribute(org.w3c.dom.Node node, String name) | ||
280 | { | ||
281 | String value = getStringAttribute(node, name); | ||
282 | if (value != null && !value.isEmpty()) | ||
283 | return Integer.valueOf(value).intValue(); | ||
284 | else | ||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | public static MyMenuBar loadMenuBar(String xml, ActionListener action) | ||
289 | { | ||
290 | MyMenuBar menuBar = null; | ||
291 | try | ||
292 | { | ||
293 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
294 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
295 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | ||
296 | Element root = doc.getDocumentElement(); | ||
297 | NodeList rootMenus = root.getChildNodes(); | ||
298 | if (rootMenus != null) | ||
299 | { | ||
300 | menuBar = new MyMenuBar(); | ||
301 | for (int i = 0; i < rootMenus.getLength(); i++) | ||
302 | { | ||
303 | org.w3c.dom.Node menu = rootMenus.item(i); | ||
304 | if (menu.getNodeType() == Node.ELEMENT_NODE) | ||
305 | { | ||
306 | if (menu.getNodeName().equalsIgnoreCase("menu")) | ||
307 | { | ||
308 | String text = MyContorlUtil.getStringAttribute(menu, "text"); | ||
309 | MyRootMenu rootMenu = new MyRootMenu(); | ||
310 | rootMenu.setText(text); | ||
311 | menuBar.add(rootMenu); | ||
312 | processMenuItem(menu, rootMenu, action); | ||
313 | } | ||
314 | if (menu.getNodeName().equalsIgnoreCase("logo")) | ||
315 | { | ||
316 | String tooltip = MyContorlUtil.getStringAttribute(menu, "tooltip"); | ||
317 | String imageURL = MyContorlUtil.getStringAttribute(menu, "image"); | ||
318 | menuBar.add(Box.createGlue()); | ||
319 | JLabel label = new JLabel(MyContorlUtil.getImageIcon(imageURL)); | ||
320 | label.setBorder(BorderFactory.createEmptyBorder(0,5, 0, 5)); | ||
321 | label.setToolTipText(tooltip); | ||
322 | menuBar.add(label); | ||
323 | } | ||
324 | } | ||
325 | } | ||
326 | } | ||
327 | } | ||
328 | catch (Exception ex) | ||
329 | { | ||
330 | ex.printStackTrace(); | ||
331 | } | ||
332 | return menuBar; | ||
333 | } | ||
334 | |||
335 | |||
336 | public static void fixSettingPath(String xml, String tool, String newPath) | ||
337 | { | ||
338 | try | ||
339 | { | ||
340 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
341 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
342 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | ||
343 | Element root = doc.getDocumentElement(); | ||
344 | NodeList tools = root.getChildNodes(); | ||
345 | if (tools != null) | ||
346 | { | ||
347 | for (int i = 0; i < tools.getLength(); i++) | ||
348 | { | ||
349 | org.w3c.dom.Node menu = tools.item(i); | ||
350 | if (menu.getNodeType() == Node.ELEMENT_NODE) | ||
351 | { | ||
352 | if (menu.getNodeName().equalsIgnoreCase("tool")) | ||
353 | { | ||
354 | org.w3c.dom.Node att = menu.getAttributes().getNamedItem("id"); | ||
355 | String toolName = MyContorlUtil.getStringAttribute(menu, "toolName"); | ||
356 | if(tool.equals("cppcheck") && toolName.equals("cppcheck") ){ | ||
357 | org.w3c.dom.Node attribute = menu.getAttributes().getNamedItem("filePath"); | ||
358 | if (attribute != null) | ||
359 | attribute.setNodeValue(newPath.replaceAll("\\\\","\\/")); | ||
360 | } | ||
361 | else if(tool.equals("flawfinder") && toolName.equals("flawfinder")){ | ||
362 | org.w3c.dom.Node attribute = menu.getAttributes().getNamedItem("filePath"); | ||
363 | if (attribute != null) | ||
364 | attribute.setNodeValue(newPath.replaceAll("\\\\","\\/")); | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | } | ||
369 | } | ||
370 | |||
371 | Transformer transformer=TransformerFactory.newInstance().newTransformer(); | ||
372 | DOMSource source=new DOMSource(doc); | ||
373 | File file =new File(ClassLoader.getSystemResource(xml).toURI()); | ||
374 | FileOutputStream outstream =new FileOutputStream("src/cppcheckplus/control/settings.xml"); | ||
375 | StreamResult reslut=new StreamResult(outstream); | ||
376 | transformer.transform(source, reslut); | ||
377 | outstream.close(); | ||
378 | |||
379 | } | ||
380 | catch (Exception ex) | ||
381 | { | ||
382 | ex.printStackTrace(); | ||
383 | } | ||
384 | |||
385 | } | ||
386 | |||
387 | public static void loadToolsRoad(String xml, Main main) | ||
388 | { | ||
389 | try | ||
390 | { | ||
391 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
392 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
393 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | ||
394 | Element root = doc.getDocumentElement(); | ||
395 | NodeList tools = root.getChildNodes(); | ||
396 | if (tools != null) | ||
397 | { | ||
398 | for (int i = 0; i < tools.getLength(); i++) | ||
399 | { | ||
400 | org.w3c.dom.Node menu = tools.item(i); | ||
401 | if (menu.getNodeType() == Node.ELEMENT_NODE) | ||
402 | { | ||
403 | if (menu.getNodeName().equalsIgnoreCase("tool")) | ||
404 | { | ||
405 | String toolName = MyContorlUtil.getStringAttribute(menu, "toolName"); | ||
406 | String filePath = MyContorlUtil.getStringAttribute(menu, "filePath"); | ||
407 | String para= MyContorlUtil.getStringAttribute(menu, "para"); | ||
408 | if(toolName.equals("cppcheck")){ | ||
409 | main.cppcheckPath=filePath; | ||
410 | main.paracppcheck=para; | ||
411 | } | ||
412 | else if(toolName.equals("flawfinder")){ | ||
413 | main.flawfinderPath=filePath; | ||
414 | main.paraflawfinder=para; | ||
415 | } | ||
416 | } | ||
417 | } | ||
418 | } | ||
419 | } | ||
420 | } | ||
421 | catch (Exception ex) | ||
422 | { | ||
423 | ex.printStackTrace(); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | |||
428 | |||
429 | private static void processMenuItem(org.w3c.dom.Node menu, | ||
430 | JMenuItem parentMenu, ActionListener action) | ||
431 | { | ||
432 | NodeList children = menu.getChildNodes(); | ||
433 | if (children != null) | ||
434 | { | ||
435 | for (int j = 0; j < children.getLength(); j++) | ||
436 | { | ||
437 | org.w3c.dom.Node itemNode = children.item(j); | ||
438 | if (itemNode.getNodeType() != Node.ELEMENT_NODE) | ||
439 | continue; | ||
440 | boolean isMenuItem = itemNode.getNodeName().equalsIgnoreCase( | ||
441 | "menuitem"); | ||
442 | boolean isMenu = itemNode.getNodeName() | ||
443 | .equalsIgnoreCase("menu"); | ||
444 | if (!isMenuItem && !isMenu) | ||
445 | continue; | ||
446 | String text = getStringAttribute(itemNode, "text"); | ||
447 | String tooltip = getStringAttribute(itemNode, "tooltip"); | ||
448 | Icon icon = getIconAttribute(itemNode, "icon"); | ||
449 | String command = getStringAttribute(itemNode, "action"); | ||
450 | JMenuItem menuItem = null; | ||
451 | if (isMenu) | ||
452 | { | ||
453 | menuItem = new MyMenu(); | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | menuItem = new MyMenuItem(); | ||
458 | menuItem.addActionListener(action); | ||
459 | } | ||
460 | menuItem.setText(text); | ||
461 | menuItem.setToolTipText(tooltip); | ||
462 | menuItem.setActionCommand(command); | ||
463 | menuItem.setIcon(icon); | ||
464 | parentMenu.add(menuItem); | ||
465 | if (isMenu) | ||
466 | processMenuItem(itemNode, menuItem, action); | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | |||
471 | //加载OutloolPanel上的最上面的快捷工具栏OutlookHeader | ||
472 | public static void loadOutlookToolBar(String xml, MyOutlookHeader header, | ||
473 | ActionListener action) | ||
474 | { | ||
475 | try | ||
476 | { | ||
477 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
478 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
479 | Document doc = db.parse(getXMLFile(xml)); | ||
480 | Element root = doc.getDocumentElement(); | ||
481 | NodeList buttons = root.getChildNodes(); | ||
482 | if (buttons != null) | ||
483 | { | ||
484 | for (int i = 0; i < buttons.getLength(); i++) | ||
485 | { | ||
486 | org.w3c.dom.Node buttonNode = buttons.item(i); | ||
487 | if (buttonNode.getNodeType() == Node.ELEMENT_NODE) | ||
488 | { | ||
489 | if (buttonNode.getNodeName().equalsIgnoreCase("button")) | ||
490 | { | ||
491 | String tooltip = getStringAttribute(buttonNode, | ||
492 | "tooltip"); | ||
493 | Icon icon = getIconAttribute(buttonNode, "icon"); | ||
494 | String command = getStringAttribute(buttonNode, | ||
495 | "action"); | ||
496 | header.addButton(icon, tooltip, action, command); | ||
497 | } | ||
498 | if (buttonNode.getNodeName().equalsIgnoreCase( | ||
499 | "separator")) | ||
500 | header.addSeparator(); | ||
501 | } | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | catch (Exception ex) | ||
506 | { | ||
507 | ex.printStackTrace(); | ||
508 | } | ||
509 | } | ||
510 | |||
511 | public static void loadOutlookPanel(String xml, MyOutlookPanel outlookPane) | ||
512 | { | ||
513 | try | ||
514 | { | ||
515 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
516 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
517 | Document doc = db.parse(getXMLFile(xml)); | ||
518 | Element root = doc.getDocumentElement(); | ||
519 | NodeList modules = root.getChildNodes(); | ||
520 | if (modules != null) | ||
521 | { | ||
522 | for (int i = 0; i < modules.getLength(); i++) | ||
523 | { | ||
524 | org.w3c.dom.Node moduleNode = modules.item(i); | ||
525 | if (moduleNode.getNodeType() == Node.ELEMENT_NODE | ||
526 | && moduleNode.getNodeName().equalsIgnoreCase( | ||
527 | "module")) | ||
528 | { | ||
529 | String text = getStringAttribute(moduleNode, "text"); | ||
530 | Icon icon = getIconAttribute(moduleNode, "icon"); | ||
531 | Icon iconSelected = getIconAttribute(moduleNode, | ||
532 | "selected_icon"); | ||
533 | MyOutlookBar bar = outlookPane.addBar(text, icon, | ||
534 | iconSelected,getOutlookPanelSubModules(moduleNode)); | ||
535 | } | ||
536 | } | ||
537 | } | ||
538 | } | ||
539 | catch (Exception ex) | ||
540 | { | ||
541 | ex.printStackTrace(); | ||
542 | } | ||
543 | } | ||
544 | |||
545 | private static MyOutlookPanelListItem[] getOutlookPanelSubModules(Node moduleNode) | ||
546 | { | ||
547 | List<MyOutlookPanelListItem> listItemList = new ArrayList<MyOutlookPanelListItem>(); | ||
548 | if(moduleNode != null) | ||
549 | { | ||
550 | NodeList subModules = moduleNode.getChildNodes(); | ||
551 | for (int i = 0; i < subModules.getLength(); i++) | ||
552 | { | ||
553 | Node subNode = subModules.item(i); | ||
554 | if( (subNode.getNodeType() == Node.ELEMENT_NODE) && (subNode.getNodeName().equalsIgnoreCase("submodule")) ) | ||
555 | { | ||
556 | MyOutlookPanelListItem item = new MyOutlookPanelListItem(); | ||
557 | item.setIcon(getIconAttribute(subNode, "icon")); | ||
558 | item.setText(getStringAttribute(subNode,"text")); | ||
559 | item.setToolTip(getStringAttribute(subNode, "tooltip")); | ||
560 | item.setActionCommand(getStringAttribute(subNode, "action")); | ||
561 | listItemList.add(item); | ||
562 | } | ||
563 | } | ||
564 | } | ||
565 | MyOutlookPanelListItem[] items = new MyOutlookPanelListItem[listItemList.size()]; | ||
566 | return listItemList.toArray(items); | ||
567 | } | ||
568 | |||
569 | public static void setupLookAndFeel() | ||
570 | { | ||
571 | //Locale.setDefault(new Locale("EN_US")); | ||
572 | com.jgoodies.looks.plastic.PlasticTheme theme = new ExperienceGreen() | ||
573 | { | ||
574 | public FontUIResource getControlTextFont() | ||
575 | { | ||
576 | return new FontUIResource(new Font("微软雅黑", 0, 11)); | ||
577 | } | ||
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 | } | ||
diff --git a/src/cppcheckplus/control/MyHeader.java b/src/cppcheckplus/control/MyHeader.java new file mode 100644 index 0000000..1b71704 --- /dev/null +++ b/src/cppcheckplus/control/MyHeader.java | |||
@@ -0,0 +1,201 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Color; | ||
6 | import java.awt.Container; | ||
7 | import java.awt.Cursor; | ||
8 | import java.awt.Dimension; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Graphics2D; | ||
11 | import java.awt.Image; | ||
12 | import java.awt.TexturePaint; | ||
13 | import java.awt.event.MouseAdapter; | ||
14 | import java.awt.event.MouseEvent; | ||
15 | import java.awt.event.MouseListener; | ||
16 | |||
17 | import javax.swing.BorderFactory; | ||
18 | import javax.swing.ImageIcon; | ||
19 | import javax.swing.JComponent; | ||
20 | import javax.swing.JLabel; | ||
21 | import javax.swing.JPanel; | ||
22 | import javax.swing.border.Border; | ||
23 | |||
24 | |||
25 | |||
26 | public class MyHeader extends JPanel | ||
27 | { | ||
28 | public static final ImageIcon RIGHT_ARROW_ICON = MyContorlUtil.getImageIcon("control/images/shrink_handler_right.png"); | ||
29 | public static final ImageIcon LEFT_ARROW_ICON = MyContorlUtil.getImageIcon("control/images/shrink_handler_left.png"); | ||
30 | private Color titleColor; | ||
31 | private boolean shrinked; | ||
32 | private ImageIcon backgroundImageIcon; | ||
33 | private Image backgroundLeftImage; | ||
34 | private Image backgroundRightImage; | ||
35 | private TexturePaint paint; | ||
36 | private int preferredHeight; | ||
37 | private JLabel lbResizeHandler; | ||
38 | private JLabel lbShrinkHandler; | ||
39 | private JLabel lbTitle; | ||
40 | private int normalPreferredWidth; | ||
41 | private MyListSplitListener splitListener; | ||
42 | private MouseListener shrinkListener; | ||
43 | |||
44 | public MyHeader() | ||
45 | { | ||
46 | super(); | ||
47 | titleColor = new Color(215, 215, 216); | ||
48 | shrinked = false; | ||
49 | backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/header_background.png"); | ||
50 | backgroundLeftImage = MyContorlUtil.getImage("control/images/header_background_left.png"); | ||
51 | backgroundRightImage = MyContorlUtil.getImage("control/images/header_background_right.png"); | ||
52 | paint = MyContorlUtil.createTexturePaint("control/images/header_background.png"); | ||
53 | preferredHeight = backgroundImageIcon.getIconHeight(); | ||
54 | lbResizeHandler = new JLabel(MyContorlUtil.getImageIcon("control/images/resize_handler.png")); | ||
55 | lbShrinkHandler = new JLabel(getShrinkIcon(shrinked)); | ||
56 | lbTitle = new JLabel(); | ||
57 | normalPreferredWidth = 0; | ||
58 | splitListener = createSplitListener(); | ||
59 | shrinkListener = new MouseAdapter() { | ||
60 | public void mouseClicked(MouseEvent e) | ||
61 | { | ||
62 | changeShrink(); | ||
63 | } | ||
64 | }; | ||
65 | init(); | ||
66 | } | ||
67 | |||
68 | protected MyListSplitListener createSplitListener() | ||
69 | { | ||
70 | return new MyListSplitListener(this); | ||
71 | } | ||
72 | |||
73 | protected Border createBorder() | ||
74 | { | ||
75 | return BorderFactory.createEmptyBorder(4, 7, 0, 0); | ||
76 | } | ||
77 | |||
78 | private void init() | ||
79 | { | ||
80 | setBorder(createBorder()); | ||
81 | setOpaque(false); | ||
82 | setLayout(new BorderLayout()); | ||
83 | add(lbResizeHandler, getResizeHandlerLayoutConstraint()); | ||
84 | add(lbShrinkHandler, getShrinkHandlerLayoutConstraint()); | ||
85 | JComponent centerComponent = getCenterComponent(); | ||
86 | if (centerComponent != null) | ||
87 | add(centerComponent, "Center"); | ||
88 | lbResizeHandler.addMouseMotionListener(splitListener); | ||
89 | lbResizeHandler.addMouseListener(splitListener); | ||
90 | lbShrinkHandler.addMouseListener(shrinkListener); | ||
91 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); | ||
92 | lbTitle.setForeground(titleColor); | ||
93 | lbTitle.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 0)); | ||
94 | updateCursor(); | ||
95 | lbShrinkHandler.setBorder(BorderFactory.createEmptyBorder(0, 8, 2, 5)); | ||
96 | } | ||
97 | |||
98 | protected JComponent getCenterComponent() | ||
99 | { | ||
100 | return lbTitle; | ||
101 | } | ||
102 | |||
103 | protected Object getResizeHandlerLayoutConstraint() | ||
104 | { | ||
105 | return "West"; | ||
106 | } | ||
107 | |||
108 | protected Object getShrinkHandlerLayoutConstraint() | ||
109 | { | ||
110 | return "East"; | ||
111 | } | ||
112 | |||
113 | protected void paintComponent(Graphics g) | ||
114 | { | ||
115 | Graphics2D g2d = (Graphics2D)g; | ||
116 | g2d.setPaint(paint); | ||
117 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
118 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | ||
119 | int x = getWidth() - backgroundRightImage.getWidth(null); | ||
120 | int y = 0; | ||
121 | g2d.drawImage(backgroundRightImage, x, y, null); | ||
122 | } | ||
123 | |||
124 | public Dimension getPreferredSize() | ||
125 | { | ||
126 | return new Dimension(super.getPreferredSize().width, preferredHeight); | ||
127 | } | ||
128 | |||
129 | public void revalidateParent() | ||
130 | { | ||
131 | if (getParent() instanceof JComponent) | ||
132 | ((JComponent)getParent()).revalidate(); | ||
133 | } | ||
134 | |||
135 | public void changeShrink() | ||
136 | { | ||
137 | setShrink(!isShrinked()); | ||
138 | } | ||
139 | |||
140 | public void setShrink(boolean shrinked) | ||
141 | { | ||
142 | if (shrinked != this.shrinked) | ||
143 | { | ||
144 | Container parent = getParent(); | ||
145 | Dimension size = parent.getPreferredSize(); | ||
146 | if (shrinked) | ||
147 | { | ||
148 | normalPreferredWidth = size.width; | ||
149 | size = new Dimension(getShrinkedWidth(), size.height); | ||
150 | } else | ||
151 | { | ||
152 | int width = normalPreferredWidth; | ||
153 | int height = parent.getPreferredSize().height; | ||
154 | size = new Dimension(width, height); | ||
155 | } | ||
156 | parent.setPreferredSize(size); | ||
157 | lbShrinkHandler.setIcon(getShrinkIcon(shrinked)); | ||
158 | revalidateParent(); | ||
159 | this.shrinked = shrinked; | ||
160 | updateCursor(); | ||
161 | lbTitle.setVisible(!shrinked); | ||
162 | lbResizeHandler.setVisible(!shrinked); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | protected ImageIcon getShrinkIcon(boolean shrinked) | ||
167 | { | ||
168 | if (shrinked) | ||
169 | return LEFT_ARROW_ICON; | ||
170 | else | ||
171 | return RIGHT_ARROW_ICON; | ||
172 | } | ||
173 | |||
174 | private void updateCursor() | ||
175 | { | ||
176 | if (shrinked) | ||
177 | lbResizeHandler.setCursor(Cursor.getDefaultCursor()); | ||
178 | else | ||
179 | lbResizeHandler.setCursor(Cursor.getPredefinedCursor(10)); | ||
180 | } | ||
181 | |||
182 | public boolean isShrinked() | ||
183 | { | ||
184 | return shrinked; | ||
185 | } | ||
186 | |||
187 | public void setTitle(String title) | ||
188 | { | ||
189 | lbTitle.setText(title); | ||
190 | } | ||
191 | |||
192 | public String getTitle() | ||
193 | { | ||
194 | return lbTitle.getText(); | ||
195 | } | ||
196 | |||
197 | protected int getShrinkedWidth() | ||
198 | { | ||
199 | return 37; | ||
200 | } | ||
201 | } | ||
diff --git a/src/cppcheckplus/control/MyList.java b/src/cppcheckplus/control/MyList.java new file mode 100644 index 0000000..2a577ff --- /dev/null +++ b/src/cppcheckplus/control/MyList.java | |||
@@ -0,0 +1,68 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.event.MouseEvent; | ||
5 | |||
6 | import javax.swing.JList; | ||
7 | import javax.swing.event.MouseInputAdapter; | ||
8 | import javax.swing.event.MouseInputListener; | ||
9 | |||
10 | import cppcheckplus.shortcut.MyShortcutItem; | ||
11 | import cppcheckplus.shortcut.MyShortcutItemClickListenter; | ||
12 | |||
13 | |||
14 | public class MyList extends JList | ||
15 | { | ||
16 | private MyShortcutItemClickListenter clickListenter; | ||
17 | |||
18 | public MyList() | ||
19 | { | ||
20 | init(); | ||
21 | } | ||
22 | public void setListenter(MyShortcutItemClickListenter itemClickListenter) | ||
23 | { | ||
24 | this.clickListenter = itemClickListenter; | ||
25 | MouseInputListener listener = new MouseInputAdapter() | ||
26 | { | ||
27 | //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 | ||
28 | @Override | ||
29 | public void mouseMoved(MouseEvent e) | ||
30 | { | ||
31 | int moveIndex = locationToIndex(e.getPoint()); | ||
32 | setSelectedIndex(moveIndex); | ||
33 | } | ||
34 | //移动出去之后,清除选中,从而触发渲染器 | ||
35 | @Override | ||
36 | public void mouseExited(MouseEvent e) | ||
37 | { | ||
38 | getSelectionModel().clearSelection(); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public void mouseClicked(MouseEvent e) | ||
43 | { | ||
44 | //因为该JList是单选模式,所以取第一个选择的就可以了 | ||
45 | Object selObj = getSelectedValue(); | ||
46 | if(selObj != null) | ||
47 | { | ||
48 | MyShortcutItem item = (MyShortcutItem)selObj; | ||
49 | if(!item.isGroup()) | ||
50 | { | ||
51 | clickListenter.ItemClick(item.getActionCommand()); | ||
52 | } | ||
53 | } | ||
54 | //itemClick.ItemClick(actionCommand) | ||
55 | } | ||
56 | }; | ||
57 | addMouseMotionListener(listener); | ||
58 | addMouseListener(listener); | ||
59 | } | ||
60 | private void init() | ||
61 | { | ||
62 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
63 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); | ||
64 | setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
65 | setCellRenderer(new MyListRenderer(this)); | ||
66 | setSelectionMode(0); | ||
67 | } | ||
68 | } | ||
diff --git a/src/cppcheckplus/control/MyListRenderer.java b/src/cppcheckplus/control/MyListRenderer.java new file mode 100644 index 0000000..1495378 --- /dev/null +++ b/src/cppcheckplus/control/MyListRenderer.java | |||
@@ -0,0 +1,138 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Color; | ||
6 | import java.awt.Component; | ||
7 | import java.awt.Dimension; | ||
8 | import java.awt.Font; | ||
9 | |||
10 | import javax.swing.BorderFactory; | ||
11 | import javax.swing.DefaultListCellRenderer; | ||
12 | import javax.swing.JLabel; | ||
13 | import javax.swing.JList; | ||
14 | import javax.swing.JPanel; | ||
15 | import javax.swing.OverlayLayout; | ||
16 | |||
17 | import cppcheckplus.shortcut.MyShortcutItem; | ||
18 | import cppcheckplus.shortcut.MyShortcutPanel; | ||
19 | |||
20 | //快捷菜单 | ||
21 | public class MyListRenderer extends DefaultListCellRenderer | ||
22 | { | ||
23 | private JPanel itemRender; | ||
24 | private int separatorHeight = 30; | ||
25 | //每组List的分割Group | ||
26 | private JPanel separatorPanel; | ||
27 | private JLabel separatorLabel; | ||
28 | private MySeparator separator; | ||
29 | private Color itemTextColor; | ||
30 | private Color separatorTextColor; | ||
31 | private Color itemSelectedBackground; | ||
32 | private Color itemSelectedBorder; | ||
33 | private Font separatorFont; | ||
34 | |||
35 | public MyListRenderer(MyList list) | ||
36 | { | ||
37 | super(); | ||
38 | itemRender = new JPanel(new BorderLayout()); | ||
39 | separatorPanel = new JPanel() { | ||
40 | |||
41 | public Dimension getPreferredSize() | ||
42 | { | ||
43 | Dimension size = super.getPreferredSize(); | ||
44 | return new Dimension(size.width, separatorHeight); | ||
45 | } | ||
46 | |||
47 | }; | ||
48 | //分割Group的样式 | ||
49 | separatorLabel = new JLabel(); | ||
50 | separator = new MySeparator(0); | ||
51 | separatorTextColor = Color.white; | ||
52 | separatorFont = MyContorlUtil.FONT_12_BOLD; | ||
53 | |||
54 | itemTextColor = MyContorlUtil.LIST_TEXT_COLOR; | ||
55 | itemSelectedBackground = new Color(199, 198, 200); | ||
56 | itemSelectedBorder = new Color(163, 163, 163); | ||
57 | itemRender.setOpaque(false); | ||
58 | itemRender.add(this, "Center"); | ||
59 | separatorPanel.setLayout(new OverlayLayout(separatorPanel)); | ||
60 | JPanel separatorHelpPane = new JPanel(new BorderLayout()); | ||
61 | separatorHelpPane.setBorder(BorderFactory.createEmptyBorder(12, 0, 0, 0)); | ||
62 | separatorHelpPane.add(separator); | ||
63 | separatorHelpPane.setOpaque(false); | ||
64 | separatorPanel.setOpaque(false); | ||
65 | separatorLabel.setOpaque(true); | ||
66 | separatorLabel.setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
67 | separatorLabel.setForeground(separatorTextColor); | ||
68 | separatorLabel.setFont(separatorFont); | ||
69 | separatorLabel.setVerticalAlignment(1); | ||
70 | separatorLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); | ||
71 | JPanel labelHelpPane = new JPanel(new BorderLayout()); | ||
72 | labelHelpPane.setBorder(BorderFactory.createEmptyBorder(6, 15, 0, 0)); | ||
73 | labelHelpPane.add(separatorLabel, "West"); | ||
74 | labelHelpPane.setOpaque(false); | ||
75 | separatorPanel.add(labelHelpPane); | ||
76 | separatorPanel.add(separatorHelpPane); | ||
77 | } | ||
78 | |||
79 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) | ||
80 | { | ||
81 | MyShortcutItem shortcutItem = (MyShortcutItem)value; | ||
82 | //Group的渲染 | ||
83 | if(shortcutItem.isGroup()) | ||
84 | { | ||
85 | String groupName = shortcutItem.getText(); | ||
86 | separatorLabel.setText(groupName); | ||
87 | separatorPanel.setToolTipText(groupName); | ||
88 | if (list.getParent() instanceof MyShortcutPanel) | ||
89 | { | ||
90 | MyShortcutPanel pane = (MyShortcutPanel)list.getParent(); | ||
91 | if (pane.isShrinked()) | ||
92 | { | ||
93 | separatorLabel.setText(" "); | ||
94 | separatorLabel.setOpaque(false); | ||
95 | } else | ||
96 | { | ||
97 | separatorLabel.setOpaque(true); | ||
98 | } | ||
99 | } | ||
100 | return separatorPanel; | ||
101 | } | ||
102 | //普通Item的渲染 | ||
103 | else | ||
104 | { | ||
105 | setText(shortcutItem.getText()); | ||
106 | setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
107 | setToolTipText(shortcutItem.getToolTip()); | ||
108 | setIcon(shortcutItem.getIcon()); | ||
109 | } | ||
110 | |||
111 | //判断List的父容器是否是快捷菜单面板,如果是,需要考虑收缩展开的处理 | ||
112 | if (list.getParent() instanceof MyShortcutPanel) | ||
113 | { | ||
114 | MyShortcutPanel pane = (MyShortcutPanel)list.getParent(); | ||
115 | if (pane.isShrinked()) | ||
116 | { | ||
117 | setBorder(BorderFactory.createEmptyBorder(2, 7, 1, 2)); | ||
118 | setText(""); | ||
119 | } else | ||
120 | { | ||
121 | setBorder(BorderFactory.createEmptyBorder(2, 20, 1, 2)); | ||
122 | } | ||
123 | } | ||
124 | if (isSelected) | ||
125 | { | ||
126 | setBackground(itemSelectedBackground); | ||
127 | itemRender.setBorder(BorderFactory.createLineBorder(itemSelectedBorder)); | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | itemRender.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); | ||
132 | } | ||
133 | setForeground(itemTextColor); | ||
134 | |||
135 | return itemRender; | ||
136 | } | ||
137 | |||
138 | } | ||
diff --git a/src/cppcheckplus/control/MyListSplitListener.java b/src/cppcheckplus/control/MyListSplitListener.java new file mode 100644 index 0000000..4ee8fea --- /dev/null +++ b/src/cppcheckplus/control/MyListSplitListener.java | |||
@@ -0,0 +1,50 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Point; | ||
6 | import java.awt.event.MouseEvent; | ||
7 | |||
8 | import javax.swing.JComponent; | ||
9 | import javax.swing.event.MouseInputAdapter; | ||
10 | |||
11 | |||
12 | public class MyListSplitListener extends MouseInputAdapter | ||
13 | { | ||
14 | protected Point lastPoint; | ||
15 | protected MyHeader header; | ||
16 | |||
17 | public MyListSplitListener(MyHeader header) | ||
18 | { | ||
19 | lastPoint = null; | ||
20 | this.header = null; | ||
21 | this.header = header; | ||
22 | } | ||
23 | |||
24 | public void mousePressed(MouseEvent e) | ||
25 | { | ||
26 | if (!header.isShrinked()) | ||
27 | lastPoint = e.getPoint(); | ||
28 | } | ||
29 | |||
30 | public void mouseReleased(MouseEvent e) | ||
31 | { | ||
32 | lastPoint = null; | ||
33 | } | ||
34 | |||
35 | public void mouseDragged(MouseEvent e) | ||
36 | { | ||
37 | if (!header.isShrinked() && lastPoint != null) | ||
38 | { | ||
39 | JComponent parent = (JComponent)header.getParent(); | ||
40 | Dimension size = parent.getPreferredSize(); | ||
41 | Point thisPoint = e.getPoint(); | ||
42 | int xMovement = thisPoint.x - lastPoint.x; | ||
43 | size.width -= xMovement; | ||
44 | size.width = Math.max(size.width, 37); | ||
45 | parent.setPreferredSize(size); | ||
46 | header.revalidateParent(); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | } | ||
diff --git a/src/cppcheckplus/control/MySeparator.java b/src/cppcheckplus/control/MySeparator.java new file mode 100644 index 0000000..f5ba4ad --- /dev/null +++ b/src/cppcheckplus/control/MySeparator.java | |||
@@ -0,0 +1,40 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.Graphics; | ||
5 | import java.awt.Graphics2D; | ||
6 | import java.awt.Image; | ||
7 | import java.awt.TexturePaint; | ||
8 | |||
9 | import javax.swing.JSeparator; | ||
10 | |||
11 | |||
12 | public class MySeparator extends JSeparator | ||
13 | { | ||
14 | private Image image; | ||
15 | private TexturePaint paint; | ||
16 | |||
17 | public MySeparator() | ||
18 | { | ||
19 | image = MyContorlUtil.getImage("control/images/separator_background.png"); | ||
20 | paint = MyContorlUtil.createTexturePaint("control/images/separator_background.png"); | ||
21 | } | ||
22 | |||
23 | public MySeparator(int direction) | ||
24 | { | ||
25 | super(direction); | ||
26 | image = MyContorlUtil.getImage("control/images/separator_background.png"); | ||
27 | paint = MyContorlUtil.createTexturePaint("control/images/separator_background.png"); | ||
28 | } | ||
29 | |||
30 | public void paintComponent(Graphics g) | ||
31 | { | ||
32 | Graphics2D g2d = (Graphics2D)g; | ||
33 | g2d.setPaint(paint); | ||
34 | int x = 0; | ||
35 | int y = 0; | ||
36 | int width = getWidth(); | ||
37 | int height = image.getHeight(null); | ||
38 | g2d.fillRect(x, y, width, height); | ||
39 | } | ||
40 | } | ||
diff --git a/src/cppcheckplus/control/MyTextField.java b/src/cppcheckplus/control/MyTextField.java new file mode 100644 index 0000000..d0ed080 --- /dev/null +++ b/src/cppcheckplus/control/MyTextField.java | |||
@@ -0,0 +1,62 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Graphics; | ||
6 | import java.awt.Graphics2D; | ||
7 | import java.awt.Image; | ||
8 | import java.awt.TexturePaint; | ||
9 | |||
10 | import javax.swing.BorderFactory; | ||
11 | import javax.swing.ImageIcon; | ||
12 | import javax.swing.JTextField; | ||
13 | import javax.swing.border.Border; | ||
14 | import javax.swing.plaf.metal.MetalTextFieldUI; | ||
15 | |||
16 | |||
17 | public class MyTextField extends JTextField | ||
18 | { | ||
19 | private Image backgroundLeftImage; | ||
20 | private Image backgroundRightImage; | ||
21 | private ImageIcon backgroundImageIcon; | ||
22 | private TexturePaint paint; | ||
23 | private Border border; | ||
24 | |||
25 | public MyTextField() | ||
26 | { | ||
27 | backgroundLeftImage = MyContorlUtil.getImage("control/images/textfield_background_left.png"); | ||
28 | backgroundRightImage = MyContorlUtil.getImage("control/images/textfield_background_right.png"); | ||
29 | backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/textfield_background.png"); | ||
30 | paint = MyContorlUtil.createTexturePaint("control/images/textfield_background.png"); | ||
31 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); | ||
32 | init(); | ||
33 | } | ||
34 | public MyTextField(String text) | ||
35 | { | ||
36 | this(); | ||
37 | setText(text); | ||
38 | } | ||
39 | |||
40 | private void init() | ||
41 | { | ||
42 | setBorder(border); | ||
43 | setUI(new MetalTextFieldUI() { | ||
44 | |||
45 | protected void paintBackground(Graphics g) | ||
46 | { | ||
47 | Graphics2D g2d = (Graphics2D)g; | ||
48 | g2d.setPaint(paint); | ||
49 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
50 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | ||
51 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | ||
52 | } | ||
53 | |||
54 | }); | ||
55 | } | ||
56 | |||
57 | public Dimension getPreferredSize() | ||
58 | { | ||
59 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | ||
60 | } | ||
61 | |||
62 | } | ||
diff --git a/src/cppcheckplus/control/MyToolbarButton.java b/src/cppcheckplus/control/MyToolbarButton.java new file mode 100644 index 0000000..e709296 --- /dev/null +++ b/src/cppcheckplus/control/MyToolbarButton.java | |||
@@ -0,0 +1,96 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Component; | ||
6 | import java.awt.Dimension; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Insets; | ||
9 | import java.awt.event.MouseAdapter; | ||
10 | import java.awt.event.MouseEvent; | ||
11 | |||
12 | import javax.swing.BorderFactory; | ||
13 | import javax.swing.Icon; | ||
14 | import javax.swing.JButton; | ||
15 | import javax.swing.border.Border; | ||
16 | |||
17 | public class MyToolbarButton extends JButton | ||
18 | { | ||
19 | private int buttonSize; | ||
20 | private Color roverBorderColor; | ||
21 | private Border roverBorder; | ||
22 | private Border emptyBorder; | ||
23 | |||
24 | public MyToolbarButton() | ||
25 | { | ||
26 | super(); | ||
27 | buttonSize = 20; | ||
28 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; | ||
29 | roverBorder = new Border() { | ||
30 | |||
31 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | ||
32 | { | ||
33 | g.setColor(roverBorderColor); | ||
34 | g.drawRect(x, y, width - 1, height - 1); | ||
35 | } | ||
36 | |||
37 | public Insets getBorderInsets(Component c) | ||
38 | { | ||
39 | return new Insets(1, 1, 1, 1); | ||
40 | } | ||
41 | |||
42 | public boolean isBorderOpaque() | ||
43 | { | ||
44 | return true; | ||
45 | } | ||
46 | }; | ||
47 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); | ||
48 | init(); | ||
49 | } | ||
50 | |||
51 | private void init() | ||
52 | { | ||
53 | setVerticalAlignment(0); | ||
54 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
55 | setOpaque(false); | ||
56 | setBorder(emptyBorder); | ||
57 | setContentAreaFilled(false); | ||
58 | setFocusPainted(false); | ||
59 | addMouseListener(new MouseAdapter() { | ||
60 | public void mouseEntered(MouseEvent e) | ||
61 | { | ||
62 | setBorder(roverBorder); | ||
63 | } | ||
64 | |||
65 | public void mouseExited(MouseEvent e) | ||
66 | { | ||
67 | setBorder(emptyBorder); | ||
68 | } | ||
69 | }); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public void setIcon(Icon icon) | ||
74 | { | ||
75 | super.setIcon(icon); | ||
76 | if (icon == null) | ||
77 | { | ||
78 | setPressedIcon(null); | ||
79 | setRolloverIcon(null); | ||
80 | } else | ||
81 | { | ||
82 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); | ||
83 | setPressedIcon(pressedIcon); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
88 | @Override | ||
89 | public Dimension getPreferredSize() | ||
90 | { | ||
91 | int width = super.getPreferredSize().width; | ||
92 | width = Math.max(width, buttonSize); | ||
93 | int height = buttonSize; | ||
94 | return new Dimension(width, height); | ||
95 | } | ||
96 | } | ||
diff --git a/src/cppcheckplus/control/XChartletFullScreenListenter.java b/src/cppcheckplus/control/XChartletFullScreenListenter.java new file mode 100644 index 0000000..c7eca34 --- /dev/null +++ b/src/cppcheckplus/control/XChartletFullScreenListenter.java | |||
@@ -0,0 +1,10 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import javax.swing.JPanel; | ||
5 | |||
6 | |||
7 | public interface XChartletFullScreenListenter | ||
8 | { | ||
9 | public void fullScreen(JPanel chartPanellet); | ||
10 | } | ||
diff --git a/src/cppcheckplus/control/menubar.xml b/src/cppcheckplus/control/menubar.xml new file mode 100644 index 0000000..f2d2f19 --- /dev/null +++ b/src/cppcheckplus/control/menubar.xml | |||
@@ -0,0 +1,32 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <menubar> | ||
3 | <menu text="文件"> | ||
4 | <menuitem text="打开文件" tooltip="可以打开你的代码" icon="control/images/toolbar/update.png" action="onMenuOpen"/> | ||
5 | <menuitem text="选择路径" tooltip="选取工程或者项目路径" icon="control/images/toolbar/add.png" action="onMenuLoad"/> | ||
6 | <menuitem text="保存文件" tooltip="可以保存你的代码" icon="control/images/toolbar/email.png" action="onMenuSave"/> | ||
7 | <menuitem text="关闭" tooltip="退出程序" icon="control/images/toolbar/right.png" action="onMenuClose"/> | ||
8 | </menu> | ||
9 | <menu text="编辑"> | ||
10 | <menuitem text="清理工作区" tooltip="clean" icon="control/images/toolbar/home.png" action="onMenuClean"/> | ||
11 | <menuitem text="导出检查结果" tooltip="选取工程或者项目路径" icon="control/images/toolbar/print.png" action="onMenuExport"/> | ||
12 | <menuitem text="cppcheck" tooltip="用cppcheck检查代码" icon="control/images/toolbar/message.png" action="onCppcheck"/> | ||
13 | <menuitem text="Clang" tooltip="用Clang检查代码" icon="control/images/toolbar/message.png" action="onClang"/> | ||
14 | <menuitem text="flawfinder" tooltip="用flawfinder检查代码" icon="control/images/toolbar/message.png" action="onFlawfinder"/> | ||
15 | </menu> | ||
16 | <menu text="设置"> | ||
17 | <menu text="结果筛选"> | ||
18 | <menuitem text="按照类别筛选" tooltip="结果按缺陷类别排序" icon="control/images/email.png" action="onOrderType"/> | ||
19 | <menuitem text="按照级别筛选" tooltip="结果按缺陷等级排序" icon="control/images/email.png" action="onOrderLevel"/> | ||
20 | <menuitem text="按照文件筛选" tooltip="结果按文件排序" icon="control/images/email.png" action="onOrderFile"/> | ||
21 | </menu> | ||
22 | <menu text="初始文件设置"> | ||
23 | <menuitem text="设置Cppcheck路径" tooltip="设置Cppcheck路径" icon="control/images/email.png" action="onSetCppcheckRoad"/> | ||
24 | <menuitem text="设置flawfinder路径" tooltip="设置flawfinder路径" icon="control/images/email.png" action="onSetFlawfinderRoad"/> | ||
25 | </menu> | ||
26 | </menu> | ||
27 | |||
28 | <menu text="帮助"> | ||
29 | <menuitem text="关于" tooltip="about" icon="control/images/email.png" action="onMenuAbout"/> | ||
30 | </menu> | ||
31 | <logo image="control/images/toolbar/message.png" tooltip="cppcheckplus" /> | ||
32 | </menubar> \ No newline at end of file | ||
diff --git a/src/cppcheckplus/control/outlook.xml b/src/cppcheckplus/control/outlook.xml new file mode 100644 index 0000000..b7a5460 --- /dev/null +++ b/src/cppcheckplus/control/outlook.xml | |||
@@ -0,0 +1,8 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <outlook> | ||
3 | <module text="检查结果" icon="control/images/outlookpanel/module_unselected.png" selected_icon="control/images/outlookpanel/module_selected.png"> | ||
4 | <submodule text="检查结果" tooltip="This is a tooltip of a button" icon="control/images/toolbar/chart.png" action="Chart2"/> | ||
5 | <submodule text="代码修改" tooltip="This is a tooltip of a button" icon="control/images/toolbar/user.png" action="Map"/> | ||
6 | <submodule text="检查进度" tooltip="This is a tooltip of a button" icon="control/images/toolbar/user.png" action="Process"/> | ||
7 | </module> | ||
8 | </outlook> \ No newline at end of file | ||
diff --git a/src/cppcheckplus/control/settings.xml b/src/cppcheckplus/control/settings.xml new file mode 100644 index 0000000..6e809a5 --- /dev/null +++ b/src/cppcheckplus/control/settings.xml | |||
@@ -0,0 +1,6 @@ | |||
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"> | ||
3 | </tool> | ||
4 | <tool filePath="C:/Users/HP/Desktop/智能软件中心/软件测试小组/工具/苏佳/苏佳的代码-代码缺陷检测工具/flawfinder-2.0.19/flawfinder-2.0.19/flawfinder.py" para="" toolName="flawfinder"> | ||
5 | </tool> | ||
6 | </settings> \ No newline at end of file | ||
diff --git a/src/cppcheckplus/control/shortcuts.xml b/src/cppcheckplus/control/shortcuts.xml new file mode 100644 index 0000000..6591a60 --- /dev/null +++ b/src/cppcheckplus/control/shortcuts.xml | |||
@@ -0,0 +1,17 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <shortcuts> | ||
3 | <button tooltip="选取工程或者项目路径" icon="control/Images/toolbar/add.png" action="onMenuLoad" /> | ||
4 | <separator/> | ||
5 | <button tooltip="打开文件" icon="control/Images/toolbar/update.png" action="onMenuOpen" /> | ||
6 | <separator/> | ||
7 | <button tooltip="可以保存你的代码" icon="control/images/toolbar/email.png" action="onMenuSave" /> | ||
8 | <separator/> | ||
9 | <button tooltip="退出程序" icon="control/Images/toolbar/right.png" action="onMenuClose" /> | ||
10 | <separator/> | ||
11 | <button tooltip="清除工作区" icon="control/Images/toolbar/home.png" action="onMenuClean" /> | ||
12 | <separator/> | ||
13 | <button tooltip="导出检查结果" icon="control/Images/toolbar/print.png" action="onMenuExport" /> | ||
14 | <separator/> | ||
15 | <button tooltip="cppcheck" icon="control/Images/toolbar/message.png" action="onCppcheck" /> | ||
16 | <separator/> | ||
17 | </shortcuts> \ No newline at end of file | ||
diff --git a/src/cppcheckplus/control/stdclang.xml b/src/cppcheckplus/control/stdclang.xml new file mode 100644 index 0000000..a361d52 --- /dev/null +++ b/src/cppcheckplus/control/stdclang.xml | |||
@@ -0,0 +1,17 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <stdclang> | ||
3 | <clangNode cwe="563" level="2" target="Value stored to" type="unreadVariable" len="16"></clangNode> | ||
4 | <clangNode cwe="401" level="4" target="Potential leak of memory" type="memleak" len="25"></clangNode> | ||
5 | <clangNode cwe="476" level="3" target="Access to field" type="nullPointerRedundantCheck" len="16"></clangNode> | ||
6 | <clangNode cwe="398" level="4" target="use of undeclared" type="useundeclaredid" len="18"></clangNode> | ||
7 | <clangNode cwe="398" level="4" target="cannot delete expression of type" type="deleteerror" len="33"></clangNode> | ||
8 | <clangNode cwe="398" level="3" target="indirection requires pointer operand" type="indirectionpointer" len="37"></clangNode> | ||
9 | <clangNode cwe="398" level="3" target="unknown type name" type="unknowntype" len="18"></clangNode> | ||
10 | <clangNode cwe="369" level="4" target="Division by zero" type="zerodiv" len="17"></clangNode> | ||
11 | <clangNode cwe="398" level="4" target="invalid operands to binary expression" type="invalidoperand" len="38"></clangNode> | ||
12 | <clangNode cwe="398" level="4" target="cannot initialize return object of type" type="returntype" len="40"></clangNode> | ||
13 | <clangNode cwe="398" level="4" target="comparison between pointer and integer" type="comppointer" len="39"></clangNode> | ||
14 | <clangNode cwe="398" level="4" target="1st function call argument is an" type="funccalluninitvalue" len="33"></clangNode> | ||
15 | <clangNode cwe="398" level="4" target="The right operand" type="opgarbagevalue" len="18"></clangNode> | ||
16 | <clangNode cwe="398" level="4" target="The left operand" type="opgarbagevalue" len="17"></clangNode> | ||
17 | </stdclang> | ||
diff --git a/src/cppcheckplus/control/toolbar.xml b/src/cppcheckplus/control/toolbar.xml new file mode 100644 index 0000000..3382f6d --- /dev/null +++ b/src/cppcheckplus/control/toolbar.xml | |||
@@ -0,0 +1,17 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <toolbar> | ||
3 | <button tooltip="选取工程或者项目路径" icon="control/Images/toolbar/add.png" action="onMenuLoad" /> | ||
4 | <separator/> | ||
5 | <button tooltip="打开文件" icon="control/Images/toolbar/update.png" action="onMenuOpen" /> | ||
6 | <separator/> | ||
7 | <button tooltip="可以保存你的代码" icon="control/images/toolbar/email.png" action="onMenuSave" /> | ||
8 | <separator/> | ||
9 | <button tooltip="退出程序" icon="control/Images/toolbar/right.png" action="onMenuClose" /> | ||
10 | <separator/> | ||
11 | <button tooltip="清除工作区" icon="control/Images/toolbar/home.png" action="onMenuClean" /> | ||
12 | <separator/> | ||
13 | <button tooltip="导出检查结果" icon="control/Images/toolbar/print.png" action="onMenuExport" /> | ||
14 | <separator/> | ||
15 | <button tooltip="cppcheck" icon="control/Images/toolbar/message.png" action="onCppcheck" /> | ||
16 | <separator/> | ||
17 | </toolbar> \ No newline at end of file | ||
diff --git a/src/cppcheckplus/menu/MyMenu.java b/src/cppcheckplus/menu/MyMenu.java new file mode 100644 index 0000000..3570408 --- /dev/null +++ b/src/cppcheckplus/menu/MyMenu.java | |||
@@ -0,0 +1,71 @@ | |||
1 | |||
2 | package cppcheckplus.menu; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Dimension; | ||
6 | import java.awt.Graphics; | ||
7 | import java.awt.Graphics2D; | ||
8 | import javax.swing.BorderFactory; | ||
9 | import javax.swing.JMenu; | ||
10 | import javax.swing.border.Border; | ||
11 | |||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | |||
14 | |||
15 | public class MyMenu extends JMenu | ||
16 | { | ||
17 | private Color backgroundColor; | ||
18 | private Color foregroundColor; | ||
19 | private int borderThickness; | ||
20 | private Border border; | ||
21 | private int preferredHeight; | ||
22 | |||
23 | public MyMenu() | ||
24 | { | ||
25 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
26 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
27 | borderThickness = 1; | ||
28 | border = BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
29 | preferredHeight = 25; | ||
30 | init(); | ||
31 | } | ||
32 | |||
33 | public MyMenu(String text) | ||
34 | { | ||
35 | super(text); | ||
36 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
37 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
38 | borderThickness = 1; | ||
39 | border = BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
40 | preferredHeight = 25; | ||
41 | init(); | ||
42 | } | ||
43 | |||
44 | private void init() | ||
45 | { | ||
46 | setForeground(foregroundColor); | ||
47 | setFont(MyContorlUtil.FONT_14_BOLD); | ||
48 | setOpaque(true); | ||
49 | setBackground(backgroundColor); | ||
50 | setBorder(border); | ||
51 | } | ||
52 | @Override | ||
53 | protected void paintComponent(Graphics g) | ||
54 | { | ||
55 | if (isSelected()) | ||
56 | { | ||
57 | Graphics2D g2d = (Graphics2D)g; | ||
58 | g2d.setColor(MyContorlUtil.MENUITEM_SELECTED_BACKGROUND); | ||
59 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
60 | super.paintComponent(g); | ||
61 | } else | ||
62 | { | ||
63 | super.paintComponent(g); | ||
64 | } | ||
65 | } | ||
66 | @Override | ||
67 | public Dimension getPreferredSize() | ||
68 | { | ||
69 | return new Dimension(super.getPreferredSize().width, preferredHeight); | ||
70 | } | ||
71 | } | ||
diff --git a/src/cppcheckplus/menu/MyMenuBar.java b/src/cppcheckplus/menu/MyMenuBar.java new file mode 100644 index 0000000..7d5d102 --- /dev/null +++ b/src/cppcheckplus/menu/MyMenuBar.java | |||
@@ -0,0 +1,56 @@ | |||
1 | |||
2 | package cppcheckplus.menu; | ||
3 | |||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Graphics; | ||
6 | import java.awt.Graphics2D; | ||
7 | import java.awt.Image; | ||
8 | import java.awt.TexturePaint; | ||
9 | import javax.swing.BorderFactory; | ||
10 | import javax.swing.ImageIcon; | ||
11 | import javax.swing.JMenuBar; | ||
12 | import javax.swing.border.Border; | ||
13 | |||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | |||
16 | |||
17 | public class MyMenuBar extends JMenuBar | ||
18 | { | ||
19 | |||
20 | private Image backgroundLeftImage; | ||
21 | private Image backgroundRightImage; | ||
22 | private ImageIcon backgroundImageIcon; | ||
23 | private TexturePaint paint; | ||
24 | private Border border; | ||
25 | |||
26 | public MyMenuBar() | ||
27 | { | ||
28 | backgroundLeftImage = MyContorlUtil.getImage("control/images/menubar_background_left.png"); | ||
29 | backgroundRightImage = MyContorlUtil.getImage("control/images/menubar_background_right.png"); | ||
30 | backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/menubar_background.png"); | ||
31 | paint = MyContorlUtil.createTexturePaint("control/images/menubar_background.png"); | ||
32 | border = BorderFactory.createEmptyBorder(); | ||
33 | init(); | ||
34 | } | ||
35 | private void init() | ||
36 | { | ||
37 | setBorder(border); | ||
38 | } | ||
39 | @Override | ||
40 | protected void paintComponent(Graphics g) | ||
41 | { | ||
42 | super.paintComponent(g); | ||
43 | Graphics2D g2d = (Graphics2D)g; | ||
44 | g2d.setPaint(paint); | ||
45 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
46 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | ||
47 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | ||
48 | } | ||
49 | @Override | ||
50 | public Dimension getPreferredSize() | ||
51 | { | ||
52 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | ||
53 | } | ||
54 | |||
55 | } | ||
56 | |||
diff --git a/src/cppcheckplus/menu/MyMenuItem.java b/src/cppcheckplus/menu/MyMenuItem.java new file mode 100644 index 0000000..6ac46e9 --- /dev/null +++ b/src/cppcheckplus/menu/MyMenuItem.java | |||
@@ -0,0 +1,52 @@ | |||
1 | |||
2 | package cppcheckplus.menu; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Dimension; | ||
6 | import javax.swing.BorderFactory; | ||
7 | import javax.swing.JMenuItem; | ||
8 | import javax.swing.border.Border; | ||
9 | |||
10 | import cppcheckplus.control.MyContorlUtil; | ||
11 | |||
12 | public class MyMenuItem extends JMenuItem | ||
13 | { | ||
14 | private static final long serialVersionUID = 1L; | ||
15 | private Color backgroundColor; | ||
16 | private Color foregroundColor; | ||
17 | private int borderThickness; | ||
18 | private Border border; | ||
19 | private int preferredHeight; | ||
20 | |||
21 | public MyMenuItem() | ||
22 | { | ||
23 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
24 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
25 | borderThickness = 1; | ||
26 | border = BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
27 | preferredHeight = 23; | ||
28 | init(); | ||
29 | } | ||
30 | public MyMenuItem(String text) | ||
31 | { | ||
32 | super(text); | ||
33 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
34 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
35 | borderThickness = 1; | ||
36 | border = BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
37 | preferredHeight = 23; | ||
38 | init(); | ||
39 | } | ||
40 | private void init() | ||
41 | { | ||
42 | setForeground(foregroundColor); | ||
43 | setFont(MyContorlUtil.FONT_14_BOLD); | ||
44 | setBackground(backgroundColor); | ||
45 | setBorder(border); | ||
46 | } | ||
47 | @Override | ||
48 | public Dimension getPreferredSize() | ||
49 | { | ||
50 | return new Dimension(super.getPreferredSize().width, preferredHeight); | ||
51 | } | ||
52 | } | ||
diff --git a/src/cppcheckplus/menu/MyRootMenu.java b/src/cppcheckplus/menu/MyRootMenu.java new file mode 100644 index 0000000..b5d442d --- /dev/null +++ b/src/cppcheckplus/menu/MyRootMenu.java | |||
@@ -0,0 +1,62 @@ | |||
1 | |||
2 | |||
3 | package cppcheckplus.menu; | ||
4 | |||
5 | import java.awt.Color; | ||
6 | import java.awt.Graphics; | ||
7 | import java.awt.Graphics2D; | ||
8 | import java.awt.TexturePaint; | ||
9 | |||
10 | import javax.swing.BorderFactory; | ||
11 | import javax.swing.JMenu; | ||
12 | import javax.swing.border.Border; | ||
13 | |||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | |||
16 | |||
17 | public class MyRootMenu extends JMenu | ||
18 | { | ||
19 | private Color foregroundColor; | ||
20 | private String selectedBackgroundImageURL; | ||
21 | private TexturePaint paint; | ||
22 | private Border border; | ||
23 | |||
24 | public MyRootMenu() | ||
25 | { | ||
26 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
27 | paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png"); | ||
28 | border = BorderFactory.createEmptyBorder(0, 5, 0, 4); | ||
29 | init(); | ||
30 | |||
31 | } | ||
32 | |||
33 | public MyRootMenu(String text) | ||
34 | { | ||
35 | super(text); | ||
36 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
37 | paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png"); | ||
38 | border = BorderFactory.createEmptyBorder(0, 5, 0, 4); | ||
39 | init(); | ||
40 | } | ||
41 | |||
42 | private void init() | ||
43 | { | ||
44 | setFont(MyContorlUtil.FONT_14_BOLD); | ||
45 | setBorder(border); | ||
46 | setForeground(foregroundColor); | ||
47 | } | ||
48 | |||
49 | protected void paintComponent(Graphics g) | ||
50 | { | ||
51 | if (isSelected()) | ||
52 | { | ||
53 | Graphics2D g2d = (Graphics2D)g; | ||
54 | g2d.setPaint(paint); | ||
55 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
56 | super.paintComponent(g); | ||
57 | } else | ||
58 | { | ||
59 | super.paintComponent(g); | ||
60 | } | ||
61 | } | ||
62 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookBar.java b/src/cppcheckplus/outlookpanel/MyOutlookBar.java new file mode 100644 index 0000000..d74345d --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookBar.java | |||
@@ -0,0 +1,223 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Color; | ||
6 | import java.awt.Component; | ||
7 | import java.awt.Dimension; | ||
8 | import java.awt.Graphics; | ||
9 | import java.awt.Graphics2D; | ||
10 | import java.awt.Image; | ||
11 | import java.awt.Insets; | ||
12 | import java.awt.TexturePaint; | ||
13 | import java.awt.event.MouseAdapter; | ||
14 | import java.awt.event.MouseEvent; | ||
15 | import java.awt.event.MouseListener; | ||
16 | import javax.swing.BorderFactory; | ||
17 | import javax.swing.Icon; | ||
18 | import javax.swing.ImageIcon; | ||
19 | import javax.swing.JComponent; | ||
20 | import javax.swing.JLabel; | ||
21 | import javax.swing.JPanel; | ||
22 | import javax.swing.JScrollPane; | ||
23 | import javax.swing.border.Border; | ||
24 | |||
25 | import cppcheckplus.control.MyContorlUtil; | ||
26 | |||
27 | |||
28 | public class MyOutlookBar extends JPanel | ||
29 | { | ||
30 | private Image backgroundSelectedLeft; | ||
31 | private Image backgroundSelectedRight; | ||
32 | private Image backgroundImage; | ||
33 | private ImageIcon handlerIcon; | ||
34 | private ImageIcon handlerSelectedIcon; | ||
35 | private TexturePaint paint; | ||
36 | private TexturePaint selectedPaint; | ||
37 | private JLabel lbHandler; | ||
38 | private Border handlerBorder; | ||
39 | private Border handlerShrinkedBorder; | ||
40 | private JLabel lbIcon; | ||
41 | private JLabel lbTitle; | ||
42 | private boolean selected; | ||
43 | private Color titleColor; | ||
44 | private Color selectedTitleColor; | ||
45 | private MouseListener mouseListener; | ||
46 | |||
47 | private Icon icon = null; | ||
48 | private Icon selectedIcon = null; | ||
49 | private MyOutlookPanel outlookPanel; | ||
50 | private MyOutlookListPanel outlookListPanel; | ||
51 | |||
52 | public MyOutlookBar(MyOutlookPanel panel) | ||
53 | { | ||
54 | super(); | ||
55 | backgroundSelectedLeft = MyContorlUtil.getImage("control/images/outlook_bar_background_selected_left.png"); | ||
56 | backgroundSelectedRight = MyContorlUtil.getImage("control/images/outlook_bar_background_selected_right.png"); | ||
57 | backgroundImage = MyContorlUtil.getImage("control/images/outlook_bar_background.png"); | ||
58 | handlerIcon = MyContorlUtil.getImageIcon("control/images/outlook_bar_handler.png"); | ||
59 | handlerSelectedIcon = MyContorlUtil.getImageIcon("control/images/outlook_bar_handler_selected.png"); | ||
60 | paint = MyContorlUtil.createTexturePaint("control/images/outlook_bar_background.png"); | ||
61 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/outlook_bar_background_selected.png"); | ||
62 | lbHandler = new JLabel(); | ||
63 | handlerBorder = BorderFactory.createEmptyBorder(0, 0, 0, 16); | ||
64 | handlerShrinkedBorder = BorderFactory.createEmptyBorder(0, 0, 0, 22); | ||
65 | lbIcon = new JLabel(); | ||
66 | lbTitle = new JLabel(); | ||
67 | selected = false; | ||
68 | titleColor = MyContorlUtil.OUTLOOK_TEXT_COLOR; | ||
69 | selectedTitleColor = Color.white; | ||
70 | mouseListener = new MouseAdapter() | ||
71 | { | ||
72 | public void mouseReleased(MouseEvent e) | ||
73 | { | ||
74 | if (((JComponent) e.getSource()).contains(e.getPoint())) | ||
75 | changeStatus(); | ||
76 | } | ||
77 | }; | ||
78 | this.outlookPanel = panel; | ||
79 | |||
80 | init(); | ||
81 | } | ||
82 | public void setOutlookListPanel(MyOutlookListPanel listPanel) | ||
83 | { | ||
84 | this.outlookListPanel=listPanel; | ||
85 | } | ||
86 | private void init() | ||
87 | { | ||
88 | setLayout(new BorderLayout()); | ||
89 | lbHandler.setVerticalAlignment(0); | ||
90 | lbHandler.setIcon(handlerIcon); | ||
91 | lbHandler.setBorder(handlerBorder); | ||
92 | add(lbHandler, "East"); | ||
93 | lbIcon.setVerticalAlignment(0); | ||
94 | lbIcon.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); | ||
95 | add(lbIcon, "West"); | ||
96 | lbTitle.setVerticalAlignment(0); | ||
97 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); | ||
98 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); | ||
99 | lbTitle.setForeground(titleColor); | ||
100 | add(lbTitle, "Center"); | ||
101 | lbHandler.addMouseListener(mouseListener); | ||
102 | lbTitle.addMouseListener(mouseListener); | ||
103 | lbIcon.addMouseListener(mouseListener); | ||
104 | } | ||
105 | protected void paintComponent(Graphics g) | ||
106 | { | ||
107 | super.paintComponent(g); | ||
108 | Graphics2D g2d = (Graphics2D) g; | ||
109 | if (isSelected()) | ||
110 | { | ||
111 | g2d.setPaint(selectedPaint); | ||
112 | if (getSelectedIcon() != null) | ||
113 | lbIcon.setIcon(getSelectedIcon()); | ||
114 | else | ||
115 | lbIcon.setIcon(getIcon()); | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | g2d.setPaint(paint); | ||
120 | lbIcon.setIcon(getIcon()); | ||
121 | } | ||
122 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
123 | if (isSelected()) | ||
124 | { | ||
125 | g2d.drawImage(backgroundSelectedLeft, 0, 0, null); | ||
126 | g2d.drawImage(backgroundSelectedRight, getWidth() | ||
127 | - backgroundSelectedRight.getWidth(null), 0, null); | ||
128 | } | ||
129 | } | ||
130 | public Dimension getPreferredSize() | ||
131 | { | ||
132 | return new Dimension(super.getPreferredSize().width, backgroundImage | ||
133 | .getHeight(null)); | ||
134 | } | ||
135 | public void setSelected(boolean selected) | ||
136 | { | ||
137 | if (selected != this.selected) | ||
138 | { | ||
139 | if (!isSelected()) | ||
140 | outlookPanel.closeAllBars(); | ||
141 | this.selected = selected; | ||
142 | if (selected) | ||
143 | { | ||
144 | lbHandler.setIcon(handlerSelectedIcon); | ||
145 | lbTitle.setForeground(selectedTitleColor); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | lbHandler.setIcon(handlerIcon); | ||
150 | lbTitle.setForeground(titleColor); | ||
151 | } | ||
152 | |||
153 | outlookPanel.updateLayoutConstraint(getContentComponent(), selected); | ||
154 | outlookPanel.setAdditionalPaneVisible(!selected); | ||
155 | outlookPanel.revalidate(); | ||
156 | } | ||
157 | } | ||
158 | public void changeStatus() | ||
159 | { | ||
160 | setSelected(!isSelected()); | ||
161 | } | ||
162 | public boolean isSelected() | ||
163 | { | ||
164 | return selected; | ||
165 | } | ||
166 | public Icon getIcon() | ||
167 | { | ||
168 | return icon; | ||
169 | } | ||
170 | public void setIcon(Icon icon) | ||
171 | { | ||
172 | this.icon = icon; | ||
173 | updateIcon(); | ||
174 | } | ||
175 | public Icon getSelectedIcon() | ||
176 | { | ||
177 | return selectedIcon; | ||
178 | } | ||
179 | public void setSelectedIcon(Icon selectedIcon) | ||
180 | { | ||
181 | this.selectedIcon = selectedIcon; | ||
182 | updateIcon(); | ||
183 | } | ||
184 | private void updateIcon() | ||
185 | { | ||
186 | if (selected) | ||
187 | lbIcon.setIcon(selectedIcon); | ||
188 | else | ||
189 | lbIcon.setIcon(icon); | ||
190 | } | ||
191 | public void setTitle(String title) | ||
192 | { | ||
193 | lbTitle.setText(title); | ||
194 | lbTitle.setToolTipText(title); | ||
195 | lbHandler.setToolTipText(title); | ||
196 | lbIcon.setToolTipText(title); | ||
197 | } | ||
198 | public String getTitle() | ||
199 | { | ||
200 | return lbTitle.getText(); | ||
201 | } | ||
202 | |||
203 | public MyOutlookListPanel getContentComponent() | ||
204 | { | ||
205 | return outlookListPanel; | ||
206 | } | ||
207 | public MyOutlookList getList() | ||
208 | { | ||
209 | return this.outlookListPanel.getOutlookList(); | ||
210 | } | ||
211 | public MyOutlookPanel getOutlookPanel() | ||
212 | { | ||
213 | return this.outlookPanel; | ||
214 | } | ||
215 | public void headerShrinkChanged(boolean headShrinked) | ||
216 | { | ||
217 | if (headShrinked) | ||
218 | lbHandler.setBorder(handlerShrinkedBorder); | ||
219 | else | ||
220 | lbHandler.setBorder(handlerBorder); | ||
221 | } | ||
222 | |||
223 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookHeader.java b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java new file mode 100644 index 0000000..c7ba589 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java | |||
@@ -0,0 +1,109 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.FlowLayout; | ||
5 | import java.awt.LayoutManager; | ||
6 | import java.awt.event.ActionEvent; | ||
7 | import java.awt.event.ActionListener; | ||
8 | import javax.swing.BorderFactory; | ||
9 | import javax.swing.Icon; | ||
10 | import javax.swing.ImageIcon; | ||
11 | import javax.swing.JComponent; | ||
12 | import javax.swing.JLabel; | ||
13 | import javax.swing.JPanel; | ||
14 | import javax.swing.border.Border; | ||
15 | |||
16 | import cppcheckplus.control.MyContorlUtil; | ||
17 | import cppcheckplus.control.MyHeader; | ||
18 | import cppcheckplus.control.MyListSplitListener; | ||
19 | import cppcheckplus.toolbar.MyToolBarButton; | ||
20 | |||
21 | public class MyOutlookHeader extends MyHeader | ||
22 | { | ||
23 | private LayoutManager toolbarLayout; | ||
24 | private JPanel toolbar; | ||
25 | private ImageIcon separatorIcon; | ||
26 | |||
27 | public MyOutlookHeader(ActionListener listener) | ||
28 | { | ||
29 | toolbarLayout = new FlowLayout(FlowLayout.LEFT,2,1); | ||
30 | toolbar = new JPanel(toolbarLayout); | ||
31 | separatorIcon = MyContorlUtil.getImageIcon("control/images/toolbar_separator.png"); | ||
32 | init(); | ||
33 | //加载工具栏 | ||
34 | MyContorlUtil.loadOutlookToolBar("cppcheckplus/control/toolbar.xml", this,listener); | ||
35 | } | ||
36 | |||
37 | private void init() | ||
38 | { | ||
39 | toolbar.setOpaque(false); | ||
40 | toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); | ||
41 | add(toolbar, "Center"); | ||
42 | } | ||
43 | //在Header上添加工具按钮 | ||
44 | public MyToolBarButton addButton(Icon icon, String tooltip, ActionListener action, String command) | ||
45 | { | ||
46 | MyToolBarButton button = new MyToolBarButton(); | ||
47 | button.setIcon(icon); | ||
48 | button.setToolTipText(tooltip); | ||
49 | if (action != null) | ||
50 | button.addActionListener(action); | ||
51 | button.setActionCommand(command); | ||
52 | toolbar.add(button); | ||
53 | return button; | ||
54 | } | ||
55 | |||
56 | public void addSeparator() | ||
57 | { | ||
58 | toolbar.add(new JLabel(separatorIcon)); | ||
59 | } | ||
60 | |||
61 | protected Object getResizeHandlerLayoutConstraint() | ||
62 | { | ||
63 | return "East"; | ||
64 | } | ||
65 | |||
66 | protected Object getShrinkHandlerLayoutConstraint() | ||
67 | { | ||
68 | return "West"; | ||
69 | } | ||
70 | |||
71 | protected MyListSplitListener createSplitListener() | ||
72 | { | ||
73 | return new MyOutlookSplitListener(this); | ||
74 | } | ||
75 | |||
76 | protected Border createBorder() | ||
77 | { | ||
78 | return BorderFactory.createEmptyBorder(4, 0, 0, 7); | ||
79 | } | ||
80 | |||
81 | protected ImageIcon getShrinkIcon(boolean shrinked) | ||
82 | { | ||
83 | if (shrinked) | ||
84 | return RIGHT_ARROW_ICON; | ||
85 | else | ||
86 | return LEFT_ARROW_ICON; | ||
87 | } | ||
88 | |||
89 | protected JComponent getCenterComponent() | ||
90 | { | ||
91 | return null; | ||
92 | } | ||
93 | |||
94 | public void setShrink(boolean shrinked) | ||
95 | { | ||
96 | super.setShrink(shrinked); | ||
97 | toolbar.setVisible(!shrinked); | ||
98 | } | ||
99 | |||
100 | protected int getShrinkedWidth() | ||
101 | { | ||
102 | return 37; | ||
103 | } | ||
104 | |||
105 | public JPanel getToolBar() | ||
106 | { | ||
107 | return toolbar; | ||
108 | } | ||
109 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookList.java b/src/cppcheckplus/outlookpanel/MyOutlookList.java new file mode 100644 index 0000000..d5c04d5 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookList.java | |||
@@ -0,0 +1,31 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import javax.swing.JList; | ||
5 | |||
6 | import cppcheckplus.control.MyContorlUtil; | ||
7 | |||
8 | public class MyOutlookList extends JList | ||
9 | { | ||
10 | //通过MyOutlookBar获得MyOutlookPanel是否sh | ||
11 | private MyOutlookBar bar; | ||
12 | public MyOutlookList(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | ||
13 | { | ||
14 | this.bar = bar; | ||
15 | setListData(listItems); | ||
16 | init(); | ||
17 | } | ||
18 | |||
19 | private void init() | ||
20 | { | ||
21 | setCellRenderer(new MyOutlookListRenderer()); | ||
22 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
23 | setForeground(MyContorlUtil.OUTLOOK_TEXT_COLOR); | ||
24 | setSelectionMode(0); | ||
25 | } | ||
26 | |||
27 | public MyOutlookBar getOutlookBar() | ||
28 | { | ||
29 | return this.bar; | ||
30 | } | ||
31 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java new file mode 100644 index 0000000..2b43866 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java | |||
@@ -0,0 +1,61 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | |||
5 | import java.awt.BorderLayout; | ||
6 | import java.awt.Color; | ||
7 | import java.awt.Component; | ||
8 | import java.awt.Dimension; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Insets; | ||
11 | import javax.swing.JPanel; | ||
12 | import javax.swing.JScrollPane; | ||
13 | import javax.swing.ScrollPaneConstants; | ||
14 | import javax.swing.border.Border; | ||
15 | |||
16 | |||
17 | public class MyOutlookListPanel extends JPanel | ||
18 | { | ||
19 | private MyOutlookList list; | ||
20 | |||
21 | //MyOutlookBar对应的MyOutlookList封装的Panel | ||
22 | private JScrollPane listScrollPane; | ||
23 | private Border scrollBorder; | ||
24 | |||
25 | public MyOutlookListPanel(MyOutlookList list) | ||
26 | { | ||
27 | this.list = list; | ||
28 | listScrollPane = new JScrollPane(list); | ||
29 | // listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); | ||
30 | listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); | ||
31 | scrollBorder = new Border() | ||
32 | { | ||
33 | public void paintBorder(Component c, Graphics g, int x, int y, | ||
34 | int width, int height) | ||
35 | { | ||
36 | g.setColor(new Color(233, 223, 207)); | ||
37 | g.drawLine(0, height, x, height); | ||
38 | } | ||
39 | public Insets getBorderInsets(Component c) | ||
40 | { | ||
41 | return new Insets(0, 0, 1, 0); | ||
42 | } | ||
43 | public boolean isBorderOpaque() | ||
44 | { | ||
45 | return true; | ||
46 | } | ||
47 | }; | ||
48 | init(); | ||
49 | } | ||
50 | private void init() | ||
51 | { | ||
52 | listScrollPane.setMinimumSize(new Dimension(0, 0)); | ||
53 | listScrollPane.setBorder(scrollBorder); | ||
54 | this.setLayout(new BorderLayout()); | ||
55 | add(listScrollPane,BorderLayout.CENTER); | ||
56 | } | ||
57 | public MyOutlookList getOutlookList() | ||
58 | { | ||
59 | return list; | ||
60 | } | ||
61 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java new file mode 100644 index 0000000..9c71301 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java | |||
@@ -0,0 +1,54 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Component; | ||
6 | import javax.swing.BorderFactory; | ||
7 | import javax.swing.DefaultListCellRenderer; | ||
8 | import javax.swing.JList; | ||
9 | import javax.swing.SwingConstants; | ||
10 | import javax.swing.border.Border; | ||
11 | |||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | |||
14 | public class MyOutlookListRenderer extends DefaultListCellRenderer | ||
15 | { | ||
16 | private Color selectedColor; | ||
17 | private Border normalBorder; | ||
18 | private Border shrinkedBorder; | ||
19 | |||
20 | public MyOutlookListRenderer() | ||
21 | { | ||
22 | super(); | ||
23 | selectedColor = new Color(253, 192, 47); | ||
24 | normalBorder = BorderFactory.createEmptyBorder(3, 19, 3, 2); | ||
25 | shrinkedBorder = BorderFactory.createEmptyBorder(2, 7, 1, 2); | ||
26 | } | ||
27 | @Override | ||
28 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) | ||
29 | { | ||
30 | super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus); | ||
31 | |||
32 | MyOutlookPanelListItem listItem = (MyOutlookPanelListItem)value; | ||
33 | MyOutlookList outlookList = (MyOutlookList)list; | ||
34 | setToolTipText(listItem.getToolTip()); | ||
35 | setIcon(listItem.getIcon()); | ||
36 | //收缩样式 | ||
37 | if (outlookList.getOutlookBar().getOutlookPanel().isShrinked()) | ||
38 | { | ||
39 | setBorder(shrinkedBorder); | ||
40 | setText(null); | ||
41 | } | ||
42 | //普通样式 | ||
43 | else | ||
44 | { | ||
45 | setBorder(normalBorder); | ||
46 | setText(listItem.getText()); | ||
47 | setHorizontalAlignment(SwingConstants.LEADING); | ||
48 | setIconTextGap(5); | ||
49 | } | ||
50 | if (isSelected) | ||
51 | setBackground(selectedColor); | ||
52 | return this; | ||
53 | } | ||
54 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java new file mode 100644 index 0000000..139f62a --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java | |||
@@ -0,0 +1,222 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Color; | ||
6 | import java.awt.Component; | ||
7 | import java.awt.Cursor; | ||
8 | import java.awt.Dimension; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Insets; | ||
11 | import java.awt.event.ActionListener; | ||
12 | import java.util.ArrayList; | ||
13 | import java.util.Hashtable; | ||
14 | import java.util.List; | ||
15 | import javax.swing.Icon; | ||
16 | import javax.swing.JButton; | ||
17 | import javax.swing.JComponent; | ||
18 | import javax.swing.JPanel; | ||
19 | import javax.swing.border.Border; | ||
20 | import javax.swing.event.ListSelectionListener; | ||
21 | |||
22 | import cppcheckplus.control.MyContorlUtil; | ||
23 | import layout.TableLayout; | ||
24 | |||
25 | public class MyOutlookPanel extends JPanel | ||
26 | { | ||
27 | //Header | ||
28 | private MyOutlookHeader header; | ||
29 | //容器Panel | ||
30 | private JPanel barPane;; | ||
31 | //右边的分割滑动线条 | ||
32 | private JPanel split; | ||
33 | private int splitWidth; | ||
34 | private Color splitColor; | ||
35 | private JPanel additionalPane; | ||
36 | private Hashtable componentLayoutRows; | ||
37 | private JPanel centerPane; | ||
38 | private TableLayout barPaneLayout; | ||
39 | private MyOutlookSplitListener splitListener; | ||
40 | private ListSelectionListener listSelectionListener; | ||
41 | |||
42 | /** | ||
43 | * 构造MyOutlookPanel | ||
44 | * @param headerListener Header的监听器 | ||
45 | * @param listSelectionListener ListItemSelection的监听器 | ||
46 | */ | ||
47 | public MyOutlookPanel(ActionListener headerListener,ListSelectionListener listSelectionListener) | ||
48 | { | ||
49 | super(); | ||
50 | //注册Header事件 | ||
51 | this.header = new MyOutlookHeader(headerListener){ | ||
52 | public void setShrink(boolean shrinked) | ||
53 | { | ||
54 | super.setShrink(shrinked); | ||
55 | shrinkChanged(shrinked); | ||
56 | } | ||
57 | |||
58 | }; | ||
59 | this.listSelectionListener = listSelectionListener; | ||
60 | barPaneLayout = new TableLayout(); | ||
61 | barPane = new JPanel(barPaneLayout); | ||
62 | |||
63 | additionalPane = new JPanel(new BorderLayout()); | ||
64 | componentLayoutRows = new Hashtable(); | ||
65 | centerPane = new JPanel(new BorderLayout()); | ||
66 | |||
67 | //分割条 | ||
68 | split = new JPanel(); | ||
69 | splitWidth = 1; | ||
70 | splitColor = new Color(166, 172, 174); | ||
71 | splitListener = new MyOutlookSplitListener(header); | ||
72 | |||
73 | init(); | ||
74 | } | ||
75 | private void init() | ||
76 | { | ||
77 | split.setPreferredSize(new Dimension(splitWidth, 0)); | ||
78 | split.setOpaque(true); | ||
79 | split.setBackground(splitColor); | ||
80 | split.setCursor(Cursor.getPredefinedCursor(10)); | ||
81 | split.addMouseListener(splitListener); | ||
82 | split.addMouseMotionListener(splitListener); | ||
83 | additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); | ||
84 | additionalPane.setPreferredSize(new Dimension(0, 0)); | ||
85 | additionalPane.setBorder(new Border() { | ||
86 | |||
87 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | ||
88 | { | ||
89 | g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); | ||
90 | g.drawLine(0, 0, width, 0); | ||
91 | } | ||
92 | |||
93 | public Insets getBorderInsets(Component c) | ||
94 | { | ||
95 | return new Insets(1, 0, 0, 0); | ||
96 | } | ||
97 | |||
98 | public boolean isBorderOpaque() | ||
99 | { | ||
100 | return true; | ||
101 | } | ||
102 | |||
103 | }); | ||
104 | |||
105 | centerPane.add(barPane, "North"); | ||
106 | centerPane.add(additionalPane, "Center"); | ||
107 | barPaneLayout.insertColumn(0, -1D); | ||
108 | setLayout(new BorderLayout()); | ||
109 | add(header, "North"); | ||
110 | add(centerPane, "Center"); | ||
111 | add(split, "East"); | ||
112 | } | ||
113 | public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon,MyOutlookPanelListItem[] listItems) | ||
114 | { | ||
115 | MyOutlookBar bar = new MyOutlookBar(this); | ||
116 | MyOutlookListPanel listPanel = getListPanel(listItems, bar); | ||
117 | //注册JList事件 | ||
118 | listPanel.getOutlookList().addListSelectionListener(listSelectionListener); | ||
119 | bar.setOutlookListPanel(listPanel); | ||
120 | bar.setSelected(false); | ||
121 | bar.setTitle(title); | ||
122 | bar.setIcon(icon); | ||
123 | bar.setSelectedIcon(selectedIcon); | ||
124 | int rowCount = barPaneLayout.getRow().length; | ||
125 | barPaneLayout.insertRow(rowCount, -2D); | ||
126 | barPane.add(bar, (new StringBuilder()).append("0,").append(rowCount).toString()); | ||
127 | componentLayoutRows.put(bar, Integer.valueOf(rowCount)); | ||
128 | rowCount++; | ||
129 | barPaneLayout.insertRow(rowCount, -3D); | ||
130 | //加载列表 | ||
131 | barPane.add(listPanel,(new StringBuilder()).append("0,").append(rowCount).toString()); | ||
132 | componentLayoutRows.put(bar.getContentComponent(), Integer.valueOf(rowCount)); | ||
133 | return bar; | ||
134 | } | ||
135 | private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | ||
136 | { | ||
137 | MyOutlookList list = new MyOutlookList(listItems,bar); | ||
138 | MyOutlookListPanel listPanel = new MyOutlookListPanel(list); | ||
139 | return listPanel; | ||
140 | } | ||
141 | public void updateLayoutConstraint(Component component, boolean selected) | ||
142 | { | ||
143 | int rowIndex = ((Integer)componentLayoutRows.get(component)).intValue(); | ||
144 | double constraint = -1D; | ||
145 | if (!selected) | ||
146 | constraint = -3D; | ||
147 | barPaneLayout.setRow(rowIndex, constraint); | ||
148 | } | ||
149 | public JComponent getAdditionalPane() | ||
150 | { | ||
151 | return additionalPane; | ||
152 | } | ||
153 | public void setAdditionalPaneVisible(boolean visible) | ||
154 | { | ||
155 | centerPane.remove(barPane); | ||
156 | centerPane.remove(additionalPane); | ||
157 | if (visible) | ||
158 | { | ||
159 | centerPane.add(barPane, "North"); | ||
160 | centerPane.add(additionalPane, "Center"); | ||
161 | } else | ||
162 | { | ||
163 | centerPane.add(barPane, "Center"); | ||
164 | } | ||
165 | } | ||
166 | public void closeAllBars() | ||
167 | { | ||
168 | for (int i = 0; i < barPane.getComponentCount(); i++) | ||
169 | { | ||
170 | Component c = barPane.getComponent(i); | ||
171 | if (!(c instanceof MyOutlookBar)) | ||
172 | continue; | ||
173 | MyOutlookBar bar = (MyOutlookBar)c; | ||
174 | if (bar.isSelected()) | ||
175 | bar.setSelected(false); | ||
176 | } | ||
177 | } | ||
178 | public MyOutlookBar getSelectedBar() | ||
179 | { | ||
180 | for (int i = 0; i < barPane.getComponentCount(); i++) | ||
181 | { | ||
182 | Component c = barPane.getComponent(i); | ||
183 | if (!(c instanceof MyOutlookBar)) | ||
184 | continue; | ||
185 | MyOutlookBar bar = (MyOutlookBar)c; | ||
186 | if (bar.isSelected()) | ||
187 | return bar; | ||
188 | } | ||
189 | |||
190 | return null; | ||
191 | } | ||
192 | public void setShrink(boolean shrinked) | ||
193 | { | ||
194 | header.setShrink(shrinked); | ||
195 | } | ||
196 | |||
197 | public boolean isShrinked() | ||
198 | { | ||
199 | return header.isShrinked(); | ||
200 | } | ||
201 | private void shrinkChanged(boolean shrinked) | ||
202 | { | ||
203 | if (shrinked) | ||
204 | split.setCursor(Cursor.getDefaultCursor()); | ||
205 | else | ||
206 | split.setCursor(Cursor.getPredefinedCursor(10)); | ||
207 | for (int i = 0; i < barPane.getComponentCount(); i++) | ||
208 | { | ||
209 | Component c = barPane.getComponent(i); | ||
210 | if (c instanceof MyOutlookBar) | ||
211 | { | ||
212 | MyOutlookBar bar = (MyOutlookBar)c; | ||
213 | bar.headerShrinkChanged(shrinked); | ||
214 | |||
215 | |||
216 | //XOutlookList list = bar.getList(); | ||
217 | |||
218 | //list.firePropertyChange("layoutOrientation", true, false); | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java new file mode 100644 index 0000000..92fd09e --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java | |||
@@ -0,0 +1,51 @@ | |||
1 | package cppcheckplus.outlookpanel; | ||
2 | |||
3 | import javax.swing.Icon; | ||
4 | |||
5 | public class MyOutlookPanelListItem | ||
6 | { | ||
7 | private Icon icon; | ||
8 | private String text; | ||
9 | private String toolTip; | ||
10 | private String actionCommand; | ||
11 | |||
12 | public void setIcon(Icon icon) | ||
13 | { | ||
14 | this.icon = icon; | ||
15 | } | ||
16 | |||
17 | public Icon getIcon() | ||
18 | { | ||
19 | return icon; | ||
20 | } | ||
21 | |||
22 | public void setText(String value) | ||
23 | { | ||
24 | this.text = value; | ||
25 | } | ||
26 | |||
27 | public String getText() | ||
28 | { | ||
29 | return text; | ||
30 | } | ||
31 | |||
32 | public void setToolTip(String toolTip) | ||
33 | { | ||
34 | this.toolTip = toolTip; | ||
35 | } | ||
36 | |||
37 | public String getToolTip() | ||
38 | { | ||
39 | return toolTip; | ||
40 | } | ||
41 | |||
42 | public void setActionCommand(String actionCommand) | ||
43 | { | ||
44 | this.actionCommand = actionCommand; | ||
45 | } | ||
46 | |||
47 | public String getActionCommand() | ||
48 | { | ||
49 | return actionCommand; | ||
50 | } | ||
51 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java new file mode 100644 index 0000000..b65e706 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java | |||
@@ -0,0 +1,33 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Point; | ||
6 | import java.awt.event.MouseEvent; | ||
7 | import javax.swing.JComponent; | ||
8 | |||
9 | import cppcheckplus.control.MyHeader; | ||
10 | import cppcheckplus.control.MyListSplitListener; | ||
11 | |||
12 | public class MyOutlookSplitListener extends MyListSplitListener | ||
13 | { | ||
14 | public MyOutlookSplitListener(MyHeader header) | ||
15 | { | ||
16 | super(header); | ||
17 | } | ||
18 | |||
19 | public void mouseDragged(MouseEvent e) | ||
20 | { | ||
21 | if (!header.isShrinked() && lastPoint != null) | ||
22 | { | ||
23 | JComponent parent = (JComponent)header.getParent(); | ||
24 | Dimension size = parent.getPreferredSize(); | ||
25 | Point thisPoint = e.getPoint(); | ||
26 | int xMovement = thisPoint.x - lastPoint.x; | ||
27 | size.width += xMovement; | ||
28 | size.width = Math.max(size.width, 37); | ||
29 | parent.setPreferredSize(size); | ||
30 | header.revalidateParent(); | ||
31 | } | ||
32 | } | ||
33 | } | ||
diff --git a/src/cppcheckplus/shortcut/MyShortcutItem.java b/src/cppcheckplus/shortcut/MyShortcutItem.java new file mode 100644 index 0000000..7461690 --- /dev/null +++ b/src/cppcheckplus/shortcut/MyShortcutItem.java | |||
@@ -0,0 +1,20 @@ | |||
1 | |||
2 | package cppcheckplus.shortcut; | ||
3 | |||
4 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; | ||
5 | |||
6 | public class MyShortcutItem extends MyOutlookPanelListItem | ||
7 | { | ||
8 | private boolean isGroup; | ||
9 | |||
10 | |||
11 | public void setGroup(boolean isGroup) | ||
12 | { | ||
13 | this.isGroup = isGroup; | ||
14 | } | ||
15 | |||
16 | public boolean isGroup() | ||
17 | { | ||
18 | return isGroup; | ||
19 | } | ||
20 | } | ||
diff --git a/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java b/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java new file mode 100644 index 0000000..b2ea232 --- /dev/null +++ b/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java | |||
@@ -0,0 +1,7 @@ | |||
1 | |||
2 | package cppcheckplus.shortcut; | ||
3 | |||
4 | public interface MyShortcutItemClickListenter | ||
5 | { | ||
6 | public void ItemClick(String actionCommand); | ||
7 | } | ||
diff --git a/src/cppcheckplus/shortcut/MyShortcutPanel.java b/src/cppcheckplus/shortcut/MyShortcutPanel.java new file mode 100644 index 0000000..5d97b08 --- /dev/null +++ b/src/cppcheckplus/shortcut/MyShortcutPanel.java | |||
@@ -0,0 +1,114 @@ | |||
1 | |||
2 | package cppcheckplus.shortcut; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Component; | ||
6 | import java.awt.Cursor; | ||
7 | import java.awt.Dimension; | ||
8 | import java.awt.Graphics; | ||
9 | import java.awt.Insets; | ||
10 | import javax.swing.JPanel; | ||
11 | import javax.swing.border.Border; | ||
12 | |||
13 | import cppcheckplus.control.MyContorlUtil; | ||
14 | import cppcheckplus.control.MyHeader; | ||
15 | import cppcheckplus.control.MyList; | ||
16 | import cppcheckplus.control.MyListSplitListener; | ||
17 | import cppcheckplus.outlookpanel.MyOutlookList; | ||
18 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; | ||
19 | |||
20 | public class MyShortcutPanel extends JPanel{ | ||
21 | private MyList list; | ||
22 | private JPanel split; | ||
23 | private MyHeader header; | ||
24 | private MyListSplitListener splitListener; | ||
25 | public MyTree mytree; | ||
26 | public MyShortcutPanel() | ||
27 | { | ||
28 | super(); | ||
29 | //list = new MyList(); | ||
30 | split = new JPanel(new BorderLayout()); | ||
31 | |||
32 | header = new MyHeader() { | ||
33 | |||
34 | public void setShrink(boolean shrinked) | ||
35 | { | ||
36 | super.setShrink(shrinked); | ||
37 | if (shrinked) | ||
38 | split.setCursor(Cursor.getDefaultCursor()); | ||
39 | else | ||
40 | split.setCursor(Cursor.getPredefinedCursor(10)); | ||
41 | } | ||
42 | }; | ||
43 | splitListener = new MyListSplitListener(header); | ||
44 | mytree = new MyTree(); | ||
45 | init(); | ||
46 | } | ||
47 | public void setData(MyShortcutItem[] items,MyShortcutItemClickListenter listenter) | ||
48 | { | ||
49 | //list.setListData(items); | ||
50 | list.setListenter(listenter); | ||
51 | } | ||
52 | private void init() | ||
53 | { | ||
54 | setLayout(new BorderLayout()); | ||
55 | JPanel rightInsetPane = new JPanel(); | ||
56 | rightInsetPane.setPreferredSize(new Dimension(2, 0)); | ||
57 | rightInsetPane.setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
58 | add(rightInsetPane, "East"); | ||
59 | add(header, "North"); | ||
60 | |||
61 | split.setBorder(new Border() { | ||
62 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | ||
63 | { | ||
64 | g.setColor(MyContorlUtil.LIST_SPLIT_COLOR); | ||
65 | g.drawLine(x, y, x, y + height); | ||
66 | } | ||
67 | |||
68 | public Insets getBorderInsets(Component c) | ||
69 | { | ||
70 | return new Insets(0, 1, 0, 0); | ||
71 | } | ||
72 | |||
73 | public boolean isBorderOpaque() | ||
74 | { | ||
75 | return true; | ||
76 | } | ||
77 | |||
78 | }); | ||
79 | split.setOpaque(true); | ||
80 | split.setPreferredSize(new Dimension(4, 0)); | ||
81 | split.setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
82 | split.setCursor(Cursor.getPredefinedCursor(10)); | ||
83 | split.addMouseListener(splitListener); | ||
84 | split.addMouseMotionListener(splitListener); | ||
85 | add(split, "West"); | ||
86 | add(mytree, "Center"); | ||
87 | //add(list, "Center"); | ||
88 | } | ||
89 | |||
90 | public MyList getList() | ||
91 | { | ||
92 | return list; | ||
93 | } | ||
94 | |||
95 | public void setTitle(String title) | ||
96 | { | ||
97 | header.setTitle(title); | ||
98 | } | ||
99 | |||
100 | public String getTitle() | ||
101 | { | ||
102 | return header.getTitle(); | ||
103 | } | ||
104 | |||
105 | public void setShrink(boolean shrinked) | ||
106 | { | ||
107 | header.setShrink(shrinked); | ||
108 | } | ||
109 | |||
110 | public boolean isShrinked() | ||
111 | { | ||
112 | return header.isShrinked(); | ||
113 | } | ||
114 | } | ||
diff --git a/src/cppcheckplus/shortcut/MyTree.java b/src/cppcheckplus/shortcut/MyTree.java new file mode 100644 index 0000000..74485b3 --- /dev/null +++ b/src/cppcheckplus/shortcut/MyTree.java | |||
@@ -0,0 +1,124 @@ | |||
1 | package cppcheckplus.shortcut; | ||
2 | |||
3 | import java.io.File; | ||
4 | |||
5 | import javax.swing.JPanel; | ||
6 | import javax.swing.JScrollPane; | ||
7 | import javax.swing.JTextArea; | ||
8 | import javax.swing.JTree; | ||
9 | import javax.swing.event.TreeExpansionEvent; | ||
10 | import javax.swing.event.TreeExpansionListener; | ||
11 | import javax.swing.event.TreeSelectionEvent; | ||
12 | import javax.swing.event.TreeSelectionListener; | ||
13 | import javax.swing.tree.DefaultMutableTreeNode; | ||
14 | import javax.swing.tree.DefaultTreeModel; | ||
15 | import javax.swing.tree.MutableTreeNode; | ||
16 | |||
17 | import cppcheckplus.control.Main; | ||
18 | import cppcheckplus.text.FileTools; | ||
19 | |||
20 | public class MyTree extends JPanel { | ||
21 | private JTree tree; | ||
22 | public File result; | ||
23 | public String src; | ||
24 | private Main jf; | ||
25 | private JTextArea textCode; | ||
26 | public MyTree() { | ||
27 | tree = new JTree(); | ||
28 | tree.addTreeExpansionListener(new TreeExpansionAction()); | ||
29 | tree.addTreeSelectionListener(new TreeSelectionListener() { | ||
30 | public void valueChanged(TreeSelectionEvent evt) { | ||
31 | jTreeValueChanged(evt); | ||
32 | } | ||
33 | }); | ||
34 | |||
35 | add(new JScrollPane(tree)); | ||
36 | setRootDir(new File("c:/")); | ||
37 | setVisible(true); | ||
38 | } | ||
39 | |||
40 | public void setCode(JTextArea textCode, Main jf){ | ||
41 | this.textCode = textCode; | ||
42 | this.jf=jf; | ||
43 | } | ||
44 | |||
45 | public void setRootDir(File dir) { | ||
46 | if(dir==null) | ||
47 | return; | ||
48 | tree.setModel(new DefaultTreeModel(createNode(dir))); | ||
49 | MutableTreeNode rootNode = (MutableTreeNode) tree.getModel().getRoot(); | ||
50 | rootNode.setUserObject(dir); | ||
51 | updateNode(rootNode); | ||
52 | tree.updateUI(); | ||
53 | } | ||
54 | private void updateNode(Object object) { | ||
55 | DefaultMutableTreeNode node = (DefaultMutableTreeNode) object; | ||
56 | for (int i = 0; i < node.getChildCount(); i++) { | ||
57 | DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) node.getChildAt(i); | ||
58 | FileObject fileObject = (FileObject) node2.getUserObject(); | ||
59 | if (!fileObject.isUpdated()) { | ||
60 | fileObject.setUpdated(true); | ||
61 | File file = fileObject.getFile(); | ||
62 | if (file.isDirectory()) { | ||
63 | addSubFile(node2, file); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | private void jTreeValueChanged(TreeSelectionEvent evt) { | ||
70 | DefaultMutableTreeNode selectedNode=(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();//返回最后选定的节点 | ||
71 | if(selectedNode!=null && selectedNode.isLeaf()){ | ||
72 | result = ((FileObject) selectedNode.getUserObject()).file; | ||
73 | jf.src = result.getAbsolutePath(); | ||
74 | if (!jf.tabPanel.isSelectTabComponents("代码")) { | ||
75 | jf.tabPanel.addTab("代码", jf.testCode); | ||
76 | jf.tabPanel.isSelectTabComponents("代码"); | ||
77 | } | ||
78 | textCode.setText(FileTools.readFile(result)); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public MutableTreeNode createNode(File dir) { | ||
83 | DefaultMutableTreeNode node = new DefaultMutableTreeNode(new FileObject(dir)); | ||
84 | if (dir.isDirectory()) { | ||
85 | addSubFile(node, dir); | ||
86 | } | ||
87 | return node; | ||
88 | } | ||
89 | private void addSubFile(DefaultMutableTreeNode node, File dir) { | ||
90 | File[] files = dir.listFiles(); | ||
91 | if (files != null) { | ||
92 | for (File file : files) { | ||
93 | node.add(new DefaultMutableTreeNode(new FileObject(file))); | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | public class TreeExpansionAction implements TreeExpansionListener { | ||
98 | public void treeExpanded(TreeExpansionEvent event) { | ||
99 | updateNode(event.getPath().getLastPathComponent()); | ||
100 | } | ||
101 | public void treeCollapsed(TreeExpansionEvent event) { | ||
102 | |||
103 | } | ||
104 | } | ||
105 | public class FileObject { | ||
106 | private File file; | ||
107 | private boolean updated; | ||
108 | public FileObject(File file) { | ||
109 | this.file = file; | ||
110 | } | ||
111 | public File getFile() { | ||
112 | return file; | ||
113 | } | ||
114 | public boolean isUpdated() { | ||
115 | return updated; | ||
116 | } | ||
117 | public void setUpdated(boolean updated) { | ||
118 | this.updated = updated; | ||
119 | } | ||
120 | public String toString() { | ||
121 | return file.getName(); | ||
122 | } | ||
123 | } | ||
124 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/tab/MyTabComponent.java b/src/cppcheckplus/tab/MyTabComponent.java new file mode 100644 index 0000000..5a1d2a6 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabComponent.java | |||
@@ -0,0 +1,173 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Color; | ||
6 | import java.awt.Dimension; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Graphics2D; | ||
9 | import java.awt.Image; | ||
10 | import java.awt.TexturePaint; | ||
11 | import java.awt.event.ActionEvent; | ||
12 | import java.awt.event.ActionListener; | ||
13 | import javax.swing.BorderFactory; | ||
14 | import javax.swing.ImageIcon; | ||
15 | import javax.swing.JButton; | ||
16 | import javax.swing.JLabel; | ||
17 | import javax.swing.JPanel; | ||
18 | import javax.swing.border.Border; | ||
19 | |||
20 | import cppcheckplus.control.MyContorlUtil; | ||
21 | |||
22 | |||
23 | public class MyTabComponent extends JPanel | ||
24 | { | ||
25 | |||
26 | private String backgroundUnselectedImageURL; | ||
27 | private TexturePaint selectedPaint; | ||
28 | private TexturePaint unselectedPaint; | ||
29 | private ImageIcon icon; | ||
30 | private ImageIcon pressedIcon; | ||
31 | private Image unselectedLeftImage; | ||
32 | private Image unselectedRightImage; | ||
33 | private Image selectedLeftImage; | ||
34 | private Image selectedRightImage; | ||
35 | private JButton btnClose; | ||
36 | private JLabel lbTitle; | ||
37 | private MyTabPanel tab; | ||
38 | private Color selectedTitleColor; | ||
39 | private Color unselectedTitleColor; | ||
40 | private Border border; | ||
41 | private String oId; | ||
42 | |||
43 | public MyTabComponent(String oId,MyTabPanel tab) | ||
44 | { | ||
45 | super(); | ||
46 | this.oId = oId; | ||
47 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); | ||
48 | unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); | ||
49 | icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); | ||
50 | pressedIcon = MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); | ||
51 | unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); | ||
52 | unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); | ||
53 | selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); | ||
54 | selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); | ||
55 | btnClose = new JButton(); | ||
56 | lbTitle = new JLabel(); | ||
57 | this.tab = null; | ||
58 | selectedTitleColor = new Color(120, 120, 125); | ||
59 | unselectedTitleColor = Color.white; | ||
60 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); | ||
61 | this.tab = tab; | ||
62 | init(); | ||
63 | } | ||
64 | |||
65 | private void init() | ||
66 | { | ||
67 | btnClose.setIcon(icon); | ||
68 | btnClose.setPressedIcon(pressedIcon); | ||
69 | btnClose.setToolTipText("Close this tab"); | ||
70 | btnClose.setMargin(MyContorlUtil.ZERO_INSETS); | ||
71 | btnClose.setFocusPainted(false); | ||
72 | btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); | ||
73 | btnClose.setContentAreaFilled(false); | ||
74 | btnClose.addActionListener(new ActionListener() { | ||
75 | |||
76 | public void actionPerformed(ActionEvent e) | ||
77 | { | ||
78 | closeTab(); | ||
79 | } | ||
80 | |||
81 | }); | ||
82 | lbTitle.setOpaque(false); | ||
83 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); | ||
84 | lbTitle.setVerticalAlignment(0); | ||
85 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); | ||
86 | setLayout(new BorderLayout()); | ||
87 | add(btnClose, "East"); | ||
88 | add(lbTitle, "Center"); | ||
89 | setBorder(border); | ||
90 | setOpaque(false); | ||
91 | } | ||
92 | |||
93 | public void paintComponent(Graphics g) | ||
94 | { | ||
95 | Graphics2D g2d = (Graphics2D)g; | ||
96 | if (isTabSelected()) | ||
97 | { | ||
98 | g2d.drawImage(selectedLeftImage, 0, 0, null); | ||
99 | g2d.setPaint(selectedPaint); | ||
100 | int x = selectedLeftImage.getWidth(null); | ||
101 | int y = 0; | ||
102 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
103 | int height = getHeight(); | ||
104 | g2d.fillRect(x, y, width, height); | ||
105 | g2d.drawImage(selectedRightImage, x + width, 0, null); | ||
106 | } else | ||
107 | { | ||
108 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | ||
109 | g2d.setPaint(unselectedPaint); | ||
110 | int x = unselectedLeftImage.getWidth(null); | ||
111 | int y = 0; | ||
112 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
113 | int height = getHeight(); | ||
114 | g2d.fillRect(x, y, width, height); | ||
115 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | ||
116 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
117 | int lineY = getHeight() - 1; | ||
118 | g2d.drawLine(0, lineY, getWidth(), lineY); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | public Dimension getPreferredSize() | ||
123 | { | ||
124 | int width = super.getPreferredSize().width; | ||
125 | if (!isTabSelected()) | ||
126 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); | ||
127 | int height = tab.getPreferredTabHeight(); | ||
128 | return new Dimension(width, height); | ||
129 | } | ||
130 | |||
131 | public boolean isTabSelected() | ||
132 | { | ||
133 | int index = tab.indexOfTabComponent(this); | ||
134 | int selectedIndex = tab.getSelectedIndex(); | ||
135 | return selectedIndex == index; | ||
136 | } | ||
137 | |||
138 | public void setTitle(String title) | ||
139 | { | ||
140 | lbTitle.setText(title); | ||
141 | } | ||
142 | |||
143 | public void updateSelection(boolean selected) | ||
144 | { | ||
145 | if (selected) | ||
146 | lbTitle.setForeground(selectedTitleColor); | ||
147 | else | ||
148 | lbTitle.setForeground(unselectedTitleColor); | ||
149 | btnClose.setVisible(selected); | ||
150 | } | ||
151 | |||
152 | private void closeTab() | ||
153 | { | ||
154 | int index = tab.indexOfTabComponent(this); | ||
155 | tab.removeTabAt(index); | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * @param oId the oId to set | ||
160 | */ | ||
161 | public void setOId(String oId) | ||
162 | { | ||
163 | this.oId = oId; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * @return the oId | ||
168 | */ | ||
169 | public String getOId() | ||
170 | { | ||
171 | return oId; | ||
172 | } | ||
173 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabComponent1.java b/src/cppcheckplus/tab/MyTabComponent1.java new file mode 100644 index 0000000..9901441 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabComponent1.java | |||
@@ -0,0 +1,136 @@ | |||
1 | package cppcheckplus.tab; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Color; | ||
5 | import java.awt.Dimension; | ||
6 | import java.awt.Graphics; | ||
7 | import java.awt.Graphics2D; | ||
8 | import java.awt.Image; | ||
9 | import java.awt.TexturePaint; | ||
10 | |||
11 | import javax.swing.BorderFactory; | ||
12 | import javax.swing.ImageIcon; | ||
13 | import javax.swing.JLabel; | ||
14 | import javax.swing.JPanel; | ||
15 | import javax.swing.border.Border; | ||
16 | |||
17 | import cppcheckplus.control.MyContorlUtil; | ||
18 | |||
19 | public class MyTabComponent1 extends JPanel{ | ||
20 | |||
21 | private String backgroundUnselectedImageURL; | ||
22 | private TexturePaint selectedPaint; | ||
23 | private TexturePaint unselectedPaint; | ||
24 | private ImageIcon pressedIcon; | ||
25 | private Image unselectedLeftImage; | ||
26 | private Image unselectedRightImage; | ||
27 | private Image selectedLeftImage; | ||
28 | private Image selectedRightImage; | ||
29 | private JLabel lbTitle; | ||
30 | private MyTabPanel1 tab; | ||
31 | private Color selectedTitleColor; | ||
32 | private Color unselectedTitleColor; | ||
33 | private Border border; | ||
34 | private String oId; | ||
35 | |||
36 | public MyTabComponent1(String oId,MyTabPanel1 tab) | ||
37 | { | ||
38 | super(); | ||
39 | this.oId = oId; | ||
40 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); | ||
41 | unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); | ||
42 | unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); | ||
43 | unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); | ||
44 | selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); | ||
45 | selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); | ||
46 | lbTitle = new JLabel(); | ||
47 | this.tab = null; | ||
48 | selectedTitleColor = new Color(120, 120, 125); | ||
49 | unselectedTitleColor = Color.white; | ||
50 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); | ||
51 | this.tab = tab; | ||
52 | init(); | ||
53 | } | ||
54 | |||
55 | private void init() | ||
56 | { | ||
57 | lbTitle.setOpaque(false); | ||
58 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); | ||
59 | lbTitle.setVerticalAlignment(0); | ||
60 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); | ||
61 | setLayout(new BorderLayout()); | ||
62 | add(lbTitle, "Center"); | ||
63 | setBorder(border); | ||
64 | setOpaque(false); | ||
65 | } | ||
66 | |||
67 | public void paintComponent(Graphics g) | ||
68 | { | ||
69 | Graphics2D g2d = (Graphics2D)g; | ||
70 | if (isTabSelected()) | ||
71 | { | ||
72 | g2d.drawImage(selectedLeftImage, 0, 0, null); | ||
73 | g2d.setPaint(selectedPaint); | ||
74 | int x = selectedLeftImage.getWidth(null); | ||
75 | int y = 0; | ||
76 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
77 | int height = getHeight(); | ||
78 | g2d.fillRect(x, y, width, height); | ||
79 | g2d.drawImage(selectedRightImage, x + width, 0, null); | ||
80 | } else | ||
81 | { | ||
82 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | ||
83 | g2d.setPaint(unselectedPaint); | ||
84 | int x = unselectedLeftImage.getWidth(null); | ||
85 | int y = 0; | ||
86 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
87 | int height = getHeight(); | ||
88 | g2d.fillRect(x, y, width, height); | ||
89 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | ||
90 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
91 | int lineY = getHeight() - 1; | ||
92 | g2d.drawLine(0, lineY, getWidth(), lineY); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public Dimension getPreferredSize() | ||
97 | { | ||
98 | int width = super.getPreferredSize().width; | ||
99 | if (!isTabSelected()) | ||
100 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); | ||
101 | int height = tab.getPreferredTabHeight(); | ||
102 | return new Dimension(width, height); | ||
103 | } | ||
104 | |||
105 | public boolean isTabSelected() | ||
106 | { | ||
107 | int index = tab.indexOfTabComponent(this); | ||
108 | int selectedIndex = tab.getSelectedIndex(); | ||
109 | return selectedIndex == index; | ||
110 | } | ||
111 | |||
112 | public void setTitle(String title) | ||
113 | { | ||
114 | lbTitle.setText(title); | ||
115 | } | ||
116 | |||
117 | public void updateSelection(boolean selected) | ||
118 | { | ||
119 | if (selected) | ||
120 | lbTitle.setForeground(selectedTitleColor); | ||
121 | else | ||
122 | lbTitle.setForeground(unselectedTitleColor); | ||
123 | } | ||
124 | |||
125 | |||
126 | |||
127 | public void setOId(String oId) | ||
128 | { | ||
129 | this.oId = oId; | ||
130 | } | ||
131 | |||
132 | public String getOId() | ||
133 | { | ||
134 | return oId; | ||
135 | } | ||
136 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabPage.java b/src/cppcheckplus/tab/MyTabPage.java new file mode 100644 index 0000000..ef26580 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPage.java | |||
@@ -0,0 +1,46 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import javax.swing.JComponent; | ||
6 | import javax.swing.JPanel; | ||
7 | |||
8 | import cppcheckplus.toolbar.MyToolBar; | ||
9 | |||
10 | |||
11 | public class MyTabPage extends JPanel | ||
12 | { | ||
13 | private MyToolBar toolbar; | ||
14 | private JPanel centerPane; | ||
15 | |||
16 | public MyTabPage() | ||
17 | { | ||
18 | this(null); | ||
19 | } | ||
20 | |||
21 | public MyTabPage(JComponent contentComponent) | ||
22 | { | ||
23 | toolbar = new MyToolBar(); | ||
24 | centerPane = new JPanel(new BorderLayout()); | ||
25 | init(contentComponent); | ||
26 | } | ||
27 | |||
28 | private void init(JComponent contentComponent) | ||
29 | { | ||
30 | setLayout(new BorderLayout()); | ||
31 | add(toolbar, "North"); | ||
32 | add(centerPane, "Center"); | ||
33 | if (contentComponent != null) | ||
34 | centerPane.add(contentComponent, "Center"); | ||
35 | } | ||
36 | |||
37 | public JPanel getCenterPane() | ||
38 | { | ||
39 | return centerPane; | ||
40 | } | ||
41 | |||
42 | public MyToolBar getToolBar() | ||
43 | { | ||
44 | return toolbar; | ||
45 | } | ||
46 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabPage1.java b/src/cppcheckplus/tab/MyTabPage1.java new file mode 100644 index 0000000..e851b3a --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPage1.java | |||
@@ -0,0 +1,30 @@ | |||
1 | package cppcheckplus.tab; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | |||
5 | import javax.swing.JComponent; | ||
6 | import javax.swing.JPanel; | ||
7 | public class MyTabPage1 extends JPanel{ | ||
8 | private JPanel centerPane; | ||
9 | |||
10 | public MyTabPage1(){ | ||
11 | this(null); | ||
12 | } | ||
13 | |||
14 | public MyTabPage1(JComponent contentComponent){ | ||
15 | centerPane = new JPanel(new BorderLayout()); | ||
16 | init(contentComponent); | ||
17 | } | ||
18 | |||
19 | private void init(JComponent contentComponent){ | ||
20 | setLayout(new BorderLayout()); | ||
21 | add(centerPane, "Center"); | ||
22 | if (contentComponent != null) | ||
23 | centerPane.add(contentComponent, "Center"); | ||
24 | } | ||
25 | |||
26 | public JPanel getCenterPane(){ | ||
27 | return centerPane; | ||
28 | } | ||
29 | |||
30 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabPanel.java b/src/cppcheckplus/tab/MyTabPanel.java new file mode 100644 index 0000000..cda8c3a --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPanel.java | |||
@@ -0,0 +1,97 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | ||
3 | |||
4 | import java.awt.Component; | ||
5 | import javax.swing.JTabbedPane; | ||
6 | import javax.swing.event.ChangeEvent; | ||
7 | import javax.swing.event.ChangeListener; | ||
8 | |||
9 | import cppcheckplus.control.MyContorlUtil; | ||
10 | |||
11 | public class MyTabPanel extends JTabbedPane | ||
12 | { | ||
13 | private int preferredUnselectedTabWidth; | ||
14 | private int preferredTabHeight; | ||
15 | |||
16 | public MyTabPanel() | ||
17 | { | ||
18 | preferredUnselectedTabWidth = 80; | ||
19 | preferredTabHeight = MyContorlUtil.getImageIcon("control/images/tab_header_background.png").getIconHeight(); | ||
20 | init(); | ||
21 | } | ||
22 | |||
23 | private void init() | ||
24 | { | ||
25 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
26 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); | ||
27 | setBorder(null); | ||
28 | setFocusable(false); | ||
29 | setTabLayoutPolicy(1); | ||
30 | setOpaque(false); | ||
31 | setUI(new MyTabPanelUI(this)); | ||
32 | addChangeListener(new ChangeListener() { | ||
33 | public void stateChanged(ChangeEvent e) | ||
34 | { | ||
35 | updateTabComponents(); | ||
36 | } | ||
37 | }); | ||
38 | } | ||
39 | |||
40 | |||
41 | @Override | ||
42 | public void addTab(String title, Component component) | ||
43 | { | ||
44 | super.addTab(title, component); | ||
45 | int index = getTabCount() - 1; | ||
46 | MyTabComponent tabComponent = new MyTabComponent(title, this); | ||
47 | tabComponent.setTitle(title); | ||
48 | setTabComponentAt(index, tabComponent); | ||
49 | setToolTipTextAt(index, title); | ||
50 | updateTabComponents(); | ||
51 | } | ||
52 | |||
53 | public boolean isSelectTabComponents(String oId) | ||
54 | { | ||
55 | for(int i=0;i<getTabCount();i++) | ||
56 | { | ||
57 | Component c = getTabComponentAt(i); | ||
58 | if (c instanceof MyTabComponent) | ||
59 | { | ||
60 | if(((MyTabComponent) c).getOId().equals(oId)) | ||
61 | { | ||
62 | setSelectedIndex(i); | ||
63 | updateTabComponents(); | ||
64 | return true; | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | return false; | ||
69 | } | ||
70 | |||
71 | public int getPreferredTabHeight() | ||
72 | { | ||
73 | return preferredTabHeight; | ||
74 | } | ||
75 | |||
76 | private void updateTabComponents() | ||
77 | { | ||
78 | int selectedIndex = getSelectedIndex(); | ||
79 | for (int i = 0; i < getTabCount(); i++) | ||
80 | { | ||
81 | Component c = getTabComponentAt(i); | ||
82 | if (c instanceof MyTabComponent) | ||
83 | { | ||
84 | MyTabComponent component = (MyTabComponent)c; | ||
85 | boolean selected = selectedIndex == i; | ||
86 | component.updateSelection(selected); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | } | ||
91 | |||
92 | public int getPreferredUnselectedTabWidth() | ||
93 | { | ||
94 | return preferredUnselectedTabWidth; | ||
95 | } | ||
96 | |||
97 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabPanel1.java b/src/cppcheckplus/tab/MyTabPanel1.java new file mode 100644 index 0000000..ace4d72 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPanel1.java | |||
@@ -0,0 +1,96 @@ | |||
1 | package cppcheckplus.tab; | ||
2 | |||
3 | import java.awt.Component; | ||
4 | import javax.swing.JTabbedPane; | ||
5 | import javax.swing.event.ChangeEvent; | ||
6 | import javax.swing.event.ChangeListener; | ||
7 | |||
8 | import cppcheckplus.control.MyContorlUtil; | ||
9 | |||
10 | public class MyTabPanel1 extends JTabbedPane | ||
11 | { | ||
12 | private int preferredUnselectedTabWidth; | ||
13 | private int preferredTabHeight; | ||
14 | |||
15 | public MyTabPanel1() | ||
16 | { | ||
17 | preferredUnselectedTabWidth = 80; | ||
18 | preferredTabHeight = MyContorlUtil.getImageIcon("control/images/tab_header_background.png").getIconHeight(); | ||
19 | init(); | ||
20 | } | ||
21 | |||
22 | private void init() | ||
23 | { | ||
24 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
25 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); | ||
26 | setBorder(null); | ||
27 | setFocusable(false); | ||
28 | setTabLayoutPolicy(1); | ||
29 | setOpaque(false); | ||
30 | setUI(new MyTabPanelUI1(this)); | ||
31 | addChangeListener(new ChangeListener() { | ||
32 | public void stateChanged(ChangeEvent e) | ||
33 | { | ||
34 | updateTabComponents(); | ||
35 | } | ||
36 | }); | ||
37 | } | ||
38 | |||
39 | |||
40 | @Override | ||
41 | public void addTab(String title, Component component) | ||
42 | { | ||
43 | super.addTab(title, component); | ||
44 | int index = getTabCount() - 1; | ||
45 | MyTabComponent1 tabComponent = new MyTabComponent1(title, this); | ||
46 | tabComponent.setTitle(title); | ||
47 | setTabComponentAt(index, tabComponent); | ||
48 | setToolTipTextAt(index, title); | ||
49 | updateTabComponents(); | ||
50 | } | ||
51 | |||
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 | |||
70 | public int getPreferredTabHeight() | ||
71 | { | ||
72 | return preferredTabHeight; | ||
73 | } | ||
74 | |||
75 | private void updateTabComponents() | ||
76 | { | ||
77 | int selectedIndex = getSelectedIndex(); | ||
78 | for (int i = 0; i < getTabCount(); i++) | ||
79 | { | ||
80 | Component c = getTabComponentAt(i); | ||
81 | if (c instanceof MyTabComponent) | ||
82 | { | ||
83 | MyTabComponent component = (MyTabComponent)c; | ||
84 | boolean selected = selectedIndex == i; | ||
85 | component.updateSelection(selected); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | } | ||
90 | |||
91 | public int getPreferredUnselectedTabWidth() | ||
92 | { | ||
93 | return preferredUnselectedTabWidth; | ||
94 | } | ||
95 | |||
96 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabPanelUI.java b/src/cppcheckplus/tab/MyTabPanelUI.java new file mode 100644 index 0000000..b576d16 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPanelUI.java | |||
@@ -0,0 +1,53 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | ||
3 | |||
4 | import java.awt.FontMetrics; | ||
5 | import java.awt.Graphics; | ||
6 | import java.awt.Rectangle; | ||
7 | import javax.swing.plaf.metal.MetalTabbedPaneUI; | ||
8 | |||
9 | import cppcheckplus.control.MyContorlUtil; | ||
10 | |||
11 | public class MyTabPanelUI extends MetalTabbedPaneUI | ||
12 | { | ||
13 | private MyTabPanel tab; | ||
14 | private int firstTabIndent; | ||
15 | |||
16 | public MyTabPanelUI(MyTabPanel tab) | ||
17 | { | ||
18 | this.tab = null; | ||
19 | firstTabIndent = 5; | ||
20 | this.tab = tab; | ||
21 | } | ||
22 | |||
23 | protected Rectangle getTabBounds(int tabIndex, Rectangle dest) | ||
24 | { | ||
25 | Rectangle bounds = super.getTabBounds(tabIndex, dest); | ||
26 | bounds.x += firstTabIndent; | ||
27 | return bounds; | ||
28 | } | ||
29 | |||
30 | protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, | ||
31 | boolean isSelected) | ||
32 | { | ||
33 | g.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
34 | int lineY = tab.getPreferredTabHeight() - 1; | ||
35 | g.drawLine(0, lineY, firstTabIndent, lineY); | ||
36 | } | ||
37 | |||
38 | protected void paintTabBackground(Graphics g1, int i, int j, int k, int l, int i1, int j1, | ||
39 | boolean flag) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) | ||
44 | { | ||
45 | int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); | ||
46 | return width - 5; | ||
47 | } | ||
48 | |||
49 | protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) | ||
50 | { | ||
51 | return tab.getPreferredTabHeight(); | ||
52 | } | ||
53 | } | ||
diff --git a/src/cppcheckplus/tab/MyTabPanelUI1.java b/src/cppcheckplus/tab/MyTabPanelUI1.java new file mode 100644 index 0000000..f98c5f9 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPanelUI1.java | |||
@@ -0,0 +1,53 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | ||
3 | |||
4 | import java.awt.FontMetrics; | ||
5 | import java.awt.Graphics; | ||
6 | import java.awt.Rectangle; | ||
7 | import javax.swing.plaf.metal.MetalTabbedPaneUI; | ||
8 | |||
9 | import cppcheckplus.control.MyContorlUtil; | ||
10 | |||
11 | public class MyTabPanelUI1 extends MetalTabbedPaneUI | ||
12 | { | ||
13 | private MyTabPanel1 tab; | ||
14 | private int firstTabIndent; | ||
15 | |||
16 | public MyTabPanelUI1(MyTabPanel1 tab) | ||
17 | { | ||
18 | this.tab = null; | ||
19 | firstTabIndent = 5; | ||
20 | this.tab = tab; | ||
21 | } | ||
22 | |||
23 | protected Rectangle getTabBounds(int tabIndex, Rectangle dest) | ||
24 | { | ||
25 | Rectangle bounds = super.getTabBounds(tabIndex, dest); | ||
26 | bounds.x += firstTabIndent; | ||
27 | return bounds; | ||
28 | } | ||
29 | |||
30 | protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, | ||
31 | boolean isSelected) | ||
32 | { | ||
33 | g.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
34 | int lineY = tab.getPreferredTabHeight() - 1; | ||
35 | g.drawLine(0, lineY, firstTabIndent, lineY); | ||
36 | } | ||
37 | |||
38 | protected void paintTabBackground(Graphics g1, int i, int j, int k, int l, int i1, int j1, | ||
39 | boolean flag) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) | ||
44 | { | ||
45 | int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); | ||
46 | return width - 5; | ||
47 | } | ||
48 | |||
49 | protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) | ||
50 | { | ||
51 | return tab.getPreferredTabHeight(); | ||
52 | } | ||
53 | } | ||
diff --git a/src/cppcheckplus/text/DeflectRow.java b/src/cppcheckplus/text/DeflectRow.java new file mode 100644 index 0000000..5b113a6 --- /dev/null +++ b/src/cppcheckplus/text/DeflectRow.java | |||
@@ -0,0 +1,126 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | public class DeflectRow { | ||
4 | |||
5 | public DeflectRow(String until, String file, String line, String level, String type, String cwe, | ||
6 | String description,int issure) { | ||
7 | super(); | ||
8 | this.until = until; | ||
9 | this.file = file; | ||
10 | this.line = line; | ||
11 | this.level = level; | ||
12 | this.type = type; | ||
13 | this.cwe = cwe; | ||
14 | this.description = description; | ||
15 | this.issure = issure; | ||
16 | } | ||
17 | @Override | ||
18 | public String toString() { | ||
19 | return "DeflectRow [until=" + until + ", file=" + file + ", line=" + line + ", level=" + level + ", type=" | ||
20 | + type + ", cwe=" + cwe + ", description=" + description + "]"; | ||
21 | } | ||
22 | private String until = null; | ||
23 | public String getUntil() { | ||
24 | return until; | ||
25 | } | ||
26 | public void setUntil(String until) { | ||
27 | this.until = until; | ||
28 | } | ||
29 | public String getFile() { | ||
30 | return file; | ||
31 | } | ||
32 | public void setFile(String file) { | ||
33 | this.file = file; | ||
34 | } | ||
35 | public String getLine() { | ||
36 | return line; | ||
37 | } | ||
38 | public void setLine(String line) { | ||
39 | this.line = line; | ||
40 | } | ||
41 | public String getLevel() { | ||
42 | return level; | ||
43 | } | ||
44 | public void setLevel(String level) { | ||
45 | this.level = level; | ||
46 | } | ||
47 | public String getType() { | ||
48 | return type; | ||
49 | } | ||
50 | public void setType(String type) { | ||
51 | this.type = type; | ||
52 | } | ||
53 | public String getCwe() { | ||
54 | return cwe; | ||
55 | } | ||
56 | public void setCwe(String cwe) { | ||
57 | this.cwe = cwe; | ||
58 | } | ||
59 | public String getDescription() { | ||
60 | return description; | ||
61 | } | ||
62 | public void setDescription(String description) { | ||
63 | this.description = description; | ||
64 | } | ||
65 | public int getIssure() { | ||
66 | return issure; | ||
67 | } | ||
68 | public void setIssure(int issure) { | ||
69 | this.issure = issure; | ||
70 | } | ||
71 | private String file = null; | ||
72 | private String line = null; | ||
73 | private String level = null; | ||
74 | private String type = null; | ||
75 | private String cwe = null; | ||
76 | private String description = null; | ||
77 | private int issure = 0; //0是未确认, 1是确认正确, 2是确认误报 | ||
78 | |||
79 | @Override | ||
80 | public int hashCode() { | ||
81 | final int prime = 31; | ||
82 | int result = 1; | ||
83 | result = prime * result + ((file == null) ? 0 : file.hashCode()); | ||
84 | result = prime * result + ((level == null) ? 0 : level.hashCode()); | ||
85 | result = prime * result + ((line == null) ? 0 : line.hashCode()); | ||
86 | result = prime * result + ((type == null) ? 0 : type.hashCode()); | ||
87 | return result; | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public boolean equals(Object obj) { | ||
92 | if (this == obj) | ||
93 | return true; | ||
94 | if (obj == null) | ||
95 | return false; | ||
96 | if (getClass() != obj.getClass()) | ||
97 | return false; | ||
98 | DeflectRow other = (DeflectRow) obj; | ||
99 | if (file == null) { | ||
100 | if (other.file != null) | ||
101 | return false; | ||
102 | } else if (!file.equals(other.file)) | ||
103 | return false; | ||
104 | if (level == null) { | ||
105 | if (other.level != null) | ||
106 | return false; | ||
107 | } else if (!level.equals(other.level)) | ||
108 | return false; | ||
109 | if (line == null) { | ||
110 | if (other.line != null) | ||
111 | return false; | ||
112 | } else if (!line.equals(other.line)) | ||
113 | return false; | ||
114 | if (type == null) { | ||
115 | if (other.type != null) | ||
116 | return false; | ||
117 | } else if (!type.equals(other.type)) | ||
118 | return false; | ||
119 | if (until == null) { | ||
120 | if (other.until != null) | ||
121 | return false; | ||
122 | } else if (until.equals(other.until)) | ||
123 | return false; | ||
124 | return true; | ||
125 | } | ||
126 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/FileTools.java b/src/cppcheckplus/text/FileTools.java new file mode 100644 index 0000000..95dd4fb --- /dev/null +++ b/src/cppcheckplus/text/FileTools.java | |||
@@ -0,0 +1,84 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.io.BufferedReader; | ||
4 | import java.io.BufferedWriter; | ||
5 | import java.io.File; | ||
6 | import java.io.FileOutputStream; | ||
7 | import java.io.FileReader; | ||
8 | import java.io.FileWriter; | ||
9 | import java.util.Vector; | ||
10 | |||
11 | import org.dom4j.Document; | ||
12 | import org.dom4j.DocumentHelper; | ||
13 | import org.dom4j.Element; | ||
14 | import org.dom4j.io.OutputFormat; | ||
15 | import org.dom4j.io.XMLWriter; | ||
16 | |||
17 | public class FileTools { | ||
18 | |||
19 | public static String readFile(File file) { | ||
20 | StringBuilder resultStr = new StringBuilder(); | ||
21 | try { | ||
22 | BufferedReader bReader = new BufferedReader(new FileReader(file)); | ||
23 | String line = bReader.readLine(); | ||
24 | while (line != null) { | ||
25 | resultStr.append(line + "\r\n"); | ||
26 | line = bReader.readLine(); | ||
27 | } | ||
28 | bReader.close(); | ||
29 | } catch (Exception e) { | ||
30 | e.printStackTrace(); | ||
31 | } | ||
32 | return resultStr.toString(); | ||
33 | } | ||
34 | |||
35 | public static void writeFile(File file, String str) { | ||
36 | try { | ||
37 | BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); | ||
38 | bWriter.write(str); | ||
39 | bWriter.close(); | ||
40 | } catch (Exception e) { | ||
41 | e.printStackTrace(); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | public static void writeFile(File file, Vector<DeflectRow> rows) {// xml | ||
46 | try { | ||
47 | Document doc = DocumentHelper.createDocument(); | ||
48 | Element root = doc.addElement("缺陷报告"); | ||
49 | int n = 0; | ||
50 | if (rows != null && rows.size() > 0) { | ||
51 | for (DeflectRow row : rows) { | ||
52 | if (row.getIssure() == 0 || row.getIssure() == 2) | ||
53 | continue; | ||
54 | n++; | ||
55 | Element empEle = root.addElement("item"); | ||
56 | |||
57 | Element untilEle = empEle.addElement("工具"); | ||
58 | untilEle.addText(row.getUntil()); | ||
59 | Element fileEle = empEle.addElement("文件路径"); | ||
60 | fileEle.addText(row.getFile()); | ||
61 | Element lineEle = empEle.addElement("行号"); | ||
62 | lineEle.addText(row.getLine()); | ||
63 | Element levelEle = empEle.addElement("级别"); | ||
64 | levelEle.addText(row.getLevel()); | ||
65 | Element typeEle = empEle.addElement("类型"); | ||
66 | typeEle.addText(row.getType()); | ||
67 | Element descEle = empEle.addElement("描述"); | ||
68 | descEle.addText(row.getDescription()); | ||
69 | empEle.addAttribute("id", n + ""); | ||
70 | } | ||
71 | XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); | ||
72 | FileOutputStream fos = new FileOutputStream(file); | ||
73 | writer.setOutputStream(fos); | ||
74 | writer.write(doc); | ||
75 | System.out.println("写出完毕!"); | ||
76 | writer.close(); | ||
77 | |||
78 | } | ||
79 | } catch (Exception e) { | ||
80 | e.printStackTrace(); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/LineNumberHeaderView.java b/src/cppcheckplus/text/LineNumberHeaderView.java new file mode 100644 index 0000000..85819fa --- /dev/null +++ b/src/cppcheckplus/text/LineNumberHeaderView.java | |||
@@ -0,0 +1,80 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.Color; | ||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Font; | ||
6 | import java.awt.FontMetrics; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Rectangle; | ||
9 | |||
10 | public class LineNumberHeaderView extends javax.swing.JComponent { | ||
11 | |||
12 | private final Font DEFAULT_FONT = new Font("Serif", 0, 16); | ||
13 | public final Color DEFAULT_BACKGROUD = new Color(228, 228, 228); | ||
14 | public final Color DEFAULT_FOREGROUD = Color.BLACK; | ||
15 | public final int nHEIGHT = Integer.MAX_VALUE - 1000000; | ||
16 | public final int MARGIN = 2; | ||
17 | private int lineHeight; | ||
18 | private int fontLineHeight; | ||
19 | private int currentRowWidth; | ||
20 | private FontMetrics fontMetrics; | ||
21 | |||
22 | public LineNumberHeaderView() { | ||
23 | setFont(DEFAULT_FONT); | ||
24 | setForeground(DEFAULT_FOREGROUD); | ||
25 | setBackground(DEFAULT_BACKGROUD); | ||
26 | setPreferredSize(9999); | ||
27 | } | ||
28 | |||
29 | public void setPreferredSize(int row) { | ||
30 | int width = fontMetrics.stringWidth(String.valueOf(row)); | ||
31 | if (currentRowWidth < width) { | ||
32 | currentRowWidth = width; | ||
33 | setPreferredSize(new Dimension(2 * MARGIN + width, nHEIGHT)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public void setFont(Font font) { | ||
39 | super.setFont(font); | ||
40 | fontMetrics = getFontMetrics(getFont()); | ||
41 | fontLineHeight = fontMetrics.getHeight(); | ||
42 | } | ||
43 | |||
44 | public int getLineHeight() { | ||
45 | if (lineHeight == 0) { | ||
46 | return fontLineHeight; | ||
47 | } | ||
48 | return lineHeight; | ||
49 | } | ||
50 | |||
51 | public void setLineHeight(int lineHeight) { | ||
52 | if (lineHeight > 0) { | ||
53 | this.lineHeight = lineHeight; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | public int getStartOffset() { | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | protected void paintComponent(Graphics g) { | ||
63 | int nlineHeight = getLineHeight(); | ||
64 | int startOffset = getStartOffset(); | ||
65 | Rectangle drawHere = g.getClipBounds(); | ||
66 | g.setColor(getBackground()); | ||
67 | g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); | ||
68 | g.setColor(getForeground()); | ||
69 | int startLineNum = (drawHere.y / nlineHeight) + 1; | ||
70 | int endLineNum = startLineNum + (drawHere.height / nlineHeight); | ||
71 | int start = (drawHere.y / nlineHeight) * nlineHeight + nlineHeight - startOffset; | ||
72 | for (int i = startLineNum; i <= endLineNum; ++i) { | ||
73 | String lineNum = String.valueOf(i); | ||
74 | int width = fontMetrics.stringWidth(lineNum); | ||
75 | g.drawString(lineNum + " ", MARGIN + currentRowWidth - width - 1, start); | ||
76 | start += nlineHeight; | ||
77 | } | ||
78 | setPreferredSize(endLineNum); | ||
79 | } | ||
80 | } | ||
diff --git a/src/cppcheckplus/text/MyButtonEditor.java b/src/cppcheckplus/text/MyButtonEditor.java new file mode 100644 index 0000000..6ce0007 --- /dev/null +++ b/src/cppcheckplus/text/MyButtonEditor.java | |||
@@ -0,0 +1,88 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Component; | ||
5 | import java.awt.event.ActionEvent; | ||
6 | import java.awt.event.ActionListener; | ||
7 | |||
8 | import javax.swing.AbstractCellEditor; | ||
9 | import javax.swing.Icon; | ||
10 | import javax.swing.JButton; | ||
11 | import javax.swing.JOptionPane; | ||
12 | import javax.swing.JPanel; | ||
13 | import javax.swing.JTable; | ||
14 | import javax.swing.table.TableCellEditor; | ||
15 | |||
16 | import cppcheckplus.control.MyContorlUtil; | ||
17 | |||
18 | public class MyButtonEditor extends AbstractCellEditor implements TableCellEditor { | ||
19 | |||
20 | /** | ||
21 | * serialVersionUID | ||
22 | */ | ||
23 | private static final long serialVersionUID = -6546334664166791132L; | ||
24 | |||
25 | private JPanel panel; | ||
26 | |||
27 | private JButton button; | ||
28 | |||
29 | private int state; | ||
30 | public static Icon icon0; | ||
31 | public static Icon icon1; | ||
32 | public static Icon icon2; | ||
33 | public MyButtonEditor() { | ||
34 | |||
35 | initButton(); | ||
36 | |||
37 | initPanel(); | ||
38 | |||
39 | panel.add(this.button, BorderLayout.CENTER); | ||
40 | } | ||
41 | |||
42 | private void initButton() { | ||
43 | button = new JButton(); | ||
44 | |||
45 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | ||
46 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | ||
47 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | ||
48 | button.addActionListener(new ActionListener() { | ||
49 | public void actionPerformed(ActionEvent e) { | ||
50 | int res = JOptionPane.showConfirmDialog(null, "你想确认报告吗?", "choose one", | ||
51 | JOptionPane.YES_NO_OPTION); | ||
52 | |||
53 | if (res == JOptionPane.YES_OPTION) { | ||
54 | state=(state+1)%3; | ||
55 | } | ||
56 | // stopped!!!! | ||
57 | fireEditingStopped(); | ||
58 | |||
59 | } | ||
60 | }); | ||
61 | |||
62 | } | ||
63 | |||
64 | private void initPanel() { | ||
65 | panel = new JPanel(); | ||
66 | |||
67 | panel.setLayout(new BorderLayout()); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { | ||
72 | state = (Integer) value; | ||
73 | |||
74 | if(state==0) | ||
75 | button.setIcon(icon0); | ||
76 | else if(state==1) | ||
77 | button.setIcon(icon1); | ||
78 | else if(state==2) | ||
79 | button.setIcon(icon2); | ||
80 | return panel; | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public Object getCellEditorValue() { | ||
85 | return state; | ||
86 | } | ||
87 | |||
88 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/MyButtonRenderer.java b/src/cppcheckplus/text/MyButtonRenderer.java new file mode 100644 index 0000000..e030620 --- /dev/null +++ b/src/cppcheckplus/text/MyButtonRenderer.java | |||
@@ -0,0 +1,62 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Component; | ||
5 | |||
6 | import javax.swing.Icon; | ||
7 | import javax.swing.JButton; | ||
8 | import javax.swing.JPanel; | ||
9 | import javax.swing.JTable; | ||
10 | import javax.swing.table.TableCellRenderer; | ||
11 | |||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | |||
14 | public class MyButtonRenderer implements TableCellRenderer { | ||
15 | private JPanel panel; | ||
16 | |||
17 | private JButton button; | ||
18 | |||
19 | public static Icon icon0; | ||
20 | public static Icon icon1; | ||
21 | public static Icon icon2; | ||
22 | private int state;//0是未确认, 1是确认正确, 2是确认误报 | ||
23 | |||
24 | public MyButtonRenderer() { | ||
25 | initButton(); | ||
26 | |||
27 | initPanel(); | ||
28 | |||
29 | panel.add(button, BorderLayout.CENTER); | ||
30 | } | ||
31 | |||
32 | private void initButton() { | ||
33 | button = new JButton(); | ||
34 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | ||
35 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | ||
36 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | ||
37 | if(state==0) | ||
38 | button.setIcon(icon0); | ||
39 | else if(state==1) | ||
40 | button.setIcon(icon1); | ||
41 | else if(state==2) | ||
42 | button.setIcon(icon2); | ||
43 | } | ||
44 | |||
45 | private void initPanel() { | ||
46 | panel = new JPanel(); | ||
47 | panel.setLayout(new BorderLayout()); | ||
48 | } | ||
49 | |||
50 | public Component getTableCellRendererComponent(JTable table, Object value, | ||
51 | boolean isSelected, boolean hasFocus, int row, int column) { | ||
52 | state = (Integer) value; | ||
53 | if(state==0) | ||
54 | button.setIcon(icon0); | ||
55 | else if(state==1) | ||
56 | button.setIcon(icon1); | ||
57 | else if(state==2) | ||
58 | button.setIcon(icon2); | ||
59 | return panel; | ||
60 | } | ||
61 | |||
62 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/MyPanel.java b/src/cppcheckplus/text/MyPanel.java new file mode 100644 index 0000000..cec59ac --- /dev/null +++ b/src/cppcheckplus/text/MyPanel.java | |||
@@ -0,0 +1,31 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Graphics; | ||
5 | import java.awt.Image; | ||
6 | |||
7 | import javax.swing.ImageIcon; | ||
8 | import javax.swing.JPanel; | ||
9 | |||
10 | import cppcheckplus.control.MyContorlUtil; | ||
11 | |||
12 | public class MyPanel extends JPanel{ | ||
13 | ImageIcon icon; | ||
14 | Image img; | ||
15 | public MyPanel(){ | ||
16 | // /img/HomeImg.jpg 是存放在你正在编写的项目的bin文件夹下的img文件夹下的一个图片 | ||
17 | icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); | ||
18 | img=icon.getImage(); | ||
19 | } | ||
20 | public MyPanel(BorderLayout borderLayout) { | ||
21 | icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); | ||
22 | img=icon.getImage(); | ||
23 | setLayout(borderLayout); | ||
24 | } | ||
25 | public void paintComponent(Graphics g) { | ||
26 | super.paintComponent(g); | ||
27 | //下面这行是为了背景图片可以跟随窗口自行调整大小,可以自己设置成固定大小 | ||
28 | g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this); | ||
29 | } | ||
30 | } | ||
31 | |||
diff --git a/src/cppcheckplus/text/MyTextArea.java b/src/cppcheckplus/text/MyTextArea.java new file mode 100644 index 0000000..9860093 --- /dev/null +++ b/src/cppcheckplus/text/MyTextArea.java | |||
@@ -0,0 +1,60 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.Dimension; | ||
4 | import java.awt.Graphics; | ||
5 | import java.awt.Graphics2D; | ||
6 | import java.awt.Image; | ||
7 | import java.awt.TexturePaint; | ||
8 | |||
9 | import javax.swing.BorderFactory; | ||
10 | import javax.swing.ImageIcon; | ||
11 | import javax.swing.JTextArea; | ||
12 | import javax.swing.border.Border; | ||
13 | import javax.swing.plaf.metal.MetalTextFieldUI; | ||
14 | |||
15 | import cppcheckplus.control.MyContorlUtil; | ||
16 | |||
17 | public class MyTextArea extends JTextArea{ | ||
18 | private Image backgroundLeftImage; | ||
19 | private Image backgroundRightImage; | ||
20 | private ImageIcon backgroundImageIcon; | ||
21 | private TexturePaint paint; | ||
22 | private Border border; | ||
23 | |||
24 | public MyTextArea () | ||
25 | { | ||
26 | backgroundLeftImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_left.png"); | ||
27 | backgroundRightImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_right.png"); | ||
28 | backgroundImageIcon = MyContorlUtil.getImageIcon("xujun/control/images/textfield_background.png"); | ||
29 | paint = MyContorlUtil.createTexturePaint("xujun/control/images/textfield_background.png"); | ||
30 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); | ||
31 | init(); | ||
32 | } | ||
33 | public MyTextArea (String text) | ||
34 | { | ||
35 | this(); | ||
36 | setText(text); | ||
37 | } | ||
38 | |||
39 | private void init() | ||
40 | { | ||
41 | setBorder(border); | ||
42 | setUI(new MetalTextFieldUI() { | ||
43 | |||
44 | protected void paintBackground(Graphics g) | ||
45 | { | ||
46 | Graphics2D g2d = (Graphics2D)g; | ||
47 | g2d.setPaint(paint); | ||
48 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
49 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | ||
50 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | ||
51 | } | ||
52 | |||
53 | }); | ||
54 | } | ||
55 | |||
56 | public Dimension getPreferredSize() | ||
57 | { | ||
58 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | ||
59 | } | ||
60 | } | ||
diff --git a/src/cppcheckplus/text/MyTextPanel.java b/src/cppcheckplus/text/MyTextPanel.java new file mode 100644 index 0000000..8ef60c4 --- /dev/null +++ b/src/cppcheckplus/text/MyTextPanel.java | |||
@@ -0,0 +1,72 @@ | |||
1 | |||
2 | package cppcheckplus.text; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Font; | ||
6 | |||
7 | import javax.swing.JPanel; | ||
8 | import javax.swing.JScrollPane; | ||
9 | import javax.swing.JTextArea; | ||
10 | |||
11 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
12 | |||
13 | |||
14 | public class MyTextPanel extends JPanel implements XChartletFullScreenListenter | ||
15 | { | ||
16 | private BorderLayout layout; | ||
17 | private boolean isFullScreen; | ||
18 | private JTextArea textArea; | ||
19 | private JScrollPane scroll; | ||
20 | private LineNumberHeaderView lineNumberHeader=null; | ||
21 | public static final int LINEHEIGHT =16; | ||
22 | public JTextArea getTextArea() { | ||
23 | return textArea; | ||
24 | } | ||
25 | |||
26 | |||
27 | public MyTextPanel() | ||
28 | { | ||
29 | layout = new BorderLayout(); | ||
30 | setLayout(layout); | ||
31 | textArea=new JTextArea(""); | ||
32 | Font x = new Font("Serif",0,LINEHEIGHT); | ||
33 | textArea.setFont(x); | ||
34 | scroll = new JScrollPane(textArea); | ||
35 | //scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | ||
36 | //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | ||
37 | //scroll.setPreferredSize(new Dimension(300, 200)); | ||
38 | |||
39 | if (lineNumberHeader == null) { | ||
40 | lineNumberHeader = new LineNumberHeaderView(); | ||
41 | //设置行号的高度,如果和textarea的行高不匹配,可以修改此值 | ||
42 | lineNumberHeader.setLineHeight(LINEHEIGHT+4); | ||
43 | } | ||
44 | scroll.setRowHeaderView(lineNumberHeader); | ||
45 | add(scroll); | ||
46 | } | ||
47 | |||
48 | public void initialize() | ||
49 | { | ||
50 | setLayout(layout); | ||
51 | add(scroll); | ||
52 | } | ||
53 | |||
54 | |||
55 | @Override | ||
56 | public void fullScreen(JPanel chartPanellet) | ||
57 | { | ||
58 | removeAll(); | ||
59 | isFullScreen = !isFullScreen; | ||
60 | if (isFullScreen) | ||
61 | { | ||
62 | setLayout(new BorderLayout()); | ||
63 | add(chartPanellet, "Center"); | ||
64 | } else | ||
65 | { | ||
66 | initialize(); | ||
67 | } | ||
68 | repaint(); | ||
69 | revalidate(); | ||
70 | } | ||
71 | |||
72 | } | ||
diff --git a/src/cppcheckplus/text/MyTextPanel1.java b/src/cppcheckplus/text/MyTextPanel1.java new file mode 100644 index 0000000..4a70ce5 --- /dev/null +++ b/src/cppcheckplus/text/MyTextPanel1.java | |||
@@ -0,0 +1,58 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.TextArea; | ||
5 | |||
6 | import javax.swing.JPanel; | ||
7 | |||
8 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
9 | |||
10 | |||
11 | |||
12 | public class MyTextPanel1 extends JPanel implements XChartletFullScreenListenter | ||
13 | { | ||
14 | private BorderLayout layout; | ||
15 | private boolean isFullScreen; | ||
16 | private TextArea textArea; | ||
17 | |||
18 | public TextArea getTextArea() { | ||
19 | return textArea; | ||
20 | } | ||
21 | public void setTextArea(TextArea textArea) { | ||
22 | this.textArea = textArea; | ||
23 | } | ||
24 | |||
25 | public MyTextPanel1() | ||
26 | { | ||
27 | layout = new BorderLayout(); | ||
28 | setLayout(layout); | ||
29 | textArea=new TextArea(""); | ||
30 | |||
31 | add(textArea); | ||
32 | } | ||
33 | |||
34 | public void initialize() | ||
35 | { | ||
36 | setLayout(layout); | ||
37 | add(textArea); | ||
38 | } | ||
39 | |||
40 | |||
41 | @Override | ||
42 | public void fullScreen(JPanel chartPanellet) | ||
43 | { | ||
44 | removeAll(); | ||
45 | isFullScreen = !isFullScreen; | ||
46 | if (isFullScreen) | ||
47 | { | ||
48 | setLayout(new BorderLayout()); | ||
49 | add(chartPanellet, "Center"); | ||
50 | } else | ||
51 | { | ||
52 | initialize(); | ||
53 | } | ||
54 | repaint(); | ||
55 | revalidate(); | ||
56 | } | ||
57 | |||
58 | } | ||
diff --git a/src/cppcheckplus/text/ViewPanel.java b/src/cppcheckplus/text/ViewPanel.java new file mode 100644 index 0000000..c5b79d9 --- /dev/null +++ b/src/cppcheckplus/text/ViewPanel.java | |||
@@ -0,0 +1,213 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.util.Vector; | ||
5 | |||
6 | import javax.swing.JPanel; | ||
7 | import javax.swing.JScrollPane; | ||
8 | import javax.swing.JTable; | ||
9 | import javax.swing.table.DefaultTableModel; | ||
10 | import javax.swing.table.TableColumn; | ||
11 | |||
12 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
13 | |||
14 | |||
15 | public class ViewPanel extends JPanel implements XChartletFullScreenListenter { | ||
16 | |||
17 | private static final long serialVersionUID = 1L; | ||
18 | private DefaultTableModel model; | ||
19 | private JScrollPane jsp; | ||
20 | private JTable table; | ||
21 | private Vector<DeflectRow> results=new Vector<DeflectRow>(); | ||
22 | private BorderLayout layout; | ||
23 | private boolean isFullScreen; | ||
24 | |||
25 | public JTable getTable() { | ||
26 | return table; | ||
27 | } | ||
28 | |||
29 | public void setTable(JTable table) { | ||
30 | this.table = table; | ||
31 | } | ||
32 | |||
33 | public ViewPanel() { | ||
34 | |||
35 | layout = new BorderLayout(); | ||
36 | setLayout(layout); | ||
37 | |||
38 | String[] colnames = { "序号", "工具", "文件", "行号", "级别", "类型", "描述", "人工确认" }; | ||
39 | // 填充数据 | ||
40 | model = new DefaultTableModel(colnames, 0){ | ||
41 | @Override | ||
42 | public Object getValueAt(int row, int column) { | ||
43 | if(results!=null && row<results.size()){ | ||
44 | switch(column){ | ||
45 | case 1: | ||
46 | return results.elementAt(row).getUntil(); | ||
47 | case 2: | ||
48 | return results.elementAt(row).getFile(); | ||
49 | case 3: | ||
50 | return results.elementAt(row).getLine(); | ||
51 | case 4: | ||
52 | return results.elementAt(row).getLevel(); | ||
53 | case 5: | ||
54 | return results.elementAt(row).getType(); | ||
55 | case 6: | ||
56 | return results.elementAt(row).getDescription(); | ||
57 | case 7: | ||
58 | return results.elementAt(row).getIssure(); | ||
59 | case 0: | ||
60 | return row+1; | ||
61 | } | ||
62 | } | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public boolean isCellEditable(int row, int column) { | ||
68 | if (column == 7 || column == 2 || column == 5) | ||
69 | return true; | ||
70 | return false; | ||
71 | } | ||
72 | /* | ||
73 | @Override | ||
74 | public int getRowCount() { | ||
75 | return results.size(); | ||
76 | }*/ | ||
77 | |||
78 | @Override | ||
79 | public int getColumnCount() { | ||
80 | return 8; | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public void setValueAt(Object aValue, int row, int column){ | ||
85 | if(results!=null && row<results.size()){ | ||
86 | switch(column){ | ||
87 | case 1: | ||
88 | results.elementAt(row).setUntil((String)aValue); | ||
89 | break; | ||
90 | case 2: | ||
91 | results.elementAt(row).setFile((String)aValue); | ||
92 | break; | ||
93 | case 3: | ||
94 | results.elementAt(row).setLine((String)aValue); | ||
95 | break; | ||
96 | case 4: | ||
97 | results.elementAt(row).setLevel((String)aValue); | ||
98 | break; | ||
99 | case 5: | ||
100 | results.elementAt(row).setType((String)aValue); | ||
101 | break; | ||
102 | case 6: | ||
103 | results.elementAt(row).setDescription((String)aValue); | ||
104 | break; | ||
105 | case 7: | ||
106 | results.elementAt(row).setIssure((Integer)aValue); | ||
107 | break; | ||
108 | } | ||
109 | } | ||
110 | fireTableCellUpdated(row, column); | ||
111 | } | ||
112 | |||
113 | }; | ||
114 | |||
115 | table = new JTable(model); | ||
116 | TableColumn c1 = table.getColumnModel().getColumn(0); | ||
117 | c1.setPreferredWidth(30); | ||
118 | c1.setMaxWidth(30); | ||
119 | c1.setMinWidth(30); | ||
120 | TableColumn c2 = table.getColumnModel().getColumn(1); | ||
121 | c2.setPreferredWidth(60); | ||
122 | c2.setMaxWidth(60); | ||
123 | c2.setMinWidth(60); | ||
124 | TableColumn c3 = table.getColumnModel().getColumn(2); | ||
125 | c3.setPreferredWidth(160); | ||
126 | c3.setMaxWidth(160); | ||
127 | c3.setMinWidth(160); | ||
128 | TableColumn c4 = table.getColumnModel().getColumn(3); | ||
129 | c4.setPreferredWidth(40); | ||
130 | c4.setMaxWidth(40); | ||
131 | c4.setMinWidth(40); | ||
132 | TableColumn c5 = table.getColumnModel().getColumn(4); | ||
133 | c5.setPreferredWidth(30); | ||
134 | c5.setMaxWidth(30); | ||
135 | c5.setMinWidth(30); | ||
136 | TableColumn c6 = table.getColumnModel().getColumn(5); | ||
137 | c6.setPreferredWidth(100); | ||
138 | c6.setMaxWidth(100); | ||
139 | c6.setMinWidth(100); | ||
140 | TableColumn c8 = table.getColumnModel().getColumn(7); | ||
141 | c8.setPreferredWidth(100); | ||
142 | c8.setMaxWidth(100); | ||
143 | c8.setMinWidth(100); | ||
144 | |||
145 | table.getColumnModel().getColumn(7).setCellEditor(new MyButtonEditor()); | ||
146 | table.getColumnModel().getColumn(7).setCellRenderer(new MyButtonRenderer()); | ||
147 | table.setRowSelectionAllowed(false); | ||
148 | |||
149 | |||
150 | jsp = new JScrollPane(table); | ||
151 | add(jsp, BorderLayout.CENTER); | ||
152 | } | ||
153 | |||
154 | public ViewPanel(Vector<DeflectRow> rows) { | ||
155 | this(); | ||
156 | results = rows; | ||
157 | fillTable(results); | ||
158 | } | ||
159 | |||
160 | public void clearTable() { | ||
161 | model.setRowCount(0);// 清除原有行 | ||
162 | results.clear(); | ||
163 | table.invalidate(); | ||
164 | } | ||
165 | |||
166 | public void update(Vector<DeflectRow> rows) { | ||
167 | results = rows; | ||
168 | fillTable(results); | ||
169 | } | ||
170 | |||
171 | public void initialize() { | ||
172 | setLayout(layout); | ||
173 | add(jsp); | ||
174 | } | ||
175 | |||
176 | public void fillTable(Vector<DeflectRow> rows) { | ||
177 | |||
178 | model.setRowCount(0);// 清除原有行 | ||
179 | int n = 0; | ||
180 | if (rows != null && rows.size() > 0) { | ||
181 | for (DeflectRow row : rows) { | ||
182 | n++; | ||
183 | Object[] arr = new Object[8]; | ||
184 | arr[0] = String.valueOf(n); | ||
185 | arr[1] = row.getUntil(); | ||
186 | arr[2] = row.getFile(); | ||
187 | arr[3] = row.getLine(); | ||
188 | arr[4] = row.getLevel(); | ||
189 | arr[5] = row.getType(); | ||
190 | arr[6] = row.getDescription(); | ||
191 | arr[7] = row.getIssure(); | ||
192 | // 添加数据到表格 | ||
193 | model.addRow(arr); | ||
194 | } | ||
195 | } | ||
196 | table.invalidate(); | ||
197 | } | ||
198 | |||
199 | @Override | ||
200 | public void fullScreen(JPanel chartPanellet) { | ||
201 | removeAll(); | ||
202 | isFullScreen = !isFullScreen; | ||
203 | if (isFullScreen) { | ||
204 | setLayout(new BorderLayout()); | ||
205 | add(chartPanellet, "Center"); | ||
206 | } else { | ||
207 | initialize(); | ||
208 | } | ||
209 | repaint(); | ||
210 | revalidate(); | ||
211 | } | ||
212 | |||
213 | } | ||
diff --git a/src/cppcheckplus/text/creatTable.java b/src/cppcheckplus/text/creatTable.java new file mode 100644 index 0000000..0295eb6 --- /dev/null +++ b/src/cppcheckplus/text/creatTable.java | |||
@@ -0,0 +1,321 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.util.Vector; | ||
4 | import java.util.regex.Pattern; | ||
5 | |||
6 | import javax.xml.parsers.DocumentBuilder; | ||
7 | import javax.xml.parsers.DocumentBuilderFactory; | ||
8 | |||
9 | import org.w3c.dom.Document; | ||
10 | import org.w3c.dom.Element; | ||
11 | import org.w3c.dom.Node; | ||
12 | import org.w3c.dom.NodeList; | ||
13 | |||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | |||
16 | public class creatTable { | ||
17 | |||
18 | public String tableNameTemp = ""; | ||
19 | public Vector<DeflectRow> cppcheckplusResults = new Vector<DeflectRow>(); | ||
20 | public Vector<DeflectRow> flawfinderResults = new Vector<DeflectRow>(); | ||
21 | public Vector<DeflectRow> clangResults = new Vector<DeflectRow>(); | ||
22 | public Vector<DeflectRow> results = new Vector<DeflectRow>(); | ||
23 | public Vector<stdClangType> stdclang = new Vector<stdClangType>(); | ||
24 | |||
25 | public void initSTDClang(String xml){ | ||
26 | try | ||
27 | { | ||
28 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
29 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
30 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | ||
31 | Element root = doc.getDocumentElement(); | ||
32 | NodeList stdlist = root.getChildNodes(); | ||
33 | if (stdlist != null) | ||
34 | { | ||
35 | for (int i = 0; i < stdlist.getLength(); i++) | ||
36 | { | ||
37 | org.w3c.dom.Node menu = stdlist.item(i); | ||
38 | if (menu.getNodeType() == Node.ELEMENT_NODE) | ||
39 | { | ||
40 | if (menu.getNodeName().equalsIgnoreCase("clangNode")) | ||
41 | { | ||
42 | stdClangType node = new stdClangType(); | ||
43 | node.cwe=MyContorlUtil.getStringAttribute(menu, "cwe"); | ||
44 | node.level=MyContorlUtil.getStringAttribute(menu, "level"); | ||
45 | node.target=MyContorlUtil.getStringAttribute(menu, "target"); | ||
46 | node.len=Integer.valueOf(MyContorlUtil.getStringAttribute(menu, "len")); | ||
47 | node.type=MyContorlUtil.getStringAttribute(menu, "type"); | ||
48 | stdclang.add(node); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | catch (Exception ex) | ||
55 | { | ||
56 | ex.printStackTrace(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | public void makeTable() {// 统一并输出 | ||
61 | results.clear(); | ||
62 | for (int i = 0; i < cppcheckplusResults.size(); i++) { | ||
63 | addObject(results,cppcheckplusResults.elementAt(i)); | ||
64 | } | ||
65 | for (int i = 0; i < clangResults.size(); i++) { | ||
66 | addObject(results,clangResults.elementAt(i)); | ||
67 | } | ||
68 | for (int i = 0; i < flawfinderResults.size(); i++) { | ||
69 | addObject(results,flawfinderResults.elementAt(i)); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | public void clearall() {// 清除 | ||
74 | results.clear(); | ||
75 | clangResults.clear(); | ||
76 | flawfinderResults.clear(); | ||
77 | cppcheckplusResults.clear(); | ||
78 | } | ||
79 | |||
80 | public static void addObject(Vector<DeflectRow> nodes, DeflectRow node) { | ||
81 | if (!nodes.contains(node)) { | ||
82 | nodes.add(node); | ||
83 | } | ||
84 | else{//重复检测的缺陷需要标注 | ||
85 | int nodesNum = nodes.size(); | ||
86 | for(int i=0; i<nodesNum; i++){ | ||
87 | if(nodes.elementAt(i).equals(node)) | ||
88 | nodes.elementAt(i).setIssure(1); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | //按文件、类型和级别排序 | ||
94 | public void ord(int ordType) {//1文件,2类型,3级别 | ||
95 | //final int prime = 31; | ||
96 | //Vector<DeflectRow> other = new Vector<DeflectRow>(); | ||
97 | if(ordType==1){//按照文件排序 | ||
98 | int memNum = results.size(); | ||
99 | for(int i=0; i<memNum-1; i++){ | ||
100 | for(int j=0; j<memNum-i-1; j++){ | ||
101 | if(results.elementAt(j).getFile().hashCode() | ||
102 | > results.elementAt(j+1).getFile().hashCode()){ | ||
103 | DeflectRow temp=results.elementAt(j); | ||
104 | results.set(j, results.elementAt(j+1)); | ||
105 | results.set(j+1, temp); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | else if(ordType==2){//按照类型排序 | ||
111 | int memNum = results.size(); | ||
112 | for(int i=0; i<memNum-1; i++){ | ||
113 | for(int j=0; j<memNum-i-1; j++){ | ||
114 | if(results.elementAt(j).getType().hashCode() | ||
115 | > results.elementAt(j+1).getType().hashCode()){ | ||
116 | DeflectRow temp=results.elementAt(j); | ||
117 | results.set(j, results.elementAt(j+1)); | ||
118 | results.set(j+1, temp); | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | else if(ordType==3){//按照级别筛选 | ||
124 | int memNum = results.size(); | ||
125 | for(int i=0; i<memNum-1; i++){ | ||
126 | for(int j=0; j<memNum-i-1; j++){ | ||
127 | if(results.elementAt(j).getLevel().hashCode() | ||
128 | > results.elementAt(j+1).getLevel().hashCode()){ | ||
129 | DeflectRow temp=results.elementAt(j); | ||
130 | results.set(j, results.elementAt(j+1)); | ||
131 | results.set(j+1, temp); | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | public void toRowsOfCppcheckResult(String input) {// | ||
139 | String[] temp = input.split("\\$"); | ||
140 | int size = temp.length; | ||
141 | String until = null; | ||
142 | String file = null; | ||
143 | String line = null; | ||
144 | String level = null; | ||
145 | String type = null; | ||
146 | String cwe = null; | ||
147 | String description = null; | ||
148 | if (size > 6) { | ||
149 | if (temp[1].length() == 0) | ||
150 | return; | ||
151 | until = temp[0]; | ||
152 | file = temp[1]; | ||
153 | line = temp[2]; | ||
154 | level = temp[3]; | ||
155 | if (temp[3].equals("error")) | ||
156 | level = "4"; | ||
157 | else if (temp[3].equals("warning")) | ||
158 | level = "3"; | ||
159 | else if (temp[2].equals("style")) | ||
160 | level = "1"; | ||
161 | else if (temp[2].equals("information")) | ||
162 | level = "0"; | ||
163 | else | ||
164 | level = "2"; | ||
165 | type = temp[4]; | ||
166 | description = temp[5]; | ||
167 | cwe = temp[6]; | ||
168 | DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); | ||
169 | stdCppcheck(node); | ||
170 | cppcheckplusResults.add(node); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | public void stdCppcheck(DeflectRow node) { | ||
175 | String cwe = node.getCwe(); | ||
176 | int cwenum = Integer.parseInt(cwe); | ||
177 | switch(cwenum){ //cppcheck向flawfinder看齐 | ||
178 | case 134: | ||
179 | node.setLevel("4"); | ||
180 | node.setType("format"); | ||
181 | break; | ||
182 | case 367: | ||
183 | node.setLevel("4"); | ||
184 | node.setType("race"); | ||
185 | break; | ||
186 | case 120: | ||
187 | node.setLevel("4"); | ||
188 | node.setType("buff"); | ||
189 | break; | ||
190 | case 78: | ||
191 | node.setLevel("4"); | ||
192 | node.setType("shell"); | ||
193 | break; | ||
194 | case 327: | ||
195 | node.setLevel("3"); | ||
196 | node.setType("random"); | ||
197 | break; | ||
198 | case 119: | ||
199 | node.setLevel("4"); | ||
200 | node.setType("buffer"); | ||
201 | break; | ||
202 | case 362: | ||
203 | node.setLevel("2"); | ||
204 | node.setType("misc"); | ||
205 | break; | ||
206 | case 190: | ||
207 | node.setLevel("2"); | ||
208 | node.setType("integer"); | ||
209 | break; | ||
210 | default: | ||
211 | ; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | public void toRowsOfClang(String input) { | ||
216 | String[] temp = input.split(":"); | ||
217 | int size = temp.length; | ||
218 | String until = null; | ||
219 | String file = null; | ||
220 | String line = null; | ||
221 | String column = null; | ||
222 | String level = null; | ||
223 | String type = null; | ||
224 | String cwe = null; | ||
225 | String description = null; | ||
226 | if (size > 5) { | ||
227 | until = "clang-tidy"; | ||
228 | file = temp[0] + ":" + temp[1]; | ||
229 | line = temp[2]; | ||
230 | column = temp[3]; | ||
231 | level = temp[4];// warning,note, error | ||
232 | type = ""; | ||
233 | description = temp[5]; | ||
234 | cwe = "0"; | ||
235 | // 标准化 | ||
236 | DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); | ||
237 | stdClang(node); | ||
238 | clangResults.add(node); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | public void stdClang(DeflectRow node) { | ||
243 | String describ = node.getDescription(); | ||
244 | int len = describ.length(); | ||
245 | boolean isFound = false; | ||
246 | for (int i = 0; i < stdclang.size(); i++) { | ||
247 | if(len>stdclang.elementAt(i).len){ | ||
248 | if (describ.substring(1, stdclang.elementAt(i).len).equals(stdclang.elementAt(i).target)) { | ||
249 | node.setCwe(stdclang.elementAt(i).cwe); | ||
250 | node.setLevel(stdclang.elementAt(i).level); | ||
251 | node.setType(stdclang.elementAt(i).type); | ||
252 | isFound=true; | ||
253 | return; | ||
254 | } | ||
255 | } | ||
256 | } | ||
257 | if(!isFound){ | ||
258 | node.setCwe("未知"); | ||
259 | node.setLevel("2"); | ||
260 | node.setType("other"); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | |||
265 | public void toRowsOfFlawfinder(String csvFileName) {// csv | ||
266 | |||
267 | String until = null; | ||
268 | // public String defObject = null; | ||
269 | String file = null; | ||
270 | String location = null; | ||
271 | String level = null; | ||
272 | String type = null; | ||
273 | String function = null; | ||
274 | String description = null; | ||
275 | DeflectRow node = new DeflectRow(until, file, location, level, type, function, description, 0); | ||
276 | } | ||
277 | |||
278 | public boolean isInteger(String str){ | ||
279 | Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); | ||
280 | return pattern.matcher(str).matches(); | ||
281 | } | ||
282 | |||
283 | public void toRowsOfflawfinder(String input) { | ||
284 | // File,Line,Column,Level,Category,Name,Warning,Suggestion,Note,CWEs,Context,Fingerprint | ||
285 | String[] temp = input.split(","); | ||
286 | int size = temp.length; | ||
287 | String until = null; | ||
288 | String file = null; | ||
289 | String line = null; | ||
290 | String column = null; | ||
291 | String level = null; | ||
292 | String category = null; | ||
293 | String name = null; | ||
294 | String warning = null; | ||
295 | String suggestion = null; | ||
296 | String note = null; | ||
297 | String cwe = null; | ||
298 | String context = null; | ||
299 | String fingerprint = null; | ||
300 | if (size > 11) { | ||
301 | if(!isInteger(temp[1])) | ||
302 | return; | ||
303 | until = "flawfinder"; | ||
304 | file = temp[0]; | ||
305 | line = temp[1]; | ||
306 | column = temp[2]; | ||
307 | level = temp[3]; | ||
308 | category = temp[4]; | ||
309 | name = temp[5]; | ||
310 | warning = temp[6]; | ||
311 | suggestion = temp[7]; | ||
312 | note = temp[8]; | ||
313 | cwe = temp[9]; | ||
314 | context = temp[10]; | ||
315 | fingerprint = temp[11]; | ||
316 | DeflectRow node = new DeflectRow(until, file, line, level, category, cwe, warning, 0); | ||
317 | flawfinderResults.add(node); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | } | ||
diff --git a/src/cppcheckplus/text/stdClangType.java b/src/cppcheckplus/text/stdClangType.java new file mode 100644 index 0000000..42e9c37 --- /dev/null +++ b/src/cppcheckplus/text/stdClangType.java | |||
@@ -0,0 +1,9 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | public class stdClangType { | ||
4 | public int len; | ||
5 | public String cwe; | ||
6 | public String type; | ||
7 | public String level; | ||
8 | public String target; | ||
9 | } | ||
diff --git a/src/cppcheckplus/toolbar/MyToolBar.java b/src/cppcheckplus/toolbar/MyToolBar.java new file mode 100644 index 0000000..e0473a6 --- /dev/null +++ b/src/cppcheckplus/toolbar/MyToolBar.java | |||
@@ -0,0 +1,60 @@ | |||
1 | |||
2 | package cppcheckplus.toolbar; | ||
3 | |||
4 | import java.awt.Dimension; | ||
5 | import java.awt.FlowLayout; | ||
6 | import java.awt.Graphics; | ||
7 | import java.awt.Graphics2D; | ||
8 | import java.awt.TexturePaint; | ||
9 | import javax.swing.BorderFactory; | ||
10 | import javax.swing.Icon; | ||
11 | import javax.swing.JPanel; | ||
12 | |||
13 | import cppcheckplus.control.MyContorlUtil; | ||
14 | |||
15 | |||
16 | public class MyToolBar extends JPanel | ||
17 | { | ||
18 | private String backgroundImageURL; | ||
19 | private int preferredHeight; | ||
20 | private TexturePaint paint; | ||
21 | private int buttonGap; | ||
22 | |||
23 | public MyToolBar() | ||
24 | { | ||
25 | preferredHeight = MyContorlUtil.getImageIcon("control/images/toolbar_background.png").getIconHeight(); | ||
26 | paint = MyContorlUtil.createTexturePaint("control/images/toolbar_background.png"); | ||
27 | buttonGap = 2; | ||
28 | init(); | ||
29 | } | ||
30 | |||
31 | private void init() | ||
32 | { | ||
33 | setLayout(new FlowLayout(3, buttonGap, 0)); | ||
34 | setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 5)); | ||
35 | } | ||
36 | public void addButton(Icon icon, String tooltip,String actionCommand,boolean rover) | ||
37 | { | ||
38 | MyToolBarButton barButton; | ||
39 | if (rover) | ||
40 | barButton = new MyToolBarRoverButton(); | ||
41 | else | ||
42 | barButton = new MyToolBarButton(); | ||
43 | barButton.setIcon(icon); | ||
44 | barButton.setToolTipText(tooltip); | ||
45 | barButton.setActionCommand(actionCommand); | ||
46 | add(barButton); | ||
47 | } | ||
48 | protected void paintComponent(Graphics g) | ||
49 | { | ||
50 | super.paintComponent(g); | ||
51 | Graphics2D g2d = (Graphics2D)g; | ||
52 | g2d.setPaint(paint); | ||
53 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
54 | } | ||
55 | |||
56 | public Dimension getPreferredSize() | ||
57 | { | ||
58 | return new Dimension(super.getPreferredSize().width, preferredHeight); | ||
59 | } | ||
60 | } | ||
diff --git a/src/cppcheckplus/toolbar/MyToolBarButton.java b/src/cppcheckplus/toolbar/MyToolBarButton.java new file mode 100644 index 0000000..d6fa386 --- /dev/null +++ b/src/cppcheckplus/toolbar/MyToolBarButton.java | |||
@@ -0,0 +1,97 @@ | |||
1 | |||
2 | package cppcheckplus.toolbar; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Component; | ||
6 | import java.awt.Dimension; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Insets; | ||
9 | import java.awt.event.MouseAdapter; | ||
10 | import java.awt.event.MouseEvent; | ||
11 | import javax.swing.BorderFactory; | ||
12 | import javax.swing.Icon; | ||
13 | import javax.swing.JButton; | ||
14 | import javax.swing.border.Border; | ||
15 | |||
16 | import cppcheckplus.control.MyContorlUtil; | ||
17 | |||
18 | public class MyToolBarButton extends JButton | ||
19 | { | ||
20 | private int buttonSize; | ||
21 | private Color roverBorderColor; | ||
22 | private Border roverBorder; | ||
23 | private Border emptyBorder; | ||
24 | |||
25 | public MyToolBarButton() | ||
26 | { | ||
27 | super(); | ||
28 | buttonSize = 20; | ||
29 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; | ||
30 | roverBorder = new Border() { | ||
31 | |||
32 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | ||
33 | { | ||
34 | g.setColor(roverBorderColor); | ||
35 | g.drawRect(x, y, width - 1, height - 1); | ||
36 | } | ||
37 | |||
38 | public Insets getBorderInsets(Component c) | ||
39 | { | ||
40 | return new Insets(1, 1, 1, 1); | ||
41 | } | ||
42 | |||
43 | public boolean isBorderOpaque() | ||
44 | { | ||
45 | return true; | ||
46 | } | ||
47 | }; | ||
48 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); | ||
49 | init(); | ||
50 | } | ||
51 | |||
52 | private void init() | ||
53 | { | ||
54 | setVerticalAlignment(0); | ||
55 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
56 | setOpaque(false); | ||
57 | setBorder(emptyBorder); | ||
58 | setContentAreaFilled(false); | ||
59 | setFocusPainted(false); | ||
60 | addMouseListener(new MouseAdapter() { | ||
61 | public void mouseEntered(MouseEvent e) | ||
62 | { | ||
63 | setBorder(roverBorder); | ||
64 | } | ||
65 | |||
66 | public void mouseExited(MouseEvent e) | ||
67 | { | ||
68 | setBorder(emptyBorder); | ||
69 | } | ||
70 | }); | ||
71 | } | ||
72 | |||
73 | @Override | ||
74 | public void setIcon(Icon icon) | ||
75 | { | ||
76 | super.setIcon(icon); | ||
77 | if (icon == null) | ||
78 | { | ||
79 | setPressedIcon(null); | ||
80 | setRolloverIcon(null); | ||
81 | } else | ||
82 | { | ||
83 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); | ||
84 | setPressedIcon(pressedIcon); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | |||
89 | @Override | ||
90 | public Dimension getPreferredSize() | ||
91 | { | ||
92 | int width = super.getPreferredSize().width; | ||
93 | width = Math.max(width, buttonSize); | ||
94 | int height = buttonSize; | ||
95 | return new Dimension(width, height); | ||
96 | } | ||
97 | } | ||
diff --git a/src/cppcheckplus/toolbar/MyToolBarRoverButton.java b/src/cppcheckplus/toolbar/MyToolBarRoverButton.java new file mode 100644 index 0000000..9ab1dc8 --- /dev/null +++ b/src/cppcheckplus/toolbar/MyToolBarRoverButton.java | |||
@@ -0,0 +1,36 @@ | |||
1 | |||
2 | package cppcheckplus.toolbar; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import javax.swing.Icon; | ||
6 | import javax.swing.ImageIcon; | ||
7 | |||
8 | import cppcheckplus.control.MyContorlUtil; | ||
9 | |||
10 | |||
11 | public class MyToolBarRoverButton extends MyToolBarButton | ||
12 | { | ||
13 | private Color roverDyeColor; | ||
14 | |||
15 | public MyToolBarRoverButton() | ||
16 | { | ||
17 | roverDyeColor = new Color(86, 146, 61); | ||
18 | } | ||
19 | |||
20 | public void setIcon(Icon icon) | ||
21 | { | ||
22 | super.setIcon(icon); | ||
23 | if (icon == null) | ||
24 | { | ||
25 | setPressedIcon(null); | ||
26 | setRolloverIcon(null); | ||
27 | } else | ||
28 | { | ||
29 | java.awt.Image image = MyContorlUtil.iconToImage(icon); | ||
30 | Icon roverIcon = MyContorlUtil.createDyedIcon(new ImageIcon(image), roverDyeColor); | ||
31 | Icon pressedIcon = MyContorlUtil.createMovedIcon(roverIcon); | ||
32 | setRolloverIcon(roverIcon); | ||
33 | setPressedIcon(pressedIcon); | ||
34 | } | ||
35 | } | ||
36 | } | ||