diff options
59 files changed, 3619 insertions, 3857 deletions
diff --git a/lib/example/GridBagVersusTable.java b/lib/example/GridBagVersusTable.java index 53e45d6..0ed367a 100644 --- a/lib/example/GridBagVersusTable.java +++ b/lib/example/GridBagVersusTable.java | |||
@@ -1,140 +1,133 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Font; | |
5 | import java.awt.*; | 5 | import java.awt.Frame; |
6 | import java.awt.event.*; | 6 | import java.awt.GridBagConstraints; |
7 | import java.awt.GridBagLayout; | ||
8 | import java.awt.event.WindowAdapter; | ||
9 | import java.awt.event.WindowEvent; | ||
10 | import java.awt.event.WindowListener; | ||
7 | import javax.swing.JButton; | 11 | import javax.swing.JButton; |
8 | import layout.TableLayout; | 12 | import layout.TableLayout; |
9 | import layout.TableLayoutConstraints; | ||
10 | 13 | ||
11 | 14 | ||
15 | public class GridBagVersusTable { | ||
12 | 16 | ||
13 | public class GridBagVersusTable | ||
14 | { | ||
15 | 17 | ||
16 | |||
17 | |||
18 | protected static void makeButton | 18 | protected static void makeButton |
19 | (Frame frame, String name, GridBagLayout gridbag, GridBagConstraints c) | 19 | (Frame frame, String name, GridBagLayout gridbag, |
20 | { | 20 | GridBagConstraints c) { |
21 | JButton button = new JButton(name); | 21 | JButton button = new JButton(name); |
22 | gridbag.setConstraints(button, c); | 22 | gridbag.setConstraints(button, c); |
23 | frame.add(button); | 23 | frame.add(button); |
24 | } | 24 | } |
25 | 25 | ||
26 | 26 | ||
27 | 27 | protected static Frame showGridBagWindow() { | |
28 | protected static Frame showGridBagWindow () | ||
29 | { | ||
30 | // Create layout and contraints object | 28 | // Create layout and contraints object |
31 | GridBagLayout gridbag = new GridBagLayout(); | 29 | GridBagLayout gridbag = new GridBagLayout(); |
32 | GridBagConstraints c = new GridBagConstraints(); | 30 | GridBagConstraints c = new GridBagConstraints(); |
33 | 31 | ||
34 | // Create frame | 32 | // Create frame |
35 | Frame frame = new Frame("GridBagLayout"); | 33 | Frame frame = new Frame("GridBagLayout"); |
36 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | 34 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); |
37 | frame.setLayout (gridbag); | 35 | frame.setLayout(gridbag); |
38 | 36 | ||
39 | // Create buttons, add buttons, and apply constraints | 37 | // Create buttons, add buttons, and apply constraints |
40 | c.fill = GridBagConstraints.BOTH; | 38 | c.fill = GridBagConstraints.BOTH; |
41 | c.weightx = 1.0; | 39 | c.weightx = 1.0; |
42 | makeButton (frame, "Button1", gridbag, c); | 40 | makeButton(frame, "Button1", gridbag, c); |
43 | makeButton (frame, "Button2", gridbag, c); | 41 | makeButton(frame, "Button2", gridbag, c); |
44 | makeButton (frame, "Button3", gridbag, c); | 42 | makeButton(frame, "Button3", gridbag, c); |
45 | 43 | ||
46 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row | 44 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row |
47 | makeButton (frame, "Button4", gridbag, c); | 45 | makeButton(frame, "Button4", gridbag, c); |
48 | 46 | ||
49 | c.weightx = 0.0; //reset to the default | 47 | c.weightx = 0.0; //reset to the default |
50 | makeButton (frame, "Button5", gridbag, c); //another row | 48 | makeButton(frame, "Button5", gridbag, c); //another row |
51 | 49 | ||
52 | c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row | 50 | c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row |
53 | makeButton (frame, "Button6", gridbag, c); | 51 | makeButton(frame, "Button6", gridbag, c); |
54 | 52 | ||
55 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row | 53 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row |
56 | makeButton (frame, "Button7", gridbag, c); | 54 | makeButton(frame, "Button7", gridbag, c); |
57 | 55 | ||
58 | c.gridwidth = 1; //reset to the default | 56 | c.gridwidth = 1; //reset to the default |
59 | c.gridheight = 2; | 57 | c.gridheight = 2; |
60 | c.weighty = 1.0; | 58 | c.weighty = 1.0; |
61 | makeButton (frame, "Button8", gridbag, c); | 59 | makeButton(frame, "Button8", gridbag, c); |
62 | 60 | ||
63 | c.weighty = 0.0; //reset to the default | 61 | c.weighty = 0.0; //reset to the default |
64 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row | 62 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row |
65 | c.gridheight = 1; //reset to the default | 63 | c.gridheight = 1; //reset to the default |
66 | makeButton (frame, "Button9", gridbag, c); | 64 | makeButton(frame, "Button9", gridbag, c); |
67 | makeButton (frame, "Button10", gridbag, c); | 65 | makeButton(frame, "Button10", gridbag, c); |
68 | 66 | ||
69 | // Show frame | 67 | // Show frame |
70 | frame.pack(); | 68 | frame.pack(); |
71 | frame.setLocation (0, 10); | 69 | frame.setLocation(0, 10); |
72 | frame.show(); | 70 | frame.show(); |
73 | 71 | ||
74 | return frame; | 72 | return frame; |
75 | } | 73 | } |
76 | 74 | ||
77 | 75 | ||
78 | 76 | protected static Frame showTableWindow() { | |
79 | protected static Frame showTableWindow () | ||
80 | { | ||
81 | // Create frame | 77 | // Create frame |
82 | Frame frame = new Frame("TableLayout"); | 78 | Frame frame = new Frame("TableLayout"); |
83 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); | 79 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); |
84 | 80 | ||
85 | // Set layout | 81 | // Set layout |
86 | double f = TableLayout.FILL; | 82 | double f = TableLayout.FILL; |
87 | double p = TableLayout.PREFERRED; | 83 | double p = TableLayout.PREFERRED; |
88 | double size[][] = {{f, f, f, f}, {p, p, p, p, f}}; | 84 | double size[][] = {{f, f, f, f}, {p, p, p, p, f}}; |
89 | 85 | ||
90 | TableLayout layout = new TableLayout(size); | 86 | TableLayout layout = new TableLayout(size); |
91 | frame.setLayout (layout); | 87 | frame.setLayout(layout); |
92 | 88 | ||
93 | // Create buttons labeled Button1 to Button10 | 89 | // Create buttons labeled Button1 to Button10 |
94 | int numButton = 10; | 90 | int numButton = 10; |
95 | JButton button[] = new JButton[numButton + 1]; | 91 | JButton button[] = new JButton[numButton + 1]; |
96 | 92 | ||
97 | for (int i = 1; i <= numButton; i++) | 93 | for (int i = 1; i <= numButton; i++) { |
98 | button[i] = new JButton("Button" + i); | 94 | button[i] = new JButton("Button" + i); |
99 | 95 | } | |
96 | |||
100 | // Add buttons | 97 | // Add buttons |
101 | frame.add (button[1], "0, 0"); | 98 | frame.add(button[1], "0, 0"); |
102 | frame.add (button[2], "1, 0"); | 99 | frame.add(button[2], "1, 0"); |
103 | frame.add (button[3], "2, 0"); | 100 | frame.add(button[3], "2, 0"); |
104 | frame.add (button[4], "3, 0"); | 101 | frame.add(button[4], "3, 0"); |
105 | frame.add (button[5], "0, 1, 3, 1"); | 102 | frame.add(button[5], "0, 1, 3, 1"); |
106 | frame.add (button[6], "0, 2, 2, 2"); | 103 | frame.add(button[6], "0, 2, 2, 2"); |
107 | frame.add (button[7], "3, 2, 3, 2"); | 104 | frame.add(button[7], "3, 2, 3, 2"); |
108 | frame.add (button[8], "0, 3, 0, 4"); | 105 | frame.add(button[8], "0, 3, 0, 4"); |
109 | frame.add (button[9], "1, 3, 3, 3"); | 106 | frame.add(button[9], "1, 3, 3, 3"); |
110 | frame.add (button[10], "1, 4, 3, 4"); | 107 | frame.add(button[10], "1, 4, 3, 4"); |
111 | 108 | ||
112 | // Show frame | 109 | // Show frame |
113 | frame.pack(); | 110 | frame.pack(); |
114 | frame.setLocation (400, 10); | 111 | frame.setLocation(400, 10); |
115 | frame.show(); | 112 | frame.show(); |
116 | 113 | ||
117 | return frame; | 114 | return frame; |
118 | } | 115 | } |
119 | 116 | ||
120 | |||
121 | 117 | ||
122 | public static void main (String args[]) | 118 | public static void main(String args[]) { |
123 | { | ||
124 | WindowListener listener = | 119 | WindowListener listener = |
125 | (new WindowAdapter() | 120 | (new WindowAdapter() { |
126 | { | 121 | public void windowClosing(WindowEvent e) { |
127 | public void windowClosing (WindowEvent e) | 122 | System.exit(0); |
128 | { | ||
129 | System.exit (0); | ||
130 | } | ||
131 | } | 123 | } |
124 | } | ||
132 | ); | 125 | ); |
133 | 126 | ||
134 | Frame frame = showGridBagWindow(); | 127 | Frame frame = showGridBagWindow(); |
135 | frame.addWindowListener (listener); | 128 | frame.addWindowListener(listener); |
136 | 129 | ||
137 | frame = showTableWindow(); | 130 | frame = showTableWindow(); |
138 | frame.addWindowListener (listener); | 131 | frame.addWindowListener(listener); |
139 | } | 132 | } |
140 | } | 133 | } |
diff --git a/lib/example/GridVersusTable.java b/lib/example/GridVersusTable.java index c5746c4..890d2e9 100644 --- a/lib/example/GridVersusTable.java +++ b/lib/example/GridVersusTable.java | |||
@@ -1,108 +1,100 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Font; | |
5 | import java.awt.*; | 5 | import java.awt.Frame; |
6 | import java.awt.event.*; | 6 | import java.awt.GridLayout; |
7 | import java.awt.event.WindowAdapter; | ||
8 | import java.awt.event.WindowEvent; | ||
9 | import java.awt.event.WindowListener; | ||
7 | import javax.swing.JButton; | 10 | import javax.swing.JButton; |
8 | import layout.TableLayout; | 11 | import layout.TableLayout; |
9 | 12 | ||
10 | 13 | ||
11 | |||
12 | public class GridVersusTable { | 14 | public class GridVersusTable { |
13 | 15 | ||
14 | 16 | ||
15 | 17 | protected static Frame showGridWindow() { | |
16 | protected static Frame showGridWindow () | ||
17 | { | ||
18 | // Create frame | 18 | // Create frame |
19 | Frame frame = new Frame("GridLayout"); | 19 | Frame frame = new Frame("GridLayout"); |
20 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | 20 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); |
21 | frame.setLayout (new GridLayout(2, 0)); | 21 | frame.setLayout(new GridLayout(2, 0)); |
22 | 22 | ||
23 | // Create and add buttons | 23 | // Create and add buttons |
24 | frame.add (new JButton("One")); | 24 | frame.add(new JButton("One")); |
25 | frame.add (new JButton("Two")); | 25 | frame.add(new JButton("Two")); |
26 | frame.add (new JButton("Three")); | 26 | frame.add(new JButton("Three")); |
27 | frame.add (new JButton("Four")); | 27 | frame.add(new JButton("Four")); |
28 | 28 | ||
29 | // Show frame | 29 | // Show frame |
30 | frame.pack(); | 30 | frame.pack(); |
31 | frame.setLocation (0, 10); | 31 | frame.setLocation(0, 10); |
32 | frame.show(); | 32 | frame.show(); |
33 | 33 | ||
34 | return frame; | 34 | return frame; |
35 | } | 35 | } |
36 | 36 | ||
37 | 37 | ||
38 | 38 | protected static Frame showTableWindow() { | |
39 | protected static Frame showTableWindow () | ||
40 | { | ||
41 | // Create frame | 39 | // Create frame |
42 | Frame frame = new Frame("TableLayout"); | 40 | Frame frame = new Frame("TableLayout"); |
43 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | 41 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); |
44 | 42 | ||
45 | // Set layout | 43 | // Set layout |
46 | double f = TableLayout.FILL; | 44 | double f = TableLayout.FILL; |
47 | double size[][] = {{f, f}, {f, f}}; | 45 | double size[][] = {{f, f}, {f, f}}; |
48 | frame.setLayout (new TableLayout(size)); | 46 | frame.setLayout(new TableLayout(size)); |
49 | 47 | ||
50 | // Create and add buttons | 48 | // Create and add buttons |
51 | frame.add (new JButton("One"), "0, 0"); | 49 | frame.add(new JButton("One"), "0, 0"); |
52 | frame.add (new JButton("Two"), "1, 0"); | 50 | frame.add(new JButton("Two"), "1, 0"); |
53 | frame.add (new JButton("Three"), "0, 1"); | 51 | frame.add(new JButton("Three"), "0, 1"); |
54 | frame.add (new JButton("Four"), "1, 1"); | 52 | frame.add(new JButton("Four"), "1, 1"); |
55 | 53 | ||
56 | // Show frame | 54 | // Show frame |
57 | frame.pack(); | 55 | frame.pack(); |
58 | frame.setLocation (200, 10); | 56 | frame.setLocation(200, 10); |
59 | frame.show(); | 57 | frame.show(); |
60 | 58 | ||
61 | return frame; | 59 | return frame; |
62 | } | 60 | } |
63 | 61 | ||
64 | 62 | ||
65 | 63 | protected static Frame showTableWindow2() { | |
66 | protected static Frame showTableWindow2 () | ||
67 | { | ||
68 | // Create frame | 64 | // Create frame |
69 | Frame frame = new Frame("TableLayout"); | 65 | Frame frame = new Frame("TableLayout"); |
70 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); | 66 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); |
71 | 67 | ||
72 | // Set layout | 68 | // Set layout |
73 | double f = TableLayout.FILL; | 69 | double f = TableLayout.FILL; |
74 | double size[][] = {{f, f}, {f, f}}; | 70 | double size[][] = {{f, f}, {f, f}}; |
75 | frame.setLayout (new TableLayout(size)); | 71 | frame.setLayout(new TableLayout(size)); |
76 | 72 | ||
77 | // Create and add buttons | 73 | // Create and add buttons |
78 | frame.add (new JButton("One"), "0, 0"); | 74 | frame.add(new JButton("One"), "0, 0"); |
79 | frame.add (new JButton("Two"), "1, 1"); | 75 | frame.add(new JButton("Two"), "1, 1"); |
80 | 76 | ||
81 | // Show frame | 77 | // Show frame |
82 | frame.pack(); | 78 | frame.pack(); |
83 | frame.setLocation (400, 10); | 79 | frame.setLocation(400, 10); |
84 | frame.show(); | 80 | frame.show(); |
85 | 81 | ||
86 | return frame; | 82 | return frame; |
87 | } | 83 | } |
88 | 84 | ||
89 | 85 | ||
90 | 86 | public static void main(String args[]) { | |
91 | public static void main (String args[]) | ||
92 | { | ||
93 | WindowListener listener = | 87 | WindowListener listener = |
94 | (new WindowAdapter() | 88 | (new WindowAdapter() { |
95 | { | 89 | public void windowClosing(WindowEvent e) { |
96 | public void windowClosing (WindowEvent e) | 90 | System.exit(0); |
97 | { | ||
98 | System.exit (0); | ||
99 | } | ||
100 | } | 91 | } |
92 | } | ||
101 | ); | 93 | ); |
102 | 94 | ||
103 | Frame frame = showGridWindow(); | 95 | Frame frame = showGridWindow(); |
104 | frame.addWindowListener(listener); | 96 | frame.addWindowListener(listener); |
105 | 97 | ||
106 | frame = showTableWindow(); | 98 | frame = showTableWindow(); |
107 | frame.addWindowListener(listener); | 99 | frame.addWindowListener(listener); |
108 | 100 | ||
diff --git a/lib/example/MyClass.java b/lib/example/MyClass.java index 632e99a..ef47ace 100644 --- a/lib/example/MyClass.java +++ b/lib/example/MyClass.java | |||
@@ -1,47 +1,44 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Button; | |
5 | import java.awt.*; | 5 | import java.awt.Frame; |
6 | import java.awt.event.*; | 6 | import java.awt.event.WindowAdapter; |
7 | import java.awt.event.WindowEvent; | ||
7 | import layout.TableLayout; | 8 | import layout.TableLayout; |
8 | 9 | ||
9 | public class MyClass | 10 | public class MyClass { |
10 | { | ||
11 | 11 | ||
12 | public static void main (String args[]) | 12 | public static void main(String args[]) { |
13 | { | ||
14 | Frame frame = new Frame("MyTitle"); | 13 | Frame frame = new Frame("MyTitle"); |
15 | frame.setBounds (100, 100, 300, 300); | 14 | frame.setBounds(100, 100, 300, 300); |
16 | 15 | ||
17 | double size[][] = | 16 | double size[][] = |
18 | {{-2.0, 10.0, 50.0, -1.0, 10.0}, // Columns | 17 | {{-2.0, 10.0, 50.0, -1.0, 10.0}, // Columns |
19 | {-2.0, 10.0, 0.25, -1.0, 10.0}}; // Rows | 18 | {-2.0, 10.0, 0.25, -1.0, 10.0}}; // Rows |
20 | 19 | ||
21 | frame.setLayout (new TableLayout(size)); | 20 | frame.setLayout(new TableLayout(size)); |
22 | 21 | ||
23 | Button button; | 22 | Button button; |
24 | button = new Button("3, 3, R, C"); | 23 | button = new Button("3, 3, R, C"); |
25 | frame.add (button, "3, 3, R, C"); | 24 | frame.add(button, "3, 3, R, C"); |
26 | button = new Button("3, 3, L, T"); | 25 | button = new Button("3, 3, L, T"); |
27 | frame.add (button, "3, 3, L, T"); | 26 | frame.add(button, "3, 3, L, T"); |
28 | button = new Button("2, 3, C, T"); | 27 | button = new Button("2, 3, C, T"); |
29 | frame.add (button, "2, 3, C, T"); | 28 | frame.add(button, "2, 3, C, T"); |
30 | button = new Button("3, 2, L, C"); | 29 | button = new Button("3, 2, L, C"); |
31 | frame.add (button, "3, 2, L, C"); | 30 | frame.add(button, "3, 2, L, C"); |
32 | button = new Button("2, 2, F, F"); | 31 | button = new Button("2, 2, F, F"); |
33 | frame.add (button, "2, 2, F, F"); | 32 | frame.add(button, "2, 2, F, F"); |
34 | button = new Button("3, 3, C, C"); | 33 | button = new Button("3, 3, C, C"); |
35 | frame.add (button, "3, 3, C, C"); | 34 | frame.add(button, "3, 3, C, C"); |
36 | 35 | ||
37 | frame.addWindowListener | 36 | frame.addWindowListener |
38 | (new WindowAdapter() | 37 | (new WindowAdapter() { |
39 | { | 38 | public void windowClosing(WindowEvent e) { |
40 | public void windowClosing (WindowEvent e) | 39 | System.exit(0); |
41 | { | 40 | } |
42 | System.exit (0); | 41 | } |
43 | } | ||
44 | } | ||
45 | ); | 42 | ); |
46 | 43 | ||
47 | frame.show(); | 44 | frame.show(); |
diff --git a/lib/example/Preferred.java b/lib/example/Preferred.java index aa1e8a6..f5fc54e 100644 --- a/lib/example/Preferred.java +++ b/lib/example/Preferred.java | |||
@@ -1,106 +1,97 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Container; | |
5 | import java.awt.*; | 5 | import java.awt.event.WindowAdapter; |
6 | import java.awt.event.*; | 6 | import java.awt.event.WindowEvent; |
7 | import javax.swing.*; | 7 | import javax.swing.JButton; |
8 | import javax.swing.JFrame; | ||
9 | import javax.swing.JLabel; | ||
10 | import javax.swing.JPanel; | ||
11 | import javax.swing.JTextField; | ||
8 | import layout.TableLayout; | 12 | import layout.TableLayout; |
9 | 13 | ||
10 | 14 | ||
15 | public class Preferred extends JFrame { | ||
16 | |||
17 | |||
18 | public Preferred() { | ||
19 | super("The Power of Preferred Sizes"); | ||
11 | 20 | ||
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(); | 21 | Container pane = getContentPane(); |
29 | 22 | ||
30 | // b - border | 23 | // b - border |
31 | // f - FILL | 24 | // f - FILL |
32 | // p - PREFERRED | 25 | // p - PREFERRED |
33 | // vs - vertical space between labels and text fields | 26 | // vs - vertical space between labels and text fields |
34 | // vg - vertical gap between form elements | 27 | // vg - vertical gap between form elements |
35 | // hg - horizontal gap between form elements | 28 | // hg - horizontal gap between form elements |
36 | 29 | ||
37 | double b = 10; | 30 | double b = 10; |
38 | double f = TableLayout.FILL; | 31 | double f = TableLayout.FILL; |
39 | double p = TableLayout.PREFERRED; | 32 | double p = TableLayout.PREFERRED; |
40 | double vs = 5; | 33 | double vs = 5; |
41 | double vg = 10; | 34 | double vg = 10; |
42 | double hg = 10; | 35 | double hg = 10; |
43 | 36 | ||
44 | double size[][] = | 37 | double size[][] = |
45 | {{b, f, hg, p, hg, p, b}, | 38 | {{b, f, hg, p, hg, p, b}, |
46 | {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; | 39 | {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; |
47 | 40 | ||
48 | TableLayout layout = new TableLayout(size); | 41 | TableLayout layout = new TableLayout(size); |
49 | pane.setLayout (layout); | 42 | pane.setLayout(layout); |
50 | 43 | ||
51 | // Create all controls | 44 | // Create all controls |
52 | JLabel labelName = new JLabel("Name"); | 45 | JLabel labelName = new JLabel("Name"); |
53 | JLabel labelAddress = new JLabel("Address"); | 46 | JLabel labelAddress = new JLabel("Address"); |
54 | JLabel labelCity = new JLabel("City"); | 47 | JLabel labelCity = new JLabel("City"); |
55 | JLabel labelState = new JLabel("State"); | 48 | JLabel labelState = new JLabel("State"); |
56 | JLabel labelZip = new JLabel("Zip"); | 49 | JLabel labelZip = new JLabel("Zip"); |
57 | 50 | ||
58 | JTextField textfieldName = new JTextField(10); | 51 | JTextField textfieldName = new JTextField(10); |
59 | JTextField textfieldAddress = new JTextField(20); | 52 | JTextField textfieldAddress = new JTextField(20); |
60 | JTextField textfieldCity = new JTextField(10); | 53 | JTextField textfieldCity = new JTextField(10); |
61 | JTextField textfieldState = new JTextField(2); | 54 | JTextField textfieldState = new JTextField(2); |
62 | JTextField textfieldZip = new JTextField(5); | 55 | JTextField textfieldZip = new JTextField(5); |
63 | 56 | ||
64 | JButton buttonOk = new JButton("OK"); | 57 | JButton buttonOk = new JButton("OK"); |
65 | JButton buttonCancel = new JButton("Cancel"); | 58 | JButton buttonCancel = new JButton("Cancel"); |
66 | JPanel panelButton = new JPanel(); | 59 | JPanel panelButton = new JPanel(); |
67 | panelButton.add (buttonOk); | 60 | panelButton.add(buttonOk); |
68 | panelButton.add (buttonCancel); | 61 | panelButton.add(buttonCancel); |
69 | 62 | ||
70 | // Add all controls | 63 | // Add all controls |
71 | pane.add (labelName, "1, 1, 5, 1"); | 64 | pane.add(labelName, "1, 1, 5, 1"); |
72 | pane.add (textfieldName, "1, 3, 5, 3"); | 65 | pane.add(textfieldName, "1, 3, 5, 3"); |
73 | pane.add (labelAddress, "1, 5, 5, 5"); | 66 | pane.add(labelAddress, "1, 5, 5, 5"); |
74 | pane.add (textfieldAddress, "1, 7, 5, 7"); | 67 | pane.add(textfieldAddress, "1, 7, 5, 7"); |
75 | pane.add (labelCity, "1, 9"); | 68 | pane.add(labelCity, "1, 9"); |
76 | pane.add (textfieldCity, "1, 11"); | 69 | pane.add(textfieldCity, "1, 11"); |
77 | pane.add (labelState, "3, 9"); | 70 | pane.add(labelState, "3, 9"); |
78 | pane.add (textfieldState, "3, 11"); | 71 | pane.add(textfieldState, "3, 11"); |
79 | pane.add (labelZip, "5, 9"); | 72 | pane.add(labelZip, "5, 9"); |
80 | pane.add (textfieldZip, "5, 11"); | 73 | pane.add(textfieldZip, "5, 11"); |
81 | pane.add (panelButton, "1, 13, 5, 13"); | 74 | pane.add(panelButton, "1, 13, 5, 13"); |
82 | 75 | ||
83 | allowClosing(); | 76 | allowClosing(); |
84 | pack(); | 77 | pack(); |
85 | setResizable (false); | 78 | setResizable(false); |
86 | show(); | 79 | show(); |
87 | } | 80 | } |
88 | 81 | ||
89 | 82 | public static void main(String args[]) { | |
90 | 83 | new Preferred(); | |
91 | public void allowClosing () | 84 | } |
92 | { | 85 | |
86 | public void allowClosing() { | ||
93 | addWindowListener | 87 | addWindowListener |
94 | (new WindowAdapter() | 88 | (new WindowAdapter() { |
95 | { | 89 | public void windowClosing(WindowEvent e) { |
96 | public void windowClosing (WindowEvent e) | 90 | System.exit(0); |
97 | { | 91 | } |
98 | System.exit (0); | 92 | } |
99 | } | ||
100 | } | ||
101 | ); | 93 | ); |
102 | } | 94 | } |
103 | 95 | ||
104 | 96 | ||
105 | |||
106 | } | 97 | } |
diff --git a/lib/example/RadTool.java b/lib/example/RadTool.java index 8ef0c55..75e7635 100644 --- a/lib/example/RadTool.java +++ b/lib/example/RadTool.java | |||
@@ -1,22 +1,33 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Choice; | |
5 | import java.awt.*; | 5 | import java.awt.Color; |
6 | import java.awt.event.*; | 6 | import java.awt.Component; |
7 | import java.util.*; | 7 | import java.awt.Container; |
8 | import javax.swing.*; | 8 | import java.awt.Dimension; |
9 | import java.awt.Frame; | ||
10 | import java.awt.Graphics; | ||
11 | import java.awt.Panel; | ||
12 | import java.awt.TextArea; | ||
13 | import java.awt.event.ActionEvent; | ||
14 | import java.awt.event.ActionListener; | ||
15 | import java.awt.event.MouseListener; | ||
16 | import java.awt.event.WindowAdapter; | ||
17 | import java.awt.event.WindowEvent; | ||
18 | import java.util.ArrayList; | ||
19 | import javax.swing.JButton; | ||
20 | import javax.swing.JLabel; | ||
21 | import javax.swing.JPanel; | ||
22 | import javax.swing.JTextField; | ||
9 | import layout.TableLayout; | 23 | import layout.TableLayout; |
10 | import layout.TableLayoutConstraints; | 24 | import layout.TableLayoutConstraints; |
11 | import support.GeneralDialog; | 25 | import support.GeneralDialog; |
12 | 26 | ||
13 | 27 | ||
28 | public class RadTool extends Frame implements ActionListener { | ||
14 | 29 | ||
15 | public class RadTool extends Frame implements ActionListener | ||
16 | { | ||
17 | 30 | ||
18 | |||
19 | |||
20 | private JTextField textfieldColumnNumber; | 31 | private JTextField textfieldColumnNumber; |
21 | private JTextField textfieldColumnSize; | 32 | private JTextField textfieldColumnSize; |
22 | private JTextField textfieldRowNumber; | 33 | private JTextField textfieldRowNumber; |
@@ -37,20 +48,11 @@ public class RadTool extends Frame implements ActionListener | |||
37 | private ArrayList boxList; | 48 | private ArrayList boxList; |
38 | 49 | ||
39 | 50 | ||
40 | |||
41 | public static void main (String args[]) | ||
42 | { | ||
43 | new RadTool(); | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /** | 51 | /** |
49 | * Constructs the user interface. | 52 | * Constructs the user interface. |
50 | */ | 53 | */ |
51 | 54 | ||
52 | public RadTool() | 55 | public RadTool() { |
53 | { | ||
54 | // Create frame | 56 | // Create frame |
55 | super("Example of Dynamic Rows and Columns"); | 57 | super("Example of Dynamic Rows and Columns"); |
56 | 58 | ||
@@ -61,9 +63,9 @@ public class RadTool extends Frame implements ActionListener | |||
61 | double p = TableLayout.PREFERRED; | 63 | double p = TableLayout.PREFERRED; |
62 | double size[][] = | 64 | double size[][] = |
63 | {{b, p, s, p, s, p, s, p, s, p, s, p, s, p, f, b}, | 65 | {{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}}; | 66 | {f, s, p, s, p, s, 100, s, p, b}}; |
65 | 67 | ||
66 | setLayout (new TableLayout(size)); | 68 | setLayout(new TableLayout(size)); |
67 | 69 | ||
68 | // Create static controls | 70 | // Create static controls |
69 | JLabel labelColumn = new JLabel("Column"); | 71 | JLabel labelColumn = new JLabel("Column"); |
@@ -81,106 +83,105 @@ public class RadTool extends Frame implements ActionListener | |||
81 | buttonAddRow = new JButton("Add"); | 83 | buttonAddRow = new JButton("Add"); |
82 | buttonRemoveRow = new JButton("Remove"); | 84 | buttonRemoveRow = new JButton("Remove"); |
83 | buttonResizeRow = new JButton("Resize"); | 85 | buttonResizeRow = new JButton("Resize"); |
84 | 86 | ||
85 | textArea = new TextArea(); | 87 | textArea = new TextArea(); |
86 | columnHeader = new ArrayList(); | 88 | columnHeader = new ArrayList(); |
87 | rowHeader = new ArrayList(); | 89 | rowHeader = new ArrayList(); |
88 | boxList = new ArrayList(); | 90 | boxList = new ArrayList(); |
89 | buttonShowLayout = new JButton("Show Layout"); | 91 | buttonShowLayout = new JButton("Show Layout"); |
90 | buttonGenerateCode = new JButton("Generate Code"); | 92 | buttonGenerateCode = new JButton("Generate Code"); |
91 | 93 | ||
92 | // Add static controls | 94 | // Add static controls |
93 | add (labelColumn, " 1, 2"); | 95 | add(labelColumn, " 1, 2"); |
94 | add (textfieldColumnNumber, " 3, 2"); | 96 | add(textfieldColumnNumber, " 3, 2"); |
95 | add (labelColumnSize, " 5, 2"); | 97 | add(labelColumnSize, " 5, 2"); |
96 | add (textfieldColumnSize, " 7, 2"); | 98 | add(textfieldColumnSize, " 7, 2"); |
97 | add (buttonAddColumn, " 9, 2"); | 99 | add(buttonAddColumn, " 9, 2"); |
98 | add (buttonRemoveColumn, "11, 2"); | 100 | add(buttonRemoveColumn, "11, 2"); |
99 | add (buttonResizeColumn, "13, 2"); | 101 | add(buttonResizeColumn, "13, 2"); |
100 | 102 | ||
101 | add (labelRow, " 1, 4"); | 103 | add(labelRow, " 1, 4"); |
102 | add (textfieldRowNumber, " 3, 4"); | 104 | add(textfieldRowNumber, " 3, 4"); |
103 | add (labelRowSize, " 5, 4"); | 105 | add(labelRowSize, " 5, 4"); |
104 | add (textfieldRowSize, " 7, 4"); | 106 | add(textfieldRowSize, " 7, 4"); |
105 | add (buttonAddRow, " 9, 4"); | 107 | add(buttonAddRow, " 9, 4"); |
106 | add (buttonRemoveRow, "11, 4"); | 108 | add(buttonRemoveRow, "11, 4"); |
107 | add (buttonResizeRow, "13, 4"); | 109 | add(buttonResizeRow, "13, 4"); |
108 | 110 | ||
109 | add (textArea, "1, 6, 14, 6"); | 111 | add(textArea, "1, 6, 14, 6"); |
110 | add (buttonShowLayout, "1, 8, 7, 6"); | 112 | add(buttonShowLayout, "1, 8, 7, 6"); |
111 | add (buttonGenerateCode, "9, 8, 12, 8"); | 113 | add(buttonGenerateCode, "9, 8, 12, 8"); |
112 | 114 | ||
113 | // Listen for button events | 115 | // Listen for button events |
114 | buttonAddColumn.addActionListener (this); | 116 | buttonAddColumn.addActionListener(this); |
115 | buttonRemoveColumn.addActionListener (this); | 117 | buttonRemoveColumn.addActionListener(this); |
116 | buttonResizeColumn.addActionListener (this); | 118 | buttonResizeColumn.addActionListener(this); |
117 | buttonAddRow.addActionListener (this); | 119 | buttonAddRow.addActionListener(this); |
118 | buttonRemoveRow.addActionListener (this); | 120 | buttonRemoveRow.addActionListener(this); |
119 | buttonResizeRow.addActionListener (this); | 121 | buttonResizeRow.addActionListener(this); |
120 | buttonShowLayout.addActionListener (this); | 122 | buttonShowLayout.addActionListener(this); |
121 | buttonGenerateCode.addActionListener (this); | 123 | buttonGenerateCode.addActionListener(this); |
122 | 124 | ||
123 | // Add a panel for RadTool controls | 125 | // Add a panel for RadTool controls |
124 | panel = new JPanel(); | 126 | panel = new JPanel(); |
125 | panel.setBackground (Color.white); | 127 | panel.setBackground(Color.white); |
126 | add (panel, "0, 0, 15, 0"); | 128 | add(panel, "0, 0, 15, 0"); |
127 | 129 | ||
128 | // Create the layout manager for the panel | 130 | // Create the layout manager for the panel |
129 | double size2[][] = {{p, -1}, {p, -1}}; | 131 | double size2[][] = {{p, -1}, {p, -1}}; |
130 | layout = new TableLayout(size2); | 132 | layout = new TableLayout(size2); |
131 | panel.setLayout (layout); | 133 | panel.setLayout(layout); |
132 | updateHeader(); | 134 | updateHeader(); |
133 | updateBox(); | 135 | updateBox(); |
134 | 136 | ||
135 | // Allow user to close the window to terminate the program | 137 | // Allow user to close the window to terminate the program |
136 | addWindowListener | 138 | addWindowListener |
137 | (new WindowAdapter() | 139 | (new WindowAdapter() { |
138 | { | 140 | public void windowClosing(WindowEvent e) { |
139 | public void windowClosing (WindowEvent e) | 141 | System.exit(0); |
140 | { | 142 | } |
141 | System.exit (0); | 143 | } |
142 | } | ||
143 | } | ||
144 | ); | 144 | ); |
145 | 145 | ||
146 | // Show frame | 146 | // Show frame |
147 | setBackground (Color.lightGray); | 147 | setBackground(Color.lightGray); |
148 | setBounds (100, 100, 500, 400); | 148 | setBounds(100, 100, 500, 400); |
149 | show(); | 149 | show(); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | public static void main(String args[]) { | |
153 | 153 | new RadTool(); | |
154 | } | ||
155 | |||
154 | /** | 156 | /** |
155 | * Handles all action events. | 157 | * Handles all action events. |
156 | */ | 158 | */ |
157 | 159 | ||
158 | public void actionPerformed (ActionEvent e) | 160 | public void actionPerformed(ActionEvent e) { |
159 | { | ||
160 | // Get row and column information from text fields | 161 | // Get row and column information from text fields |
161 | int row = getInt(textfieldRowNumber); | 162 | int row = getInt(textfieldRowNumber); |
162 | int col = getInt(textfieldColumnNumber); | 163 | int col = getInt(textfieldColumnNumber); |
163 | double rowSize = getDouble(textfieldRowSize); | 164 | double rowSize = getDouble(textfieldRowSize); |
164 | double colSize = getDouble(textfieldColumnSize); | 165 | double colSize = getDouble(textfieldColumnSize); |
165 | 166 | ||
166 | // Get source of the event | 167 | // Get source of the event |
167 | Object source = e.getSource(); | 168 | Object source = e.getSource(); |
168 | 169 | ||
169 | try | 170 | try { |
170 | { | ||
171 | // Update layout | 171 | // Update layout |
172 | if (source == buttonAddColumn) | 172 | if (source == buttonAddColumn) { |
173 | layout.insertColumn (col, colSize); | 173 | layout.insertColumn(col, colSize); |
174 | else if (source == buttonRemoveColumn) | 174 | } else if (source == buttonRemoveColumn) { |
175 | layout.deleteColumn (col); | 175 | layout.deleteColumn(col); |
176 | else if (source == buttonResizeColumn) | 176 | } else if (source == buttonResizeColumn) { |
177 | layout.setColumn (col, colSize); | 177 | layout.setColumn(col, colSize); |
178 | else if (source == buttonAddRow) | 178 | } else if (source == buttonAddRow) { |
179 | layout.insertRow (row, rowSize); | 179 | layout.insertRow(row, rowSize); |
180 | else if (source == buttonRemoveRow) | 180 | } else if (source == buttonRemoveRow) { |
181 | layout.deleteRow (row); | 181 | layout.deleteRow(row); |
182 | else if (source == buttonResizeRow) | 182 | } else if (source == buttonResizeRow) { |
183 | layout.setRow (row, rowSize); | 183 | layout.setRow(row, rowSize); |
184 | } | ||
184 | 185 | ||
185 | // Update headers, etc. to reflect layout's change | 186 | // Update headers, etc. to reflect layout's change |
186 | updateHeader(); | 187 | updateHeader(); |
@@ -189,258 +190,242 @@ public class RadTool extends Frame implements ActionListener | |||
189 | // Layout and repaint panel since the layout has changed | 190 | // Layout and repaint panel since the layout has changed |
190 | panel.doLayout(); | 191 | panel.doLayout(); |
191 | panel.repaint(); | 192 | panel.repaint(); |
192 | 193 | ||
193 | // Update layout's description | 194 | // Update layout's description |
194 | textArea.setText(layout.toString()); | 195 | textArea.setText(layout.toString()); |
195 | 196 | ||
196 | // Generate code if desired | 197 | // Generate code if desired |
197 | if (source == buttonGenerateCode) | 198 | if (source == buttonGenerateCode) { |
198 | generateCode(); | 199 | generateCode(); |
199 | } | 200 | } |
200 | catch (Throwable error) | 201 | } catch (Throwable error) { |
201 | { | ||
202 | error.printStackTrace(); | 202 | error.printStackTrace(); |
203 | textArea.setText (error.toString()); | 203 | textArea.setText(error.toString()); |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | 207 | ||
208 | |||
209 | /** | 208 | /** |
210 | * Converts the text in a text field to an integer. | 209 | * Converts the text in a text field to an integer. |
211 | */ | 210 | */ |
212 | 211 | ||
213 | private int getInt (JTextField field) | 212 | private int getInt(JTextField field) { |
214 | { | ||
215 | int value = 0; | 213 | int value = 0; |
216 | 214 | ||
217 | try | 215 | try { |
218 | { | ||
219 | value = Integer.parseInt(field.getText()); | 216 | value = Integer.parseInt(field.getText()); |
217 | } catch (NumberFormatException e) { | ||
220 | } | 218 | } |
221 | catch (NumberFormatException e) {} | 219 | |
222 | |||
223 | return value; | 220 | return value; |
224 | } | 221 | } |
225 | 222 | ||
226 | 223 | ||
227 | |||
228 | /** | 224 | /** |
229 | * Converts the text in a text field to a double. | 225 | * Converts the text in a text field to a double. |
230 | */ | 226 | */ |
231 | 227 | ||
232 | private double getDouble (JTextField field) | 228 | private double getDouble(JTextField field) { |
233 | { | ||
234 | double value = -1.0; | 229 | double value = -1.0; |
235 | 230 | ||
236 | try | 231 | try { |
237 | { | ||
238 | value = Double.parseDouble(field.getText()); | 232 | value = Double.parseDouble(field.getText()); |
233 | } catch (NumberFormatException e) { | ||
239 | } | 234 | } |
240 | catch (NumberFormatException e) {} | 235 | |
241 | |||
242 | return value; | 236 | return value; |
243 | } | 237 | } |
244 | 238 | ||
245 | |||
246 | 239 | ||
247 | /** | 240 | /** |
248 | * Updates all the row and columns headers by bruce force. The headers | 241 | * Updates all the row and columns headers by bruce force. The headers |
249 | * are removed and then recreated based on the current layout configuration. | 242 | * are removed and then recreated based on the current layout configuration. |
250 | */ | 243 | */ |
251 | 244 | ||
252 | private void updateHeader () | 245 | private void updateHeader() { |
253 | { | ||
254 | TableLayoutConstraints c = new TableLayoutConstraints | 246 | TableLayoutConstraints c = new TableLayoutConstraints |
255 | (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); | 247 | (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); |
256 | 248 | ||
257 | double size[] = layout.getColumn(); | 249 | double size[] = layout.getColumn(); |
258 | 250 | ||
259 | for (int i = columnHeader.size() - 1; i >= 0; i--) | 251 | for (int i = columnHeader.size() - 1; i >= 0; i--) { |
260 | { | ||
261 | JButton header = (JButton) columnHeader.remove(i); | 252 | JButton header = (JButton) columnHeader.remove(i); |
262 | panel.remove(header); | 253 | panel.remove(header); |
263 | } | 254 | } |
264 | 255 | ||
265 | for (int i = 0; i < size.length; i++) | 256 | for (int i = 0; i < size.length; i++) { |
266 | { | ||
267 | c.col1 = c.col2 = i; | 257 | c.col1 = c.col2 = i; |
268 | JButton header = new JButton("" + i + ": " + size[i]); | 258 | JButton header = new JButton("" + i + ": " + size[i]); |
269 | columnHeader.add(i, header); | 259 | columnHeader.add(i, header); |
270 | panel.add (header, c); | 260 | panel.add(header, c); |
271 | } | 261 | } |
272 | 262 | ||
273 | c.col1 = c.col2 = 0; | 263 | c.col1 = c.col2 = 0; |
274 | size = layout.getRow(); | 264 | size = layout.getRow(); |
275 | 265 | ||
276 | for (int i = rowHeader.size() - 1; i >= 0; i--) | 266 | for (int i = rowHeader.size() - 1; i >= 0; i--) { |
277 | { | ||
278 | JButton header = (JButton) rowHeader.remove(i); | 267 | JButton header = (JButton) rowHeader.remove(i); |
279 | panel.remove(header); | 268 | panel.remove(header); |
280 | } | 269 | } |
281 | 270 | ||
282 | for (int i = 0; i < size.length; i++) | 271 | for (int i = 0; i < size.length; i++) { |
283 | { | ||
284 | c.row1 = c.row2 = i; | 272 | c.row1 = c.row2 = i; |
285 | JButton header = new JButton("" + i + ": " + size[i]); | 273 | JButton header = new JButton("" + i + ": " + size[i]); |
286 | rowHeader.add(i, header); | 274 | rowHeader.add(i, header); |
287 | panel.add (header, c); | 275 | panel.add(header, c); |
288 | } | 276 | } |
289 | } | 277 | } |
290 | 278 | ||
291 | 279 | ||
292 | |||
293 | /** | 280 | /** |
294 | * Updates the boxes used to illustrate cells. This is a brute force, | 281 | * Updates the boxes used to illustrate cells. This is a brute force, |
295 | * unoptimized method. | 282 | * unoptimized method. |
296 | */ | 283 | */ |
297 | 284 | ||
298 | private void updateBox () | 285 | private void updateBox() { |
299 | { | 286 | for (int i = boxList.size() - 1; i >= 0; i--) { |
300 | for (int i = boxList.size() - 1; i >= 0; i--) | ||
301 | { | ||
302 | Box box = (Box) boxList.remove(i); | 287 | Box box = (Box) boxList.remove(i); |
303 | panel.remove(box); | 288 | panel.remove(box); |
304 | } | 289 | } |
305 | 290 | ||
306 | TableLayoutConstraints constraint = new TableLayoutConstraints | 291 | TableLayoutConstraints constraint = new TableLayoutConstraints |
307 | (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); | 292 | (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); |
308 | 293 | ||
309 | double col[] = layout.getColumn(); | 294 | double col[] = layout.getColumn(); |
310 | double row[] = layout.getRow(); | 295 | double row[] = layout.getRow(); |
311 | 296 | ||
312 | for (int c = 1; c < col.length; c++) | 297 | for (int c = 1; c < col.length; c++) { |
313 | for (int r = 1; r < row.length; r++) | 298 | for (int r = 1; r < row.length; r++) { |
314 | { | ||
315 | constraint.col1 = constraint.col2 = c; | 299 | constraint.col1 = constraint.col2 = c; |
316 | constraint.row1 = constraint.row2 = r; | 300 | constraint.row1 = constraint.row2 = r; |
317 | Box box = new Box(); | 301 | Box box = new Box(); |
318 | panel.add (box, constraint); | 302 | panel.add(box, constraint); |
319 | } | 303 | } |
304 | } | ||
320 | } | 305 | } |
321 | 306 | ||
322 | 307 | ||
323 | |||
324 | /** | 308 | /** |
325 | * Generates code based on the current layout and Smiley controls. | 309 | * Generates code based on the current layout and Smiley controls. |
326 | */ | 310 | */ |
327 | 311 | ||
328 | private void generateCode () | 312 | private void generateCode() { |
329 | { | ||
330 | String code = | 313 | String code = |
331 | "import java.awt.*;\n" + | 314 | "import java.awt.*;\n" + |
332 | "import java.awt.event.*;\n" + | 315 | "import java.awt.event.*;\n" + |
333 | "import layout.TableLayout;\n\n" + | 316 | "import layout.TableLayout;\n\n" + |
334 | 317 | ||
335 | "public class MyClass\n" + | 318 | "public class MyClass\n" + |
336 | "{\n\n" + | 319 | "{\n\n" + |
337 | 320 | ||
338 | " public static void main (String args[])\n" + | 321 | " public static void main (String args[])\n" + |
339 | " {\n" + | 322 | " {\n" + |
340 | " Frame frame = new Frame(\"MyTitle\");\n" + | 323 | " Frame frame = new Frame(\"MyTitle\");\n" + |
341 | " frame.setBounds (100, 100, 300, 300);\n\n" + | 324 | " frame.setBounds (100, 100, 300, 300);\n\n" + |
325 | |||
326 | " double size[][] =\n" + | ||
327 | " {{"; | ||
342 | 328 | ||
343 | " double size[][] =\n" + | ||
344 | " {{"; | ||
345 | |||
346 | double size[] = layout.getColumn(); | 329 | double size[] = layout.getColumn(); |
347 | 330 | ||
348 | if (size.length > 0) | 331 | if (size.length > 0) { |
349 | code += size[0]; | 332 | code += size[0]; |
333 | } | ||
350 | 334 | ||
351 | for (int i = 1; i < size.length; i++) | 335 | for (int i = 1; i < size.length; i++) { |
352 | code += ", " + size[i]; | 336 | code += ", " + size[i]; |
337 | } | ||
353 | 338 | ||
354 | code += "}, // Columns\n" + | 339 | code += "}, // Columns\n" + |
355 | " {"; | 340 | " {"; |
356 | 341 | ||
357 | size = layout.getRow(); | 342 | size = layout.getRow(); |
358 | 343 | ||
359 | if (size.length > 0) | 344 | if (size.length > 0) { |
360 | code += size[0]; | 345 | code += size[0]; |
346 | } | ||
361 | 347 | ||
362 | for (int i = 1; i < size.length; i++) | 348 | for (int i = 1; i < size.length; i++) { |
363 | code += ", " + size[i]; | 349 | code += ", " + size[i]; |
350 | } | ||
364 | 351 | ||
365 | code += "}}; // Rows\n\n" + | 352 | code += "}}; // Rows\n\n" + |
366 | " frame.setLayout (new TableLayout(size));\n\n" + | 353 | " frame.setLayout (new TableLayout(size));\n\n" + |
367 | " Button button;\n"; | 354 | " Button button;\n"; |
368 | 355 | ||
369 | Component component[] = panel.getComponents(); | 356 | Component component[] = panel.getComponents(); |
370 | 357 | ||
371 | for (int i = 0; i < component.length; i++) | 358 | for (int i = 0; i < component.length; i++) { |
372 | { | 359 | if (component[i] instanceof Smiley) { |
373 | if (component[i] instanceof Smiley) | ||
374 | { | ||
375 | TableLayoutConstraints c = layout.getConstraints(component[i]); | 360 | TableLayoutConstraints c = layout.getConstraints(component[i]); |
376 | String constraint = "" + c.col1 + ", " + c.row1 + ", "; | 361 | String constraint = "" + c.col1 + ", " + c.row1 + ", "; |
377 | 362 | ||
378 | if ((c.col1 == c.col2) && (c.row1 == c.row2)) | 363 | if ((c.col1 == c.col2) && (c.row1 == c.row2)) { |
379 | { | ||
380 | String h[] = {"L", "C", "F", "R"}; | 364 | String h[] = {"L", "C", "F", "R"}; |
381 | String v[] = {"T", "C", "F", "B"}; | 365 | String v[] = {"T", "C", "F", "B"}; |
382 | constraint += h[c.hAlign] + ", " + v[c.vAlign]; | 366 | constraint += h[c.hAlign] + ", " + v[c.vAlign]; |
383 | } | 367 | } else { |
384 | else | ||
385 | constraint += c.col2 + ", " + c.row2; | 368 | constraint += c.col2 + ", " + c.row2; |
386 | 369 | } | |
370 | |||
387 | code += | 371 | code += |
388 | " button = new Button(\"" + constraint + "\");\n" + | 372 | " button = new Button(\"" + constraint + "\");\n" + |
389 | " frame.add (button, \"" + constraint + "\");\n"; | 373 | " frame.add (button, \"" + constraint + "\");\n"; |
390 | } | 374 | } |
391 | } | 375 | } |
392 | 376 | ||
393 | code += | 377 | code += |
394 | "\n" + | 378 | "\n" + |
395 | " frame.addWindowListener\n" + | 379 | " frame.addWindowListener\n" + |
396 | " (new WindowAdapter()\n" + | 380 | " (new WindowAdapter()\n" + |
397 | " {\n" + | 381 | " {\n" + |
398 | " public void windowClosing (WindowEvent e)\n" + | 382 | " public void windowClosing (WindowEvent e)\n" + |
399 | " {\n" + | 383 | " {\n" + |
400 | " System.exit (0);\n" + | 384 | " System.exit (0);\n" + |
401 | " }\n" + | 385 | " }\n" + |
402 | " }\n" + | 386 | " }\n" + |
403 | " );\n\n" + | 387 | " );\n\n" + |
404 | " frame.show();\n" + | 388 | " frame.show();\n" + |
405 | " }\n" + | 389 | " }\n" + |
406 | "}\n"; | 390 | "}\n"; |
407 | 391 | ||
408 | textArea.setText (code); | 392 | textArea.setText(code); |
409 | } | 393 | } |
410 | 394 | ||
411 | 395 | ||
412 | |||
413 | /** | 396 | /** |
414 | * This inner class is a component that looks like a box. | 397 | * This inner class is a component that looks like a box. |
415 | */ | 398 | */ |
416 | 399 | ||
417 | public class Box extends Component implements MouseListener | 400 | public class Box extends Component implements MouseListener { |
418 | { | 401 | public Box() { |
419 | public Box () | ||
420 | { | ||
421 | super(); | 402 | super(); |
422 | addMouseListener(this); | 403 | addMouseListener(this); |
423 | } | 404 | } |
424 | 405 | ||
425 | public void update (Graphics g) | 406 | public void update(Graphics g) { |
426 | { | 407 | paint(g); |
427 | paint (g); | ||
428 | } | 408 | } |
429 | 409 | ||
430 | public void paint (Graphics g) | 410 | public void paint(Graphics g) { |
431 | { | ||
432 | Dimension d = getSize(); | 411 | Dimension d = getSize(); |
433 | g.setColor (Color.black); | 412 | g.setColor(Color.black); |
434 | g.drawRect (0, 0, d.width - 1, d.height - 1); | 413 | g.drawRect(0, 0, d.width - 1, d.height - 1); |
414 | } | ||
415 | |||
416 | public void mouseExited(java.awt.event.MouseEvent mouseEvent) { | ||
417 | } | ||
418 | |||
419 | public void mousePressed(java.awt.event.MouseEvent mouseEvent) { | ||
420 | } | ||
421 | |||
422 | public void mouseClicked(java.awt.event.MouseEvent mouseEvent) { | ||
435 | } | 423 | } |
436 | 424 | ||
437 | public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} | 425 | public void mouseEntered(java.awt.event.MouseEvent mouseEvent) { |
438 | public void mousePressed(java.awt.event.MouseEvent mouseEvent) {} | 426 | } |
439 | public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {} | 427 | |
440 | public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {} | 428 | public void mouseReleased(java.awt.event.MouseEvent mouseEvent) { |
441 | |||
442 | public void mouseReleased(java.awt.event.MouseEvent mouseEvent) | ||
443 | { | ||
444 | TableLayoutConstraints c = layout.getConstraints(this); | 429 | TableLayoutConstraints c = layout.getConstraints(this); |
445 | Smiley smiley = new Smiley(); | 430 | Smiley smiley = new Smiley(); |
446 | Container container = getParent(); | 431 | Container container = getParent(); |
@@ -449,32 +434,26 @@ public class RadTool extends Frame implements ActionListener | |||
449 | } | 434 | } |
450 | } | 435 | } |
451 | 436 | ||
452 | |||
453 | 437 | ||
454 | /** | 438 | /** |
455 | * This inner class is a component that looks like a smiley face. | 439 | * This inner class is a component that looks like a smiley face. |
456 | */ | 440 | */ |
457 | 441 | ||
458 | public class Smiley extends Component implements MouseListener | 442 | public class Smiley extends Component implements MouseListener { |
459 | { | 443 | public Smiley() { |
460 | public Smiley () | ||
461 | { | ||
462 | super(); | 444 | super(); |
463 | addMouseListener (this); | 445 | addMouseListener(this); |
464 | } | 446 | } |
465 | 447 | ||
466 | public Dimension getPreferredSize () | 448 | public Dimension getPreferredSize() { |
467 | { | ||
468 | return new Dimension(64, 64); | 449 | return new Dimension(64, 64); |
469 | } | 450 | } |
470 | 451 | ||
471 | public void update (Graphics g) | 452 | public void update(Graphics g) { |
472 | { | 453 | paint(g); |
473 | paint (g); | ||
474 | } | 454 | } |
475 | 455 | ||
476 | public void paint (Graphics g) | 456 | public void paint(Graphics g) { |
477 | { | ||
478 | Dimension d = getSize(); | 457 | Dimension d = getSize(); |
479 | int width_1_8 = d.width >> 3; | 458 | int width_1_8 = d.width >> 3; |
480 | int width_7_8 = d.width - width_1_8; | 459 | int width_7_8 = d.width - width_1_8; |
@@ -487,131 +466,132 @@ public class RadTool extends Frame implements ActionListener | |||
487 | int height_1_4 = d.height >> 2; | 466 | int height_1_4 = d.height >> 2; |
488 | int height_3_4 = d.height - height_1_4; | 467 | int height_3_4 = d.height - height_1_4; |
489 | int height_5_8 = height_7_8 - height_1_4; | 468 | int height_5_8 = height_7_8 - height_1_4; |
490 | 469 | ||
491 | g.setColor (Color.yellow); | 470 | g.setColor(Color.yellow); |
492 | g.fillArc (0, 0, d.width - 1, d.height - 1, 0, 360); | 471 | g.fillArc(0, 0, d.width - 1, d.height - 1, 0, 360); |
493 | g.setColor (Color.blue); | 472 | g.setColor(Color.blue); |
494 | g.fillArc (width_1_4, height_1_4, width_1_8, height_1_8, 0, 360); | 473 | 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); | 474 | g.fillArc(width_5_8, height_1_4, width_1_8, height_1_8, 0, 360); |
496 | g.setColor (Color.red); | 475 | g.setColor(Color.red); |
497 | g.fillArc (width_1_4, height_5_8, width_1_2, height_1_4, 180, 180); | 476 | g.fillArc(width_1_4, height_5_8, width_1_2, height_1_4, 180, 180); |
477 | } | ||
478 | |||
479 | public void mouseExited(java.awt.event.MouseEvent mouseEvent) { | ||
480 | } | ||
481 | |||
482 | public void mousePressed(java.awt.event.MouseEvent mouseEvent) { | ||
483 | } | ||
484 | |||
485 | public void mouseClicked(java.awt.event.MouseEvent mouseEvent) { | ||
486 | } | ||
487 | |||
488 | public void mouseEntered(java.awt.event.MouseEvent mouseEvent) { | ||
498 | } | 489 | } |
499 | 490 | ||
500 | public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} | 491 | public void mouseReleased(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 | 492 | // Get constraints applied to this Smiley |
508 | TableLayoutConstraints c = layout.getConstraints(this); | 493 | TableLayoutConstraints c = layout.getConstraints(this); |
509 | 494 | ||
510 | // Create controls | 495 | // Create controls |
511 | Panel panel = new Panel(); | 496 | Panel panel = new Panel(); |
512 | 497 | ||
513 | int numRow = layout.getNumRow(); | 498 | int numRow = layout.getNumRow(); |
514 | int numColumn = layout.getNumColumn(); | 499 | int numColumn = layout.getNumColumn(); |
515 | 500 | ||
516 | Choice choiceCol1 = new Choice(); | 501 | Choice choiceCol1 = new Choice(); |
517 | Choice choiceCol2 = new Choice(); | 502 | Choice choiceCol2 = new Choice(); |
518 | Choice choiceRow1 = new Choice(); | 503 | Choice choiceRow1 = new Choice(); |
519 | Choice choiceRow2 = new Choice(); | 504 | Choice choiceRow2 = new Choice(); |
520 | 505 | ||
521 | for (int i = 1; i < numColumn; i++) | 506 | for (int i = 1; i < numColumn; i++) { |
522 | { | 507 | choiceCol1.add("" + i); |
523 | choiceCol1.add ("" + i); | 508 | choiceCol2.add("" + i); |
524 | choiceCol2.add ("" + i); | ||
525 | } | 509 | } |
526 | 510 | ||
527 | for (int i = 1; i < numRow; i++) | 511 | for (int i = 1; i < numRow; i++) { |
528 | { | 512 | choiceRow1.add("" + i); |
529 | choiceRow1.add ("" + i); | 513 | choiceRow2.add("" + i); |
530 | choiceRow2.add ("" + i); | ||
531 | } | 514 | } |
532 | 515 | ||
533 | choiceCol1.select (c.col1 - 1); | 516 | choiceCol1.select(c.col1 - 1); |
534 | choiceCol2.select (c.col2 - 1); | 517 | choiceCol2.select(c.col2 - 1); |
535 | choiceRow1.select (c.row1 - 1); | 518 | choiceRow1.select(c.row1 - 1); |
536 | choiceRow2.select (c.row2 - 1); | 519 | choiceRow2.select(c.row2 - 1); |
537 | 520 | ||
538 | Choice choiceAlignH = new Choice(); | 521 | Choice choiceAlignH = new Choice(); |
539 | choiceAlignH.add ("Left"); | 522 | choiceAlignH.add("Left"); |
540 | choiceAlignH.add ("Center"); | 523 | choiceAlignH.add("Center"); |
541 | choiceAlignH.add ("Full"); | 524 | choiceAlignH.add("Full"); |
542 | choiceAlignH.add ("Right"); | 525 | choiceAlignH.add("Right"); |
543 | choiceAlignH.select (c.hAlign); | 526 | choiceAlignH.select(c.hAlign); |
544 | 527 | ||
545 | Choice choiceAlignV = new Choice(); | 528 | Choice choiceAlignV = new Choice(); |
546 | choiceAlignV.add ("Top"); | 529 | choiceAlignV.add("Top"); |
547 | choiceAlignV.add ("Center"); | 530 | choiceAlignV.add("Center"); |
548 | choiceAlignV.add ("Full"); | 531 | choiceAlignV.add("Full"); |
549 | choiceAlignV.add ("Bottom"); | 532 | choiceAlignV.add("Bottom"); |
550 | choiceAlignV.select (c.vAlign); | 533 | choiceAlignV.select(c.vAlign); |
551 | 534 | ||
552 | JLabel labelCol1 = new JLabel("Column 1"); | 535 | JLabel labelCol1 = new JLabel("Column 1"); |
553 | JLabel labelCol2 = new JLabel("Column 2"); | 536 | JLabel labelCol2 = new JLabel("Column 2"); |
554 | JLabel labelRow1 = new JLabel("Row 1"); | 537 | JLabel labelRow1 = new JLabel("Row 1"); |
555 | JLabel labelRow2 = new JLabel("Row 2"); | 538 | JLabel labelRow2 = new JLabel("Row 2"); |
556 | JLabel labelAlignH = new JLabel("Horizontal Justification"); | 539 | JLabel labelAlignH = new JLabel("Horizontal Justification"); |
557 | JLabel labelAlignV = new JLabel("Vertical Justification"); | 540 | JLabel labelAlignV = new JLabel("Vertical Justification"); |
558 | labelAlignH.setHorizontalAlignment (JLabel.RIGHT); | 541 | labelAlignH.setHorizontalAlignment(JLabel.RIGHT); |
559 | labelAlignV.setHorizontalAlignment (JLabel.RIGHT); | 542 | labelAlignV.setHorizontalAlignment(JLabel.RIGHT); |
560 | 543 | ||
561 | // Create layout | 544 | // Create layout |
562 | double f = TableLayout.FILL; | 545 | double f = TableLayout.FILL; |
563 | double p = TableLayout.PREFERRED; | 546 | double p = TableLayout.PREFERRED; |
564 | double s = 10; | 547 | double s = 10; |
565 | 548 | ||
566 | double size[][] = | 549 | double size[][] = |
567 | {{f, p, s, p, s, p, s, p, f}, | 550 | {{f, p, s, p, s, p, s, p, f}, |
568 | {p, s, p, s, p, s, p, s, p, s, p}}; | 551 | {p, s, p, s, p, s, p, s, p, s, p}}; |
569 | 552 | ||
570 | TableLayout panelLayout = new TableLayout(size); | 553 | TableLayout panelLayout = new TableLayout(size); |
571 | panel.setLayout (panelLayout); | 554 | panel.setLayout(panelLayout); |
572 | 555 | ||
573 | // Add controls | 556 | // Add controls |
574 | panel.add (labelCol1, "1, 0, R, B"); | 557 | panel.add(labelCol1, "1, 0, R, B"); |
575 | panel.add (choiceCol1, "3, 0, L, B"); | 558 | panel.add(choiceCol1, "3, 0, L, B"); |
576 | panel.add (labelRow1, "5, 0, R, B"); | 559 | panel.add(labelRow1, "5, 0, R, B"); |
577 | panel.add (choiceRow1, "7, 0, L, B"); | 560 | panel.add(choiceRow1, "7, 0, L, B"); |
578 | panel.add (labelCol2, "1, 2, R, B"); | 561 | panel.add(labelCol2, "1, 2, R, B"); |
579 | panel.add (choiceCol2, "3, 2, L, B"); | 562 | panel.add(choiceCol2, "3, 2, L, B"); |
580 | panel.add (labelRow2, "5, 2, R, B"); | 563 | panel.add(labelRow2, "5, 2, R, B"); |
581 | panel.add (choiceRow2, "7, 2, L, B"); | 564 | panel.add(choiceRow2, "7, 2, L, B"); |
582 | panel.add (labelAlignH, "0, 4, 3, 4"); | 565 | panel.add(labelAlignH, "0, 4, 3, 4"); |
583 | panel.add (choiceAlignH, "5, 4, 7, 4"); | 566 | panel.add(choiceAlignH, "5, 4, 7, 4"); |
584 | panel.add (labelAlignV, "0, 6, 3, 6"); | 567 | panel.add(labelAlignV, "0, 6, 3, 6"); |
585 | panel.add (choiceAlignV, "5, 6, 7, 6"); | 568 | panel.add(choiceAlignV, "5, 6, 7, 6"); |
586 | 569 | ||
587 | // Prompt user | 570 | // Prompt user |
588 | String button[] = {"Update Smiley", "Remove Smiley", "Cancel"}; | 571 | String button[] = {"Update Smiley", "Remove Smiley", "Cancel"}; |
589 | 572 | ||
590 | GeneralDialog dialog = new GeneralDialog | 573 | GeneralDialog dialog = new GeneralDialog |
591 | (RadTool.this, "Update Smiley", "", button, null, panel); | 574 | (RadTool.this, "Update Smiley", "", button, null, panel); |
592 | 575 | ||
593 | String answer = dialog.promptUser(); | 576 | String answer = dialog.promptUser(); |
594 | 577 | ||
595 | // Update constraints applied to this Smiley | 578 | // Update constraints applied to this Smiley |
596 | if (answer.equals("Update Smiley")) | 579 | if (answer.equals("Update Smiley")) { |
597 | { | ||
598 | // Get columns | 580 | // Get columns |
599 | int col1 = choiceCol1.getSelectedIndex() + 1; | 581 | int col1 = choiceCol1.getSelectedIndex() + 1; |
600 | int col2 = choiceCol2.getSelectedIndex() + 1; | 582 | int col2 = choiceCol2.getSelectedIndex() + 1; |
601 | int row1 = choiceRow1.getSelectedIndex() + 1; | 583 | int row1 = choiceRow1.getSelectedIndex() + 1; |
602 | int row2 = choiceRow2.getSelectedIndex() + 1; | 584 | int row2 = choiceRow2.getSelectedIndex() + 1; |
603 | 585 | ||
604 | // Make sure col1 < col2 | 586 | // Make sure col1 < col2 |
605 | if (col1 > col2) | 587 | if (col1 > col2) { |
606 | { | ||
607 | int temp = col1; | 588 | int temp = col1; |
608 | col1 = col2; | 589 | col1 = col2; |
609 | col2 = temp; | 590 | col2 = temp; |
610 | } | 591 | } |
611 | 592 | ||
612 | // Make sure row1 < row2 | 593 | // Make sure row1 < row2 |
613 | if (row1 > row2) | 594 | if (row1 > row2) { |
614 | { | ||
615 | int temp = row1; | 595 | int temp = row1; |
616 | row1 = row2; | 596 | row1 = row2; |
617 | row2 = temp; | 597 | row2 = temp; |
@@ -624,7 +604,7 @@ public class RadTool extends Frame implements ActionListener | |||
624 | c.row2 = row2; | 604 | c.row2 = row2; |
625 | c.hAlign = choiceAlignH.getSelectedIndex(); | 605 | c.hAlign = choiceAlignH.getSelectedIndex(); |
626 | c.vAlign = choiceAlignV.getSelectedIndex(); | 606 | c.vAlign = choiceAlignV.getSelectedIndex(); |
627 | layout.setConstraints (this, c); | 607 | layout.setConstraints(this, c); |
628 | 608 | ||
629 | // Repaint and layout container since layout has changed | 609 | // Repaint and layout container since layout has changed |
630 | Container container = getParent(); | 610 | Container container = getParent(); |
@@ -632,16 +612,14 @@ public class RadTool extends Frame implements ActionListener | |||
632 | container.repaint(); | 612 | container.repaint(); |
633 | } | 613 | } |
634 | // Remove Smiley | 614 | // Remove Smiley |
635 | else if (answer.equals("Remove Smiley")) | 615 | else if (answer.equals("Remove Smiley")) { |
636 | { | ||
637 | Container container = getParent(); | 616 | Container container = getParent(); |
638 | container.remove (this); | 617 | container.remove(this); |
639 | container.doLayout(); | 618 | container.doLayout(); |
640 | container.repaint(); | 619 | container.repaint(); |
641 | } | 620 | } |
642 | } | 621 | } |
643 | } | 622 | } |
644 | 623 | ||
645 | 624 | ||
646 | |||
647 | } | 625 | } |
diff --git a/lib/example/Simple.java b/lib/example/Simple.java index 3ff9fb9..b49f8df 100644 --- a/lib/example/Simple.java +++ b/lib/example/Simple.java | |||
@@ -1,62 +1,58 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Button; | |
5 | import java.awt.*; | 5 | import java.awt.Frame; |
6 | import java.awt.event.*; | 6 | import java.awt.event.WindowAdapter; |
7 | import java.awt.event.WindowEvent; | ||
7 | import layout.TableLayout; | 8 | import layout.TableLayout; |
8 | 9 | ||
9 | 10 | ||
10 | 11 | public class Simple { | |
11 | public class Simple | ||
12 | { | ||
13 | 12 | ||
14 | 13 | ||
15 | 14 | public static void main(String args[]) { | |
16 | public static void main (String args[]) | ||
17 | { | ||
18 | // Create a frame | 15 | // Create a frame |
19 | Frame frame = new Frame("Example of TableLayout"); | 16 | Frame frame = new Frame("Example of TableLayout"); |
20 | frame.setBounds (100, 100, 300, 300); | 17 | frame.setBounds(100, 100, 300, 300); |
21 | 18 | ||
22 | // Create a TableLayout for the frame | 19 | // Create a TableLayout for the frame |
23 | double border = 10; | 20 | double border = 10; |
24 | double size[][] = | 21 | double size[][] = |
25 | {{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns | 22 | {{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns |
26 | {border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows | 23 | {border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows |
27 | 24 | ||
28 | frame.setLayout (new TableLayout(size)); | 25 | frame.setLayout(new TableLayout(size)); |
29 | 26 | ||
30 | // Create some buttons | 27 | // Create some buttons |
31 | String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"}; | 28 | String label[] = |
29 | {"Top", "Bottom", "Left", "Right", "Center", "Overlap"}; | ||
32 | Button button[] = new Button[label.length]; | 30 | Button button[] = new Button[label.length]; |
33 | 31 | ||
34 | for (int i = 0; i < label.length; i++) | 32 | for (int i = 0; i < label.length; i++) { |
35 | button[i] = new Button(label[i]); | 33 | button[i] = new Button(label[i]); |
34 | } | ||
36 | 35 | ||
37 | // Add buttons | 36 | // Add buttons |
38 | frame.add (button[0], "1, 1, 5, 1"); // Top | 37 | frame.add(button[0], "1, 1, 5, 1"); // Top |
39 | frame.add (button[1], "1, 5, 5, 5"); // Bottom | 38 | frame.add(button[1], "1, 5, 5, 5"); // Bottom |
40 | frame.add (button[2], "1, 3 "); // Left | 39 | frame.add(button[2], "1, 3 "); // Left |
41 | frame.add (button[3], "5, 3 "); // Right | 40 | frame.add(button[3], "5, 3 "); // Right |
42 | frame.add (button[4], "3, 3, c, c"); // Center | 41 | frame.add(button[4], "3, 3, c, c"); // Center |
43 | frame.add (button[5], "3, 3, 3, 5"); // Overlap | 42 | frame.add(button[5], "3, 3, 3, 5"); // Overlap |
44 | 43 | ||
45 | // Allow user to close the window to terminate the program | 44 | // Allow user to close the window to terminate the program |
46 | frame.addWindowListener | 45 | frame.addWindowListener |
47 | (new WindowAdapter() | 46 | (new WindowAdapter() { |
48 | { | 47 | public void windowClosing(WindowEvent e) { |
49 | public void windowClosing (WindowEvent e) | 48 | System.exit(0); |
50 | { | 49 | } |
51 | System.exit (0); | 50 | } |
52 | } | ||
53 | } | ||
54 | ); | 51 | ); |
55 | 52 | ||
56 | // Show frame | 53 | // Show frame |
57 | frame.show(); | 54 | frame.show(); |
58 | } | 55 | } |
59 | 56 | ||
60 | 57 | ||
61 | |||
62 | } \ No newline at end of file | 58 | } \ No newline at end of file |
diff --git a/lib/example/TypicalGui.java b/lib/example/TypicalGui.java index ab80ff1..e44a371 100644 --- a/lib/example/TypicalGui.java +++ b/lib/example/TypicalGui.java | |||
@@ -1,179 +1,158 @@ | |||
1 | package example; | 1 | package example; |
2 | 2 | ||
3 | 3 | ||
4 | 4 | import java.awt.Color; | |
5 | import java.awt.*; | 5 | import java.awt.Component; |
6 | import java.awt.event.*; | 6 | import java.awt.Container; |
7 | import javax.swing.*; | 7 | import java.awt.Dimension; |
8 | import java.awt.Graphics; | ||
9 | import java.awt.event.WindowAdapter; | ||
10 | import java.awt.event.WindowEvent; | ||
11 | import javax.swing.JButton; | ||
12 | import javax.swing.JFrame; | ||
13 | import javax.swing.JMenu; | ||
14 | import javax.swing.JMenuBar; | ||
15 | import javax.swing.JMenuItem; | ||
16 | import javax.swing.JPanel; | ||
17 | import javax.swing.JTextPane; | ||
8 | import layout.TableLayout; | 18 | import layout.TableLayout; |
9 | 19 | ||
10 | 20 | ||
21 | public class TypicalGui extends JFrame { | ||
22 | |||
23 | |||
24 | public TypicalGui() { | ||
25 | super("A Typical GUI"); | ||
11 | 26 | ||
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(); | 27 | Container pane = getContentPane(); |
29 | 28 | ||
30 | double b = 10; | 29 | double b = 10; |
31 | double f = TableLayout.FILL; | 30 | double f = TableLayout.FILL; |
32 | double p = TableLayout.PREFERRED; | 31 | double p = TableLayout.PREFERRED; |
33 | double size[][] = {{b, f, 5, p, 5, p, b}, {p, b, f, 10, p, b}}; | 32 | double size[][] = {{b, f, 5, p, 5, p, b}, {p, b, f, 10, p, b}}; |
34 | TableLayout layout = new TableLayout(size); | 33 | TableLayout layout = new TableLayout(size); |
35 | pane.setLayout (layout); | 34 | pane.setLayout(layout); |
36 | 35 | ||
37 | addMenu(pane); | 36 | addMenu(pane); |
38 | addCommandButtons(pane, layout); | 37 | addCommandButtons(pane, layout); |
39 | addColorBoxes(pane, layout); | 38 | addColorBoxes(pane, layout); |
40 | addTextArea(pane, layout); | 39 | addTextArea(pane, layout); |
41 | 40 | ||
42 | allowClosing(); | 41 | allowClosing(); |
43 | setSize (640, 480); | 42 | setSize(640, 480); |
44 | show(); | 43 | show(); |
45 | } | 44 | } |
46 | 45 | ||
47 | 46 | public static void main(String args[]) { | |
48 | 47 | new TypicalGui(); | |
49 | public void addMenu (Container pane) | 48 | } |
50 | { | 49 | |
50 | public void addMenu(Container pane) { | ||
51 | JMenuBar menuBar = new JMenuBar(); | 51 | JMenuBar menuBar = new JMenuBar(); |
52 | 52 | ||
53 | String menuText[] = {"File", "Edit", "View", "Help"}; | 53 | String menuText[] = {"File", "Edit", "View", "Help"}; |
54 | String itemText[][] = | 54 | String itemText[][] = |
55 | {{"New", "Open", "Save", "Print", "Exit"}, | 55 | {{"New", "Open", "Save", "Print", "Exit"}, |
56 | {"Cut", "Copy", "Paste"}, | 56 | {"Cut", "Copy", "Paste"}, |
57 | {"Zoom in", "Zoom out"}, | 57 | {"Zoom in", "Zoom out"}, |
58 | {"About", "Index", "Search"}}; | 58 | {"About", "Index", "Search"}}; |
59 | 59 | ||
60 | for (int i = 0; i < menuText.length; i++) | 60 | for (int i = 0; i < menuText.length; i++) { |
61 | { | ||
62 | JMenu menu = new JMenu(menuText[i]); | 61 | JMenu menu = new JMenu(menuText[i]); |
63 | menuBar.add (menu); | 62 | menuBar.add(menu); |
64 | 63 | ||
65 | for (int j = 0; j < itemText[i].length; j++) | 64 | for (int j = 0; j < itemText[i].length; j++) { |
66 | { | ||
67 | JMenuItem item = new JMenuItem(itemText[i][j]); | 65 | JMenuItem item = new JMenuItem(itemText[i][j]); |
68 | menu.add (item); | 66 | menu.add(item); |
69 | } | 67 | } |
70 | } | 68 | } |
71 | 69 | ||
72 | pane.add (menuBar, "0, 0, 6, 0"); | 70 | pane.add(menuBar, "0, 0, 6, 0"); |
73 | } | 71 | } |
74 | 72 | ||
75 | |||
76 | 73 | ||
77 | public void addCommandButtons (Container pane, TableLayout layout) | 74 | public void addCommandButtons(Container pane, TableLayout layout) { |
78 | { | ||
79 | JPanel buttonPanel = new JPanel(); | 75 | JPanel buttonPanel = new JPanel(); |
80 | pane.add (buttonPanel, "1, 4, 5, 4"); | 76 | pane.add(buttonPanel, "1, 4, 5, 4"); |
81 | 77 | ||
82 | for (int i = 1; i <= 5; i++) | 78 | for (int i = 1; i <= 5; i++) { |
83 | { | ||
84 | JButton button = new JButton("Button " + i); | 79 | JButton button = new JButton("Button " + i); |
85 | buttonPanel.add (button); | 80 | buttonPanel.add(button); |
86 | } | 81 | } |
87 | } | 82 | } |
88 | 83 | ||
89 | 84 | ||
90 | 85 | public void addColorBoxes(Container pane, TableLayout layout) { | |
91 | public void addColorBoxes (Container pane, TableLayout layout) | ||
92 | { | ||
93 | Color color[][] = | 86 | Color color[][] = |
94 | {{Color.white, Color.black}, | 87 | {{Color.white, Color.black}, |
95 | {Color.green, Color.blue}, | 88 | {Color.green, Color.blue}, |
96 | {Color.red, Color.yellow}, | 89 | {Color.red, Color.yellow}, |
97 | {Color.pink, Color.orange}, | 90 | {Color.pink, Color.orange}, |
98 | {Color.magenta, Color.cyan}}; | 91 | {Color.magenta, Color.cyan}}; |
99 | 92 | ||
100 | for (int i = 0; i < color.length; i++) | 93 | for (int i = 0; i < color.length; i++) { |
101 | { | ||
102 | // Add a row for spacing and a row for the color boxes | 94 | // Add a row for spacing and a row for the color boxes |
103 | layout.insertRow (2, TableLayout.PREFERRED); | 95 | layout.insertRow(2, TableLayout.PREFERRED); |
104 | layout.insertRow (2, 5); | 96 | layout.insertRow(2, 5); |
105 | 97 | ||
106 | // Add color boxes | 98 | // Add color boxes |
107 | pane.add (new ColorBox(color[i][0]), "3, 3"); | 99 | pane.add(new ColorBox(color[i][0]), "3, 3"); |
108 | pane.add (new ColorBox(color[i][1]), "5, 3"); | 100 | pane.add(new ColorBox(color[i][1]), "5, 3"); |
109 | } | 101 | } |
110 | 102 | ||
111 | // Remove the unnecessary leading space | 103 | // Remove the unnecessary leading space |
112 | layout.deleteRow (2); | 104 | layout.deleteRow(2); |
113 | } | 105 | } |
114 | 106 | ||
115 | 107 | ||
116 | 108 | public void addTextArea(Container pane, TableLayout layout) { | |
117 | public void addTextArea (Container pane, TableLayout layout) | ||
118 | { | ||
119 | int numRow = layout.getRow().length; | 109 | int numRow = layout.getRow().length; |
120 | JTextPane textArea = new JTextPane(); | 110 | JTextPane textArea = new JTextPane(); |
121 | pane.add (textArea, "1, 2, 1, " + (numRow - 4)); | 111 | pane.add(textArea, "1, 2, 1, " + (numRow - 4)); |
122 | } | 112 | } |
123 | 113 | ||
124 | 114 | ||
125 | 115 | public void allowClosing() { | |
126 | public void allowClosing () | ||
127 | { | ||
128 | addWindowListener | 116 | addWindowListener |
129 | (new WindowAdapter() | 117 | (new WindowAdapter() { |
130 | { | 118 | public void windowClosing(WindowEvent e) { |
131 | public void windowClosing (WindowEvent e) | 119 | System.exit(0); |
132 | { | 120 | } |
133 | System.exit (0); | 121 | } |
134 | } | ||
135 | } | ||
136 | ); | 122 | ); |
137 | } | 123 | } |
138 | 124 | ||
139 | 125 | ||
140 | |||
141 | //************************************************************************** | 126 | //************************************************************************** |
142 | //*** Inner classes *** | 127 | //*** Inner classes *** |
143 | //************************************************************************** | 128 | //************************************************************************** |
144 | 129 | ||
145 | 130 | ||
146 | 131 | protected class ColorBox extends Component { | |
147 | protected class ColorBox extends Component | ||
148 | { | ||
149 | protected Color color; | 132 | protected Color color; |
150 | 133 | ||
151 | protected ColorBox (Color color) | 134 | protected ColorBox(Color color) { |
152 | { | ||
153 | this.color = color; | 135 | this.color = color; |
154 | } | 136 | } |
155 | 137 | ||
156 | public void update (Graphics g) | 138 | public void update(Graphics g) { |
157 | { | 139 | paint(g); |
158 | paint (g); | ||
159 | } | 140 | } |
160 | 141 | ||
161 | public void paint (Graphics g) | 142 | public void paint(Graphics g) { |
162 | { | ||
163 | Dimension d = getSize(); | 143 | Dimension d = getSize(); |
164 | g.setColor (Color.black); | 144 | g.setColor(Color.black); |
165 | g.drawRect (0, 0, d.width - 1, d.height - 1); | 145 | g.drawRect(0, 0, d.width - 1, d.height - 1); |
166 | 146 | ||
167 | g.setColor (color); | 147 | g.setColor(color); |
168 | g.fillRect (1, 1, d.width - 1, d.height - 1); | 148 | g.fillRect(1, 1, d.width - 1, d.height - 1); |
169 | } | 149 | } |
170 | 150 | ||
171 | public Dimension getPreferredSize () | 151 | public Dimension getPreferredSize() { |
172 | { | 152 | return new Dimension(40, 20); |
173 | return new Dimension(40, 20);; | 153 | ; |
174 | } | 154 | } |
175 | } | 155 | } |
176 | 156 | ||
177 | 157 | ||
178 | |||
179 | } | 158 | } |
diff --git a/src/control/images/agree_notsure.png b/src/control/images/agree_notsure.png new file mode 100644 index 0000000..32dceb0 --- /dev/null +++ b/src/control/images/agree_notsure.png | |||
Binary files differ | |||
diff --git a/src/cppcheckplus/control/MyContentPanel.java b/src/cppcheckplus/control/MyContentPanel.java index 63d792a..f676cc8 100644 --- a/src/cppcheckplus/control/MyContentPanel.java +++ b/src/cppcheckplus/control/MyContentPanel.java | |||
@@ -1,16 +1,12 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import java.awt.BorderLayout; | 3 | import java.awt.BorderLayout; |
5 | |||
6 | import javax.swing.JPanel; | 4 | import javax.swing.JPanel; |
7 | 5 | ||
8 | public class MyContentPanel extends JPanel | 6 | public class MyContentPanel extends JPanel { |
9 | { | 7 | public MyContentPanel() { |
10 | public MyContentPanel() | 8 | super(); |
11 | { | 9 | setLayout(new BorderLayout()); |
12 | super(); | 10 | setBackground(MyContorlUtil.CONTENT_PANE_BACKGROUND); |
13 | setLayout(new BorderLayout()); | 11 | } |
14 | setBackground(MyContorlUtil.CONTENT_PANE_BACKGROUND); | ||
15 | } | ||
16 | } | 12 | } |
diff --git a/src/cppcheckplus/control/MyHeader.java b/src/cppcheckplus/control/MyHeader.java index 1b71704..2cd11b8 100644 --- a/src/cppcheckplus/control/MyHeader.java +++ b/src/cppcheckplus/control/MyHeader.java | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import java.awt.BorderLayout; | 3 | import java.awt.BorderLayout; |
@@ -13,7 +12,6 @@ import java.awt.TexturePaint; | |||
13 | import java.awt.event.MouseAdapter; | 12 | import java.awt.event.MouseAdapter; |
14 | import java.awt.event.MouseEvent; | 13 | import java.awt.event.MouseEvent; |
15 | import java.awt.event.MouseListener; | 14 | import java.awt.event.MouseListener; |
16 | |||
17 | import javax.swing.BorderFactory; | 15 | import javax.swing.BorderFactory; |
18 | import javax.swing.ImageIcon; | 16 | import javax.swing.ImageIcon; |
19 | import javax.swing.JComponent; | 17 | import javax.swing.JComponent; |
@@ -22,180 +20,167 @@ import javax.swing.JPanel; | |||
22 | import javax.swing.border.Border; | 20 | import javax.swing.border.Border; |
23 | 21 | ||
24 | 22 | ||
25 | 23 | public class MyHeader extends JPanel { | |
26 | public class MyHeader extends JPanel | 24 | public static final ImageIcon RIGHT_ARROW_ICON = |
27 | { | 25 | MyContorlUtil.getImageIcon("control/images/shrink_handler_right.png"); |
28 | public static final ImageIcon RIGHT_ARROW_ICON = MyContorlUtil.getImageIcon("control/images/shrink_handler_right.png"); | 26 | public static final ImageIcon LEFT_ARROW_ICON = |
29 | public static final ImageIcon LEFT_ARROW_ICON = MyContorlUtil.getImageIcon("control/images/shrink_handler_left.png"); | 27 | MyContorlUtil.getImageIcon("control/images/shrink_handler_left.png"); |
30 | private Color titleColor; | 28 | private Color titleColor; |
31 | private boolean shrinked; | 29 | private boolean shrinked; |
32 | private ImageIcon backgroundImageIcon; | 30 | private ImageIcon backgroundImageIcon; |
33 | private Image backgroundLeftImage; | 31 | private Image backgroundLeftImage; |
34 | private Image backgroundRightImage; | 32 | private Image backgroundRightImage; |
35 | private TexturePaint paint; | 33 | private TexturePaint paint; |
36 | private int preferredHeight; | 34 | private int preferredHeight; |
37 | private JLabel lbResizeHandler; | 35 | private JLabel lbResizeHandler; |
38 | private JLabel lbShrinkHandler; | 36 | private JLabel lbShrinkHandler; |
39 | private JLabel lbTitle; | 37 | private JLabel lbTitle; |
40 | private int normalPreferredWidth; | 38 | private int normalPreferredWidth; |
41 | private MyListSplitListener splitListener; | 39 | private MyListSplitListener splitListener; |
42 | private MouseListener shrinkListener; | 40 | private MouseListener shrinkListener; |
43 | 41 | ||
44 | public MyHeader() | 42 | public MyHeader() { |
45 | { | 43 | super(); |
46 | super(); | 44 | titleColor = new Color(215, 215, 216); |
47 | titleColor = new Color(215, 215, 216); | 45 | shrinked = false; |
48 | shrinked = false; | 46 | backgroundImageIcon = |
49 | backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/header_background.png"); | 47 | MyContorlUtil.getImageIcon("control/images/header_background.png"); |
50 | backgroundLeftImage = MyContorlUtil.getImage("control/images/header_background_left.png"); | 48 | backgroundLeftImage = |
51 | backgroundRightImage = MyContorlUtil.getImage("control/images/header_background_right.png"); | 49 | MyContorlUtil.getImage("control/images/header_background_left.png"); |
52 | paint = MyContorlUtil.createTexturePaint("control/images/header_background.png"); | 50 | backgroundRightImage = MyContorlUtil.getImage( |
53 | preferredHeight = backgroundImageIcon.getIconHeight(); | 51 | "control/images/header_background_right.png"); |
54 | lbResizeHandler = new JLabel(MyContorlUtil.getImageIcon("control/images/resize_handler.png")); | 52 | paint = MyContorlUtil.createTexturePaint( |
55 | lbShrinkHandler = new JLabel(getShrinkIcon(shrinked)); | 53 | "control/images/header_background.png"); |
56 | lbTitle = new JLabel(); | 54 | preferredHeight = backgroundImageIcon.getIconHeight(); |
57 | normalPreferredWidth = 0; | 55 | lbResizeHandler = new JLabel( |
58 | splitListener = createSplitListener(); | 56 | MyContorlUtil.getImageIcon("control/images/resize_handler.png")); |
59 | shrinkListener = new MouseAdapter() { | 57 | lbShrinkHandler = new JLabel(getShrinkIcon(shrinked)); |
60 | public void mouseClicked(MouseEvent e) | 58 | lbTitle = new JLabel(); |
61 | { | 59 | normalPreferredWidth = 0; |
62 | changeShrink(); | 60 | splitListener = createSplitListener(); |
63 | } | 61 | shrinkListener = new MouseAdapter() { |
64 | }; | 62 | public void mouseClicked(MouseEvent e) { |
65 | init(); | 63 | changeShrink(); |
66 | } | 64 | } |
67 | 65 | }; | |
68 | protected MyListSplitListener createSplitListener() | 66 | init(); |
69 | { | 67 | } |
70 | return new MyListSplitListener(this); | 68 | |
71 | } | 69 | protected MyListSplitListener createSplitListener() { |
72 | 70 | return new MyListSplitListener(this); | |
73 | protected Border createBorder() | 71 | } |
74 | { | 72 | |
75 | return BorderFactory.createEmptyBorder(4, 7, 0, 0); | 73 | protected Border createBorder() { |
76 | } | 74 | return BorderFactory.createEmptyBorder(4, 7, 0, 0); |
77 | 75 | } | |
78 | private void init() | 76 | |
79 | { | 77 | private void init() { |
80 | setBorder(createBorder()); | 78 | setBorder(createBorder()); |
81 | setOpaque(false); | 79 | setOpaque(false); |
82 | setLayout(new BorderLayout()); | 80 | setLayout(new BorderLayout()); |
83 | add(lbResizeHandler, getResizeHandlerLayoutConstraint()); | 81 | add(lbResizeHandler, getResizeHandlerLayoutConstraint()); |
84 | add(lbShrinkHandler, getShrinkHandlerLayoutConstraint()); | 82 | add(lbShrinkHandler, getShrinkHandlerLayoutConstraint()); |
85 | JComponent centerComponent = getCenterComponent(); | 83 | JComponent centerComponent = getCenterComponent(); |
86 | if (centerComponent != null) | 84 | if (centerComponent != null) { |
87 | add(centerComponent, "Center"); | 85 | add(centerComponent, "Center"); |
88 | lbResizeHandler.addMouseMotionListener(splitListener); | 86 | } |
89 | lbResizeHandler.addMouseListener(splitListener); | 87 | lbResizeHandler.addMouseMotionListener(splitListener); |
90 | lbShrinkHandler.addMouseListener(shrinkListener); | 88 | lbResizeHandler.addMouseListener(splitListener); |
91 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); | 89 | lbShrinkHandler.addMouseListener(shrinkListener); |
92 | lbTitle.setForeground(titleColor); | 90 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); |
93 | lbTitle.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 0)); | 91 | lbTitle.setForeground(titleColor); |
94 | updateCursor(); | 92 | lbTitle.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 0)); |
95 | lbShrinkHandler.setBorder(BorderFactory.createEmptyBorder(0, 8, 2, 5)); | 93 | updateCursor(); |
96 | } | 94 | lbShrinkHandler.setBorder(BorderFactory.createEmptyBorder(0, 8, 2, 5)); |
97 | 95 | } | |
98 | protected JComponent getCenterComponent() | 96 | |
99 | { | 97 | protected JComponent getCenterComponent() { |
100 | return lbTitle; | 98 | return lbTitle; |
101 | } | 99 | } |
102 | 100 | ||
103 | protected Object getResizeHandlerLayoutConstraint() | 101 | protected Object getResizeHandlerLayoutConstraint() { |
104 | { | 102 | return "West"; |
105 | return "West"; | 103 | } |
106 | } | 104 | |
107 | 105 | protected Object getShrinkHandlerLayoutConstraint() { | |
108 | protected Object getShrinkHandlerLayoutConstraint() | 106 | return "East"; |
109 | { | 107 | } |
110 | return "East"; | 108 | |
111 | } | 109 | protected void paintComponent(Graphics g) { |
112 | 110 | Graphics2D g2d = (Graphics2D) g; | |
113 | protected void paintComponent(Graphics g) | 111 | g2d.setPaint(paint); |
114 | { | 112 | g2d.fillRect(0, 0, getWidth(), getHeight()); |
115 | Graphics2D g2d = (Graphics2D)g; | 113 | g2d.drawImage(backgroundLeftImage, 0, 0, null); |
116 | g2d.setPaint(paint); | 114 | int x = getWidth() - backgroundRightImage.getWidth(null); |
117 | g2d.fillRect(0, 0, getWidth(), getHeight()); | 115 | int y = 0; |
118 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | 116 | g2d.drawImage(backgroundRightImage, x, y, null); |
119 | int x = getWidth() - backgroundRightImage.getWidth(null); | 117 | } |
120 | int y = 0; | 118 | |
121 | g2d.drawImage(backgroundRightImage, x, y, null); | 119 | public Dimension getPreferredSize() { |
122 | } | 120 | return new Dimension(super.getPreferredSize().width, preferredHeight); |
123 | 121 | } | |
124 | public Dimension getPreferredSize() | 122 | |
125 | { | 123 | public void revalidateParent() { |
126 | return new Dimension(super.getPreferredSize().width, preferredHeight); | 124 | if (getParent() instanceof JComponent) { |
127 | } | 125 | ((JComponent) getParent()).revalidate(); |
128 | 126 | } | |
129 | public void revalidateParent() | 127 | } |
130 | { | 128 | |
131 | if (getParent() instanceof JComponent) | 129 | public void changeShrink() { |
132 | ((JComponent)getParent()).revalidate(); | 130 | setShrink(!isShrinked()); |
133 | } | 131 | } |
134 | 132 | ||
135 | public void changeShrink() | 133 | public void setShrink(boolean shrinked) { |
136 | { | 134 | if (shrinked != this.shrinked) { |
137 | setShrink(!isShrinked()); | 135 | Container parent = getParent(); |
138 | } | 136 | Dimension size = parent.getPreferredSize(); |
139 | 137 | if (shrinked) { | |
140 | public void setShrink(boolean shrinked) | 138 | normalPreferredWidth = size.width; |
141 | { | 139 | size = new Dimension(getShrinkedWidth(), size.height); |
142 | if (shrinked != this.shrinked) | 140 | } else { |
143 | { | 141 | int width = normalPreferredWidth; |
144 | Container parent = getParent(); | 142 | int height = parent.getPreferredSize().height; |
145 | Dimension size = parent.getPreferredSize(); | 143 | size = new Dimension(width, height); |
146 | if (shrinked) | 144 | } |
147 | { | 145 | parent.setPreferredSize(size); |
148 | normalPreferredWidth = size.width; | 146 | lbShrinkHandler.setIcon(getShrinkIcon(shrinked)); |
149 | size = new Dimension(getShrinkedWidth(), size.height); | 147 | revalidateParent(); |
150 | } else | 148 | this.shrinked = shrinked; |
151 | { | 149 | updateCursor(); |
152 | int width = normalPreferredWidth; | 150 | lbTitle.setVisible(!shrinked); |
153 | int height = parent.getPreferredSize().height; | 151 | lbResizeHandler.setVisible(!shrinked); |
154 | size = new Dimension(width, height); | 152 | } |
155 | } | 153 | } |
156 | parent.setPreferredSize(size); | 154 | |
157 | lbShrinkHandler.setIcon(getShrinkIcon(shrinked)); | 155 | protected ImageIcon getShrinkIcon(boolean shrinked) { |
158 | revalidateParent(); | 156 | if (shrinked) { |
159 | this.shrinked = shrinked; | 157 | return LEFT_ARROW_ICON; |
160 | updateCursor(); | 158 | } else { |
161 | lbTitle.setVisible(!shrinked); | 159 | return RIGHT_ARROW_ICON; |
162 | lbResizeHandler.setVisible(!shrinked); | 160 | } |
163 | } | 161 | } |
164 | } | 162 | |
165 | 163 | private void updateCursor() { | |
166 | protected ImageIcon getShrinkIcon(boolean shrinked) | 164 | if (shrinked) { |
167 | { | 165 | lbResizeHandler.setCursor(Cursor.getDefaultCursor()); |
168 | if (shrinked) | 166 | } else { |
169 | return LEFT_ARROW_ICON; | 167 | lbResizeHandler.setCursor(Cursor.getPredefinedCursor(10)); |
170 | else | 168 | } |
171 | return RIGHT_ARROW_ICON; | 169 | } |
172 | } | 170 | |
173 | 171 | public boolean isShrinked() { | |
174 | private void updateCursor() | 172 | return shrinked; |
175 | { | 173 | } |
176 | if (shrinked) | 174 | |
177 | lbResizeHandler.setCursor(Cursor.getDefaultCursor()); | 175 | public String getTitle() { |
178 | else | 176 | return lbTitle.getText(); |
179 | lbResizeHandler.setCursor(Cursor.getPredefinedCursor(10)); | 177 | } |
180 | } | 178 | |
181 | 179 | public void setTitle(String title) { | |
182 | public boolean isShrinked() | 180 | lbTitle.setText(title); |
183 | { | 181 | } |
184 | return shrinked; | 182 | |
185 | } | 183 | protected int getShrinkedWidth() { |
186 | 184 | return 37; | |
187 | public void setTitle(String title) | 185 | } |
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 | } | 186 | } |
diff --git a/src/cppcheckplus/control/MyList.java b/src/cppcheckplus/control/MyList.java index 2a577ff..084ee74 100644 --- a/src/cppcheckplus/control/MyList.java +++ b/src/cppcheckplus/control/MyList.java | |||
@@ -1,68 +1,58 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
3 | import cppcheckplus.shortcut.MyShortcutItem; | ||
4 | import cppcheckplus.shortcut.MyShortcutItemClickListenter; | ||
4 | import java.awt.event.MouseEvent; | 5 | import java.awt.event.MouseEvent; |
5 | |||
6 | import javax.swing.JList; | 6 | import javax.swing.JList; |
7 | import javax.swing.event.MouseInputAdapter; | 7 | import javax.swing.event.MouseInputAdapter; |
8 | import javax.swing.event.MouseInputListener; | 8 | import javax.swing.event.MouseInputListener; |
9 | 9 | ||
10 | import cppcheckplus.shortcut.MyShortcutItem; | ||
11 | import cppcheckplus.shortcut.MyShortcutItemClickListenter; | ||
12 | 10 | ||
11 | public class MyList extends JList { | ||
12 | private MyShortcutItemClickListenter clickListenter; | ||
13 | |||
14 | public MyList() { | ||
15 | init(); | ||
16 | } | ||
17 | |||
18 | public void setListenter(MyShortcutItemClickListenter itemClickListenter) { | ||
19 | this.clickListenter = itemClickListenter; | ||
20 | MouseInputListener listener = new MouseInputAdapter() { | ||
21 | //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 | ||
22 | @Override | ||
23 | public void mouseMoved(MouseEvent e) { | ||
24 | int moveIndex = locationToIndex(e.getPoint()); | ||
25 | setSelectedIndex(moveIndex); | ||
26 | } | ||
27 | |||
28 | //移动出去之后,清除选中,从而触发渲染器 | ||
29 | @Override | ||
30 | public void mouseExited(MouseEvent e) { | ||
31 | getSelectionModel().clearSelection(); | ||
32 | } | ||
13 | 33 | ||
14 | public class MyList extends JList | 34 | @Override |
15 | { | 35 | public void mouseClicked(MouseEvent e) { |
16 | private MyShortcutItemClickListenter clickListenter; | 36 | //因为该JList是单选模式,所以取第一个选择的就可以了 |
17 | 37 | Object selObj = getSelectedValue(); | |
18 | public MyList() | 38 | if (selObj != null) { |
19 | { | 39 | MyShortcutItem item = (MyShortcutItem) selObj; |
20 | init(); | 40 | if (!item.isGroup()) { |
21 | } | 41 | clickListenter.ItemClick(item.getActionCommand()); |
22 | public void setListenter(MyShortcutItemClickListenter itemClickListenter) | 42 | } |
23 | { | 43 | } |
24 | this.clickListenter = itemClickListenter; | 44 | //itemClick.ItemClick(actionCommand) |
25 | MouseInputListener listener = new MouseInputAdapter() | 45 | } |
26 | { | 46 | }; |
27 | //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 | 47 | addMouseMotionListener(listener); |
28 | @Override | 48 | addMouseListener(listener); |
29 | public void mouseMoved(MouseEvent e) | 49 | } |
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 | 50 | ||
41 | @Override | 51 | private void init() { |
42 | public void mouseClicked(MouseEvent e) | 52 | setFont(MyContorlUtil.FONT_12_BOLD); |
43 | { | 53 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); |
44 | //因为该JList是单选模式,所以取第一个选择的就可以了 | 54 | setBackground(MyContorlUtil.LIST_BACKGROUND); |
45 | Object selObj = getSelectedValue(); | 55 | setCellRenderer(new MyListRenderer(this)); |
46 | if(selObj != null) | 56 | setSelectionMode(0); |
47 | { | 57 | } |
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 | } | 58 | } |
diff --git a/src/cppcheckplus/control/MyListRenderer.java b/src/cppcheckplus/control/MyListRenderer.java index 1495378..b407227 100644 --- a/src/cppcheckplus/control/MyListRenderer.java +++ b/src/cppcheckplus/control/MyListRenderer.java | |||
@@ -1,12 +1,12 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
3 | import cppcheckplus.shortcut.MyShortcutItem; | ||
4 | import cppcheckplus.shortcut.MyShortcutPanel; | ||
4 | import java.awt.BorderLayout; | 5 | import java.awt.BorderLayout; |
5 | import java.awt.Color; | 6 | import java.awt.Color; |
6 | import java.awt.Component; | 7 | import java.awt.Component; |
7 | import java.awt.Dimension; | 8 | import java.awt.Dimension; |
8 | import java.awt.Font; | 9 | import java.awt.Font; |
9 | |||
10 | import javax.swing.BorderFactory; | 10 | import javax.swing.BorderFactory; |
11 | import javax.swing.DefaultListCellRenderer; | 11 | import javax.swing.DefaultListCellRenderer; |
12 | import javax.swing.JLabel; | 12 | import javax.swing.JLabel; |
@@ -14,125 +14,111 @@ import javax.swing.JList; | |||
14 | import javax.swing.JPanel; | 14 | import javax.swing.JPanel; |
15 | import javax.swing.OverlayLayout; | 15 | import javax.swing.OverlayLayout; |
16 | 16 | ||
17 | import cppcheckplus.shortcut.MyShortcutItem; | ||
18 | import cppcheckplus.shortcut.MyShortcutPanel; | ||
19 | |||
20 | //快捷菜单 | 17 | //快捷菜单 |
21 | public class MyListRenderer extends DefaultListCellRenderer | 18 | public class MyListRenderer extends DefaultListCellRenderer { |
22 | { | 19 | private JPanel itemRender; |
23 | private JPanel itemRender; | 20 | private int separatorHeight = 30; |
24 | private int separatorHeight = 30; | 21 | //每组List的分割Group |
25 | //每组List的分割Group | 22 | private JPanel separatorPanel; |
26 | private JPanel separatorPanel; | 23 | private JLabel separatorLabel; |
27 | private JLabel separatorLabel; | 24 | private MySeparator separator; |
28 | private MySeparator separator; | 25 | private Color itemTextColor; |
29 | private Color itemTextColor; | 26 | private Color separatorTextColor; |
30 | private Color separatorTextColor; | 27 | private Color itemSelectedBackground; |
31 | private Color itemSelectedBackground; | 28 | private Color itemSelectedBorder; |
32 | private Color itemSelectedBorder; | 29 | private Font separatorFont; |
33 | private Font separatorFont; | 30 | |
34 | 31 | public MyListRenderer(MyList list) { | |
35 | public MyListRenderer(MyList list) | 32 | super(); |
36 | { | 33 | itemRender = new JPanel(new BorderLayout()); |
37 | super(); | 34 | separatorPanel = new JPanel() { |
38 | itemRender = new JPanel(new BorderLayout()); | 35 | |
39 | separatorPanel = new JPanel() { | 36 | public Dimension getPreferredSize() { |
37 | Dimension size = super.getPreferredSize(); | ||
38 | return new Dimension(size.width, separatorHeight); | ||
39 | } | ||
40 | |||
41 | }; | ||
42 | //分割Group的样式 | ||
43 | separatorLabel = new JLabel(); | ||
44 | separator = new MySeparator(0); | ||
45 | separatorTextColor = Color.white; | ||
46 | separatorFont = MyContorlUtil.FONT_12_BOLD; | ||
47 | |||
48 | itemTextColor = MyContorlUtil.LIST_TEXT_COLOR; | ||
49 | itemSelectedBackground = new Color(199, 198, 200); | ||
50 | itemSelectedBorder = new Color(163, 163, 163); | ||
51 | itemRender.setOpaque(false); | ||
52 | itemRender.add(this, "Center"); | ||
53 | separatorPanel.setLayout(new OverlayLayout(separatorPanel)); | ||
54 | JPanel separatorHelpPane = new JPanel(new BorderLayout()); | ||
55 | separatorHelpPane.setBorder( | ||
56 | BorderFactory.createEmptyBorder(12, 0, 0, 0)); | ||
57 | separatorHelpPane.add(separator); | ||
58 | separatorHelpPane.setOpaque(false); | ||
59 | separatorPanel.setOpaque(false); | ||
60 | separatorLabel.setOpaque(true); | ||
61 | separatorLabel.setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
62 | separatorLabel.setForeground(separatorTextColor); | ||
63 | separatorLabel.setFont(separatorFont); | ||
64 | separatorLabel.setVerticalAlignment(1); | ||
65 | separatorLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); | ||
66 | JPanel labelHelpPane = new JPanel(new BorderLayout()); | ||
67 | labelHelpPane.setBorder(BorderFactory.createEmptyBorder(6, 15, 0, 0)); | ||
68 | labelHelpPane.add(separatorLabel, "West"); | ||
69 | labelHelpPane.setOpaque(false); | ||
70 | separatorPanel.add(labelHelpPane); | ||
71 | separatorPanel.add(separatorHelpPane); | ||
72 | } | ||
40 | 73 | ||
41 | public Dimension getPreferredSize() | 74 | public Component getListCellRendererComponent(JList list, Object value, |
42 | { | 75 | int index, boolean isSelected, |
43 | Dimension size = super.getPreferredSize(); | 76 | boolean cellHasFocus) { |
44 | return new Dimension(size.width, separatorHeight); | 77 | MyShortcutItem shortcutItem = (MyShortcutItem) value; |
45 | } | 78 | //Group的渲染 |
79 | if (shortcutItem.isGroup()) { | ||
80 | String groupName = shortcutItem.getText(); | ||
81 | separatorLabel.setText(groupName); | ||
82 | separatorPanel.setToolTipText(groupName); | ||
83 | if (list.getParent() instanceof MyShortcutPanel) { | ||
84 | MyShortcutPanel pane = (MyShortcutPanel) list.getParent(); | ||
85 | if (pane.isShrinked()) { | ||
86 | separatorLabel.setText(" "); | ||
87 | separatorLabel.setOpaque(false); | ||
88 | } else { | ||
89 | separatorLabel.setOpaque(true); | ||
90 | } | ||
91 | } | ||
92 | return separatorPanel; | ||
93 | } | ||
94 | //普通Item的渲染 | ||
95 | else { | ||
96 | setText(shortcutItem.getText()); | ||
97 | setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
98 | setToolTipText(shortcutItem.getToolTip()); | ||
99 | setIcon(shortcutItem.getIcon()); | ||
100 | } | ||
46 | 101 | ||
47 | }; | 102 | //判断List的父容器是否是快捷菜单面板,如果是,需要考虑收缩展开的处理 |
48 | //分割Group的样式 | 103 | if (list.getParent() instanceof MyShortcutPanel) { |
49 | separatorLabel = new JLabel(); | 104 | MyShortcutPanel pane = (MyShortcutPanel) list.getParent(); |
50 | separator = new MySeparator(0); | 105 | if (pane.isShrinked()) { |
51 | separatorTextColor = Color.white; | 106 | setBorder(BorderFactory.createEmptyBorder(2, 7, 1, 2)); |
52 | separatorFont = MyContorlUtil.FONT_12_BOLD; | 107 | setText(""); |
53 | 108 | } else { | |
54 | itemTextColor = MyContorlUtil.LIST_TEXT_COLOR; | 109 | setBorder(BorderFactory.createEmptyBorder(2, 20, 1, 2)); |
55 | itemSelectedBackground = new Color(199, 198, 200); | 110 | } |
56 | itemSelectedBorder = new Color(163, 163, 163); | 111 | } |
57 | itemRender.setOpaque(false); | 112 | if (isSelected) { |
58 | itemRender.add(this, "Center"); | 113 | setBackground(itemSelectedBackground); |
59 | separatorPanel.setLayout(new OverlayLayout(separatorPanel)); | 114 | itemRender.setBorder( |
60 | JPanel separatorHelpPane = new JPanel(new BorderLayout()); | 115 | BorderFactory.createLineBorder(itemSelectedBorder)); |
61 | separatorHelpPane.setBorder(BorderFactory.createEmptyBorder(12, 0, 0, 0)); | 116 | } else { |
62 | separatorHelpPane.add(separator); | 117 | itemRender.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
63 | separatorHelpPane.setOpaque(false); | 118 | } |
64 | separatorPanel.setOpaque(false); | 119 | setForeground(itemTextColor); |
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 | 120 | ||
79 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) | 121 | return itemRender; |
80 | { | 122 | } |
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 | 123 | ||
138 | } | 124 | } |
diff --git a/src/cppcheckplus/control/MyListSplitListener.java b/src/cppcheckplus/control/MyListSplitListener.java index 4ee8fea..b594f98 100644 --- a/src/cppcheckplus/control/MyListSplitListener.java +++ b/src/cppcheckplus/control/MyListSplitListener.java | |||
@@ -1,50 +1,43 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import java.awt.Dimension; | 3 | import java.awt.Dimension; |
5 | import java.awt.Point; | 4 | import java.awt.Point; |
6 | import java.awt.event.MouseEvent; | 5 | import java.awt.event.MouseEvent; |
7 | |||
8 | import javax.swing.JComponent; | 6 | import javax.swing.JComponent; |
9 | import javax.swing.event.MouseInputAdapter; | 7 | import javax.swing.event.MouseInputAdapter; |
10 | 8 | ||
11 | 9 | ||
12 | public class MyListSplitListener extends MouseInputAdapter | 10 | public class MyListSplitListener extends MouseInputAdapter { |
13 | { | 11 | protected Point lastPoint; |
14 | protected Point lastPoint; | 12 | protected MyHeader header; |
15 | protected MyHeader header; | 13 | |
16 | 14 | public MyListSplitListener(MyHeader header) { | |
17 | public MyListSplitListener(MyHeader header) | 15 | lastPoint = null; |
18 | { | 16 | this.header = null; |
19 | lastPoint = null; | 17 | this.header = header; |
20 | this.header = null; | 18 | } |
21 | this.header = header; | 19 | |
22 | } | 20 | public void mousePressed(MouseEvent e) { |
23 | 21 | if (!header.isShrinked()) { | |
24 | public void mousePressed(MouseEvent e) | 22 | lastPoint = e.getPoint(); |
25 | { | 23 | } |
26 | if (!header.isShrinked()) | 24 | } |
27 | lastPoint = e.getPoint(); | 25 | |
28 | } | 26 | public void mouseReleased(MouseEvent e) { |
29 | 27 | lastPoint = null; | |
30 | public void mouseReleased(MouseEvent e) | 28 | } |
31 | { | 29 | |
32 | lastPoint = null; | 30 | public void mouseDragged(MouseEvent e) { |
33 | } | 31 | if (!header.isShrinked() && lastPoint != null) { |
34 | 32 | JComponent parent = (JComponent) header.getParent(); | |
35 | public void mouseDragged(MouseEvent e) | 33 | Dimension size = parent.getPreferredSize(); |
36 | { | 34 | Point thisPoint = e.getPoint(); |
37 | if (!header.isShrinked() && lastPoint != null) | 35 | int xMovement = thisPoint.x - lastPoint.x; |
38 | { | 36 | size.width -= xMovement; |
39 | JComponent parent = (JComponent)header.getParent(); | 37 | size.width = Math.max(size.width, 37); |
40 | Dimension size = parent.getPreferredSize(); | 38 | parent.setPreferredSize(size); |
41 | Point thisPoint = e.getPoint(); | 39 | header.revalidateParent(); |
42 | int xMovement = thisPoint.x - lastPoint.x; | 40 | } |
43 | size.width -= xMovement; | 41 | } |
44 | size.width = Math.max(size.width, 37); | ||
45 | parent.setPreferredSize(size); | ||
46 | header.revalidateParent(); | ||
47 | } | ||
48 | } | ||
49 | 42 | ||
50 | } | 43 | } |
diff --git a/src/cppcheckplus/control/MySeparator.java b/src/cppcheckplus/control/MySeparator.java index f5ba4ad..a7769d7 100644 --- a/src/cppcheckplus/control/MySeparator.java +++ b/src/cppcheckplus/control/MySeparator.java | |||
@@ -1,40 +1,38 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import java.awt.Graphics; | 3 | import java.awt.Graphics; |
5 | import java.awt.Graphics2D; | 4 | import java.awt.Graphics2D; |
6 | import java.awt.Image; | 5 | import java.awt.Image; |
7 | import java.awt.TexturePaint; | 6 | import java.awt.TexturePaint; |
8 | |||
9 | import javax.swing.JSeparator; | 7 | import javax.swing.JSeparator; |
10 | 8 | ||
11 | 9 | ||
12 | public class MySeparator extends JSeparator | 10 | public class MySeparator extends JSeparator { |
13 | { | 11 | private Image image; |
14 | private Image image; | 12 | private TexturePaint paint; |
15 | private TexturePaint paint; | 13 | |
16 | 14 | public MySeparator() { | |
17 | public MySeparator() | 15 | image = |
18 | { | 16 | MyContorlUtil.getImage("control/images/separator_background.png"); |
19 | image = MyContorlUtil.getImage("control/images/separator_background.png"); | 17 | paint = MyContorlUtil.createTexturePaint( |
20 | paint = MyContorlUtil.createTexturePaint("control/images/separator_background.png"); | 18 | "control/images/separator_background.png"); |
21 | } | 19 | } |
22 | 20 | ||
23 | public MySeparator(int direction) | 21 | public MySeparator(int direction) { |
24 | { | 22 | super(direction); |
25 | super(direction); | 23 | image = |
26 | image = MyContorlUtil.getImage("control/images/separator_background.png"); | 24 | MyContorlUtil.getImage("control/images/separator_background.png"); |
27 | paint = MyContorlUtil.createTexturePaint("control/images/separator_background.png"); | 25 | paint = MyContorlUtil.createTexturePaint( |
28 | } | 26 | "control/images/separator_background.png"); |
29 | 27 | } | |
30 | public void paintComponent(Graphics g) | 28 | |
31 | { | 29 | public void paintComponent(Graphics g) { |
32 | Graphics2D g2d = (Graphics2D)g; | 30 | Graphics2D g2d = (Graphics2D) g; |
33 | g2d.setPaint(paint); | 31 | g2d.setPaint(paint); |
34 | int x = 0; | 32 | int x = 0; |
35 | int y = 0; | 33 | int y = 0; |
36 | int width = getWidth(); | 34 | int width = getWidth(); |
37 | int height = image.getHeight(null); | 35 | int height = image.getHeight(null); |
38 | g2d.fillRect(x, y, width, height); | 36 | g2d.fillRect(x, y, width, height); |
39 | } | 37 | } |
40 | } | 38 | } |
diff --git a/src/cppcheckplus/control/MyTextField.java b/src/cppcheckplus/control/MyTextField.java index d0ed080..1edae1e 100644 --- a/src/cppcheckplus/control/MyTextField.java +++ b/src/cppcheckplus/control/MyTextField.java | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import java.awt.Dimension; | 3 | import java.awt.Dimension; |
@@ -6,7 +5,6 @@ import java.awt.Graphics; | |||
6 | import java.awt.Graphics2D; | 5 | import java.awt.Graphics2D; |
7 | import java.awt.Image; | 6 | import java.awt.Image; |
8 | import java.awt.TexturePaint; | 7 | import java.awt.TexturePaint; |
9 | |||
10 | import javax.swing.BorderFactory; | 8 | import javax.swing.BorderFactory; |
11 | import javax.swing.ImageIcon; | 9 | import javax.swing.ImageIcon; |
12 | import javax.swing.JTextField; | 10 | import javax.swing.JTextField; |
@@ -14,49 +12,50 @@ import javax.swing.border.Border; | |||
14 | import javax.swing.plaf.metal.MetalTextFieldUI; | 12 | import javax.swing.plaf.metal.MetalTextFieldUI; |
15 | 13 | ||
16 | 14 | ||
17 | public class MyTextField extends JTextField | 15 | public class MyTextField extends JTextField { |
18 | { | 16 | private Image backgroundLeftImage; |
19 | private Image backgroundLeftImage; | 17 | private Image backgroundRightImage; |
20 | private Image backgroundRightImage; | 18 | private ImageIcon backgroundImageIcon; |
21 | private ImageIcon backgroundImageIcon; | 19 | private TexturePaint paint; |
22 | private TexturePaint paint; | 20 | private Border border; |
23 | private Border border; | 21 | |
24 | 22 | public MyTextField() { | |
25 | public MyTextField() | 23 | backgroundLeftImage = MyContorlUtil.getImage( |
26 | { | 24 | "control/images/textfield_background_left.png"); |
27 | backgroundLeftImage = MyContorlUtil.getImage("control/images/textfield_background_left.png"); | 25 | backgroundRightImage = MyContorlUtil.getImage( |
28 | backgroundRightImage = MyContorlUtil.getImage("control/images/textfield_background_right.png"); | 26 | "control/images/textfield_background_right.png"); |
29 | backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/textfield_background.png"); | 27 | backgroundImageIcon = MyContorlUtil.getImageIcon( |
30 | paint = MyContorlUtil.createTexturePaint("control/images/textfield_background.png"); | 28 | "control/images/textfield_background.png"); |
31 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); | 29 | paint = MyContorlUtil.createTexturePaint( |
32 | init(); | 30 | "control/images/textfield_background.png"); |
33 | } | 31 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); |
34 | public MyTextField(String text) | 32 | init(); |
35 | { | 33 | } |
36 | this(); | 34 | |
37 | setText(text); | 35 | public MyTextField(String text) { |
38 | } | 36 | this(); |
39 | 37 | setText(text); | |
40 | private void init() | 38 | } |
41 | { | 39 | |
42 | setBorder(border); | 40 | private void init() { |
43 | setUI(new MetalTextFieldUI() { | 41 | setBorder(border); |
44 | 42 | setUI(new MetalTextFieldUI() { | |
45 | protected void paintBackground(Graphics g) | 43 | |
46 | { | 44 | protected void paintBackground(Graphics g) { |
47 | Graphics2D g2d = (Graphics2D)g; | 45 | Graphics2D g2d = (Graphics2D) g; |
48 | g2d.setPaint(paint); | 46 | g2d.setPaint(paint); |
49 | g2d.fillRect(0, 0, getWidth(), getHeight()); | 47 | g2d.fillRect(0, 0, getWidth(), getHeight()); |
50 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | 48 | g2d.drawImage(backgroundLeftImage, 0, 0, null); |
51 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | 49 | g2d.drawImage(backgroundRightImage, |
52 | } | 50 | getWidth() - backgroundRightImage.getWidth(null), 0, null); |
53 | 51 | } | |
54 | }); | 52 | |
55 | } | 53 | }); |
56 | 54 | } | |
57 | public Dimension getPreferredSize() | 55 | |
58 | { | 56 | public Dimension getPreferredSize() { |
59 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | 57 | return new Dimension(super.getPreferredSize().width, |
60 | } | 58 | backgroundImageIcon.getIconHeight()); |
61 | 59 | } | |
60 | |||
62 | } | 61 | } |
diff --git a/src/cppcheckplus/control/MyToolbarButton.java b/src/cppcheckplus/control/MyToolbarButton.java index e709296..dff78cd 100644 --- a/src/cppcheckplus/control/MyToolbarButton.java +++ b/src/cppcheckplus/control/MyToolbarButton.java | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import java.awt.Color; | 3 | import java.awt.Color; |
@@ -8,89 +7,77 @@ import java.awt.Graphics; | |||
8 | import java.awt.Insets; | 7 | import java.awt.Insets; |
9 | import java.awt.event.MouseAdapter; | 8 | import java.awt.event.MouseAdapter; |
10 | import java.awt.event.MouseEvent; | 9 | import java.awt.event.MouseEvent; |
11 | |||
12 | import javax.swing.BorderFactory; | 10 | import javax.swing.BorderFactory; |
13 | import javax.swing.Icon; | 11 | import javax.swing.Icon; |
14 | import javax.swing.JButton; | 12 | import javax.swing.JButton; |
15 | import javax.swing.border.Border; | 13 | import javax.swing.border.Border; |
16 | 14 | ||
17 | public class MyToolbarButton extends JButton | 15 | public class MyToolbarButton extends JButton { |
18 | { | 16 | private int buttonSize; |
19 | private int buttonSize; | 17 | private Color roverBorderColor; |
20 | private Color roverBorderColor; | 18 | private Border roverBorder; |
21 | private Border roverBorder; | 19 | private Border emptyBorder; |
22 | private Border emptyBorder; | ||
23 | 20 | ||
24 | public MyToolbarButton() | 21 | public MyToolbarButton() { |
25 | { | 22 | super(); |
26 | super(); | 23 | buttonSize = 20; |
27 | buttonSize = 20; | 24 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; |
28 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; | 25 | roverBorder = new Border() { |
29 | roverBorder = new Border() { | ||
30 | 26 | ||
31 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | 27 | public void paintBorder(Component c, Graphics g, int x, int y, |
32 | { | 28 | int width, int height) { |
33 | g.setColor(roverBorderColor); | 29 | g.setColor(roverBorderColor); |
34 | g.drawRect(x, y, width - 1, height - 1); | 30 | g.drawRect(x, y, width - 1, height - 1); |
35 | } | 31 | } |
36 | 32 | ||
37 | public Insets getBorderInsets(Component c) | 33 | public Insets getBorderInsets(Component c) { |
38 | { | 34 | return new Insets(1, 1, 1, 1); |
39 | return new Insets(1, 1, 1, 1); | 35 | } |
40 | } | ||
41 | 36 | ||
42 | public boolean isBorderOpaque() | 37 | public boolean isBorderOpaque() { |
43 | { | 38 | return true; |
44 | return true; | 39 | } |
45 | } | 40 | }; |
46 | }; | 41 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); |
47 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); | 42 | init(); |
48 | init(); | 43 | } |
49 | } | ||
50 | 44 | ||
51 | private void init() | 45 | private void init() { |
52 | { | 46 | setVerticalAlignment(0); |
53 | setVerticalAlignment(0); | 47 | setFont(MyContorlUtil.FONT_12_BOLD); |
54 | setFont(MyContorlUtil.FONT_12_BOLD); | 48 | setOpaque(false); |
55 | setOpaque(false); | 49 | setBorder(emptyBorder); |
56 | setBorder(emptyBorder); | 50 | setContentAreaFilled(false); |
57 | setContentAreaFilled(false); | 51 | setFocusPainted(false); |
58 | setFocusPainted(false); | 52 | addMouseListener(new MouseAdapter() { |
59 | addMouseListener(new MouseAdapter() { | 53 | public void mouseEntered(MouseEvent e) { |
60 | public void mouseEntered(MouseEvent e) | 54 | setBorder(roverBorder); |
61 | { | 55 | } |
62 | setBorder(roverBorder); | ||
63 | } | ||
64 | 56 | ||
65 | public void mouseExited(MouseEvent e) | 57 | public void mouseExited(MouseEvent e) { |
66 | { | 58 | setBorder(emptyBorder); |
67 | setBorder(emptyBorder); | 59 | } |
68 | } | 60 | }); |
69 | }); | 61 | } |
70 | } | ||
71 | 62 | ||
72 | @Override | 63 | @Override |
73 | public void setIcon(Icon icon) | 64 | public void setIcon(Icon icon) { |
74 | { | 65 | super.setIcon(icon); |
75 | super.setIcon(icon); | 66 | if (icon == null) { |
76 | if (icon == null) | 67 | setPressedIcon(null); |
77 | { | 68 | setRolloverIcon(null); |
78 | setPressedIcon(null); | 69 | } else { |
79 | setRolloverIcon(null); | 70 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); |
80 | } else | 71 | setPressedIcon(pressedIcon); |
81 | { | 72 | } |
82 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); | 73 | } |
83 | setPressedIcon(pressedIcon); | ||
84 | } | ||
85 | } | ||
86 | 74 | ||
87 | 75 | ||
88 | @Override | 76 | @Override |
89 | public Dimension getPreferredSize() | 77 | public Dimension getPreferredSize() { |
90 | { | 78 | int width = super.getPreferredSize().width; |
91 | int width = super.getPreferredSize().width; | 79 | width = Math.max(width, buttonSize); |
92 | width = Math.max(width, buttonSize); | 80 | int height = buttonSize; |
93 | int height = buttonSize; | 81 | return new Dimension(width, height); |
94 | return new Dimension(width, height); | 82 | } |
95 | } | ||
96 | } | 83 | } |
diff --git a/src/cppcheckplus/control/UIFrame.java b/src/cppcheckplus/control/UIFrame.java index a2a04ab..bb15707 100644 --- a/src/cppcheckplus/control/UIFrame.java +++ b/src/cppcheckplus/control/UIFrame.java | |||
@@ -21,16 +21,9 @@ import java.awt.event.ActionEvent; | |||
21 | import java.awt.event.ActionListener; | 21 | import java.awt.event.ActionListener; |
22 | import java.awt.event.MouseAdapter; | 22 | import java.awt.event.MouseAdapter; |
23 | import java.awt.event.MouseEvent; | 23 | import java.awt.event.MouseEvent; |
24 | import java.io.BufferedReader; | ||
25 | import java.io.File; | 24 | import java.io.File; |
26 | import java.io.IOException; | ||
27 | import java.io.InputStream; | ||
28 | import java.io.InputStreamReader; | ||
29 | import java.io.UnsupportedEncodingException; | 25 | import java.io.UnsupportedEncodingException; |
30 | import java.nio.charset.StandardCharsets; | 26 | 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; | 27 | import javax.swing.BorderFactory; |
35 | import javax.swing.JComponent; | 28 | import javax.swing.JComponent; |
36 | import javax.swing.JFileChooser; | 29 | import javax.swing.JFileChooser; |
@@ -193,7 +186,8 @@ public class UIFrame extends JFrame { | |||
193 | if (src != null && src.length() != 0) { | 186 | if (src != null && src.length() != 0) { |
194 | new Thread() { | 187 | new Thread() { |
195 | public void run() { | 188 | public void run() { |
196 | ToolsRegistry.executeTool("flawfinder", src); | 189 | ToolsRegistry.executeTool("flawfinder", |
190 | src); | ||
197 | viewResult("flawfinder"); | 191 | viewResult("flawfinder"); |
198 | } | 192 | } |
199 | }.start(); | 193 | }.start(); |
diff --git a/src/cppcheckplus/control/XChartletFullScreenListenter.java b/src/cppcheckplus/control/XChartletFullScreenListenter.java index c7eca34..8890357 100644 --- a/src/cppcheckplus/control/XChartletFullScreenListenter.java +++ b/src/cppcheckplus/control/XChartletFullScreenListenter.java | |||
@@ -1,10 +1,8 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
4 | import javax.swing.JPanel; | 3 | import javax.swing.JPanel; |
5 | 4 | ||
6 | 5 | ||
7 | public interface XChartletFullScreenListenter | 6 | public interface XChartletFullScreenListenter { |
8 | { | 7 | public void fullScreen(JPanel chartPanellet); |
9 | public void fullScreen(JPanel chartPanellet); | ||
10 | } | 8 | } |
diff --git a/src/cppcheckplus/menu/MyMenu.java b/src/cppcheckplus/menu/MyMenu.java index 3570408..73cf5ab 100644 --- a/src/cppcheckplus/menu/MyMenu.java +++ b/src/cppcheckplus/menu/MyMenu.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.menu; | 1 | package cppcheckplus.menu; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Color; | 4 | import java.awt.Color; |
5 | import java.awt.Dimension; | 5 | import java.awt.Dimension; |
6 | import java.awt.Graphics; | 6 | import java.awt.Graphics; |
@@ -9,63 +9,57 @@ import javax.swing.BorderFactory; | |||
9 | import javax.swing.JMenu; | 9 | import javax.swing.JMenu; |
10 | import javax.swing.border.Border; | 10 | import javax.swing.border.Border; |
11 | 11 | ||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | 12 | ||
13 | public class MyMenu extends JMenu { | ||
14 | private Color backgroundColor; | ||
15 | private Color foregroundColor; | ||
16 | private int borderThickness; | ||
17 | private Border border; | ||
18 | private int preferredHeight; | ||
19 | |||
20 | public MyMenu() { | ||
21 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
22 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
23 | borderThickness = 1; | ||
24 | border = | ||
25 | BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
26 | preferredHeight = 25; | ||
27 | init(); | ||
28 | } | ||
14 | 29 | ||
15 | public class MyMenu extends JMenu | 30 | public MyMenu(String text) { |
16 | { | 31 | super(text); |
17 | private Color backgroundColor; | 32 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; |
18 | private Color foregroundColor; | 33 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; |
19 | private int borderThickness; | 34 | borderThickness = 1; |
20 | private Border border; | 35 | border = |
21 | private int preferredHeight; | 36 | BorderFactory.createLineBorder(backgroundColor, borderThickness); |
37 | preferredHeight = 25; | ||
38 | init(); | ||
39 | } | ||
22 | 40 | ||
23 | public MyMenu() | 41 | private void init() { |
24 | { | 42 | setForeground(foregroundColor); |
25 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | 43 | setFont(MyContorlUtil.FONT_14_BOLD); |
26 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | 44 | setOpaque(true); |
27 | borderThickness = 1; | 45 | setBackground(backgroundColor); |
28 | border = BorderFactory.createLineBorder(backgroundColor, borderThickness); | 46 | setBorder(border); |
29 | preferredHeight = 25; | 47 | } |
30 | init(); | ||
31 | } | ||
32 | 48 | ||
33 | public MyMenu(String text) | 49 | @Override |
34 | { | 50 | protected void paintComponent(Graphics g) { |
35 | super(text); | 51 | if (isSelected()) { |
36 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | 52 | Graphics2D g2d = (Graphics2D) g; |
37 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | 53 | g2d.setColor(MyContorlUtil.MENUITEM_SELECTED_BACKGROUND); |
38 | borderThickness = 1; | 54 | g2d.fillRect(0, 0, getWidth(), getHeight()); |
39 | border = BorderFactory.createLineBorder(backgroundColor, borderThickness); | 55 | super.paintComponent(g); |
40 | preferredHeight = 25; | 56 | } else { |
41 | init(); | 57 | super.paintComponent(g); |
42 | } | 58 | } |
59 | } | ||
43 | 60 | ||
44 | private void init() | 61 | @Override |
45 | { | 62 | public Dimension getPreferredSize() { |
46 | setForeground(foregroundColor); | 63 | return new Dimension(super.getPreferredSize().width, preferredHeight); |
47 | setFont(MyContorlUtil.FONT_14_BOLD); | 64 | } |
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 | } | 65 | } |
diff --git a/src/cppcheckplus/menu/MyMenuBar.java b/src/cppcheckplus/menu/MyMenuBar.java index 7d5d102..d1fd952 100644 --- a/src/cppcheckplus/menu/MyMenuBar.java +++ b/src/cppcheckplus/menu/MyMenuBar.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.menu; | 1 | package cppcheckplus.menu; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Dimension; | 4 | import java.awt.Dimension; |
5 | import java.awt.Graphics; | 5 | import java.awt.Graphics; |
6 | import java.awt.Graphics2D; | 6 | import java.awt.Graphics2D; |
@@ -11,46 +11,48 @@ import javax.swing.ImageIcon; | |||
11 | import javax.swing.JMenuBar; | 11 | import javax.swing.JMenuBar; |
12 | import javax.swing.border.Border; | 12 | import javax.swing.border.Border; |
13 | 13 | ||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | 14 | ||
15 | public class MyMenuBar extends JMenuBar { | ||
16 | |||
17 | private Image backgroundLeftImage; | ||
18 | private Image backgroundRightImage; | ||
19 | private ImageIcon backgroundImageIcon; | ||
20 | private TexturePaint paint; | ||
21 | private Border border; | ||
22 | |||
23 | public MyMenuBar() { | ||
24 | backgroundLeftImage = MyContorlUtil.getImage( | ||
25 | "control/images/menubar_background_left.png"); | ||
26 | backgroundRightImage = MyContorlUtil.getImage( | ||
27 | "control/images/menubar_background_right.png"); | ||
28 | backgroundImageIcon = | ||
29 | MyContorlUtil.getImageIcon("control/images/menubar_background.png"); | ||
30 | paint = MyContorlUtil.createTexturePaint( | ||
31 | "control/images/menubar_background.png"); | ||
32 | border = BorderFactory.createEmptyBorder(); | ||
33 | init(); | ||
34 | } | ||
35 | |||
36 | private void init() { | ||
37 | setBorder(border); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | protected void paintComponent(Graphics g) { | ||
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, | ||
48 | getWidth() - backgroundRightImage.getWidth(null), 0, null); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public Dimension getPreferredSize() { | ||
53 | return new Dimension(super.getPreferredSize().width, | ||
54 | backgroundImageIcon.getIconHeight()); | ||
55 | } | ||
16 | 56 | ||
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 | } | 57 | } |
56 | 58 | ||
diff --git a/src/cppcheckplus/menu/MyMenuItem.java b/src/cppcheckplus/menu/MyMenuItem.java index 6ac46e9..5b71233 100644 --- a/src/cppcheckplus/menu/MyMenuItem.java +++ b/src/cppcheckplus/menu/MyMenuItem.java | |||
@@ -1,52 +1,50 @@ | |||
1 | |||
2 | package cppcheckplus.menu; | 1 | package cppcheckplus.menu; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Color; | 4 | import java.awt.Color; |
5 | import java.awt.Dimension; | 5 | import java.awt.Dimension; |
6 | import javax.swing.BorderFactory; | 6 | import javax.swing.BorderFactory; |
7 | import javax.swing.JMenuItem; | 7 | import javax.swing.JMenuItem; |
8 | import javax.swing.border.Border; | 8 | import javax.swing.border.Border; |
9 | 9 | ||
10 | import cppcheckplus.control.MyContorlUtil; | 10 | public class MyMenuItem extends JMenuItem { |
11 | private static final long serialVersionUID = 1L; | ||
12 | private Color backgroundColor; | ||
13 | private Color foregroundColor; | ||
14 | private int borderThickness; | ||
15 | private Border border; | ||
16 | private int preferredHeight; | ||
17 | |||
18 | public MyMenuItem() { | ||
19 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
20 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
21 | borderThickness = 1; | ||
22 | border = | ||
23 | BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
24 | preferredHeight = 23; | ||
25 | init(); | ||
26 | } | ||
27 | |||
28 | public MyMenuItem(String text) { | ||
29 | super(text); | ||
30 | backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; | ||
31 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | ||
32 | borderThickness = 1; | ||
33 | border = | ||
34 | BorderFactory.createLineBorder(backgroundColor, borderThickness); | ||
35 | preferredHeight = 23; | ||
36 | init(); | ||
37 | } | ||
38 | |||
39 | private void init() { | ||
40 | setForeground(foregroundColor); | ||
41 | setFont(MyContorlUtil.FONT_14_BOLD); | ||
42 | setBackground(backgroundColor); | ||
43 | setBorder(border); | ||
44 | } | ||
11 | 45 | ||
12 | public class MyMenuItem extends JMenuItem | 46 | @Override |
13 | { | 47 | public Dimension getPreferredSize() { |
14 | private static final long serialVersionUID = 1L; | 48 | return new Dimension(super.getPreferredSize().width, preferredHeight); |
15 | private Color backgroundColor; | 49 | } |
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 | } | 50 | } |
diff --git a/src/cppcheckplus/menu/MyRootMenu.java b/src/cppcheckplus/menu/MyRootMenu.java index b5d442d..55a06d6 100644 --- a/src/cppcheckplus/menu/MyRootMenu.java +++ b/src/cppcheckplus/menu/MyRootMenu.java | |||
@@ -1,62 +1,53 @@ | |||
1 | |||
2 | |||
3 | package cppcheckplus.menu; | 1 | package cppcheckplus.menu; |
4 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
5 | import java.awt.Color; | 4 | import java.awt.Color; |
6 | import java.awt.Graphics; | 5 | import java.awt.Graphics; |
7 | import java.awt.Graphics2D; | 6 | import java.awt.Graphics2D; |
8 | import java.awt.TexturePaint; | 7 | import java.awt.TexturePaint; |
9 | |||
10 | import javax.swing.BorderFactory; | 8 | import javax.swing.BorderFactory; |
11 | import javax.swing.JMenu; | 9 | import javax.swing.JMenu; |
12 | import javax.swing.border.Border; | 10 | import javax.swing.border.Border; |
13 | 11 | ||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | |||
16 | 12 | ||
17 | public class MyRootMenu extends JMenu | 13 | public class MyRootMenu extends JMenu { |
18 | { | 14 | private Color foregroundColor; |
19 | private Color foregroundColor; | 15 | private String selectedBackgroundImageURL; |
20 | private String selectedBackgroundImageURL; | 16 | private TexturePaint paint; |
21 | private TexturePaint paint; | 17 | private Border border; |
22 | private Border border; | 18 | |
23 | 19 | public MyRootMenu() { | |
24 | public MyRootMenu() | 20 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; |
25 | { | 21 | paint = MyContorlUtil.createTexturePaint( |
26 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | 22 | "control/images/menubar_background_selected.png"); |
27 | paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png"); | 23 | border = BorderFactory.createEmptyBorder(0, 5, 0, 4); |
28 | border = BorderFactory.createEmptyBorder(0, 5, 0, 4); | 24 | init(); |
29 | init(); | 25 | |
30 | 26 | } | |
31 | } | 27 | |
32 | 28 | public MyRootMenu(String text) { | |
33 | public MyRootMenu(String text) | 29 | super(text); |
34 | { | 30 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; |
35 | super(text); | 31 | paint = MyContorlUtil.createTexturePaint( |
36 | foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; | 32 | "control/images/menubar_background_selected.png"); |
37 | paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png"); | 33 | border = BorderFactory.createEmptyBorder(0, 5, 0, 4); |
38 | border = BorderFactory.createEmptyBorder(0, 5, 0, 4); | 34 | init(); |
39 | init(); | 35 | } |
40 | } | 36 | |
41 | 37 | private void init() { | |
42 | private void init() | 38 | setFont(MyContorlUtil.FONT_14_BOLD); |
43 | { | 39 | setBorder(border); |
44 | setFont(MyContorlUtil.FONT_14_BOLD); | 40 | setForeground(foregroundColor); |
45 | setBorder(border); | 41 | } |
46 | setForeground(foregroundColor); | 42 | |
47 | } | 43 | protected void paintComponent(Graphics g) { |
48 | 44 | if (isSelected()) { | |
49 | protected void paintComponent(Graphics g) | 45 | Graphics2D g2d = (Graphics2D) g; |
50 | { | 46 | g2d.setPaint(paint); |
51 | if (isSelected()) | 47 | g2d.fillRect(0, 0, getWidth(), getHeight()); |
52 | { | 48 | super.paintComponent(g); |
53 | Graphics2D g2d = (Graphics2D)g; | 49 | } else { |
54 | g2d.setPaint(paint); | 50 | super.paintComponent(g); |
55 | g2d.fillRect(0, 0, getWidth(), getHeight()); | 51 | } |
56 | super.paintComponent(g); | 52 | } |
57 | } else | ||
58 | { | ||
59 | super.paintComponent(g); | ||
60 | } | ||
61 | } | ||
62 | } | 53 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookBar.java b/src/cppcheckplus/outlookpanel/MyOutlookBar.java index d74345d..ce61489 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookBar.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookBar.java | |||
@@ -1,14 +1,12 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import java.awt.Color; | 5 | import java.awt.Color; |
6 | import java.awt.Component; | ||
7 | import java.awt.Dimension; | 6 | import java.awt.Dimension; |
8 | import java.awt.Graphics; | 7 | import java.awt.Graphics; |
9 | import java.awt.Graphics2D; | 8 | import java.awt.Graphics2D; |
10 | import java.awt.Image; | 9 | import java.awt.Image; |
11 | import java.awt.Insets; | ||
12 | import java.awt.TexturePaint; | 10 | import java.awt.TexturePaint; |
13 | import java.awt.event.MouseAdapter; | 11 | import java.awt.event.MouseAdapter; |
14 | import java.awt.event.MouseEvent; | 12 | import java.awt.event.MouseEvent; |
@@ -19,205 +17,202 @@ import javax.swing.ImageIcon; | |||
19 | import javax.swing.JComponent; | 17 | import javax.swing.JComponent; |
20 | import javax.swing.JLabel; | 18 | import javax.swing.JLabel; |
21 | import javax.swing.JPanel; | 19 | import javax.swing.JPanel; |
22 | import javax.swing.JScrollPane; | ||
23 | import javax.swing.border.Border; | 20 | import javax.swing.border.Border; |
24 | 21 | ||
25 | import cppcheckplus.control.MyContorlUtil; | ||
26 | 22 | ||
23 | public class MyOutlookBar extends JPanel { | ||
24 | private Image backgroundSelectedLeft; | ||
25 | private Image backgroundSelectedRight; | ||
26 | private Image backgroundImage; | ||
27 | private ImageIcon handlerIcon; | ||
28 | private ImageIcon handlerSelectedIcon; | ||
29 | private TexturePaint paint; | ||
30 | private TexturePaint selectedPaint; | ||
31 | private JLabel lbHandler; | ||
32 | private Border handlerBorder; | ||
33 | private Border handlerShrinkedBorder; | ||
34 | private JLabel lbIcon; | ||
35 | private JLabel lbTitle; | ||
36 | private boolean selected; | ||
37 | private Color titleColor; | ||
38 | private Color selectedTitleColor; | ||
39 | private MouseListener mouseListener; | ||
40 | |||
41 | private Icon icon = null; | ||
42 | private Icon selectedIcon = null; | ||
43 | private MyOutlookPanel outlookPanel; | ||
44 | private MyOutlookListPanel outlookListPanel; | ||
45 | |||
46 | public MyOutlookBar(MyOutlookPanel panel) { | ||
47 | super(); | ||
48 | backgroundSelectedLeft = MyContorlUtil.getImage( | ||
49 | "control/images/outlook_bar_background_selected_left.png"); | ||
50 | backgroundSelectedRight = MyContorlUtil.getImage( | ||
51 | "control/images/outlook_bar_background_selected_right.png"); | ||
52 | backgroundImage = | ||
53 | MyContorlUtil.getImage("control/images/outlook_bar_background.png"); | ||
54 | handlerIcon = MyContorlUtil.getImageIcon( | ||
55 | "control/images/outlook_bar_handler.png"); | ||
56 | handlerSelectedIcon = MyContorlUtil.getImageIcon( | ||
57 | "control/images/outlook_bar_handler_selected.png"); | ||
58 | paint = MyContorlUtil.createTexturePaint( | ||
59 | "control/images/outlook_bar_background.png"); | ||
60 | selectedPaint = MyContorlUtil.createTexturePaint( | ||
61 | "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 | public void mouseReleased(MouseEvent e) { | ||
72 | if (((JComponent) e.getSource()).contains(e.getPoint())) { | ||
73 | changeStatus(); | ||
74 | } | ||
75 | } | ||
76 | }; | ||
77 | this.outlookPanel = panel; | ||
78 | |||
79 | init(); | ||
80 | } | ||
81 | |||
82 | public void setOutlookListPanel(MyOutlookListPanel listPanel) { | ||
83 | this.outlookListPanel = listPanel; | ||
84 | } | ||
85 | |||
86 | private void init() { | ||
87 | setLayout(new BorderLayout()); | ||
88 | lbHandler.setVerticalAlignment(0); | ||
89 | lbHandler.setIcon(handlerIcon); | ||
90 | lbHandler.setBorder(handlerBorder); | ||
91 | add(lbHandler, "East"); | ||
92 | lbIcon.setVerticalAlignment(0); | ||
93 | lbIcon.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); | ||
94 | add(lbIcon, "West"); | ||
95 | lbTitle.setVerticalAlignment(0); | ||
96 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); | ||
97 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); | ||
98 | lbTitle.setForeground(titleColor); | ||
99 | add(lbTitle, "Center"); | ||
100 | lbHandler.addMouseListener(mouseListener); | ||
101 | lbTitle.addMouseListener(mouseListener); | ||
102 | lbIcon.addMouseListener(mouseListener); | ||
103 | } | ||
104 | |||
105 | protected void paintComponent(Graphics g) { | ||
106 | super.paintComponent(g); | ||
107 | Graphics2D g2d = (Graphics2D) g; | ||
108 | if (isSelected()) { | ||
109 | g2d.setPaint(selectedPaint); | ||
110 | if (getSelectedIcon() != null) { | ||
111 | lbIcon.setIcon(getSelectedIcon()); | ||
112 | } else { | ||
113 | lbIcon.setIcon(getIcon()); | ||
114 | } | ||
115 | } else { | ||
116 | g2d.setPaint(paint); | ||
117 | lbIcon.setIcon(getIcon()); | ||
118 | } | ||
119 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
120 | if (isSelected()) { | ||
121 | g2d.drawImage(backgroundSelectedLeft, 0, 0, null); | ||
122 | g2d.drawImage(backgroundSelectedRight, getWidth() | ||
123 | - backgroundSelectedRight.getWidth(null), 0, null); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public Dimension getPreferredSize() { | ||
128 | return new Dimension(super.getPreferredSize().width, backgroundImage | ||
129 | .getHeight(null)); | ||
130 | } | ||
131 | |||
132 | public void changeStatus() { | ||
133 | setSelected(!isSelected()); | ||
134 | } | ||
135 | |||
136 | public boolean isSelected() { | ||
137 | return selected; | ||
138 | } | ||
139 | |||
140 | public void setSelected(boolean selected) { | ||
141 | if (selected != this.selected) { | ||
142 | if (!isSelected()) { | ||
143 | outlookPanel.closeAllBars(); | ||
144 | } | ||
145 | this.selected = selected; | ||
146 | if (selected) { | ||
147 | lbHandler.setIcon(handlerSelectedIcon); | ||
148 | lbTitle.setForeground(selectedTitleColor); | ||
149 | } else { | ||
150 | lbHandler.setIcon(handlerIcon); | ||
151 | lbTitle.setForeground(titleColor); | ||
152 | } | ||
153 | |||
154 | outlookPanel.updateLayoutConstraint(getContentComponent(), | ||
155 | selected); | ||
156 | outlookPanel.setAdditionalPaneVisible(!selected); | ||
157 | outlookPanel.revalidate(); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | public Icon getIcon() { | ||
162 | return icon; | ||
163 | } | ||
164 | |||
165 | public void setIcon(Icon icon) { | ||
166 | this.icon = icon; | ||
167 | updateIcon(); | ||
168 | } | ||
169 | |||
170 | public Icon getSelectedIcon() { | ||
171 | return selectedIcon; | ||
172 | } | ||
173 | |||
174 | public void setSelectedIcon(Icon selectedIcon) { | ||
175 | this.selectedIcon = selectedIcon; | ||
176 | updateIcon(); | ||
177 | } | ||
178 | |||
179 | private void updateIcon() { | ||
180 | if (selected) { | ||
181 | lbIcon.setIcon(selectedIcon); | ||
182 | } else { | ||
183 | lbIcon.setIcon(icon); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | public String getTitle() { | ||
188 | return lbTitle.getText(); | ||
189 | } | ||
190 | |||
191 | public void setTitle(String title) { | ||
192 | lbTitle.setText(title); | ||
193 | lbTitle.setToolTipText(title); | ||
194 | lbHandler.setToolTipText(title); | ||
195 | lbIcon.setToolTipText(title); | ||
196 | } | ||
197 | |||
198 | public MyOutlookListPanel getContentComponent() { | ||
199 | return outlookListPanel; | ||
200 | } | ||
201 | |||
202 | public MyOutlookList getList() { | ||
203 | return this.outlookListPanel.getOutlookList(); | ||
204 | } | ||
205 | |||
206 | public MyOutlookPanel getOutlookPanel() { | ||
207 | return this.outlookPanel; | ||
208 | } | ||
27 | 209 | ||
28 | public class MyOutlookBar extends JPanel | 210 | public void headerShrinkChanged(boolean headShrinked) { |
29 | { | 211 | if (headShrinked) { |
30 | private Image backgroundSelectedLeft; | 212 | lbHandler.setBorder(handlerShrinkedBorder); |
31 | private Image backgroundSelectedRight; | 213 | } else { |
32 | private Image backgroundImage; | 214 | lbHandler.setBorder(handlerBorder); |
33 | private ImageIcon handlerIcon; | 215 | } |
34 | private ImageIcon handlerSelectedIcon; | 216 | } |
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 | 217 | ||
223 | } | 218 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookHeader.java b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java index c7ba589..9cd4026 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookHeader.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java | |||
@@ -1,9 +1,11 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import cppcheckplus.control.MyHeader; | ||
5 | import cppcheckplus.control.MyListSplitListener; | ||
6 | import cppcheckplus.toolbar.MyToolBarButton; | ||
4 | import java.awt.FlowLayout; | 7 | import java.awt.FlowLayout; |
5 | import java.awt.LayoutManager; | 8 | import java.awt.LayoutManager; |
6 | import java.awt.event.ActionEvent; | ||
7 | import java.awt.event.ActionListener; | 9 | import java.awt.event.ActionListener; |
8 | import javax.swing.BorderFactory; | 10 | import javax.swing.BorderFactory; |
9 | import javax.swing.Icon; | 11 | import javax.swing.Icon; |
@@ -13,97 +15,84 @@ import javax.swing.JLabel; | |||
13 | import javax.swing.JPanel; | 15 | import javax.swing.JPanel; |
14 | import javax.swing.border.Border; | 16 | import javax.swing.border.Border; |
15 | 17 | ||
16 | import cppcheckplus.control.MyContorlUtil; | 18 | public class MyOutlookHeader extends MyHeader { |
17 | import cppcheckplus.control.MyHeader; | 19 | private LayoutManager toolbarLayout; |
18 | import cppcheckplus.control.MyListSplitListener; | 20 | private JPanel toolbar; |
19 | import cppcheckplus.toolbar.MyToolBarButton; | 21 | private ImageIcon separatorIcon; |
20 | 22 | ||
21 | public class MyOutlookHeader extends MyHeader | 23 | public MyOutlookHeader(ActionListener listener) { |
22 | { | 24 | toolbarLayout = new FlowLayout(FlowLayout.LEFT, 2, 1); |
23 | private LayoutManager toolbarLayout; | 25 | toolbar = new JPanel(toolbarLayout); |
24 | private JPanel toolbar; | 26 | separatorIcon = |
25 | private ImageIcon separatorIcon; | 27 | MyContorlUtil.getImageIcon("control/images/toolbar_separator.png"); |
26 | 28 | init(); | |
27 | public MyOutlookHeader(ActionListener listener) | 29 | //加载工具栏 |
28 | { | 30 | MyContorlUtil.loadOutlookToolBar("cppcheckplus/control/toolbar.xml", |
29 | toolbarLayout = new FlowLayout(FlowLayout.LEFT,2,1); | 31 | this, listener); |
30 | toolbar = new JPanel(toolbarLayout); | 32 | } |
31 | separatorIcon = MyContorlUtil.getImageIcon("control/images/toolbar_separator.png"); | 33 | |
32 | init(); | 34 | private void init() { |
33 | //加载工具栏 | 35 | toolbar.setOpaque(false); |
34 | MyContorlUtil.loadOutlookToolBar("cppcheckplus/control/toolbar.xml", this,listener); | 36 | toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); |
35 | } | 37 | add(toolbar, "Center"); |
36 | 38 | } | |
37 | private void init() | 39 | |
38 | { | 40 | //在Header上添加工具按钮 |
39 | toolbar.setOpaque(false); | 41 | public MyToolBarButton addButton(Icon icon, String tooltip, |
40 | toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); | 42 | ActionListener action, String command) { |
41 | add(toolbar, "Center"); | 43 | MyToolBarButton button = new MyToolBarButton(); |
42 | } | 44 | button.setIcon(icon); |
43 | //在Header上添加工具按钮 | 45 | button.setToolTipText(tooltip); |
44 | public MyToolBarButton addButton(Icon icon, String tooltip, ActionListener action, String command) | 46 | if (action != null) { |
45 | { | 47 | button.addActionListener(action); |
46 | MyToolBarButton button = new MyToolBarButton(); | 48 | } |
47 | button.setIcon(icon); | 49 | button.setActionCommand(command); |
48 | button.setToolTipText(tooltip); | 50 | toolbar.add(button); |
49 | if (action != null) | 51 | return button; |
50 | button.addActionListener(action); | 52 | } |
51 | button.setActionCommand(command); | 53 | |
52 | toolbar.add(button); | 54 | public void addSeparator() { |
53 | return button; | 55 | toolbar.add(new JLabel(separatorIcon)); |
54 | } | 56 | } |
55 | 57 | ||
56 | public void addSeparator() | 58 | protected Object getResizeHandlerLayoutConstraint() { |
57 | { | 59 | return "East"; |
58 | toolbar.add(new JLabel(separatorIcon)); | 60 | } |
59 | } | 61 | |
60 | 62 | protected Object getShrinkHandlerLayoutConstraint() { | |
61 | protected Object getResizeHandlerLayoutConstraint() | 63 | return "West"; |
62 | { | 64 | } |
63 | return "East"; | 65 | |
64 | } | 66 | protected MyListSplitListener createSplitListener() { |
65 | 67 | return new MyOutlookSplitListener(this); | |
66 | protected Object getShrinkHandlerLayoutConstraint() | 68 | } |
67 | { | 69 | |
68 | return "West"; | 70 | protected Border createBorder() { |
69 | } | 71 | return BorderFactory.createEmptyBorder(4, 0, 0, 7); |
70 | 72 | } | |
71 | protected MyListSplitListener createSplitListener() | 73 | |
72 | { | 74 | protected ImageIcon getShrinkIcon(boolean shrinked) { |
73 | return new MyOutlookSplitListener(this); | 75 | if (shrinked) { |
74 | } | 76 | return RIGHT_ARROW_ICON; |
75 | 77 | } else { | |
76 | protected Border createBorder() | 78 | return LEFT_ARROW_ICON; |
77 | { | 79 | } |
78 | return BorderFactory.createEmptyBorder(4, 0, 0, 7); | 80 | } |
79 | } | 81 | |
80 | 82 | protected JComponent getCenterComponent() { | |
81 | protected ImageIcon getShrinkIcon(boolean shrinked) | 83 | return null; |
82 | { | 84 | } |
83 | if (shrinked) | 85 | |
84 | return RIGHT_ARROW_ICON; | 86 | public void setShrink(boolean shrinked) { |
85 | else | 87 | super.setShrink(shrinked); |
86 | return LEFT_ARROW_ICON; | 88 | toolbar.setVisible(!shrinked); |
87 | } | 89 | } |
88 | 90 | ||
89 | protected JComponent getCenterComponent() | 91 | protected int getShrinkedWidth() { |
90 | { | 92 | return 37; |
91 | return null; | 93 | } |
92 | } | 94 | |
93 | 95 | public JPanel getToolBar() { | |
94 | public void setShrink(boolean shrinked) | 96 | return toolbar; |
95 | { | 97 | } |
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 | } | 98 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookList.java b/src/cppcheckplus/outlookpanel/MyOutlookList.java index d5c04d5..9af3c24 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookList.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookList.java | |||
@@ -1,31 +1,26 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import javax.swing.JList; | 4 | import javax.swing.JList; |
5 | 5 | ||
6 | import cppcheckplus.control.MyContorlUtil; | 6 | public class MyOutlookList extends JList { |
7 | //通过MyOutlookBar获得MyOutlookPanel是否sh | ||
8 | private MyOutlookBar bar; | ||
7 | 9 | ||
8 | public class MyOutlookList extends JList | 10 | public MyOutlookList(MyOutlookPanelListItem[] listItems, MyOutlookBar bar) { |
9 | { | 11 | this.bar = bar; |
10 | //通过MyOutlookBar获得MyOutlookPanel是否sh | 12 | setListData(listItems); |
11 | private MyOutlookBar bar; | 13 | init(); |
12 | public MyOutlookList(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | 14 | } |
13 | { | ||
14 | this.bar = bar; | ||
15 | setListData(listItems); | ||
16 | init(); | ||
17 | } | ||
18 | 15 | ||
19 | private void init() | 16 | private void init() { |
20 | { | 17 | setCellRenderer(new MyOutlookListRenderer()); |
21 | setCellRenderer(new MyOutlookListRenderer()); | 18 | setFont(MyContorlUtil.FONT_12_BOLD); |
22 | setFont(MyContorlUtil.FONT_12_BOLD); | 19 | setForeground(MyContorlUtil.OUTLOOK_TEXT_COLOR); |
23 | setForeground(MyContorlUtil.OUTLOOK_TEXT_COLOR); | 20 | setSelectionMode(0); |
24 | setSelectionMode(0); | 21 | } |
25 | } | ||
26 | 22 | ||
27 | public MyOutlookBar getOutlookBar() | 23 | public MyOutlookBar getOutlookBar() { |
28 | { | 24 | return this.bar; |
29 | return this.bar; | 25 | } |
30 | } | ||
31 | } | 26 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java index 2b43866..6195b4c 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
4 | 3 | ||
@@ -14,48 +13,45 @@ import javax.swing.ScrollPaneConstants; | |||
14 | import javax.swing.border.Border; | 13 | import javax.swing.border.Border; |
15 | 14 | ||
16 | 15 | ||
17 | public class MyOutlookListPanel extends JPanel | 16 | public class MyOutlookListPanel extends JPanel { |
18 | { | 17 | private MyOutlookList list; |
19 | private MyOutlookList list; | 18 | |
20 | 19 | //MyOutlookBar对应的MyOutlookList封装的Panel | |
21 | //MyOutlookBar对应的MyOutlookList封装的Panel | 20 | private JScrollPane listScrollPane; |
22 | private JScrollPane listScrollPane; | 21 | private Border scrollBorder; |
23 | private Border scrollBorder; | 22 | |
24 | 23 | public MyOutlookListPanel(MyOutlookList list) { | |
25 | public MyOutlookListPanel(MyOutlookList list) | 24 | this.list = list; |
26 | { | 25 | listScrollPane = new JScrollPane(list); |
27 | this.list = list; | 26 | // listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); |
28 | listScrollPane = new JScrollPane(list); | 27 | listScrollPane.setHorizontalScrollBarPolicy( |
29 | // listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); | 28 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
30 | listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); | 29 | scrollBorder = new Border() { |
31 | scrollBorder = new Border() | 30 | public void paintBorder(Component c, Graphics g, int x, int y, |
32 | { | 31 | int width, int height) { |
33 | public void paintBorder(Component c, Graphics g, int x, int y, | 32 | g.setColor(new Color(233, 223, 207)); |
34 | int width, int height) | 33 | g.drawLine(0, height, x, height); |
35 | { | 34 | } |
36 | g.setColor(new Color(233, 223, 207)); | 35 | |
37 | g.drawLine(0, height, x, height); | 36 | public Insets getBorderInsets(Component c) { |
38 | } | 37 | return new Insets(0, 0, 1, 0); |
39 | public Insets getBorderInsets(Component c) | 38 | } |
40 | { | 39 | |
41 | return new Insets(0, 0, 1, 0); | 40 | public boolean isBorderOpaque() { |
42 | } | 41 | return true; |
43 | public boolean isBorderOpaque() | 42 | } |
44 | { | 43 | }; |
45 | return true; | 44 | init(); |
46 | } | 45 | } |
47 | }; | 46 | |
48 | init(); | 47 | private void init() { |
49 | } | 48 | listScrollPane.setMinimumSize(new Dimension(0, 0)); |
50 | private void init() | 49 | listScrollPane.setBorder(scrollBorder); |
51 | { | 50 | this.setLayout(new BorderLayout()); |
52 | listScrollPane.setMinimumSize(new Dimension(0, 0)); | 51 | add(listScrollPane, BorderLayout.CENTER); |
53 | listScrollPane.setBorder(scrollBorder); | 52 | } |
54 | this.setLayout(new BorderLayout()); | 53 | |
55 | add(listScrollPane,BorderLayout.CENTER); | 54 | public MyOutlookList getOutlookList() { |
56 | } | 55 | return list; |
57 | public MyOutlookList getOutlookList() | 56 | } |
58 | { | ||
59 | return list; | ||
60 | } | ||
61 | } | 57 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java index 9c71301..1b29f68 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
4 | import java.awt.Color; | 3 | import java.awt.Color; |
@@ -9,46 +8,44 @@ import javax.swing.JList; | |||
9 | import javax.swing.SwingConstants; | 8 | import javax.swing.SwingConstants; |
10 | import javax.swing.border.Border; | 9 | import javax.swing.border.Border; |
11 | 10 | ||
12 | import cppcheckplus.control.MyContorlUtil; | 11 | public class MyOutlookListRenderer extends DefaultListCellRenderer { |
12 | private Color selectedColor; | ||
13 | private Border normalBorder; | ||
14 | private Border shrinkedBorder; | ||
15 | |||
16 | public MyOutlookListRenderer() { | ||
17 | super(); | ||
18 | selectedColor = new Color(253, 192, 47); | ||
19 | normalBorder = BorderFactory.createEmptyBorder(3, 19, 3, 2); | ||
20 | shrinkedBorder = BorderFactory.createEmptyBorder(2, 7, 1, 2); | ||
21 | } | ||
22 | |||
23 | @Override | ||
24 | public Component getListCellRendererComponent(JList list, Object value, | ||
25 | int index, boolean isSelected, | ||
26 | boolean cellHasFocus) { | ||
27 | super.getListCellRendererComponent(list, value, index, isSelected, | ||
28 | cellHasFocus); | ||
13 | 29 | ||
14 | public class MyOutlookListRenderer extends DefaultListCellRenderer | 30 | MyOutlookPanelListItem listItem = (MyOutlookPanelListItem) value; |
15 | { | 31 | MyOutlookList outlookList = (MyOutlookList) list; |
16 | private Color selectedColor; | 32 | setToolTipText(listItem.getToolTip()); |
17 | private Border normalBorder; | 33 | setIcon(listItem.getIcon()); |
18 | private Border shrinkedBorder; | 34 | //收缩样式 |
19 | 35 | if (outlookList.getOutlookBar().getOutlookPanel().isShrinked()) { | |
20 | public MyOutlookListRenderer() | 36 | setBorder(shrinkedBorder); |
21 | { | 37 | setText(null); |
22 | super(); | 38 | } |
23 | selectedColor = new Color(253, 192, 47); | 39 | //普通样式 |
24 | normalBorder = BorderFactory.createEmptyBorder(3, 19, 3, 2); | 40 | else { |
25 | shrinkedBorder = BorderFactory.createEmptyBorder(2, 7, 1, 2); | 41 | setBorder(normalBorder); |
26 | } | 42 | setText(listItem.getText()); |
27 | @Override | 43 | setHorizontalAlignment(SwingConstants.LEADING); |
28 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) | 44 | setIconTextGap(5); |
29 | { | 45 | } |
30 | super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus); | 46 | if (isSelected) { |
31 | 47 | setBackground(selectedColor); | |
32 | MyOutlookPanelListItem listItem = (MyOutlookPanelListItem)value; | 48 | } |
33 | MyOutlookList outlookList = (MyOutlookList)list; | 49 | return this; |
34 | setToolTipText(listItem.getToolTip()); | 50 | } |
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 | } | 51 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java index 139f62a..afa7392 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import java.awt.Color; | 5 | import java.awt.Color; |
6 | import java.awt.Component; | 6 | import java.awt.Component; |
@@ -9,214 +9,213 @@ import java.awt.Dimension; | |||
9 | import java.awt.Graphics; | 9 | import java.awt.Graphics; |
10 | import java.awt.Insets; | 10 | import java.awt.Insets; |
11 | import java.awt.event.ActionListener; | 11 | import java.awt.event.ActionListener; |
12 | import java.util.ArrayList; | ||
13 | import java.util.Hashtable; | 12 | import java.util.Hashtable; |
14 | import java.util.List; | ||
15 | import javax.swing.Icon; | 13 | import javax.swing.Icon; |
16 | import javax.swing.JButton; | ||
17 | import javax.swing.JComponent; | 14 | import javax.swing.JComponent; |
18 | import javax.swing.JPanel; | 15 | import javax.swing.JPanel; |
19 | import javax.swing.border.Border; | 16 | import javax.swing.border.Border; |
20 | import javax.swing.event.ListSelectionListener; | 17 | import javax.swing.event.ListSelectionListener; |
21 | |||
22 | import cppcheckplus.control.MyContorlUtil; | ||
23 | import layout.TableLayout; | 18 | import layout.TableLayout; |
24 | 19 | ||
25 | public class MyOutlookPanel extends JPanel | 20 | public class MyOutlookPanel extends JPanel { |
26 | { | 21 | //Header |
27 | //Header | 22 | private MyOutlookHeader header; |
28 | private MyOutlookHeader header; | 23 | //容器Panel |
29 | //容器Panel | 24 | private JPanel barPane; |
30 | private JPanel barPane;; | 25 | ; |
31 | //右边的分割滑动线条 | 26 | //右边的分割滑动线条 |
32 | private JPanel split; | 27 | private JPanel split; |
33 | private int splitWidth; | 28 | private int splitWidth; |
34 | private Color splitColor; | 29 | private Color splitColor; |
35 | private JPanel additionalPane; | 30 | private JPanel additionalPane; |
36 | private Hashtable componentLayoutRows; | 31 | private Hashtable componentLayoutRows; |
37 | private JPanel centerPane; | 32 | private JPanel centerPane; |
38 | private TableLayout barPaneLayout; | 33 | private TableLayout barPaneLayout; |
39 | private MyOutlookSplitListener splitListener; | 34 | private MyOutlookSplitListener splitListener; |
40 | private ListSelectionListener listSelectionListener; | 35 | private ListSelectionListener listSelectionListener; |
41 | 36 | ||
42 | /** | 37 | /** |
43 | * 构造MyOutlookPanel | 38 | * 构造MyOutlookPanel |
44 | * @param headerListener Header的监听器 | 39 | * |
45 | * @param listSelectionListener ListItemSelection的监听器 | 40 | * @param headerListener Header的监听器 |
46 | */ | 41 | * @param listSelectionListener ListItemSelection的监听器 |
47 | public MyOutlookPanel(ActionListener headerListener,ListSelectionListener listSelectionListener) | 42 | */ |
48 | { | 43 | public MyOutlookPanel(ActionListener headerListener, |
49 | super(); | 44 | ListSelectionListener listSelectionListener) { |
50 | //注册Header事件 | 45 | super(); |
51 | this.header = new MyOutlookHeader(headerListener){ | 46 | //注册Header事件 |
52 | public void setShrink(boolean shrinked) | 47 | this.header = new MyOutlookHeader(headerListener) { |
53 | { | 48 | public void setShrink(boolean shrinked) { |
54 | super.setShrink(shrinked); | 49 | super.setShrink(shrinked); |
55 | shrinkChanged(shrinked); | 50 | shrinkChanged(shrinked); |
56 | } | 51 | } |
57 | 52 | ||
58 | }; | 53 | }; |
59 | this.listSelectionListener = listSelectionListener; | 54 | this.listSelectionListener = listSelectionListener; |
60 | barPaneLayout = new TableLayout(); | 55 | barPaneLayout = new TableLayout(); |
61 | barPane = new JPanel(barPaneLayout); | 56 | barPane = new JPanel(barPaneLayout); |
62 | 57 | ||
63 | additionalPane = new JPanel(new BorderLayout()); | 58 | additionalPane = new JPanel(new BorderLayout()); |
64 | componentLayoutRows = new Hashtable(); | 59 | componentLayoutRows = new Hashtable(); |
65 | centerPane = new JPanel(new BorderLayout()); | 60 | centerPane = new JPanel(new BorderLayout()); |
66 | 61 | ||
67 | //分割条 | 62 | //分割条 |
68 | split = new JPanel(); | 63 | split = new JPanel(); |
69 | splitWidth = 1; | 64 | splitWidth = 1; |
70 | splitColor = new Color(166, 172, 174); | 65 | splitColor = new Color(166, 172, 174); |
71 | splitListener = new MyOutlookSplitListener(header); | 66 | splitListener = new MyOutlookSplitListener(header); |
72 | 67 | ||
73 | init(); | 68 | init(); |
74 | } | 69 | } |
75 | private void init() | 70 | |
76 | { | 71 | private void init() { |
77 | split.setPreferredSize(new Dimension(splitWidth, 0)); | 72 | split.setPreferredSize(new Dimension(splitWidth, 0)); |
78 | split.setOpaque(true); | 73 | split.setOpaque(true); |
79 | split.setBackground(splitColor); | 74 | split.setBackground(splitColor); |
80 | split.setCursor(Cursor.getPredefinedCursor(10)); | 75 | split.setCursor(Cursor.getPredefinedCursor(10)); |
81 | split.addMouseListener(splitListener); | 76 | split.addMouseListener(splitListener); |
82 | split.addMouseMotionListener(splitListener); | 77 | split.addMouseMotionListener(splitListener); |
83 | additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); | 78 | additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); |
84 | additionalPane.setPreferredSize(new Dimension(0, 0)); | 79 | additionalPane.setPreferredSize(new Dimension(0, 0)); |
85 | additionalPane.setBorder(new Border() { | 80 | additionalPane.setBorder(new Border() { |
86 | 81 | ||
87 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | 82 | public void paintBorder(Component c, Graphics g, int x, int y, |
88 | { | 83 | int width, int height) { |
89 | g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); | 84 | g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); |
90 | g.drawLine(0, 0, width, 0); | 85 | g.drawLine(0, 0, width, 0); |
91 | } | 86 | } |
92 | 87 | ||
93 | public Insets getBorderInsets(Component c) | 88 | public Insets getBorderInsets(Component c) { |
94 | { | 89 | return new Insets(1, 0, 0, 0); |
95 | return new Insets(1, 0, 0, 0); | 90 | } |
96 | } | 91 | |
97 | 92 | public boolean isBorderOpaque() { | |
98 | public boolean isBorderOpaque() | 93 | return true; |
99 | { | 94 | } |
100 | return true; | 95 | |
101 | } | 96 | }); |
102 | 97 | ||
103 | }); | 98 | centerPane.add(barPane, "North"); |
104 | 99 | centerPane.add(additionalPane, "Center"); | |
105 | centerPane.add(barPane, "North"); | 100 | barPaneLayout.insertColumn(0, -1D); |
106 | centerPane.add(additionalPane, "Center"); | 101 | setLayout(new BorderLayout()); |
107 | barPaneLayout.insertColumn(0, -1D); | 102 | add(header, "North"); |
108 | setLayout(new BorderLayout()); | 103 | add(centerPane, "Center"); |
109 | add(header, "North"); | 104 | add(split, "East"); |
110 | add(centerPane, "Center"); | 105 | } |
111 | add(split, "East"); | 106 | |
112 | } | 107 | public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon, |
113 | public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon,MyOutlookPanelListItem[] listItems) | 108 | MyOutlookPanelListItem[] listItems) { |
114 | { | 109 | MyOutlookBar bar = new MyOutlookBar(this); |
115 | MyOutlookBar bar = new MyOutlookBar(this); | 110 | MyOutlookListPanel listPanel = getListPanel(listItems, bar); |
116 | MyOutlookListPanel listPanel = getListPanel(listItems, bar); | 111 | //注册JList事件 |
117 | //注册JList事件 | 112 | listPanel.getOutlookList() |
118 | listPanel.getOutlookList().addListSelectionListener(listSelectionListener); | 113 | .addListSelectionListener(listSelectionListener); |
119 | bar.setOutlookListPanel(listPanel); | 114 | bar.setOutlookListPanel(listPanel); |
120 | bar.setSelected(false); | 115 | bar.setSelected(false); |
121 | bar.setTitle(title); | 116 | bar.setTitle(title); |
122 | bar.setIcon(icon); | 117 | bar.setIcon(icon); |
123 | bar.setSelectedIcon(selectedIcon); | 118 | bar.setSelectedIcon(selectedIcon); |
124 | int rowCount = barPaneLayout.getRow().length; | 119 | int rowCount = barPaneLayout.getRow().length; |
125 | barPaneLayout.insertRow(rowCount, -2D); | 120 | barPaneLayout.insertRow(rowCount, -2D); |
126 | barPane.add(bar, (new StringBuilder()).append("0,").append(rowCount).toString()); | 121 | barPane.add(bar, |
127 | componentLayoutRows.put(bar, Integer.valueOf(rowCount)); | 122 | (new StringBuilder()).append("0,").append(rowCount).toString()); |
128 | rowCount++; | 123 | componentLayoutRows.put(bar, Integer.valueOf(rowCount)); |
129 | barPaneLayout.insertRow(rowCount, -3D); | 124 | rowCount++; |
130 | //加载列表 | 125 | barPaneLayout.insertRow(rowCount, -3D); |
131 | barPane.add(listPanel,(new StringBuilder()).append("0,").append(rowCount).toString()); | 126 | //加载列表 |
132 | componentLayoutRows.put(bar.getContentComponent(), Integer.valueOf(rowCount)); | 127 | barPane.add(listPanel, |
133 | return bar; | 128 | (new StringBuilder()).append("0,").append(rowCount).toString()); |
134 | } | 129 | componentLayoutRows.put(bar.getContentComponent(), |
135 | private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | 130 | Integer.valueOf(rowCount)); |
136 | { | 131 | return bar; |
137 | MyOutlookList list = new MyOutlookList(listItems,bar); | 132 | } |
138 | MyOutlookListPanel listPanel = new MyOutlookListPanel(list); | 133 | |
139 | return listPanel; | 134 | private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems, |
140 | } | 135 | MyOutlookBar bar) { |
141 | public void updateLayoutConstraint(Component component, boolean selected) | 136 | MyOutlookList list = new MyOutlookList(listItems, bar); |
142 | { | 137 | MyOutlookListPanel listPanel = new MyOutlookListPanel(list); |
143 | int rowIndex = ((Integer)componentLayoutRows.get(component)).intValue(); | 138 | return listPanel; |
144 | double constraint = -1D; | 139 | } |
145 | if (!selected) | 140 | |
146 | constraint = -3D; | 141 | public void updateLayoutConstraint(Component component, boolean selected) { |
147 | barPaneLayout.setRow(rowIndex, constraint); | 142 | int rowIndex = |
148 | } | 143 | ((Integer) componentLayoutRows.get(component)).intValue(); |
149 | public JComponent getAdditionalPane() | 144 | double constraint = -1D; |
150 | { | 145 | if (!selected) { |
151 | return additionalPane; | 146 | constraint = -3D; |
152 | } | 147 | } |
153 | public void setAdditionalPaneVisible(boolean visible) | 148 | barPaneLayout.setRow(rowIndex, constraint); |
154 | { | 149 | } |
155 | centerPane.remove(barPane); | 150 | |
156 | centerPane.remove(additionalPane); | 151 | public JComponent getAdditionalPane() { |
157 | if (visible) | 152 | return additionalPane; |
158 | { | 153 | } |
159 | centerPane.add(barPane, "North"); | 154 | |
160 | centerPane.add(additionalPane, "Center"); | 155 | public void setAdditionalPaneVisible(boolean visible) { |
161 | } else | 156 | centerPane.remove(barPane); |
162 | { | 157 | centerPane.remove(additionalPane); |
163 | centerPane.add(barPane, "Center"); | 158 | if (visible) { |
164 | } | 159 | centerPane.add(barPane, "North"); |
165 | } | 160 | centerPane.add(additionalPane, "Center"); |
166 | public void closeAllBars() | 161 | } else { |
167 | { | 162 | centerPane.add(barPane, "Center"); |
168 | for (int i = 0; i < barPane.getComponentCount(); i++) | 163 | } |
169 | { | 164 | } |
170 | Component c = barPane.getComponent(i); | 165 | |
171 | if (!(c instanceof MyOutlookBar)) | 166 | public void closeAllBars() { |
172 | continue; | 167 | for (int i = 0; i < barPane.getComponentCount(); i++) { |
173 | MyOutlookBar bar = (MyOutlookBar)c; | 168 | Component c = barPane.getComponent(i); |
174 | if (bar.isSelected()) | 169 | if (!(c instanceof MyOutlookBar)) { |
175 | bar.setSelected(false); | 170 | continue; |
176 | } | 171 | } |
177 | } | 172 | MyOutlookBar bar = (MyOutlookBar) c; |
178 | public MyOutlookBar getSelectedBar() | 173 | if (bar.isSelected()) { |
179 | { | 174 | bar.setSelected(false); |
180 | for (int i = 0; i < barPane.getComponentCount(); i++) | 175 | } |
181 | { | 176 | } |
182 | Component c = barPane.getComponent(i); | 177 | } |
183 | if (!(c instanceof MyOutlookBar)) | 178 | |
184 | continue; | 179 | public MyOutlookBar getSelectedBar() { |
185 | MyOutlookBar bar = (MyOutlookBar)c; | 180 | for (int i = 0; i < barPane.getComponentCount(); i++) { |
186 | if (bar.isSelected()) | 181 | Component c = barPane.getComponent(i); |
187 | return bar; | 182 | if (!(c instanceof MyOutlookBar)) { |
188 | } | 183 | continue; |
189 | 184 | } | |
190 | return null; | 185 | MyOutlookBar bar = (MyOutlookBar) c; |
191 | } | 186 | if (bar.isSelected()) { |
192 | public void setShrink(boolean shrinked) | 187 | return bar; |
193 | { | 188 | } |
194 | header.setShrink(shrinked); | 189 | } |
195 | } | 190 | |
196 | 191 | return null; | |
197 | public boolean isShrinked() | 192 | } |
198 | { | 193 | |
199 | return header.isShrinked(); | 194 | public void setShrink(boolean shrinked) { |
200 | } | 195 | header.setShrink(shrinked); |
201 | private void shrinkChanged(boolean shrinked) | 196 | } |
202 | { | 197 | |
203 | if (shrinked) | 198 | public boolean isShrinked() { |
204 | split.setCursor(Cursor.getDefaultCursor()); | 199 | return header.isShrinked(); |
205 | else | 200 | } |
206 | split.setCursor(Cursor.getPredefinedCursor(10)); | 201 | |
207 | for (int i = 0; i < barPane.getComponentCount(); i++) | 202 | private void shrinkChanged(boolean shrinked) { |
208 | { | 203 | if (shrinked) { |
209 | Component c = barPane.getComponent(i); | 204 | split.setCursor(Cursor.getDefaultCursor()); |
210 | if (c instanceof MyOutlookBar) | 205 | } else { |
211 | { | 206 | split.setCursor(Cursor.getPredefinedCursor(10)); |
212 | MyOutlookBar bar = (MyOutlookBar)c; | 207 | } |
213 | bar.headerShrinkChanged(shrinked); | 208 | for (int i = 0; i < barPane.getComponentCount(); i++) { |
214 | 209 | Component c = barPane.getComponent(i); | |
215 | 210 | if (c instanceof MyOutlookBar) { | |
216 | //XOutlookList list = bar.getList(); | 211 | MyOutlookBar bar = (MyOutlookBar) c; |
217 | 212 | bar.headerShrinkChanged(shrinked); | |
218 | //list.firePropertyChange("layoutOrientation", true, false); | 213 | |
219 | } | 214 | |
220 | } | 215 | //XOutlookList list = bar.getList(); |
221 | } | 216 | |
217 | //list.firePropertyChange("layoutOrientation", true, false); | ||
218 | } | ||
219 | } | ||
220 | } | ||
222 | } | 221 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java index 92fd09e..421ff09 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java | |||
@@ -2,50 +2,41 @@ package cppcheckplus.outlookpanel; | |||
2 | 2 | ||
3 | import javax.swing.Icon; | 3 | import javax.swing.Icon; |
4 | 4 | ||
5 | public class MyOutlookPanelListItem | 5 | public class MyOutlookPanelListItem { |
6 | { | 6 | private Icon icon; |
7 | private Icon icon; | 7 | private String text; |
8 | private String text; | 8 | private String toolTip; |
9 | private String toolTip; | 9 | private String actionCommand; |
10 | private String actionCommand; | 10 | |
11 | 11 | public Icon getIcon() { | |
12 | public void setIcon(Icon icon) | 12 | return icon; |
13 | { | 13 | } |
14 | this.icon = icon; | 14 | |
15 | } | 15 | public void setIcon(Icon icon) { |
16 | 16 | this.icon = icon; | |
17 | public Icon getIcon() | 17 | } |
18 | { | 18 | |
19 | return icon; | 19 | public String getText() { |
20 | } | 20 | return text; |
21 | 21 | } | |
22 | public void setText(String value) | 22 | |
23 | { | 23 | public void setText(String value) { |
24 | this.text = value; | 24 | this.text = value; |
25 | } | 25 | } |
26 | 26 | ||
27 | public String getText() | 27 | public String getToolTip() { |
28 | { | 28 | return toolTip; |
29 | return text; | 29 | } |
30 | } | 30 | |
31 | 31 | public void setToolTip(String toolTip) { | |
32 | public void setToolTip(String toolTip) | 32 | this.toolTip = toolTip; |
33 | { | 33 | } |
34 | this.toolTip = toolTip; | 34 | |
35 | } | 35 | public String getActionCommand() { |
36 | 36 | return actionCommand; | |
37 | public String getToolTip() | 37 | } |
38 | { | 38 | |
39 | return toolTip; | 39 | public void setActionCommand(String actionCommand) { |
40 | } | 40 | this.actionCommand = actionCommand; |
41 | 41 | } | |
42 | public void setActionCommand(String actionCommand) | ||
43 | { | ||
44 | this.actionCommand = actionCommand; | ||
45 | } | ||
46 | |||
47 | public String getActionCommand() | ||
48 | { | ||
49 | return actionCommand; | ||
50 | } | ||
51 | } | 42 | } |
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java index b65e706..c78b1c5 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java | |||
@@ -1,33 +1,27 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
3 | import cppcheckplus.control.MyHeader; | ||
4 | import cppcheckplus.control.MyListSplitListener; | ||
4 | import java.awt.Dimension; | 5 | import java.awt.Dimension; |
5 | import java.awt.Point; | 6 | import java.awt.Point; |
6 | import java.awt.event.MouseEvent; | 7 | import java.awt.event.MouseEvent; |
7 | import javax.swing.JComponent; | 8 | import javax.swing.JComponent; |
8 | 9 | ||
9 | import cppcheckplus.control.MyHeader; | 10 | public class MyOutlookSplitListener extends MyListSplitListener { |
10 | import cppcheckplus.control.MyListSplitListener; | 11 | public MyOutlookSplitListener(MyHeader header) { |
11 | 12 | super(header); | |
12 | public class MyOutlookSplitListener extends MyListSplitListener | 13 | } |
13 | { | ||
14 | public MyOutlookSplitListener(MyHeader header) | ||
15 | { | ||
16 | super(header); | ||
17 | } | ||
18 | 14 | ||
19 | public void mouseDragged(MouseEvent e) | 15 | public void mouseDragged(MouseEvent e) { |
20 | { | 16 | if (!header.isShrinked() && lastPoint != null) { |
21 | if (!header.isShrinked() && lastPoint != null) | 17 | JComponent parent = (JComponent) header.getParent(); |
22 | { | 18 | Dimension size = parent.getPreferredSize(); |
23 | JComponent parent = (JComponent)header.getParent(); | 19 | Point thisPoint = e.getPoint(); |
24 | Dimension size = parent.getPreferredSize(); | 20 | int xMovement = thisPoint.x - lastPoint.x; |
25 | Point thisPoint = e.getPoint(); | 21 | size.width += xMovement; |
26 | int xMovement = thisPoint.x - lastPoint.x; | 22 | size.width = Math.max(size.width, 37); |
27 | size.width += xMovement; | 23 | parent.setPreferredSize(size); |
28 | size.width = Math.max(size.width, 37); | 24 | header.revalidateParent(); |
29 | parent.setPreferredSize(size); | 25 | } |
30 | header.revalidateParent(); | 26 | } |
31 | } | ||
32 | } | ||
33 | } | 27 | } |
diff --git a/src/cppcheckplus/shortcut/MyShortcutItem.java b/src/cppcheckplus/shortcut/MyShortcutItem.java index 7461690..1baf836 100644 --- a/src/cppcheckplus/shortcut/MyShortcutItem.java +++ b/src/cppcheckplus/shortcut/MyShortcutItem.java | |||
@@ -1,20 +1,15 @@ | |||
1 | |||
2 | package cppcheckplus.shortcut; | 1 | package cppcheckplus.shortcut; |
3 | 2 | ||
4 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; | 3 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; |
5 | 4 | ||
6 | public class MyShortcutItem extends MyOutlookPanelListItem | 5 | public class MyShortcutItem extends MyOutlookPanelListItem { |
7 | { | 6 | private boolean isGroup; |
8 | private boolean isGroup; | ||
9 | |||
10 | 7 | ||
11 | public void setGroup(boolean isGroup) | 8 | public boolean isGroup() { |
12 | { | 9 | return isGroup; |
13 | this.isGroup = isGroup; | 10 | } |
14 | } | ||
15 | 11 | ||
16 | public boolean isGroup() | 12 | public void setGroup(boolean isGroup) { |
17 | { | 13 | this.isGroup = isGroup; |
18 | return isGroup; | 14 | } |
19 | } | ||
20 | } | 15 | } |
diff --git a/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java b/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java index b2ea232..47b61fa 100644 --- a/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java +++ b/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java | |||
@@ -1,7 +1,5 @@ | |||
1 | |||
2 | package cppcheckplus.shortcut; | 1 | package cppcheckplus.shortcut; |
3 | 2 | ||
4 | public interface MyShortcutItemClickListenter | 3 | public interface MyShortcutItemClickListenter { |
5 | { | 4 | public void ItemClick(String actionCommand); |
6 | public void ItemClick(String actionCommand); | ||
7 | } | 5 | } |
diff --git a/src/cppcheckplus/shortcut/MyShortcutPanel.java b/src/cppcheckplus/shortcut/MyShortcutPanel.java index 5d97b08..c1e6a72 100644 --- a/src/cppcheckplus/shortcut/MyShortcutPanel.java +++ b/src/cppcheckplus/shortcut/MyShortcutPanel.java | |||
@@ -1,6 +1,9 @@ | |||
1 | |||
2 | package cppcheckplus.shortcut; | 1 | package cppcheckplus.shortcut; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import cppcheckplus.control.MyHeader; | ||
5 | import cppcheckplus.control.MyList; | ||
6 | import cppcheckplus.control.MyListSplitListener; | ||
4 | import java.awt.BorderLayout; | 7 | import java.awt.BorderLayout; |
5 | import java.awt.Component; | 8 | import java.awt.Component; |
6 | import java.awt.Cursor; | 9 | import java.awt.Cursor; |
@@ -10,105 +13,92 @@ import java.awt.Insets; | |||
10 | import javax.swing.JPanel; | 13 | import javax.swing.JPanel; |
11 | import javax.swing.border.Border; | 14 | import javax.swing.border.Border; |
12 | 15 | ||
13 | import cppcheckplus.control.MyContorlUtil; | 16 | public class MyShortcutPanel extends JPanel { |
14 | import cppcheckplus.control.MyHeader; | 17 | public MyTree mytree; |
15 | import cppcheckplus.control.MyList; | 18 | private MyList list; |
16 | import cppcheckplus.control.MyListSplitListener; | 19 | private JPanel split; |
17 | import cppcheckplus.outlookpanel.MyOutlookList; | 20 | private MyHeader header; |
18 | import cppcheckplus.outlookpanel.MyOutlookPanelListItem; | 21 | private MyListSplitListener splitListener; |
19 | 22 | ||
20 | public class MyShortcutPanel extends JPanel{ | 23 | public MyShortcutPanel() { |
21 | private MyList list; | 24 | super(); |
22 | private JPanel split; | 25 | //list = new MyList(); |
23 | private MyHeader header; | 26 | split = new JPanel(new BorderLayout()); |
24 | private MyListSplitListener splitListener; | 27 | |
25 | public MyTree mytree; | 28 | header = new MyHeader() { |
26 | public MyShortcutPanel() | 29 | |
27 | { | 30 | public void setShrink(boolean shrinked) { |
28 | super(); | 31 | super.setShrink(shrinked); |
29 | //list = new MyList(); | 32 | if (shrinked) { |
30 | split = new JPanel(new BorderLayout()); | 33 | split.setCursor(Cursor.getDefaultCursor()); |
31 | 34 | } else { | |
32 | header = new MyHeader() { | 35 | split.setCursor(Cursor.getPredefinedCursor(10)); |
33 | 36 | } | |
34 | public void setShrink(boolean shrinked) | 37 | } |
35 | { | 38 | }; |
36 | super.setShrink(shrinked); | 39 | splitListener = new MyListSplitListener(header); |
37 | if (shrinked) | 40 | mytree = new MyTree(); |
38 | split.setCursor(Cursor.getDefaultCursor()); | 41 | init(); |
39 | else | 42 | } |
40 | split.setCursor(Cursor.getPredefinedCursor(10)); | 43 | |
41 | } | 44 | public void setData(MyShortcutItem[] items, |
42 | }; | 45 | MyShortcutItemClickListenter listenter) { |
43 | splitListener = new MyListSplitListener(header); | 46 | //list.setListData(items); |
44 | mytree = new MyTree(); | 47 | list.setListenter(listenter); |
45 | init(); | 48 | } |
46 | } | 49 | |
47 | public void setData(MyShortcutItem[] items,MyShortcutItemClickListenter listenter) | 50 | private void init() { |
48 | { | 51 | setLayout(new BorderLayout()); |
49 | //list.setListData(items); | 52 | JPanel rightInsetPane = new JPanel(); |
50 | list.setListenter(listenter); | 53 | rightInsetPane.setPreferredSize(new Dimension(2, 0)); |
51 | } | 54 | rightInsetPane.setBackground(MyContorlUtil.LIST_BACKGROUND); |
52 | private void init() | 55 | add(rightInsetPane, "East"); |
53 | { | 56 | add(header, "North"); |
54 | setLayout(new BorderLayout()); | 57 | |
55 | JPanel rightInsetPane = new JPanel(); | 58 | split.setBorder(new Border() { |
56 | rightInsetPane.setPreferredSize(new Dimension(2, 0)); | 59 | public void paintBorder(Component c, Graphics g, int x, int y, |
57 | rightInsetPane.setBackground(MyContorlUtil.LIST_BACKGROUND); | 60 | int width, int height) { |
58 | add(rightInsetPane, "East"); | 61 | g.setColor(MyContorlUtil.LIST_SPLIT_COLOR); |
59 | add(header, "North"); | 62 | g.drawLine(x, y, x, y + height); |
60 | 63 | } | |
61 | split.setBorder(new Border() { | 64 | |
62 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | 65 | public Insets getBorderInsets(Component c) { |
63 | { | 66 | return new Insets(0, 1, 0, 0); |
64 | g.setColor(MyContorlUtil.LIST_SPLIT_COLOR); | 67 | } |
65 | g.drawLine(x, y, x, y + height); | 68 | |
66 | } | 69 | public boolean isBorderOpaque() { |
67 | 70 | return true; | |
68 | public Insets getBorderInsets(Component c) | 71 | } |
69 | { | 72 | |
70 | return new Insets(0, 1, 0, 0); | 73 | }); |
71 | } | 74 | split.setOpaque(true); |
72 | 75 | split.setPreferredSize(new Dimension(4, 0)); | |
73 | public boolean isBorderOpaque() | 76 | split.setBackground(MyContorlUtil.LIST_BACKGROUND); |
74 | { | 77 | split.setCursor(Cursor.getPredefinedCursor(10)); |
75 | return true; | 78 | split.addMouseListener(splitListener); |
76 | } | 79 | split.addMouseMotionListener(splitListener); |
77 | 80 | add(split, "West"); | |
78 | }); | 81 | add(mytree, "Center"); |
79 | split.setOpaque(true); | 82 | //add(list, "Center"); |
80 | split.setPreferredSize(new Dimension(4, 0)); | 83 | } |
81 | split.setBackground(MyContorlUtil.LIST_BACKGROUND); | 84 | |
82 | split.setCursor(Cursor.getPredefinedCursor(10)); | 85 | public MyList getList() { |
83 | split.addMouseListener(splitListener); | 86 | return list; |
84 | split.addMouseMotionListener(splitListener); | 87 | } |
85 | add(split, "West"); | 88 | |
86 | add(mytree, "Center"); | 89 | public String getTitle() { |
87 | //add(list, "Center"); | 90 | return header.getTitle(); |
88 | } | 91 | } |
89 | 92 | ||
90 | public MyList getList() | 93 | public void setTitle(String title) { |
91 | { | 94 | header.setTitle(title); |
92 | return list; | 95 | } |
93 | } | 96 | |
94 | 97 | public void setShrink(boolean shrinked) { | |
95 | public void setTitle(String title) | 98 | header.setShrink(shrinked); |
96 | { | 99 | } |
97 | header.setTitle(title); | 100 | |
98 | } | 101 | public boolean isShrinked() { |
99 | 102 | return header.isShrinked(); | |
100 | public String getTitle() | 103 | } |
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 | } | 104 | } |
diff --git a/src/cppcheckplus/shortcut/MyTree.java b/src/cppcheckplus/shortcut/MyTree.java index 5286dde..e13fc1a 100644 --- a/src/cppcheckplus/shortcut/MyTree.java +++ b/src/cppcheckplus/shortcut/MyTree.java | |||
@@ -16,9 +16,9 @@ import javax.swing.tree.DefaultTreeModel; | |||
16 | import javax.swing.tree.MutableTreeNode; | 16 | import javax.swing.tree.MutableTreeNode; |
17 | 17 | ||
18 | public class MyTree extends JPanel { | 18 | public class MyTree extends JPanel { |
19 | private final JTree tree; | ||
19 | public File result; | 20 | public File result; |
20 | public String src; | 21 | public String src; |
21 | private final JTree tree; | ||
22 | private UIFrame jf; | 22 | private UIFrame jf; |
23 | private JTextArea textCode; | 23 | private JTextArea textCode; |
24 | 24 | ||
diff --git a/src/cppcheckplus/tab/MyTabComponent.java b/src/cppcheckplus/tab/MyTabComponent.java index 5a1d2a6..4ed4b1d 100644 --- a/src/cppcheckplus/tab/MyTabComponent.java +++ b/src/cppcheckplus/tab/MyTabComponent.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import java.awt.Color; | 5 | import java.awt.Color; |
6 | import java.awt.Dimension; | 6 | import java.awt.Dimension; |
@@ -17,157 +17,150 @@ import javax.swing.JLabel; | |||
17 | import javax.swing.JPanel; | 17 | import javax.swing.JPanel; |
18 | import javax.swing.border.Border; | 18 | import javax.swing.border.Border; |
19 | 19 | ||
20 | import cppcheckplus.control.MyContorlUtil; | ||
21 | |||
22 | 20 | ||
23 | public class MyTabComponent extends JPanel | 21 | public class MyTabComponent extends JPanel { |
24 | { | 22 | |
25 | 23 | private String backgroundUnselectedImageURL; | |
26 | private String backgroundUnselectedImageURL; | 24 | private TexturePaint selectedPaint; |
27 | private TexturePaint selectedPaint; | 25 | private TexturePaint unselectedPaint; |
28 | private TexturePaint unselectedPaint; | 26 | private ImageIcon icon; |
29 | private ImageIcon icon; | 27 | private ImageIcon pressedIcon; |
30 | private ImageIcon pressedIcon; | 28 | private Image unselectedLeftImage; |
31 | private Image unselectedLeftImage; | 29 | private Image unselectedRightImage; |
32 | private Image unselectedRightImage; | 30 | private Image selectedLeftImage; |
33 | private Image selectedLeftImage; | 31 | private Image selectedRightImage; |
34 | private Image selectedRightImage; | 32 | private JButton btnClose; |
35 | private JButton btnClose; | 33 | private JLabel lbTitle; |
36 | private JLabel lbTitle; | 34 | private MyTabPanel tab; |
37 | private MyTabPanel tab; | 35 | private Color selectedTitleColor; |
38 | private Color selectedTitleColor; | 36 | private Color unselectedTitleColor; |
39 | private Color unselectedTitleColor; | 37 | private Border border; |
40 | private Border border; | 38 | private String oId; |
41 | private String oId; | 39 | |
42 | 40 | public MyTabComponent(String oId, MyTabPanel tab) { | |
43 | public MyTabComponent(String oId,MyTabPanel tab) | 41 | super(); |
44 | { | 42 | this.oId = oId; |
45 | super(); | 43 | selectedPaint = MyContorlUtil.createTexturePaint( |
46 | this.oId = oId; | 44 | "control/images/tab_header_background.png"); |
47 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); | 45 | unselectedPaint = MyContorlUtil.createTexturePaint( |
48 | unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); | 46 | "control/images/tab_header_unselected_background.png"); |
49 | icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); | 47 | icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); |
50 | pressedIcon = MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); | 48 | pressedIcon = |
51 | unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); | 49 | MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); |
52 | unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); | 50 | unselectedLeftImage = MyContorlUtil.getImage( |
53 | selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); | 51 | "control/images/tab_header_unselected_background_left.png"); |
54 | selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); | 52 | unselectedRightImage = MyContorlUtil.getImage( |
55 | btnClose = new JButton(); | 53 | "control/images/tab_header_unselected_background_right.png"); |
56 | lbTitle = new JLabel(); | 54 | selectedLeftImage = MyContorlUtil.getImage( |
57 | this.tab = null; | 55 | "control/images/tab_header_selected_background_left.png"); |
58 | selectedTitleColor = new Color(120, 120, 125); | 56 | selectedRightImage = MyContorlUtil.getImage( |
59 | unselectedTitleColor = Color.white; | 57 | "control/images/tab_header_selected_background_right.png"); |
60 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); | 58 | btnClose = new JButton(); |
61 | this.tab = tab; | 59 | lbTitle = new JLabel(); |
62 | init(); | 60 | this.tab = null; |
63 | } | 61 | selectedTitleColor = new Color(120, 120, 125); |
64 | 62 | unselectedTitleColor = Color.white; | |
65 | private void init() | 63 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); |
66 | { | 64 | this.tab = tab; |
67 | btnClose.setIcon(icon); | 65 | init(); |
68 | btnClose.setPressedIcon(pressedIcon); | 66 | } |
69 | btnClose.setToolTipText("Close this tab"); | 67 | |
70 | btnClose.setMargin(MyContorlUtil.ZERO_INSETS); | 68 | private void init() { |
71 | btnClose.setFocusPainted(false); | 69 | btnClose.setIcon(icon); |
72 | btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); | 70 | btnClose.setPressedIcon(pressedIcon); |
73 | btnClose.setContentAreaFilled(false); | 71 | btnClose.setToolTipText("Close this tab"); |
74 | btnClose.addActionListener(new ActionListener() { | 72 | btnClose.setMargin(MyContorlUtil.ZERO_INSETS); |
75 | 73 | btnClose.setFocusPainted(false); | |
76 | public void actionPerformed(ActionEvent e) | 74 | btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); |
77 | { | 75 | btnClose.setContentAreaFilled(false); |
78 | closeTab(); | 76 | btnClose.addActionListener(new ActionListener() { |
79 | } | 77 | |
80 | 78 | public void actionPerformed(ActionEvent e) { | |
81 | }); | 79 | closeTab(); |
82 | lbTitle.setOpaque(false); | 80 | } |
83 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); | 81 | |
84 | lbTitle.setVerticalAlignment(0); | 82 | }); |
85 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); | 83 | lbTitle.setOpaque(false); |
86 | setLayout(new BorderLayout()); | 84 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); |
87 | add(btnClose, "East"); | 85 | lbTitle.setVerticalAlignment(0); |
88 | add(lbTitle, "Center"); | 86 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); |
89 | setBorder(border); | 87 | setLayout(new BorderLayout()); |
90 | setOpaque(false); | 88 | add(btnClose, "East"); |
91 | } | 89 | add(lbTitle, "Center"); |
92 | 90 | setBorder(border); | |
93 | public void paintComponent(Graphics g) | 91 | setOpaque(false); |
94 | { | 92 | } |
95 | Graphics2D g2d = (Graphics2D)g; | 93 | |
96 | if (isTabSelected()) | 94 | public void paintComponent(Graphics g) { |
97 | { | 95 | Graphics2D g2d = (Graphics2D) g; |
98 | g2d.drawImage(selectedLeftImage, 0, 0, null); | 96 | if (isTabSelected()) { |
99 | g2d.setPaint(selectedPaint); | 97 | g2d.drawImage(selectedLeftImage, 0, 0, null); |
100 | int x = selectedLeftImage.getWidth(null); | 98 | g2d.setPaint(selectedPaint); |
101 | int y = 0; | 99 | int x = selectedLeftImage.getWidth(null); |
102 | int width = getWidth() - x - selectedRightImage.getWidth(null); | 100 | int y = 0; |
103 | int height = getHeight(); | 101 | int width = getWidth() - x - selectedRightImage.getWidth(null); |
104 | g2d.fillRect(x, y, width, height); | 102 | int height = getHeight(); |
105 | g2d.drawImage(selectedRightImage, x + width, 0, null); | 103 | g2d.fillRect(x, y, width, height); |
106 | } else | 104 | g2d.drawImage(selectedRightImage, x + width, 0, null); |
107 | { | 105 | } else { |
108 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | 106 | g2d.drawImage(unselectedLeftImage, 0, 0, null); |
109 | g2d.setPaint(unselectedPaint); | 107 | g2d.setPaint(unselectedPaint); |
110 | int x = unselectedLeftImage.getWidth(null); | 108 | int x = unselectedLeftImage.getWidth(null); |
111 | int y = 0; | 109 | int y = 0; |
112 | int width = getWidth() - x - selectedRightImage.getWidth(null); | 110 | int width = getWidth() - x - selectedRightImage.getWidth(null); |
113 | int height = getHeight(); | 111 | int height = getHeight(); |
114 | g2d.fillRect(x, y, width, height); | 112 | g2d.fillRect(x, y, width, height); |
115 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | 113 | g2d.drawImage(unselectedRightImage, x + width, 0, null); |
116 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | 114 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); |
117 | int lineY = getHeight() - 1; | 115 | int lineY = getHeight() - 1; |
118 | g2d.drawLine(0, lineY, getWidth(), lineY); | 116 | g2d.drawLine(0, lineY, getWidth(), lineY); |
119 | } | 117 | } |
120 | } | 118 | } |
121 | 119 | ||
122 | public Dimension getPreferredSize() | 120 | public Dimension getPreferredSize() { |
123 | { | 121 | int width = super.getPreferredSize().width; |
124 | int width = super.getPreferredSize().width; | 122 | if (!isTabSelected()) { |
125 | if (!isTabSelected()) | 123 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); |
126 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); | 124 | } |
127 | int height = tab.getPreferredTabHeight(); | 125 | int height = tab.getPreferredTabHeight(); |
128 | return new Dimension(width, height); | 126 | return new Dimension(width, height); |
129 | } | 127 | } |
130 | 128 | ||
131 | public boolean isTabSelected() | 129 | public boolean isTabSelected() { |
132 | { | 130 | int index = tab.indexOfTabComponent(this); |
133 | int index = tab.indexOfTabComponent(this); | 131 | int selectedIndex = tab.getSelectedIndex(); |
134 | int selectedIndex = tab.getSelectedIndex(); | 132 | return selectedIndex == index; |
135 | return selectedIndex == index; | 133 | } |
136 | } | 134 | |
137 | 135 | public void setTitle(String title) { | |
138 | public void setTitle(String title) | 136 | lbTitle.setText(title); |
139 | { | 137 | } |
140 | lbTitle.setText(title); | 138 | |
141 | } | 139 | public void updateSelection(boolean selected) { |
142 | 140 | if (selected) { | |
143 | public void updateSelection(boolean selected) | 141 | lbTitle.setForeground(selectedTitleColor); |
144 | { | 142 | } else { |
145 | if (selected) | 143 | lbTitle.setForeground(unselectedTitleColor); |
146 | lbTitle.setForeground(selectedTitleColor); | 144 | } |
147 | else | 145 | btnClose.setVisible(selected); |
148 | lbTitle.setForeground(unselectedTitleColor); | 146 | } |
149 | btnClose.setVisible(selected); | 147 | |
150 | } | 148 | private void closeTab() { |
151 | 149 | int index = tab.indexOfTabComponent(this); | |
152 | private void closeTab() | 150 | tab.removeTabAt(index); |
153 | { | 151 | } |
154 | int index = tab.indexOfTabComponent(this); | 152 | |
155 | tab.removeTabAt(index); | 153 | /** |
156 | } | 154 | * @return the oId |
157 | 155 | */ | |
158 | /** | 156 | public String getOId() { |
159 | * @param oId the oId to set | 157 | return oId; |
160 | */ | 158 | } |
161 | public void setOId(String oId) | 159 | |
162 | { | 160 | /** |
163 | this.oId = oId; | 161 | * @param oId the oId to set |
164 | } | 162 | */ |
165 | 163 | public void setOId(String oId) { | |
166 | /** | 164 | this.oId = oId; |
167 | * @return the oId | 165 | } |
168 | */ | ||
169 | public String getOId() | ||
170 | { | ||
171 | return oId; | ||
172 | } | ||
173 | } | 166 | } |
diff --git a/src/cppcheckplus/tab/MyTabComponent1.java b/src/cppcheckplus/tab/MyTabComponent1.java index 9901441..5ca0dfb 100644 --- a/src/cppcheckplus/tab/MyTabComponent1.java +++ b/src/cppcheckplus/tab/MyTabComponent1.java | |||
@@ -1,5 +1,6 @@ | |||
1 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
3 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
4 | import java.awt.Color; | 5 | import java.awt.Color; |
5 | import java.awt.Dimension; | 6 | import java.awt.Dimension; |
@@ -7,130 +8,122 @@ import java.awt.Graphics; | |||
7 | import java.awt.Graphics2D; | 8 | import java.awt.Graphics2D; |
8 | import java.awt.Image; | 9 | import java.awt.Image; |
9 | import java.awt.TexturePaint; | 10 | import java.awt.TexturePaint; |
10 | |||
11 | import javax.swing.BorderFactory; | 11 | import javax.swing.BorderFactory; |
12 | import javax.swing.ImageIcon; | 12 | import javax.swing.ImageIcon; |
13 | import javax.swing.JLabel; | 13 | import javax.swing.JLabel; |
14 | import javax.swing.JPanel; | 14 | import javax.swing.JPanel; |
15 | import javax.swing.border.Border; | 15 | import javax.swing.border.Border; |
16 | 16 | ||
17 | import cppcheckplus.control.MyContorlUtil; | 17 | public class MyTabComponent1 extends JPanel { |
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 | 18 | ||
55 | private void init() | 19 | private String backgroundUnselectedImageURL; |
56 | { | 20 | private TexturePaint selectedPaint; |
57 | lbTitle.setOpaque(false); | 21 | private TexturePaint unselectedPaint; |
58 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); | 22 | private ImageIcon pressedIcon; |
59 | lbTitle.setVerticalAlignment(0); | 23 | private Image unselectedLeftImage; |
60 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); | 24 | private Image unselectedRightImage; |
61 | setLayout(new BorderLayout()); | 25 | private Image selectedLeftImage; |
62 | add(lbTitle, "Center"); | 26 | private Image selectedRightImage; |
63 | setBorder(border); | 27 | private JLabel lbTitle; |
64 | setOpaque(false); | 28 | private MyTabPanel1 tab; |
65 | } | 29 | private Color selectedTitleColor; |
30 | private Color unselectedTitleColor; | ||
31 | private Border border; | ||
32 | private String oId; | ||
66 | 33 | ||
67 | public void paintComponent(Graphics g) | 34 | public MyTabComponent1(String oId, MyTabPanel1 tab) { |
68 | { | 35 | super(); |
69 | Graphics2D g2d = (Graphics2D)g; | 36 | this.oId = oId; |
70 | if (isTabSelected()) | 37 | selectedPaint = MyContorlUtil.createTexturePaint( |
71 | { | 38 | "control/images/tab_header_background.png"); |
72 | g2d.drawImage(selectedLeftImage, 0, 0, null); | 39 | unselectedPaint = MyContorlUtil.createTexturePaint( |
73 | g2d.setPaint(selectedPaint); | 40 | "control/images/tab_header_unselected_background.png"); |
74 | int x = selectedLeftImage.getWidth(null); | 41 | unselectedLeftImage = MyContorlUtil.getImage( |
75 | int y = 0; | 42 | "control/images/tab_header_unselected_background_left.png"); |
76 | int width = getWidth() - x - selectedRightImage.getWidth(null); | 43 | unselectedRightImage = MyContorlUtil.getImage( |
77 | int height = getHeight(); | 44 | "control/images/tab_header_unselected_background_right.png"); |
78 | g2d.fillRect(x, y, width, height); | 45 | selectedLeftImage = MyContorlUtil.getImage( |
79 | g2d.drawImage(selectedRightImage, x + width, 0, null); | 46 | "control/images/tab_header_selected_background_left.png"); |
80 | } else | 47 | selectedRightImage = MyContorlUtil.getImage( |
81 | { | 48 | "control/images/tab_header_selected_background_right.png"); |
82 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | 49 | lbTitle = new JLabel(); |
83 | g2d.setPaint(unselectedPaint); | 50 | this.tab = null; |
84 | int x = unselectedLeftImage.getWidth(null); | 51 | selectedTitleColor = new Color(120, 120, 125); |
85 | int y = 0; | 52 | unselectedTitleColor = Color.white; |
86 | int width = getWidth() - x - selectedRightImage.getWidth(null); | 53 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); |
87 | int height = getHeight(); | 54 | this.tab = tab; |
88 | g2d.fillRect(x, y, width, height); | 55 | init(); |
89 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | 56 | } |
90 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
91 | int lineY = getHeight() - 1; | ||
92 | g2d.drawLine(0, lineY, getWidth(), lineY); | ||
93 | } | ||
94 | } | ||
95 | 57 | ||
96 | public Dimension getPreferredSize() | 58 | private void init() { |
97 | { | 59 | lbTitle.setOpaque(false); |
98 | int width = super.getPreferredSize().width; | 60 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); |
99 | if (!isTabSelected()) | 61 | lbTitle.setVerticalAlignment(0); |
100 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); | 62 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); |
101 | int height = tab.getPreferredTabHeight(); | 63 | setLayout(new BorderLayout()); |
102 | return new Dimension(width, height); | 64 | add(lbTitle, "Center"); |
103 | } | 65 | setBorder(border); |
66 | setOpaque(false); | ||
67 | } | ||
104 | 68 | ||
105 | public boolean isTabSelected() | 69 | public void paintComponent(Graphics g) { |
106 | { | 70 | Graphics2D g2d = (Graphics2D) g; |
107 | int index = tab.indexOfTabComponent(this); | 71 | if (isTabSelected()) { |
108 | int selectedIndex = tab.getSelectedIndex(); | 72 | g2d.drawImage(selectedLeftImage, 0, 0, null); |
109 | return selectedIndex == index; | 73 | g2d.setPaint(selectedPaint); |
110 | } | 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 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | ||
82 | g2d.setPaint(unselectedPaint); | ||
83 | int x = unselectedLeftImage.getWidth(null); | ||
84 | int y = 0; | ||
85 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
86 | int height = getHeight(); | ||
87 | g2d.fillRect(x, y, width, height); | ||
88 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | ||
89 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
90 | int lineY = getHeight() - 1; | ||
91 | g2d.drawLine(0, lineY, getWidth(), lineY); | ||
92 | } | ||
93 | } | ||
111 | 94 | ||
112 | public void setTitle(String title) | 95 | public Dimension getPreferredSize() { |
113 | { | 96 | int width = super.getPreferredSize().width; |
114 | lbTitle.setText(title); | 97 | if (!isTabSelected()) { |
115 | } | 98 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); |
99 | } | ||
100 | int height = tab.getPreferredTabHeight(); | ||
101 | return new Dimension(width, height); | ||
102 | } | ||
116 | 103 | ||
117 | public void updateSelection(boolean selected) | 104 | public boolean isTabSelected() { |
118 | { | 105 | int index = tab.indexOfTabComponent(this); |
119 | if (selected) | 106 | int selectedIndex = tab.getSelectedIndex(); |
120 | lbTitle.setForeground(selectedTitleColor); | 107 | return selectedIndex == index; |
121 | else | 108 | } |
122 | lbTitle.setForeground(unselectedTitleColor); | ||
123 | } | ||
124 | 109 | ||
110 | public void setTitle(String title) { | ||
111 | lbTitle.setText(title); | ||
112 | } | ||
125 | 113 | ||
114 | public void updateSelection(boolean selected) { | ||
115 | if (selected) { | ||
116 | lbTitle.setForeground(selectedTitleColor); | ||
117 | } else { | ||
118 | lbTitle.setForeground(unselectedTitleColor); | ||
119 | } | ||
120 | } | ||
126 | 121 | ||
127 | public void setOId(String oId) | 122 | public String getOId() { |
128 | { | 123 | return oId; |
129 | this.oId = oId; | 124 | } |
130 | } | ||
131 | 125 | ||
132 | public String getOId() | 126 | public void setOId(String oId) { |
133 | { | 127 | this.oId = oId; |
134 | return oId; | 128 | } |
135 | } | ||
136 | } | 129 | } |
diff --git a/src/cppcheckplus/tab/MyTabPage.java b/src/cppcheckplus/tab/MyTabPage.java index ef26580..a240b58 100644 --- a/src/cppcheckplus/tab/MyTabPage.java +++ b/src/cppcheckplus/tab/MyTabPage.java | |||
@@ -1,46 +1,39 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
3 | 2 | ||
3 | import cppcheckplus.toolbar.MyToolBar; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import javax.swing.JComponent; | 5 | import javax.swing.JComponent; |
6 | import javax.swing.JPanel; | 6 | import javax.swing.JPanel; |
7 | 7 | ||
8 | import cppcheckplus.toolbar.MyToolBar; | ||
9 | |||
10 | 8 | ||
11 | public class MyTabPage extends JPanel | 9 | public class MyTabPage extends JPanel { |
12 | { | 10 | private MyToolBar toolbar; |
13 | private MyToolBar toolbar; | 11 | private JPanel centerPane; |
14 | private JPanel centerPane; | 12 | |
15 | 13 | public MyTabPage() { | |
16 | public MyTabPage() | 14 | this(null); |
17 | { | 15 | } |
18 | this(null); | 16 | |
19 | } | 17 | public MyTabPage(JComponent contentComponent) { |
20 | 18 | toolbar = new MyToolBar(); | |
21 | public MyTabPage(JComponent contentComponent) | 19 | centerPane = new JPanel(new BorderLayout()); |
22 | { | 20 | init(contentComponent); |
23 | toolbar = new MyToolBar(); | 21 | } |
24 | centerPane = new JPanel(new BorderLayout()); | 22 | |
25 | init(contentComponent); | 23 | private void init(JComponent contentComponent) { |
26 | } | 24 | setLayout(new BorderLayout()); |
27 | 25 | add(toolbar, "North"); | |
28 | private void init(JComponent contentComponent) | 26 | add(centerPane, "Center"); |
29 | { | 27 | if (contentComponent != null) { |
30 | setLayout(new BorderLayout()); | 28 | centerPane.add(contentComponent, "Center"); |
31 | add(toolbar, "North"); | 29 | } |
32 | add(centerPane, "Center"); | 30 | } |
33 | if (contentComponent != null) | 31 | |
34 | centerPane.add(contentComponent, "Center"); | 32 | public JPanel getCenterPane() { |
35 | } | 33 | return centerPane; |
36 | 34 | } | |
37 | public JPanel getCenterPane() | 35 | |
38 | { | 36 | public MyToolBar getToolBar() { |
39 | return centerPane; | 37 | return toolbar; |
40 | } | 38 | } |
41 | |||
42 | public MyToolBar getToolBar() | ||
43 | { | ||
44 | return toolbar; | ||
45 | } | ||
46 | } | 39 | } |
diff --git a/src/cppcheckplus/tab/MyTabPage1.java b/src/cppcheckplus/tab/MyTabPage1.java index e851b3a..d20b78c 100644 --- a/src/cppcheckplus/tab/MyTabPage1.java +++ b/src/cppcheckplus/tab/MyTabPage1.java | |||
@@ -1,30 +1,31 @@ | |||
1 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
2 | 2 | ||
3 | import java.awt.BorderLayout; | 3 | import java.awt.BorderLayout; |
4 | |||
5 | import javax.swing.JComponent; | 4 | import javax.swing.JComponent; |
6 | import javax.swing.JPanel; | 5 | import javax.swing.JPanel; |
7 | public class MyTabPage1 extends JPanel{ | ||
8 | private JPanel centerPane; | ||
9 | 6 | ||
10 | public MyTabPage1(){ | 7 | public class MyTabPage1 extends JPanel { |
11 | this(null); | 8 | private JPanel centerPane; |
12 | } | 9 | |
10 | public MyTabPage1() { | ||
11 | this(null); | ||
12 | } | ||
13 | 13 | ||
14 | public MyTabPage1(JComponent contentComponent){ | 14 | public MyTabPage1(JComponent contentComponent) { |
15 | centerPane = new JPanel(new BorderLayout()); | 15 | centerPane = new JPanel(new BorderLayout()); |
16 | init(contentComponent); | 16 | init(contentComponent); |
17 | } | 17 | } |
18 | 18 | ||
19 | private void init(JComponent contentComponent){ | 19 | private void init(JComponent contentComponent) { |
20 | setLayout(new BorderLayout()); | 20 | setLayout(new BorderLayout()); |
21 | add(centerPane, "Center"); | 21 | add(centerPane, "Center"); |
22 | if (contentComponent != null) | 22 | if (contentComponent != null) { |
23 | centerPane.add(contentComponent, "Center"); | 23 | centerPane.add(contentComponent, "Center"); |
24 | } | 24 | } |
25 | } | ||
25 | 26 | ||
26 | public JPanel getCenterPane(){ | 27 | public JPanel getCenterPane() { |
27 | return centerPane; | 28 | return centerPane; |
28 | } | 29 | } |
29 | 30 | ||
30 | } | 31 | } |
diff --git a/src/cppcheckplus/tab/MyTabPanel.java b/src/cppcheckplus/tab/MyTabPanel.java index cda8c3a..3dff0f4 100644 --- a/src/cppcheckplus/tab/MyTabPanel.java +++ b/src/cppcheckplus/tab/MyTabPanel.java | |||
@@ -1,97 +1,82 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Component; | 4 | import java.awt.Component; |
5 | import javax.swing.JTabbedPane; | 5 | import javax.swing.JTabbedPane; |
6 | import javax.swing.event.ChangeEvent; | 6 | import javax.swing.event.ChangeEvent; |
7 | import javax.swing.event.ChangeListener; | 7 | import javax.swing.event.ChangeListener; |
8 | 8 | ||
9 | import cppcheckplus.control.MyContorlUtil; | 9 | public class MyTabPanel extends JTabbedPane { |
10 | private int preferredUnselectedTabWidth; | ||
11 | private int preferredTabHeight; | ||
12 | |||
13 | public MyTabPanel() { | ||
14 | preferredUnselectedTabWidth = 80; | ||
15 | preferredTabHeight = MyContorlUtil.getImageIcon( | ||
16 | "control/images/tab_header_background.png").getIconHeight(); | ||
17 | init(); | ||
18 | } | ||
10 | 19 | ||
11 | public class MyTabPanel extends JTabbedPane | 20 | private void init() { |
12 | { | 21 | setFont(MyContorlUtil.FONT_12_BOLD); |
13 | private int preferredUnselectedTabWidth; | 22 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); |
14 | private int preferredTabHeight; | 23 | setBorder(null); |
24 | setFocusable(false); | ||
25 | setTabLayoutPolicy(1); | ||
26 | setOpaque(false); | ||
27 | setUI(new MyTabPanelUI(this)); | ||
28 | addChangeListener(new ChangeListener() { | ||
29 | public void stateChanged(ChangeEvent e) { | ||
30 | updateTabComponents(); | ||
31 | } | ||
32 | }); | ||
33 | } | ||
15 | 34 | ||
16 | public MyTabPanel() | ||
17 | { | ||
18 | preferredUnselectedTabWidth = 80; | ||
19 | preferredTabHeight = MyContorlUtil.getImageIcon("control/images/tab_header_background.png").getIconHeight(); | ||
20 | init(); | ||
21 | } | ||
22 | 35 | ||
23 | private void init() | 36 | @Override |
24 | { | 37 | public void addTab(String title, Component component) { |
25 | setFont(MyContorlUtil.FONT_12_BOLD); | 38 | super.addTab(title, component); |
26 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); | 39 | int index = getTabCount() - 1; |
27 | setBorder(null); | 40 | MyTabComponent tabComponent = new MyTabComponent(title, this); |
28 | setFocusable(false); | 41 | tabComponent.setTitle(title); |
29 | setTabLayoutPolicy(1); | 42 | setTabComponentAt(index, tabComponent); |
30 | setOpaque(false); | 43 | setToolTipTextAt(index, title); |
31 | setUI(new MyTabPanelUI(this)); | 44 | updateTabComponents(); |
32 | addChangeListener(new ChangeListener() { | 45 | } |
33 | public void stateChanged(ChangeEvent e) | ||
34 | { | ||
35 | updateTabComponents(); | ||
36 | } | ||
37 | }); | ||
38 | } | ||
39 | 46 | ||
40 | 47 | public boolean isSelectTabComponents(String oId) { | |
41 | @Override | 48 | for (int i = 0; i < getTabCount(); i++) { |
42 | public void addTab(String title, Component component) | 49 | Component c = getTabComponentAt(i); |
43 | { | 50 | if (c instanceof MyTabComponent) { |
44 | super.addTab(title, component); | 51 | if (((MyTabComponent) c).getOId().equals(oId)) { |
45 | int index = getTabCount() - 1; | 52 | setSelectedIndex(i); |
46 | MyTabComponent tabComponent = new MyTabComponent(title, this); | 53 | updateTabComponents(); |
47 | tabComponent.setTitle(title); | 54 | return true; |
48 | setTabComponentAt(index, tabComponent); | 55 | } |
49 | setToolTipTextAt(index, title); | 56 | } |
50 | updateTabComponents(); | 57 | } |
51 | } | 58 | return false; |
52 | 59 | } | |
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 | 60 | ||
71 | public int getPreferredTabHeight() | 61 | public int getPreferredTabHeight() { |
72 | { | 62 | return preferredTabHeight; |
73 | return preferredTabHeight; | 63 | } |
74 | } | ||
75 | 64 | ||
76 | private void updateTabComponents() | 65 | private void updateTabComponents() { |
77 | { | 66 | int selectedIndex = getSelectedIndex(); |
78 | int selectedIndex = getSelectedIndex(); | 67 | for (int i = 0; i < getTabCount(); i++) { |
79 | for (int i = 0; i < getTabCount(); i++) | 68 | Component c = getTabComponentAt(i); |
80 | { | 69 | if (c instanceof MyTabComponent) { |
81 | Component c = getTabComponentAt(i); | 70 | MyTabComponent component = (MyTabComponent) c; |
82 | if (c instanceof MyTabComponent) | 71 | boolean selected = selectedIndex == i; |
83 | { | 72 | component.updateSelection(selected); |
84 | MyTabComponent component = (MyTabComponent)c; | 73 | } |
85 | boolean selected = selectedIndex == i; | 74 | } |
86 | component.updateSelection(selected); | ||
87 | } | ||
88 | } | ||
89 | 75 | ||
90 | } | 76 | } |
91 | 77 | ||
92 | public int getPreferredUnselectedTabWidth() | 78 | public int getPreferredUnselectedTabWidth() { |
93 | { | 79 | return preferredUnselectedTabWidth; |
94 | return preferredUnselectedTabWidth; | 80 | } |
95 | } | ||
96 | 81 | ||
97 | } | 82 | } |
diff --git a/src/cppcheckplus/tab/MyTabPanelUI.java b/src/cppcheckplus/tab/MyTabPanelUI.java index b576d16..dea3a2e 100644 --- a/src/cppcheckplus/tab/MyTabPanelUI.java +++ b/src/cppcheckplus/tab/MyTabPanelUI.java | |||
@@ -1,53 +1,48 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.FontMetrics; | 4 | import java.awt.FontMetrics; |
5 | import java.awt.Graphics; | 5 | import java.awt.Graphics; |
6 | import java.awt.Rectangle; | 6 | import java.awt.Rectangle; |
7 | import javax.swing.plaf.metal.MetalTabbedPaneUI; | 7 | import javax.swing.plaf.metal.MetalTabbedPaneUI; |
8 | 8 | ||
9 | import cppcheckplus.control.MyContorlUtil; | 9 | public class MyTabPanelUI extends MetalTabbedPaneUI { |
10 | 10 | private MyTabPanel tab; | |
11 | public class MyTabPanelUI extends MetalTabbedPaneUI | 11 | private int firstTabIndent; |
12 | { | 12 | |
13 | private MyTabPanel tab; | 13 | public MyTabPanelUI(MyTabPanel tab) { |
14 | private int firstTabIndent; | 14 | this.tab = null; |
15 | 15 | firstTabIndent = 5; | |
16 | public MyTabPanelUI(MyTabPanel tab) | 16 | this.tab = tab; |
17 | { | 17 | } |
18 | this.tab = null; | 18 | |
19 | firstTabIndent = 5; | 19 | protected Rectangle getTabBounds(int tabIndex, Rectangle dest) { |
20 | this.tab = tab; | 20 | Rectangle bounds = super.getTabBounds(tabIndex, dest); |
21 | } | 21 | bounds.x += firstTabIndent; |
22 | 22 | return bounds; | |
23 | protected Rectangle getTabBounds(int tabIndex, Rectangle dest) | 23 | } |
24 | { | 24 | |
25 | Rectangle bounds = super.getTabBounds(tabIndex, dest); | 25 | protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, |
26 | bounds.x += firstTabIndent; | 26 | int x, int y, int w, int h, |
27 | return bounds; | 27 | boolean isSelected) { |
28 | } | 28 | g.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); |
29 | 29 | int lineY = tab.getPreferredTabHeight() - 1; | |
30 | protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, | 30 | g.drawLine(0, lineY, firstTabIndent, lineY); |
31 | boolean isSelected) | 31 | } |
32 | { | 32 | |
33 | g.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | 33 | protected void paintTabBackground(Graphics g1, int i, int j, int k, int l, |
34 | int lineY = tab.getPreferredTabHeight() - 1; | 34 | int i1, int j1, |
35 | g.drawLine(0, lineY, firstTabIndent, lineY); | 35 | boolean flag) { |
36 | } | 36 | } |
37 | 37 | ||
38 | protected void paintTabBackground(Graphics g1, int i, int j, int k, int l, int i1, int j1, | 38 | protected int calculateTabWidth(int tabPlacement, int tabIndex, |
39 | boolean flag) | 39 | FontMetrics metrics) { |
40 | { | 40 | int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); |
41 | } | 41 | return width - 5; |
42 | 42 | } | |
43 | protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) | 43 | |
44 | { | 44 | protected int calculateTabHeight(int tabPlacement, int tabIndex, |
45 | int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); | 45 | int fontHeight) { |
46 | return width - 5; | 46 | return tab.getPreferredTabHeight(); |
47 | } | 47 | } |
48 | |||
49 | protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) | ||
50 | { | ||
51 | return tab.getPreferredTabHeight(); | ||
52 | } | ||
53 | } | 48 | } |
diff --git a/src/cppcheckplus/tab/MyTabPanelUI1.java b/src/cppcheckplus/tab/MyTabPanelUI1.java index f98c5f9..5afb20c 100644 --- a/src/cppcheckplus/tab/MyTabPanelUI1.java +++ b/src/cppcheckplus/tab/MyTabPanelUI1.java | |||
@@ -1,53 +1,48 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.FontMetrics; | 4 | import java.awt.FontMetrics; |
5 | import java.awt.Graphics; | 5 | import java.awt.Graphics; |
6 | import java.awt.Rectangle; | 6 | import java.awt.Rectangle; |
7 | import javax.swing.plaf.metal.MetalTabbedPaneUI; | 7 | import javax.swing.plaf.metal.MetalTabbedPaneUI; |
8 | 8 | ||
9 | import cppcheckplus.control.MyContorlUtil; | 9 | public class MyTabPanelUI1 extends MetalTabbedPaneUI { |
10 | 10 | private MyTabPanel1 tab; | |
11 | public class MyTabPanelUI1 extends MetalTabbedPaneUI | 11 | private int firstTabIndent; |
12 | { | 12 | |
13 | private MyTabPanel1 tab; | 13 | public MyTabPanelUI1(MyTabPanel1 tab) { |
14 | private int firstTabIndent; | 14 | this.tab = null; |
15 | 15 | firstTabIndent = 5; | |
16 | public MyTabPanelUI1(MyTabPanel1 tab) | 16 | this.tab = tab; |
17 | { | 17 | } |
18 | this.tab = null; | 18 | |
19 | firstTabIndent = 5; | 19 | protected Rectangle getTabBounds(int tabIndex, Rectangle dest) { |
20 | this.tab = tab; | 20 | Rectangle bounds = super.getTabBounds(tabIndex, dest); |
21 | } | 21 | bounds.x += firstTabIndent; |
22 | 22 | return bounds; | |
23 | protected Rectangle getTabBounds(int tabIndex, Rectangle dest) | 23 | } |
24 | { | 24 | |
25 | Rectangle bounds = super.getTabBounds(tabIndex, dest); | 25 | protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, |
26 | bounds.x += firstTabIndent; | 26 | int x, int y, int w, int h, |
27 | return bounds; | 27 | boolean isSelected) { |
28 | } | 28 | g.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); |
29 | 29 | int lineY = tab.getPreferredTabHeight() - 1; | |
30 | protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, | 30 | g.drawLine(0, lineY, firstTabIndent, lineY); |
31 | boolean isSelected) | 31 | } |
32 | { | 32 | |
33 | g.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | 33 | protected void paintTabBackground(Graphics g1, int i, int j, int k, int l, |
34 | int lineY = tab.getPreferredTabHeight() - 1; | 34 | int i1, int j1, |
35 | g.drawLine(0, lineY, firstTabIndent, lineY); | 35 | boolean flag) { |
36 | } | 36 | } |
37 | 37 | ||
38 | protected void paintTabBackground(Graphics g1, int i, int j, int k, int l, int i1, int j1, | 38 | protected int calculateTabWidth(int tabPlacement, int tabIndex, |
39 | boolean flag) | 39 | FontMetrics metrics) { |
40 | { | 40 | int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); |
41 | } | 41 | return width - 5; |
42 | 42 | } | |
43 | protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) | 43 | |
44 | { | 44 | protected int calculateTabHeight(int tabPlacement, int tabIndex, |
45 | int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); | 45 | int fontHeight) { |
46 | return width - 5; | 46 | return tab.getPreferredTabHeight(); |
47 | } | 47 | } |
48 | |||
49 | protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) | ||
50 | { | ||
51 | return tab.getPreferredTabHeight(); | ||
52 | } | ||
53 | } | 48 | } |
diff --git a/src/cppcheckplus/text/DeflectRow.java b/src/cppcheckplus/text/DeflectRow.java index 5b113a6..9cc96a2 100644 --- a/src/cppcheckplus/text/DeflectRow.java +++ b/src/cppcheckplus/text/DeflectRow.java | |||
@@ -1,126 +1,165 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | public class DeflectRow { | 3 | public class DeflectRow { |
4 | 4 | private String until = null; | |
5 | public DeflectRow(String until, String file, String line, String level, String type, String cwe, | 5 | private String file = null; |
6 | String description,int issure) { | 6 | private String line = null; |
7 | super(); | 7 | private String level = null; |
8 | this.until = until; | 8 | private String type = null; |
9 | this.file = file; | 9 | private String cwe = null; |
10 | this.line = line; | 10 | private String description = null; |
11 | this.level = level; | 11 | private Issure issure = Issure.NOTSURE_ISSURE; |
12 | this.type = type; | 12 | |
13 | this.cwe = cwe; | 13 | public DeflectRow(String until, String file, String line, String level, |
14 | this.description = description; | 14 | String type, String cwe, String description, int issure) { |
15 | this.issure = issure; | 15 | super(); |
16 | } | 16 | this.until = until; |
17 | @Override | 17 | this.file = file; |
18 | public String toString() { | 18 | this.line = line; |
19 | return "DeflectRow [until=" + until + ", file=" + file + ", line=" + line + ", level=" + level + ", type=" | 19 | this.level = level; |
20 | + type + ", cwe=" + cwe + ", description=" + description + "]"; | 20 | this.type = type; |
21 | } | 21 | this.cwe = cwe; |
22 | private String until = null; | 22 | this.description = description; |
23 | public String getUntil() { | 23 | this.issure = Issure.values()[issure]; |
24 | return until; | 24 | } |
25 | } | 25 | |
26 | public void setUntil(String until) { | 26 | @Override |
27 | this.until = until; | 27 | public String toString() { |
28 | } | 28 | return "DeflectRow [until=" + until + ", file=" + file + ", line=" + |
29 | public String getFile() { | 29 | line + ", level=" + level + ", type=" + type + ", cwe=" + cwe + |
30 | return file; | 30 | ", description=" + description + "]"; |
31 | } | 31 | } |
32 | public void setFile(String file) { | 32 | |
33 | this.file = file; | 33 | public String getUntil() { |
34 | } | 34 | return until; |
35 | public String getLine() { | 35 | } |
36 | return line; | 36 | |
37 | } | 37 | public void setUntil(String until) { |
38 | public void setLine(String line) { | 38 | this.until = until; |
39 | this.line = line; | 39 | } |
40 | } | 40 | |
41 | public String getLevel() { | 41 | public String getFile() { |
42 | return level; | 42 | return file; |
43 | } | 43 | } |
44 | public void setLevel(String level) { | 44 | |
45 | this.level = level; | 45 | public void setFile(String file) { |
46 | } | 46 | this.file = file; |
47 | public String getType() { | 47 | } |
48 | return type; | 48 | |
49 | } | 49 | public String getLine() { |
50 | public void setType(String type) { | 50 | return line; |
51 | this.type = type; | 51 | } |
52 | } | 52 | |
53 | public String getCwe() { | 53 | public void setLine(String line) { |
54 | return cwe; | 54 | this.line = line; |
55 | } | 55 | } |
56 | public void setCwe(String cwe) { | 56 | |
57 | this.cwe = cwe; | 57 | public String getLevel() { |
58 | } | 58 | return level; |
59 | public String getDescription() { | 59 | } |
60 | return description; | 60 | |
61 | } | 61 | public void setLevel(String level) { |
62 | public void setDescription(String description) { | 62 | this.level = level; |
63 | this.description = description; | 63 | } |
64 | } | 64 | |
65 | public int getIssure() { | 65 | public String getType() { |
66 | return issure; | 66 | return type; |
67 | } | 67 | } |
68 | public void setIssure(int issure) { | 68 | |
69 | this.issure = issure; | 69 | public void setType(String type) { |
70 | } | 70 | this.type = type; |
71 | private String file = null; | 71 | } |
72 | private String line = null; | 72 | |
73 | private String level = null; | 73 | public String getCwe() { |
74 | private String type = null; | 74 | return cwe; |
75 | private String cwe = null; | 75 | } |
76 | private String description = null; | 76 | |
77 | private int issure = 0; //0是未确认, 1是确认正确, 2是确认误报 | 77 | public void setCwe(String cwe) { |
78 | 78 | this.cwe = cwe; | |
79 | @Override | 79 | } |
80 | public int hashCode() { | 80 | |
81 | final int prime = 31; | 81 | public String getDescription() { |
82 | int result = 1; | 82 | return description; |
83 | result = prime * result + ((file == null) ? 0 : file.hashCode()); | 83 | } |
84 | result = prime * result + ((level == null) ? 0 : level.hashCode()); | 84 | |
85 | result = prime * result + ((line == null) ? 0 : line.hashCode()); | 85 | public void setDescription(String description) { |
86 | result = prime * result + ((type == null) ? 0 : type.hashCode()); | 86 | this.description = description; |
87 | return result; | 87 | } |
88 | } | 88 | |
89 | 89 | public Issure getIssure() { | |
90 | @Override | 90 | return issure; |
91 | public boolean equals(Object obj) { | 91 | } |
92 | if (this == obj) | 92 | |
93 | return true; | 93 | public void setIssure(Issure issure) { |
94 | if (obj == null) | 94 | this.issure = issure; |
95 | return false; | 95 | } |
96 | if (getClass() != obj.getClass()) | 96 | |
97 | return false; | 97 | @Override |
98 | DeflectRow other = (DeflectRow) obj; | 98 | public int hashCode() { |
99 | if (file == null) { | 99 | final int prime = 31; |
100 | if (other.file != null) | 100 | int result = 1; |
101 | return false; | 101 | result = prime * result + ((file == null) ? 0 : file.hashCode()); |
102 | } else if (!file.equals(other.file)) | 102 | result = prime * result + ((level == null) ? 0 : level.hashCode()); |
103 | return false; | 103 | result = prime * result + ((line == null) ? 0 : line.hashCode()); |
104 | if (level == null) { | 104 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
105 | if (other.level != null) | 105 | return result; |
106 | return false; | 106 | } |
107 | } else if (!level.equals(other.level)) | 107 | |
108 | return false; | 108 | @Override |
109 | if (line == null) { | 109 | public boolean equals(Object obj) { |
110 | if (other.line != null) | 110 | if (this == obj) { |
111 | return false; | 111 | return true; |
112 | } else if (!line.equals(other.line)) | 112 | } |
113 | return false; | 113 | if (obj == null) { |
114 | if (type == null) { | 114 | return false; |
115 | if (other.type != null) | 115 | } |
116 | return false; | 116 | if (getClass() != obj.getClass()) { |
117 | } else if (!type.equals(other.type)) | 117 | return false; |
118 | return false; | 118 | } |
119 | if (until == null) { | 119 | DeflectRow other = (DeflectRow) obj; |
120 | if (other.until != null) | 120 | if (file == null) { |
121 | return false; | 121 | if (other.file != null) { |
122 | } else if (until.equals(other.until)) | 122 | return false; |
123 | return false; | 123 | } |
124 | return true; | 124 | } else if (!file.equals(other.file)) { |
125 | } | 125 | return false; |
126 | } | ||
127 | if (level == null) { | ||
128 | if (other.level != null) { | ||
129 | return false; | ||
130 | } | ||
131 | } else if (!level.equals(other.level)) { | ||
132 | return false; | ||
133 | } | ||
134 | if (line == null) { | ||
135 | if (other.line != null) { | ||
136 | return false; | ||
137 | } | ||
138 | } else if (!line.equals(other.line)) { | ||
139 | return false; | ||
140 | } | ||
141 | if (type == null) { | ||
142 | if (other.type != null) { | ||
143 | return false; | ||
144 | } | ||
145 | } else if (!type.equals(other.type)) { | ||
146 | return false; | ||
147 | } | ||
148 | if (until == null) { | ||
149 | return other.until == null; | ||
150 | } else { | ||
151 | return !until.equals(other.until); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | public enum Issure { | ||
156 | NOTSURE_ISSURE, CURRECT_ISSURE, WRONG_ISSURE; | ||
157 | |||
158 | public static Issure fromInt(int i) { | ||
159 | if (i < 0 || i >= values().length) { | ||
160 | return NOTSURE_ISSURE; // 传入非法数据,默认为待定 | ||
161 | } | ||
162 | return values()[i]; | ||
163 | } | ||
164 | } | ||
126 | } \ No newline at end of file | 165 | } \ No newline at end of file |
diff --git a/src/cppcheckplus/text/FileTools.java b/src/cppcheckplus/text/FileTools.java index 95dd4fb..9da0c75 100644 --- a/src/cppcheckplus/text/FileTools.java +++ b/src/cppcheckplus/text/FileTools.java | |||
@@ -7,7 +7,6 @@ import java.io.FileOutputStream; | |||
7 | import java.io.FileReader; | 7 | import java.io.FileReader; |
8 | import java.io.FileWriter; | 8 | import java.io.FileWriter; |
9 | import java.util.Vector; | 9 | import java.util.Vector; |
10 | |||
11 | import org.dom4j.Document; | 10 | import org.dom4j.Document; |
12 | import org.dom4j.DocumentHelper; | 11 | import org.dom4j.DocumentHelper; |
13 | import org.dom4j.Element; | 12 | import org.dom4j.Element; |
@@ -16,69 +15,71 @@ import org.dom4j.io.XMLWriter; | |||
16 | 15 | ||
17 | public class FileTools { | 16 | public class FileTools { |
18 | 17 | ||
19 | public static String readFile(File file) { | 18 | public static String readFile(File file) { |
20 | StringBuilder resultStr = new StringBuilder(); | 19 | StringBuilder resultStr = new StringBuilder(); |
21 | try { | 20 | try { |
22 | BufferedReader bReader = new BufferedReader(new FileReader(file)); | 21 | BufferedReader bReader = new BufferedReader(new FileReader(file)); |
23 | String line = bReader.readLine(); | 22 | String line = bReader.readLine(); |
24 | while (line != null) { | 23 | while (line != null) { |
25 | resultStr.append(line + "\r\n"); | 24 | resultStr.append(line + "\r\n"); |
26 | line = bReader.readLine(); | 25 | line = bReader.readLine(); |
27 | } | 26 | } |
28 | bReader.close(); | 27 | bReader.close(); |
29 | } catch (Exception e) { | 28 | } catch (Exception e) { |
30 | e.printStackTrace(); | 29 | e.printStackTrace(); |
31 | } | 30 | } |
32 | return resultStr.toString(); | 31 | return resultStr.toString(); |
33 | } | 32 | } |
34 | 33 | ||
35 | public static void writeFile(File file, String str) { | 34 | public static void writeFile(File file, String str) { |
36 | try { | 35 | try { |
37 | BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); | 36 | BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); |
38 | bWriter.write(str); | 37 | bWriter.write(str); |
39 | bWriter.close(); | 38 | bWriter.close(); |
40 | } catch (Exception e) { | 39 | } catch (Exception e) { |
41 | e.printStackTrace(); | 40 | e.printStackTrace(); |
42 | } | 41 | } |
43 | } | 42 | } |
44 | 43 | ||
45 | public static void writeFile(File file, Vector<DeflectRow> rows) {// xml | 44 | public static void writeFile(File file, Vector<DeflectRow> rows) {// xml |
46 | try { | 45 | try { |
47 | Document doc = DocumentHelper.createDocument(); | 46 | Document doc = DocumentHelper.createDocument(); |
48 | Element root = doc.addElement("缺陷报告"); | 47 | Element root = doc.addElement("缺陷报告"); |
49 | int n = 0; | 48 | int n = 0; |
50 | if (rows != null && rows.size() > 0) { | 49 | if (rows != null && rows.size() > 0) { |
51 | for (DeflectRow row : rows) { | 50 | for (DeflectRow row : rows) { |
52 | if (row.getIssure() == 0 || row.getIssure() == 2) | 51 | if (row.getIssure() == DeflectRow.Issure.WRONG_ISSURE) { |
53 | continue; | 52 | continue; |
54 | n++; | 53 | } |
55 | Element empEle = root.addElement("item"); | 54 | n++; |
55 | Element empEle = root.addElement("item"); | ||
56 | 56 | ||
57 | Element untilEle = empEle.addElement("工具"); | 57 | Element untilEle = empEle.addElement("工具"); |
58 | untilEle.addText(row.getUntil()); | 58 | untilEle.addText(row.getUntil()); |
59 | Element fileEle = empEle.addElement("文件路径"); | 59 | Element fileEle = empEle.addElement("文件路径"); |
60 | fileEle.addText(row.getFile()); | 60 | fileEle.addText(row.getFile()); |
61 | Element lineEle = empEle.addElement("行号"); | 61 | Element lineEle = empEle.addElement("行号"); |
62 | lineEle.addText(row.getLine()); | 62 | lineEle.addText(row.getLine()); |
63 | Element levelEle = empEle.addElement("级别"); | 63 | Element levelEle = empEle.addElement("级别"); |
64 | levelEle.addText(row.getLevel()); | 64 | levelEle.addText(row.getLevel()); |
65 | Element typeEle = empEle.addElement("类型"); | 65 | Element typeEle = empEle.addElement("类型"); |
66 | typeEle.addText(row.getType()); | 66 | typeEle.addText(row.getType()); |
67 | Element descEle = empEle.addElement("描述"); | 67 | Element descEle = empEle.addElement("描述"); |
68 | descEle.addText(row.getDescription()); | 68 | descEle.addText(row.getDescription()); |
69 | empEle.addAttribute("id", n + ""); | 69 | empEle.addAttribute("id", n + ""); |
70 | } | 70 | } |
71 | XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); | 71 | XMLWriter writer = |
72 | FileOutputStream fos = new FileOutputStream(file); | 72 | new XMLWriter(OutputFormat.createPrettyPrint()); |
73 | writer.setOutputStream(fos); | 73 | FileOutputStream fos = new FileOutputStream(file); |
74 | writer.write(doc); | 74 | writer.setOutputStream(fos); |
75 | System.out.println("写出完毕!"); | 75 | writer.write(doc); |
76 | writer.close(); | 76 | System.out.println("写出完毕!"); |
77 | writer.close(); | ||
77 | 78 | ||
78 | } | 79 | } |
79 | } catch (Exception e) { | 80 | } catch (Exception e) { |
80 | e.printStackTrace(); | 81 | e.printStackTrace(); |
81 | } | 82 | } |
82 | } | 83 | } |
83 | 84 | ||
84 | } \ No newline at end of file | 85 | } \ No newline at end of file |
diff --git a/src/cppcheckplus/text/LineNumberHeaderView.java b/src/cppcheckplus/text/LineNumberHeaderView.java index 85819fa..af837fa 100644 --- a/src/cppcheckplus/text/LineNumberHeaderView.java +++ b/src/cppcheckplus/text/LineNumberHeaderView.java | |||
@@ -7,74 +7,76 @@ import java.awt.FontMetrics; | |||
7 | import java.awt.Graphics; | 7 | import java.awt.Graphics; |
8 | import java.awt.Rectangle; | 8 | import java.awt.Rectangle; |
9 | 9 | ||
10 | public class LineNumberHeaderView extends javax.swing.JComponent { | 10 | public class LineNumberHeaderView extends javax.swing.JComponent { |
11 | 11 | ||
12 | private final Font DEFAULT_FONT = new Font("Serif", 0, 16); | 12 | public final Color DEFAULT_BACKGROUD = new Color(228, 228, 228); |
13 | public final Color DEFAULT_BACKGROUD = new Color(228, 228, 228); | 13 | public final Color DEFAULT_FOREGROUD = Color.BLACK; |
14 | public final Color DEFAULT_FOREGROUD = Color.BLACK; | 14 | public final int nHEIGHT = Integer.MAX_VALUE - 1000000; |
15 | public final int nHEIGHT = Integer.MAX_VALUE - 1000000; | 15 | public final int MARGIN = 2; |
16 | public final int MARGIN = 2; | 16 | private final Font DEFAULT_FONT = new Font("Serif", 0, 16); |
17 | private int lineHeight; | 17 | private int lineHeight; |
18 | private int fontLineHeight; | 18 | private int fontLineHeight; |
19 | private int currentRowWidth; | 19 | private int currentRowWidth; |
20 | private FontMetrics fontMetrics; | 20 | private FontMetrics fontMetrics; |
21 | 21 | ||
22 | public LineNumberHeaderView() { | 22 | public LineNumberHeaderView() { |
23 | setFont(DEFAULT_FONT); | 23 | setFont(DEFAULT_FONT); |
24 | setForeground(DEFAULT_FOREGROUD); | 24 | setForeground(DEFAULT_FOREGROUD); |
25 | setBackground(DEFAULT_BACKGROUD); | 25 | setBackground(DEFAULT_BACKGROUD); |
26 | setPreferredSize(9999); | 26 | setPreferredSize(9999); |
27 | } | 27 | } |
28 | 28 | ||
29 | public void setPreferredSize(int row) { | 29 | public void setPreferredSize(int row) { |
30 | int width = fontMetrics.stringWidth(String.valueOf(row)); | 30 | int width = fontMetrics.stringWidth(String.valueOf(row)); |
31 | if (currentRowWidth < width) { | 31 | if (currentRowWidth < width) { |
32 | currentRowWidth = width; | 32 | currentRowWidth = width; |
33 | setPreferredSize(new Dimension(2 * MARGIN + width, nHEIGHT)); | 33 | setPreferredSize(new Dimension(2 * MARGIN + width, nHEIGHT)); |
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | @Override | 37 | @Override |
38 | public void setFont(Font font) { | 38 | public void setFont(Font font) { |
39 | super.setFont(font); | 39 | super.setFont(font); |
40 | fontMetrics = getFontMetrics(getFont()); | 40 | fontMetrics = getFontMetrics(getFont()); |
41 | fontLineHeight = fontMetrics.getHeight(); | 41 | fontLineHeight = fontMetrics.getHeight(); |
42 | } | 42 | } |
43 | 43 | ||
44 | public int getLineHeight() { | 44 | public int getLineHeight() { |
45 | if (lineHeight == 0) { | 45 | if (lineHeight == 0) { |
46 | return fontLineHeight; | 46 | return fontLineHeight; |
47 | } | 47 | } |
48 | return lineHeight; | 48 | return lineHeight; |
49 | } | 49 | } |
50 | 50 | ||
51 | public void setLineHeight(int lineHeight) { | 51 | public void setLineHeight(int lineHeight) { |
52 | if (lineHeight > 0) { | 52 | if (lineHeight > 0) { |
53 | this.lineHeight = lineHeight; | 53 | this.lineHeight = lineHeight; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | public int getStartOffset() { | 57 | public int getStartOffset() { |
58 | return 0; | 58 | return 0; |
59 | } | 59 | } |
60 | 60 | ||
61 | @Override | 61 | @Override |
62 | protected void paintComponent(Graphics g) { | 62 | protected void paintComponent(Graphics g) { |
63 | int nlineHeight = getLineHeight(); | 63 | int nlineHeight = getLineHeight(); |
64 | int startOffset = getStartOffset(); | 64 | int startOffset = getStartOffset(); |
65 | Rectangle drawHere = g.getClipBounds(); | 65 | Rectangle drawHere = g.getClipBounds(); |
66 | g.setColor(getBackground()); | 66 | g.setColor(getBackground()); |
67 | g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); | 67 | g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); |
68 | g.setColor(getForeground()); | 68 | g.setColor(getForeground()); |
69 | int startLineNum = (drawHere.y / nlineHeight) + 1; | 69 | int startLineNum = (drawHere.y / nlineHeight) + 1; |
70 | int endLineNum = startLineNum + (drawHere.height / nlineHeight); | 70 | int endLineNum = startLineNum + (drawHere.height / nlineHeight); |
71 | int start = (drawHere.y / nlineHeight) * nlineHeight + nlineHeight - startOffset; | 71 | int start = (drawHere.y / nlineHeight) * nlineHeight + nlineHeight - |
72 | for (int i = startLineNum; i <= endLineNum; ++i) { | 72 | startOffset; |
73 | String lineNum = String.valueOf(i); | 73 | for (int i = startLineNum; i <= endLineNum; ++i) { |
74 | int width = fontMetrics.stringWidth(lineNum); | 74 | String lineNum = String.valueOf(i); |
75 | g.drawString(lineNum + " ", MARGIN + currentRowWidth - width - 1, start); | 75 | int width = fontMetrics.stringWidth(lineNum); |
76 | start += nlineHeight; | 76 | g.drawString(lineNum + " ", MARGIN + currentRowWidth - width - 1, |
77 | } | 77 | start); |
78 | setPreferredSize(endLineNum); | 78 | start += nlineHeight; |
79 | } | 79 | } |
80 | setPreferredSize(endLineNum); | ||
81 | } | ||
80 | } | 82 | } |
diff --git a/src/cppcheckplus/text/MyButtonEditor.java b/src/cppcheckplus/text/MyButtonEditor.java index 6ce0007..22345e3 100644 --- a/src/cppcheckplus/text/MyButtonEditor.java +++ b/src/cppcheckplus/text/MyButtonEditor.java | |||
@@ -1,10 +1,10 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
3 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
4 | import java.awt.Component; | 5 | import java.awt.Component; |
5 | import java.awt.event.ActionEvent; | 6 | import java.awt.event.ActionEvent; |
6 | import java.awt.event.ActionListener; | 7 | import java.awt.event.ActionListener; |
7 | |||
8 | import javax.swing.AbstractCellEditor; | 8 | import javax.swing.AbstractCellEditor; |
9 | import javax.swing.Icon; | 9 | import javax.swing.Icon; |
10 | import javax.swing.JButton; | 10 | import javax.swing.JButton; |
@@ -13,76 +13,76 @@ import javax.swing.JPanel; | |||
13 | import javax.swing.JTable; | 13 | import javax.swing.JTable; |
14 | import javax.swing.table.TableCellEditor; | 14 | import javax.swing.table.TableCellEditor; |
15 | 15 | ||
16 | import cppcheckplus.control.MyContorlUtil; | 16 | public class MyButtonEditor extends AbstractCellEditor |
17 | 17 | implements TableCellEditor { | |
18 | public class MyButtonEditor extends AbstractCellEditor implements TableCellEditor { | 18 | |
19 | 19 | /** | |
20 | /** | 20 | * serialVersionUID |
21 | * serialVersionUID | 21 | */ |
22 | */ | 22 | private static final long serialVersionUID = -6546334664166791132L; |
23 | private static final long serialVersionUID = -6546334664166791132L; | 23 | public static Icon[] icon = new Icon[3]; |
24 | 24 | // public static Icon icon[1]; | |
25 | private JPanel panel; | 25 | // public static Icon icon[2]; |
26 | 26 | private JPanel panel; | |
27 | private JButton button; | 27 | private JButton button; |
28 | 28 | private DeflectRow.Issure state = DeflectRow.Issure.NOTSURE_ISSURE; | |
29 | private int state; | 29 | |
30 | public static Icon icon0; | 30 | public MyButtonEditor() { |
31 | public static Icon icon1; | 31 | initButton(); |
32 | public static Icon icon2; | 32 | initPanel(); |
33 | public MyButtonEditor() { | 33 | panel.add(this.button, BorderLayout.CENTER); |
34 | 34 | } | |
35 | initButton(); | 35 | |
36 | 36 | private void initButton() { | |
37 | initPanel(); | 37 | button = new JButton(); |
38 | 38 | ||
39 | panel.add(this.button, BorderLayout.CENTER); | 39 | icon[0] = |
40 | } | 40 | MyContorlUtil.getImageIcon("control/images/agree_notsure.png"); |
41 | 41 | icon[1] = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | |
42 | private void initButton() { | 42 | icon[2] = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); |
43 | button = new JButton(); | 43 | button.addActionListener(new ActionListener() { |
44 | 44 | public void actionPerformed(ActionEvent e) { | |
45 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | 45 | Object[] options = {"待定", "确认", "误报"}; |
46 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | 46 | int res = JOptionPane.showOptionDialog(null, "请确认报告状态", |
47 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | 47 | "选择状态", JOptionPane.DEFAULT_OPTION, |
48 | button.addActionListener(new ActionListener() { | 48 | JOptionPane.QUESTION_MESSAGE, null, options, options[0]); |
49 | public void actionPerformed(ActionEvent e) { | 49 | state = DeflectRow.Issure.values()[res]; |
50 | int res = JOptionPane.showConfirmDialog(null, "你想确认报告吗?", "choose one", | 50 | fireEditingStopped(); |
51 | JOptionPane.YES_NO_OPTION); | 51 | } |
52 | 52 | }); | |
53 | if (res == JOptionPane.YES_OPTION) { | 53 | } |
54 | state=(state+1)%3; | 54 | |
55 | } | 55 | private void initPanel() { |
56 | // stopped!!!! | 56 | panel = new JPanel(); |
57 | fireEditingStopped(); | 57 | |
58 | 58 | panel.setLayout(new BorderLayout()); | |
59 | } | 59 | } |
60 | }); | 60 | |
61 | 61 | @Override | |
62 | } | 62 | public Component getTableCellEditorComponent(JTable table, Object value, |
63 | 63 | boolean isSelected, int row, | |
64 | private void initPanel() { | 64 | int column) { |
65 | panel = new JPanel(); | 65 | state = (DeflectRow.Issure) value; |
66 | 66 | switch (state) { | |
67 | panel.setLayout(new BorderLayout()); | 67 | case NOTSURE_ISSURE: |
68 | } | 68 | button.setIcon(icon[0]); |
69 | 69 | break; | |
70 | @Override | 70 | case CURRECT_ISSURE: |
71 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { | 71 | button.setIcon(icon[1]); |
72 | state = (Integer) value; | 72 | break; |
73 | 73 | case WRONG_ISSURE: | |
74 | if(state==0) | 74 | button.setIcon(icon[2]); |
75 | button.setIcon(icon0); | 75 | break; |
76 | else if(state==1) | 76 | default: |
77 | button.setIcon(icon1); | 77 | button.setIcon(icon[0]); |
78 | else if(state==2) | 78 | break; |
79 | button.setIcon(icon2); | 79 | } |
80 | return panel; | 80 | return panel; |
81 | } | 81 | } |
82 | 82 | ||
83 | @Override | 83 | @Override |
84 | public Object getCellEditorValue() { | 84 | public Object getCellEditorValue() { |
85 | return state; | 85 | return state; |
86 | } | 86 | } |
87 | 87 | ||
88 | } \ No newline at end of file | 88 | } \ No newline at end of file |
diff --git a/src/cppcheckplus/text/MyButtonRenderer.java b/src/cppcheckplus/text/MyButtonRenderer.java index e030620..0ff148b 100644 --- a/src/cppcheckplus/text/MyButtonRenderer.java +++ b/src/cppcheckplus/text/MyButtonRenderer.java | |||
@@ -1,26 +1,20 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
3 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
4 | import java.awt.Component; | 5 | import java.awt.Component; |
5 | |||
6 | import javax.swing.Icon; | 6 | import javax.swing.Icon; |
7 | import javax.swing.JButton; | 7 | import javax.swing.JButton; |
8 | import javax.swing.JPanel; | 8 | import javax.swing.JPanel; |
9 | import javax.swing.JTable; | 9 | import javax.swing.JTable; |
10 | import javax.swing.table.TableCellRenderer; | 10 | import javax.swing.table.TableCellRenderer; |
11 | 11 | ||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | |||
14 | public class MyButtonRenderer implements TableCellRenderer { | 12 | public class MyButtonRenderer implements TableCellRenderer { |
13 | public static Icon[] icon = new Icon[3]; | ||
15 | private JPanel panel; | 14 | private JPanel panel; |
16 | |||
17 | private JButton button; | 15 | private JButton button; |
16 | private DeflectRow.Issure state = DeflectRow.Issure.NOTSURE_ISSURE; | ||
18 | 17 | ||
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() { | 18 | public MyButtonRenderer() { |
25 | initButton(); | 19 | initButton(); |
26 | 20 | ||
@@ -31,15 +25,24 @@ public class MyButtonRenderer implements TableCellRenderer { | |||
31 | 25 | ||
32 | private void initButton() { | 26 | private void initButton() { |
33 | button = new JButton(); | 27 | button = new JButton(); |
34 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | 28 | icon[0] = |
35 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | 29 | MyContorlUtil.getImageIcon("control/images/agree_notsure.png"); |
36 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | 30 | icon[1] = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); |
37 | if(state==0) | 31 | icon[2] = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); |
38 | button.setIcon(icon0); | 32 | switch (state) { |
39 | else if(state==1) | 33 | case NOTSURE_ISSURE: |
40 | button.setIcon(icon1); | 34 | button.setIcon(icon[0]); |
41 | else if(state==2) | 35 | break; |
42 | button.setIcon(icon2); | 36 | case CURRECT_ISSURE: |
37 | button.setIcon(icon[1]); | ||
38 | break; | ||
39 | case WRONG_ISSURE: | ||
40 | button.setIcon(icon[2]); | ||
41 | break; | ||
42 | default: | ||
43 | button.setIcon(icon[0]); | ||
44 | break; | ||
45 | } | ||
43 | } | 46 | } |
44 | 47 | ||
45 | private void initPanel() { | 48 | private void initPanel() { |
@@ -48,14 +51,24 @@ public class MyButtonRenderer implements TableCellRenderer { | |||
48 | } | 51 | } |
49 | 52 | ||
50 | public Component getTableCellRendererComponent(JTable table, Object value, | 53 | public Component getTableCellRendererComponent(JTable table, Object value, |
51 | boolean isSelected, boolean hasFocus, int row, int column) { | 54 | boolean isSelected, |
52 | state = (Integer) value; | 55 | boolean hasFocus, int row, |
53 | if(state==0) | 56 | int column) { |
54 | button.setIcon(icon0); | 57 | state = (DeflectRow.Issure) value; |
55 | else if(state==1) | 58 | switch (state) { |
56 | button.setIcon(icon1); | 59 | case NOTSURE_ISSURE: |
57 | else if(state==2) | 60 | button.setIcon(icon[0]); |
58 | button.setIcon(icon2); | 61 | break; |
62 | case CURRECT_ISSURE: | ||
63 | button.setIcon(icon[1]); | ||
64 | break; | ||
65 | case WRONG_ISSURE: | ||
66 | button.setIcon(icon[2]); | ||
67 | break; | ||
68 | default: | ||
69 | button.setIcon(icon[0]); | ||
70 | break; | ||
71 | } | ||
59 | return panel; | 72 | return panel; |
60 | } | 73 | } |
61 | 74 | ||
diff --git a/src/cppcheckplus/text/MyPanel.java b/src/cppcheckplus/text/MyPanel.java index cec59ac..89aae3a 100644 --- a/src/cppcheckplus/text/MyPanel.java +++ b/src/cppcheckplus/text/MyPanel.java | |||
@@ -1,31 +1,34 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
3 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
4 | import java.awt.Graphics; | 5 | import java.awt.Graphics; |
5 | import java.awt.Image; | 6 | import java.awt.Image; |
6 | |||
7 | import javax.swing.ImageIcon; | 7 | import javax.swing.ImageIcon; |
8 | import javax.swing.JPanel; | 8 | import javax.swing.JPanel; |
9 | 9 | ||
10 | import cppcheckplus.control.MyContorlUtil; | 10 | public class MyPanel extends JPanel { |
11 | ImageIcon icon; | ||
12 | Image img; | ||
11 | 13 | ||
12 | public class MyPanel extends JPanel{ | 14 | public MyPanel() { |
13 | ImageIcon icon; | 15 | // /img/HomeImg.jpg 是存放在你正在编写的项目的bin文件夹下的img文件夹下的一个图片 |
14 | Image img; | 16 | icon = |
15 | public MyPanel(){ | 17 | new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); |
16 | // /img/HomeImg.jpg 是存放在你正在编写的项目的bin文件夹下的img文件夹下的一个图片 | 18 | img = icon.getImage(); |
17 | icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); | ||
18 | img=icon.getImage(); | ||
19 | } | 19 | } |
20 | |||
20 | public MyPanel(BorderLayout borderLayout) { | 21 | public MyPanel(BorderLayout borderLayout) { |
21 | icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); | 22 | icon = |
22 | img=icon.getImage(); | 23 | new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); |
24 | img = icon.getImage(); | ||
23 | setLayout(borderLayout); | 25 | setLayout(borderLayout); |
24 | } | 26 | } |
25 | public void paintComponent(Graphics g) { | 27 | |
26 | super.paintComponent(g); | 28 | public void paintComponent(Graphics g) { |
29 | super.paintComponent(g); | ||
27 | //下面这行是为了背景图片可以跟随窗口自行调整大小,可以自己设置成固定大小 | 30 | //下面这行是为了背景图片可以跟随窗口自行调整大小,可以自己设置成固定大小 |
28 | g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this); | 31 | g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); |
29 | } | 32 | } |
30 | } | 33 | } |
31 | 34 | ||
diff --git a/src/cppcheckplus/text/MyTextArea.java b/src/cppcheckplus/text/MyTextArea.java index 9860093..9c6c101 100644 --- a/src/cppcheckplus/text/MyTextArea.java +++ b/src/cppcheckplus/text/MyTextArea.java | |||
@@ -1,60 +1,60 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
3 | import java.awt.Dimension; | 4 | import java.awt.Dimension; |
4 | import java.awt.Graphics; | 5 | import java.awt.Graphics; |
5 | import java.awt.Graphics2D; | 6 | import java.awt.Graphics2D; |
6 | import java.awt.Image; | 7 | import java.awt.Image; |
7 | import java.awt.TexturePaint; | 8 | import java.awt.TexturePaint; |
8 | |||
9 | import javax.swing.BorderFactory; | 9 | import javax.swing.BorderFactory; |
10 | import javax.swing.ImageIcon; | 10 | import javax.swing.ImageIcon; |
11 | import javax.swing.JTextArea; | 11 | import javax.swing.JTextArea; |
12 | import javax.swing.border.Border; | 12 | import javax.swing.border.Border; |
13 | import javax.swing.plaf.metal.MetalTextFieldUI; | 13 | import javax.swing.plaf.metal.MetalTextFieldUI; |
14 | 14 | ||
15 | import cppcheckplus.control.MyContorlUtil; | 15 | public class MyTextArea extends JTextArea { |
16 | 16 | private Image backgroundLeftImage; | |
17 | public class MyTextArea extends JTextArea{ | 17 | private Image backgroundRightImage; |
18 | private Image backgroundLeftImage; | 18 | private ImageIcon backgroundImageIcon; |
19 | private Image backgroundRightImage; | 19 | private TexturePaint paint; |
20 | private ImageIcon backgroundImageIcon; | 20 | private Border border; |
21 | private TexturePaint paint; | 21 | |
22 | private Border border; | 22 | public MyTextArea() { |
23 | 23 | backgroundLeftImage = MyContorlUtil.getImage( | |
24 | public MyTextArea () | 24 | "xujun/control/images/textfield_background_left.png"); |
25 | { | 25 | backgroundRightImage = MyContorlUtil.getImage( |
26 | backgroundLeftImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_left.png"); | 26 | "xujun/control/images/textfield_background_right.png"); |
27 | backgroundRightImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_right.png"); | 27 | backgroundImageIcon = MyContorlUtil.getImageIcon( |
28 | backgroundImageIcon = MyContorlUtil.getImageIcon("xujun/control/images/textfield_background.png"); | 28 | "xujun/control/images/textfield_background.png"); |
29 | paint = MyContorlUtil.createTexturePaint("xujun/control/images/textfield_background.png"); | 29 | paint = MyContorlUtil.createTexturePaint( |
30 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); | 30 | "xujun/control/images/textfield_background.png"); |
31 | init(); | 31 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); |
32 | } | 32 | init(); |
33 | public MyTextArea (String text) | 33 | } |
34 | { | 34 | |
35 | this(); | 35 | public MyTextArea(String text) { |
36 | setText(text); | 36 | this(); |
37 | } | 37 | setText(text); |
38 | 38 | } | |
39 | private void init() | 39 | |
40 | { | 40 | private void init() { |
41 | setBorder(border); | 41 | setBorder(border); |
42 | setUI(new MetalTextFieldUI() { | 42 | setUI(new MetalTextFieldUI() { |
43 | 43 | ||
44 | protected void paintBackground(Graphics g) | 44 | protected void paintBackground(Graphics g) { |
45 | { | 45 | Graphics2D g2d = (Graphics2D) g; |
46 | Graphics2D g2d = (Graphics2D)g; | 46 | g2d.setPaint(paint); |
47 | g2d.setPaint(paint); | 47 | g2d.fillRect(0, 0, getWidth(), getHeight()); |
48 | g2d.fillRect(0, 0, getWidth(), getHeight()); | 48 | g2d.drawImage(backgroundLeftImage, 0, 0, null); |
49 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | 49 | g2d.drawImage(backgroundRightImage, |
50 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | 50 | getWidth() - backgroundRightImage.getWidth(null), 0, null); |
51 | } | 51 | } |
52 | 52 | ||
53 | }); | 53 | }); |
54 | } | 54 | } |
55 | 55 | ||
56 | public Dimension getPreferredSize() | 56 | public Dimension getPreferredSize() { |
57 | { | 57 | return new Dimension(super.getPreferredSize().width, |
58 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | 58 | backgroundImageIcon.getIconHeight()); |
59 | } | 59 | } |
60 | } | 60 | } |
diff --git a/src/cppcheckplus/text/MyTextPanel.java b/src/cppcheckplus/text/MyTextPanel.java index 8ef60c4..d2f29ee 100644 --- a/src/cppcheckplus/text/MyTextPanel.java +++ b/src/cppcheckplus/text/MyTextPanel.java | |||
@@ -1,72 +1,64 @@ | |||
1 | |||
2 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
3 | 2 | ||
3 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import java.awt.Font; | 5 | import java.awt.Font; |
6 | |||
7 | import javax.swing.JPanel; | 6 | import javax.swing.JPanel; |
8 | import javax.swing.JScrollPane; | 7 | import javax.swing.JScrollPane; |
9 | import javax.swing.JTextArea; | 8 | import javax.swing.JTextArea; |
10 | 9 | ||
11 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
12 | 10 | ||
11 | public class MyTextPanel extends JPanel | ||
12 | implements XChartletFullScreenListenter { | ||
13 | public static final int LINEHEIGHT = 16; | ||
14 | private BorderLayout layout; | ||
15 | private boolean isFullScreen; | ||
16 | private JTextArea textArea; | ||
17 | private JScrollPane scroll; | ||
18 | private LineNumberHeaderView lineNumberHeader = null; | ||
19 | |||
20 | public MyTextPanel() { | ||
21 | layout = new BorderLayout(); | ||
22 | setLayout(layout); | ||
23 | textArea = new JTextArea(""); | ||
24 | Font x = new Font("Serif", 0, LINEHEIGHT); | ||
25 | textArea.setFont(x); | ||
26 | scroll = new JScrollPane(textArea); | ||
27 | //scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | ||
28 | //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | ||
29 | //scroll.setPreferredSize(new Dimension(300, 200)); | ||
30 | |||
31 | if (lineNumberHeader == null) { | ||
32 | lineNumberHeader = new LineNumberHeaderView(); | ||
33 | //设置行号的高度,如果和textarea的行高不匹配,可以修改此值 | ||
34 | lineNumberHeader.setLineHeight(LINEHEIGHT + 4); | ||
35 | } | ||
36 | scroll.setRowHeaderView(lineNumberHeader); | ||
37 | add(scroll); | ||
38 | } | ||
39 | |||
40 | public JTextArea getTextArea() { | ||
41 | return textArea; | ||
42 | } | ||
13 | 43 | ||
14 | public class MyTextPanel extends JPanel implements XChartletFullScreenListenter | 44 | public void initialize() { |
15 | { | 45 | setLayout(layout); |
16 | private BorderLayout layout; | 46 | add(scroll); |
17 | private boolean isFullScreen; | 47 | } |
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 | 48 | ||
54 | 49 | ||
55 | @Override | 50 | @Override |
56 | public void fullScreen(JPanel chartPanellet) | 51 | public void fullScreen(JPanel chartPanellet) { |
57 | { | 52 | removeAll(); |
58 | removeAll(); | 53 | isFullScreen = !isFullScreen; |
59 | isFullScreen = !isFullScreen; | 54 | if (isFullScreen) { |
60 | if (isFullScreen) | 55 | setLayout(new BorderLayout()); |
61 | { | 56 | add(chartPanellet, "Center"); |
62 | setLayout(new BorderLayout()); | 57 | } else { |
63 | add(chartPanellet, "Center"); | 58 | initialize(); |
64 | } else | 59 | } |
65 | { | 60 | repaint(); |
66 | initialize(); | 61 | revalidate(); |
67 | } | 62 | } |
68 | repaint(); | ||
69 | revalidate(); | ||
70 | } | ||
71 | 63 | ||
72 | } | 64 | } |
diff --git a/src/cppcheckplus/text/MyTextPanel1.java b/src/cppcheckplus/text/MyTextPanel1.java index fb07c7d..5553995 100644 --- a/src/cppcheckplus/text/MyTextPanel1.java +++ b/src/cppcheckplus/text/MyTextPanel1.java | |||
@@ -1,59 +1,53 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
3 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
4 | import java.awt.TextArea; | ||
5 | import java.awt.Font; | 5 | import java.awt.Font; |
6 | import java.awt.TextArea; | ||
6 | import javax.swing.JPanel; | 7 | import javax.swing.JPanel; |
7 | 8 | ||
8 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
9 | |||
10 | |||
11 | 9 | ||
12 | public class MyTextPanel1 extends JPanel implements XChartletFullScreenListenter | 10 | public class MyTextPanel1 extends JPanel |
13 | { | 11 | implements XChartletFullScreenListenter { |
14 | private BorderLayout layout; | 12 | private BorderLayout layout; |
15 | private boolean isFullScreen; | 13 | private boolean isFullScreen; |
16 | private TextArea textArea; | 14 | private TextArea textArea; |
17 | 15 | ||
18 | public TextArea getTextArea() { | 16 | public MyTextPanel1() { |
19 | return textArea; | 17 | layout = new BorderLayout(); |
20 | } | 18 | setLayout(layout); |
21 | public void setTextArea(TextArea textArea) { | 19 | textArea = new TextArea(""); |
22 | this.textArea = textArea; | 20 | textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 12)); |
23 | } | 21 | |
24 | 22 | add(textArea); | |
25 | public MyTextPanel1() | 23 | } |
26 | { | 24 | |
27 | layout = new BorderLayout(); | 25 | public TextArea getTextArea() { |
28 | setLayout(layout); | 26 | return textArea; |
29 | textArea=new TextArea(""); | 27 | } |
30 | textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 12)); | 28 | |
31 | 29 | public void setTextArea(TextArea textArea) { | |
32 | add(textArea); | 30 | this.textArea = textArea; |
33 | } | 31 | } |
34 | 32 | ||
35 | public void initialize() | 33 | public void initialize() { |
36 | { | 34 | setLayout(layout); |
37 | setLayout(layout); | 35 | add(textArea); |
38 | add(textArea); | 36 | } |
39 | } | 37 | |
40 | 38 | ||
41 | 39 | @Override | |
42 | @Override | 40 | public void fullScreen(JPanel chartPanellet) { |
43 | public void fullScreen(JPanel chartPanellet) | 41 | removeAll(); |
44 | { | 42 | isFullScreen = !isFullScreen; |
45 | removeAll(); | 43 | if (isFullScreen) { |
46 | isFullScreen = !isFullScreen; | 44 | setLayout(new BorderLayout()); |
47 | if (isFullScreen) | 45 | add(chartPanellet, "Center"); |
48 | { | 46 | } else { |
49 | setLayout(new BorderLayout()); | 47 | initialize(); |
50 | add(chartPanellet, "Center"); | 48 | } |
51 | } else | 49 | repaint(); |
52 | { | 50 | revalidate(); |
53 | initialize(); | 51 | } |
54 | } | ||
55 | repaint(); | ||
56 | revalidate(); | ||
57 | } | ||
58 | 52 | ||
59 | } | 53 | } |
diff --git a/src/cppcheckplus/text/ViewPanel.java b/src/cppcheckplus/text/ViewPanel.java index c5b79d9..6c1a765 100644 --- a/src/cppcheckplus/text/ViewPanel.java +++ b/src/cppcheckplus/text/ViewPanel.java | |||
@@ -1,72 +1,65 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
3 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
4 | import java.util.Vector; | 5 | import java.util.Vector; |
5 | |||
6 | import javax.swing.JPanel; | 6 | import javax.swing.JPanel; |
7 | import javax.swing.JScrollPane; | 7 | import javax.swing.JScrollPane; |
8 | import javax.swing.JTable; | 8 | import javax.swing.JTable; |
9 | import javax.swing.table.DefaultTableModel; | 9 | import javax.swing.table.DefaultTableModel; |
10 | import javax.swing.table.TableColumn; | 10 | import javax.swing.table.TableColumn; |
11 | 11 | ||
12 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
13 | |||
14 | 12 | ||
15 | public class ViewPanel extends JPanel implements XChartletFullScreenListenter { | 13 | public class ViewPanel extends JPanel implements XChartletFullScreenListenter { |
16 | 14 | ||
17 | private static final long serialVersionUID = 1L; | 15 | private static final long serialVersionUID = 1L; |
18 | private DefaultTableModel model; | 16 | private DefaultTableModel model; |
19 | private JScrollPane jsp; | 17 | private JScrollPane jsp; |
20 | private JTable table; | 18 | private JTable table; |
21 | private Vector<DeflectRow> results=new Vector<DeflectRow>(); | 19 | private Vector<DeflectRow> results = new Vector<DeflectRow>(); |
22 | private BorderLayout layout; | 20 | private BorderLayout layout; |
23 | private boolean isFullScreen; | 21 | private boolean isFullScreen; |
24 | 22 | ||
25 | public JTable getTable() { | 23 | public ViewPanel() { |
26 | return table; | 24 | |
27 | } | 25 | layout = new BorderLayout(); |
28 | 26 | setLayout(layout); | |
29 | public void setTable(JTable table) { | 27 | |
30 | this.table = table; | 28 | String[] colnames = |
31 | } | 29 | {"序号", "工具", "文件", "行号", "级别", "类型", "描述", |
32 | 30 | "人工确认"}; | |
33 | public ViewPanel() { | 31 | // 填充数据 |
34 | 32 | model = new DefaultTableModel(colnames, 0) { | |
35 | layout = new BorderLayout(); | 33 | @Override |
36 | setLayout(layout); | 34 | public Object getValueAt(int row, int column) { |
37 | 35 | if (results != null && row < results.size()) { | |
38 | String[] colnames = { "序号", "工具", "文件", "行号", "级别", "类型", "描述", "人工确认" }; | 36 | switch (column) { |
39 | // 填充数据 | 37 | case 1: |
40 | model = new DefaultTableModel(colnames, 0){ | 38 | return results.elementAt(row).getUntil(); |
41 | @Override | 39 | case 2: |
42 | public Object getValueAt(int row, int column) { | 40 | return results.elementAt(row).getFile(); |
43 | if(results!=null && row<results.size()){ | 41 | case 3: |
44 | switch(column){ | 42 | return results.elementAt(row).getLine(); |
45 | case 1: | 43 | case 4: |
46 | return results.elementAt(row).getUntil(); | 44 | return results.elementAt(row).getLevel(); |
47 | case 2: | 45 | case 5: |
48 | return results.elementAt(row).getFile(); | 46 | return results.elementAt(row).getType(); |
49 | case 3: | 47 | case 6: |
50 | return results.elementAt(row).getLine(); | 48 | return results.elementAt(row).getDescription(); |
51 | case 4: | 49 | case 7: |
52 | return results.elementAt(row).getLevel(); | 50 | return results.elementAt(row).getIssure(); |
53 | case 5: | 51 | case 0: |
54 | return results.elementAt(row).getType(); | 52 | return row + 1; |
55 | case 6: | 53 | } |
56 | return results.elementAt(row).getDescription(); | 54 | } |
57 | case 7: | 55 | return null; |
58 | return results.elementAt(row).getIssure(); | 56 | } |
59 | case 0: | 57 | |
60 | return row+1; | ||
61 | } | ||
62 | } | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | @Override | 58 | @Override |
67 | public boolean isCellEditable(int row, int column) { | 59 | public boolean isCellEditable(int row, int column) { |
68 | if (column == 7 || column == 2 || column == 5) | 60 | if (column == 7 || column == 2 || column == 5) { |
69 | return true; | 61 | return true; |
62 | } | ||
70 | return false; | 63 | return false; |
71 | } | 64 | } |
72 | /* | 65 | /* |
@@ -79,135 +72,146 @@ public class ViewPanel extends JPanel implements XChartletFullScreenListenter { | |||
79 | public int getColumnCount() { | 72 | public int getColumnCount() { |
80 | return 8; | 73 | return 8; |
81 | } | 74 | } |
82 | 75 | ||
83 | @Override | 76 | @Override |
84 | public void setValueAt(Object aValue, int row, int column){ | 77 | public void setValueAt(Object aValue, int row, int column) { |
85 | if(results!=null && row<results.size()){ | 78 | if (results != null && row < results.size()) { |
86 | switch(column){ | 79 | switch (column) { |
87 | case 1: | 80 | case 1: |
88 | results.elementAt(row).setUntil((String)aValue); | 81 | results.elementAt(row).setUntil((String) aValue); |
89 | break; | 82 | break; |
90 | case 2: | 83 | case 2: |
91 | results.elementAt(row).setFile((String)aValue); | 84 | results.elementAt(row).setFile((String) aValue); |
92 | break; | 85 | break; |
93 | case 3: | 86 | case 3: |
94 | results.elementAt(row).setLine((String)aValue); | 87 | results.elementAt(row).setLine((String) aValue); |
95 | break; | 88 | break; |
96 | case 4: | 89 | case 4: |
97 | results.elementAt(row).setLevel((String)aValue); | 90 | results.elementAt(row).setLevel((String) aValue); |
98 | break; | 91 | break; |
99 | case 5: | 92 | case 5: |
100 | results.elementAt(row).setType((String)aValue); | 93 | results.elementAt(row).setType((String) aValue); |
101 | break; | 94 | break; |
102 | case 6: | 95 | case 6: |
103 | results.elementAt(row).setDescription((String)aValue); | 96 | results.elementAt(row) |
104 | break; | 97 | .setDescription((String) aValue); |
105 | case 7: | 98 | break; |
106 | results.elementAt(row).setIssure((Integer)aValue); | 99 | case 7: |
107 | break; | 100 | results.elementAt(row) |
108 | } | 101 | .setIssure((DeflectRow.Issure) aValue); |
109 | } | 102 | break; |
103 | } | ||
104 | } | ||
110 | fireTableCellUpdated(row, column); | 105 | fireTableCellUpdated(row, column); |
111 | } | 106 | } |
112 | 107 | ||
113 | }; | 108 | }; |
114 | 109 | ||
115 | table = new JTable(model); | 110 | table = new JTable(model); |
116 | TableColumn c1 = table.getColumnModel().getColumn(0); | 111 | TableColumn c1 = table.getColumnModel().getColumn(0); |
117 | c1.setPreferredWidth(30); | 112 | c1.setPreferredWidth(30); |
118 | c1.setMaxWidth(30); | 113 | c1.setMaxWidth(30); |
119 | c1.setMinWidth(30); | 114 | c1.setMinWidth(30); |
120 | TableColumn c2 = table.getColumnModel().getColumn(1); | 115 | TableColumn c2 = table.getColumnModel().getColumn(1); |
121 | c2.setPreferredWidth(60); | 116 | c2.setPreferredWidth(60); |
122 | c2.setMaxWidth(60); | 117 | c2.setMaxWidth(60); |
123 | c2.setMinWidth(60); | 118 | c2.setMinWidth(60); |
124 | TableColumn c3 = table.getColumnModel().getColumn(2); | 119 | TableColumn c3 = table.getColumnModel().getColumn(2); |
125 | c3.setPreferredWidth(160); | 120 | c3.setPreferredWidth(160); |
126 | c3.setMaxWidth(160); | 121 | c3.setMaxWidth(160); |
127 | c3.setMinWidth(160); | 122 | c3.setMinWidth(160); |
128 | TableColumn c4 = table.getColumnModel().getColumn(3); | 123 | TableColumn c4 = table.getColumnModel().getColumn(3); |
129 | c4.setPreferredWidth(40); | 124 | c4.setPreferredWidth(40); |
130 | c4.setMaxWidth(40); | 125 | c4.setMaxWidth(40); |
131 | c4.setMinWidth(40); | 126 | c4.setMinWidth(40); |
132 | TableColumn c5 = table.getColumnModel().getColumn(4); | 127 | TableColumn c5 = table.getColumnModel().getColumn(4); |
133 | c5.setPreferredWidth(30); | 128 | c5.setPreferredWidth(30); |
134 | c5.setMaxWidth(30); | 129 | c5.setMaxWidth(30); |
135 | c5.setMinWidth(30); | 130 | c5.setMinWidth(30); |
136 | TableColumn c6 = table.getColumnModel().getColumn(5); | 131 | TableColumn c6 = table.getColumnModel().getColumn(5); |
137 | c6.setPreferredWidth(100); | 132 | c6.setPreferredWidth(100); |
138 | c6.setMaxWidth(100); | 133 | c6.setMaxWidth(100); |
139 | c6.setMinWidth(100); | 134 | c6.setMinWidth(100); |
140 | TableColumn c8 = table.getColumnModel().getColumn(7); | 135 | TableColumn c8 = table.getColumnModel().getColumn(7); |
141 | c8.setPreferredWidth(100); | 136 | c8.setPreferredWidth(100); |
142 | c8.setMaxWidth(100); | 137 | c8.setMaxWidth(100); |
143 | c8.setMinWidth(100); | 138 | c8.setMinWidth(100); |
144 | 139 | ||
145 | table.getColumnModel().getColumn(7).setCellEditor(new MyButtonEditor()); | 140 | table.getColumnModel().getColumn(7).setCellEditor(new MyButtonEditor()); |
146 | table.getColumnModel().getColumn(7).setCellRenderer(new MyButtonRenderer()); | 141 | table.getColumnModel().getColumn(7) |
142 | .setCellRenderer(new MyButtonRenderer()); | ||
147 | table.setRowSelectionAllowed(false); | 143 | table.setRowSelectionAllowed(false); |
148 | 144 | ||
149 | 145 | ||
150 | jsp = new JScrollPane(table); | 146 | jsp = new JScrollPane(table); |
151 | add(jsp, BorderLayout.CENTER); | 147 | add(jsp, BorderLayout.CENTER); |
152 | } | 148 | } |
153 | 149 | ||
154 | public ViewPanel(Vector<DeflectRow> rows) { | 150 | public ViewPanel(Vector<DeflectRow> rows) { |
155 | this(); | 151 | this(); |
156 | results = rows; | 152 | results = rows; |
157 | fillTable(results); | 153 | fillTable(results); |
158 | } | 154 | } |
159 | 155 | ||
160 | public void clearTable() { | 156 | public JTable getTable() { |
161 | model.setRowCount(0);// 清除原有行 | 157 | return table; |
162 | results.clear(); | 158 | } |
163 | table.invalidate(); | 159 | |
164 | } | 160 | public void setTable(JTable table) { |
165 | 161 | this.table = table; | |
166 | public void update(Vector<DeflectRow> rows) { | 162 | } |
167 | results = rows; | 163 | |
168 | fillTable(results); | 164 | public void clearTable() { |
169 | } | 165 | model.setRowCount(0);// 清除原有行 |
170 | 166 | results.clear(); | |
171 | public void initialize() { | 167 | table.invalidate(); |
172 | setLayout(layout); | 168 | } |
173 | add(jsp); | 169 | |
174 | } | 170 | public void update(Vector<DeflectRow> rows) { |
175 | 171 | results = rows; | |
176 | public void fillTable(Vector<DeflectRow> rows) { | 172 | fillTable(results); |
177 | 173 | } | |
178 | model.setRowCount(0);// 清除原有行 | 174 | |
179 | int n = 0; | 175 | public void initialize() { |
180 | if (rows != null && rows.size() > 0) { | 176 | setLayout(layout); |
181 | for (DeflectRow row : rows) { | 177 | add(jsp); |
182 | n++; | 178 | } |
183 | Object[] arr = new Object[8]; | 179 | |
184 | arr[0] = String.valueOf(n); | 180 | public void fillTable(Vector<DeflectRow> rows) { |
185 | arr[1] = row.getUntil(); | 181 | |
186 | arr[2] = row.getFile(); | 182 | model.setRowCount(0);// 清除原有行 |
187 | arr[3] = row.getLine(); | 183 | int n = 0; |
188 | arr[4] = row.getLevel(); | 184 | if (rows != null && rows.size() > 0) { |
189 | arr[5] = row.getType(); | 185 | for (DeflectRow row : rows) { |
190 | arr[6] = row.getDescription(); | 186 | n++; |
191 | arr[7] = row.getIssure(); | 187 | Object[] arr = new Object[8]; |
192 | // 添加数据到表格 | 188 | arr[0] = String.valueOf(n); |
193 | model.addRow(arr); | 189 | arr[1] = row.getUntil(); |
194 | } | 190 | arr[2] = row.getFile(); |
195 | } | 191 | arr[3] = row.getLine(); |
196 | table.invalidate(); | 192 | arr[4] = row.getLevel(); |
197 | } | 193 | arr[5] = row.getType(); |
198 | 194 | arr[6] = row.getDescription(); | |
199 | @Override | 195 | arr[7] = row.getIssure(); |
200 | public void fullScreen(JPanel chartPanellet) { | 196 | // 添加数据到表格 |
201 | removeAll(); | 197 | model.addRow(arr); |
202 | isFullScreen = !isFullScreen; | 198 | } |
203 | if (isFullScreen) { | 199 | } |
204 | setLayout(new BorderLayout()); | 200 | table.invalidate(); |
205 | add(chartPanellet, "Center"); | 201 | } |
206 | } else { | 202 | |
207 | initialize(); | 203 | @Override |
208 | } | 204 | public void fullScreen(JPanel chartPanellet) { |
209 | repaint(); | 205 | removeAll(); |
210 | revalidate(); | 206 | isFullScreen = !isFullScreen; |
211 | } | 207 | if (isFullScreen) { |
208 | setLayout(new BorderLayout()); | ||
209 | add(chartPanellet, "Center"); | ||
210 | } else { | ||
211 | initialize(); | ||
212 | } | ||
213 | repaint(); | ||
214 | revalidate(); | ||
215 | } | ||
212 | 216 | ||
213 | } | 217 | } |
diff --git a/src/cppcheckplus/text/creatTable.java b/src/cppcheckplus/text/creatTable.java index 0295eb6..f261e3a 100644 --- a/src/cppcheckplus/text/creatTable.java +++ b/src/cppcheckplus/text/creatTable.java | |||
@@ -1,321 +1,328 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
3 | import java.util.Vector; | 4 | import java.util.Vector; |
4 | import java.util.regex.Pattern; | 5 | import java.util.regex.Pattern; |
5 | |||
6 | import javax.xml.parsers.DocumentBuilder; | 6 | import javax.xml.parsers.DocumentBuilder; |
7 | import javax.xml.parsers.DocumentBuilderFactory; | 7 | import javax.xml.parsers.DocumentBuilderFactory; |
8 | |||
9 | import org.w3c.dom.Document; | 8 | import org.w3c.dom.Document; |
10 | import org.w3c.dom.Element; | 9 | import org.w3c.dom.Element; |
11 | import org.w3c.dom.Node; | 10 | import org.w3c.dom.Node; |
12 | import org.w3c.dom.NodeList; | 11 | import org.w3c.dom.NodeList; |
13 | 12 | ||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | |||
16 | public class creatTable { | 13 | public class creatTable { |
17 | 14 | ||
18 | public String tableNameTemp = ""; | 15 | public String tableNameTemp = ""; |
19 | public Vector<DeflectRow> cppcheckplusResults = new Vector<DeflectRow>(); | 16 | public Vector<DeflectRow> cppcheckplusResults = new Vector<DeflectRow>(); |
20 | public Vector<DeflectRow> flawfinderResults = new Vector<DeflectRow>(); | 17 | public Vector<DeflectRow> flawfinderResults = new Vector<DeflectRow>(); |
21 | public Vector<DeflectRow> clangResults = new Vector<DeflectRow>(); | 18 | public Vector<DeflectRow> clangResults = new Vector<DeflectRow>(); |
22 | public Vector<DeflectRow> results = new Vector<DeflectRow>(); | 19 | public Vector<DeflectRow> results = new Vector<DeflectRow>(); |
23 | public Vector<stdClangType> stdclang = new Vector<stdClangType>(); | 20 | public Vector<stdClangType> stdclang = new Vector<stdClangType>(); |
24 | 21 | ||
25 | public void initSTDClang(String xml){ | 22 | public static void addObject(Vector<DeflectRow> nodes, DeflectRow node) { |
26 | try | 23 | if (!nodes.contains(node)) { |
27 | { | 24 | nodes.add(node); |
28 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | 25 | } else {//重复检测的缺陷需要标注 |
29 | DocumentBuilder db = dbf.newDocumentBuilder(); | 26 | int nodesNum = nodes.size(); |
30 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | 27 | for (int i = 0; i < nodesNum; i++) { |
31 | Element root = doc.getDocumentElement(); | 28 | if (nodes.elementAt(i).equals(node)) |
32 | NodeList stdlist = root.getChildNodes(); | 29 | // FIXME: 这里作用不明 |
33 | if (stdlist != null) | 30 | { |
34 | { | 31 | nodes.elementAt(i) |
35 | for (int i = 0; i < stdlist.getLength(); i++) | 32 | .setIssure(DeflectRow.Issure.CURRECT_ISSURE); |
36 | { | 33 | } |
37 | org.w3c.dom.Node menu = stdlist.item(i); | 34 | } |
38 | if (menu.getNodeType() == Node.ELEMENT_NODE) | 35 | } |
39 | { | 36 | } |
40 | if (menu.getNodeName().equalsIgnoreCase("clangNode")) | 37 | |
41 | { | 38 | public void initSTDClang(String xml) { |
42 | stdClangType node = new stdClangType(); | 39 | try { |
43 | node.cwe=MyContorlUtil.getStringAttribute(menu, "cwe"); | 40 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
44 | node.level=MyContorlUtil.getStringAttribute(menu, "level"); | 41 | DocumentBuilder db = dbf.newDocumentBuilder(); |
45 | node.target=MyContorlUtil.getStringAttribute(menu, "target"); | 42 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); |
46 | node.len=Integer.valueOf(MyContorlUtil.getStringAttribute(menu, "len")); | 43 | Element root = doc.getDocumentElement(); |
47 | node.type=MyContorlUtil.getStringAttribute(menu, "type"); | 44 | NodeList stdlist = root.getChildNodes(); |
48 | stdclang.add(node); | 45 | if (stdlist != null) { |
49 | } | 46 | for (int i = 0; i < stdlist.getLength(); i++) { |
50 | } | 47 | org.w3c.dom.Node menu = stdlist.item(i); |
51 | } | 48 | if (menu.getNodeType() == Node.ELEMENT_NODE) { |
52 | } | 49 | if (menu.getNodeName().equalsIgnoreCase("clangNode")) { |
53 | } | 50 | stdClangType node = new stdClangType(); |
54 | catch (Exception ex) | 51 | node.cwe = |
55 | { | 52 | MyContorlUtil.getStringAttribute(menu, "cwe"); |
56 | ex.printStackTrace(); | 53 | node.level = |
57 | } | 54 | MyContorlUtil.getStringAttribute(menu, "level"); |
55 | node.target = MyContorlUtil.getStringAttribute(menu, | ||
56 | "target"); | ||
57 | node.len = Integer.valueOf( | ||
58 | MyContorlUtil.getStringAttribute(menu, "len")); | ||
59 | node.type = | ||
60 | MyContorlUtil.getStringAttribute(menu, "type"); | ||
61 | stdclang.add(node); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | } catch (Exception ex) { | ||
67 | ex.printStackTrace(); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | public void makeTable() {// 统一并输出 | ||
72 | results.clear(); | ||
73 | for (int i = 0; i < cppcheckplusResults.size(); i++) { | ||
74 | addObject(results, cppcheckplusResults.elementAt(i)); | ||
75 | } | ||
76 | for (int i = 0; i < clangResults.size(); i++) { | ||
77 | addObject(results, clangResults.elementAt(i)); | ||
78 | } | ||
79 | for (int i = 0; i < flawfinderResults.size(); i++) { | ||
80 | addObject(results, flawfinderResults.elementAt(i)); | ||
81 | } | ||
58 | } | 82 | } |
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 | 83 | ||
80 | public static void addObject(Vector<DeflectRow> nodes, DeflectRow node) { | 84 | public void clearall() {// 清除 |
81 | if (!nodes.contains(node)) { | 85 | results.clear(); |
82 | nodes.add(node); | 86 | clangResults.clear(); |
83 | } | 87 | flawfinderResults.clear(); |
84 | else{//重复检测的缺陷需要标注 | 88 | cppcheckplusResults.clear(); |
85 | int nodesNum = nodes.size(); | 89 | } |
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 | 90 | ||
138 | public void toRowsOfCppcheckResult(String input) {// | 91 | //按文件、类型和级别排序 |
139 | String[] temp = input.split("\\$"); | 92 | public void ord(int ordType) {//1文件,2类型,3级别 |
140 | int size = temp.length; | 93 | //final int prime = 31; |
141 | String until = null; | 94 | //Vector<DeflectRow> other = new Vector<DeflectRow>(); |
142 | String file = null; | 95 | if (ordType == 1) {//按照文件排序 |
143 | String line = null; | 96 | int memNum = results.size(); |
144 | String level = null; | 97 | for (int i = 0; i < memNum - 1; i++) { |
145 | String type = null; | 98 | for (int j = 0; j < memNum - i - 1; j++) { |
146 | String cwe = null; | 99 | if (results.elementAt(j).getFile().hashCode() |
147 | String description = null; | 100 | > results.elementAt(j + 1).getFile().hashCode()) { |
148 | if (size > 6) { | 101 | DeflectRow temp = results.elementAt(j); |
149 | if (temp[1].length() == 0) | 102 | results.set(j, results.elementAt(j + 1)); |
150 | return; | 103 | results.set(j + 1, temp); |
151 | until = temp[0]; | 104 | } |
152 | file = temp[1]; | 105 | } |
153 | line = temp[2]; | 106 | } |
154 | level = temp[3]; | 107 | } else if (ordType == 2) {//按照类型排序 |
155 | if (temp[3].equals("error")) | 108 | int memNum = results.size(); |
156 | level = "4"; | 109 | for (int i = 0; i < memNum - 1; i++) { |
157 | else if (temp[3].equals("warning")) | 110 | for (int j = 0; j < memNum - i - 1; j++) { |
158 | level = "3"; | 111 | if (results.elementAt(j).getType().hashCode() |
159 | else if (temp[2].equals("style")) | 112 | > results.elementAt(j + 1).getType().hashCode()) { |
160 | level = "1"; | 113 | DeflectRow temp = results.elementAt(j); |
161 | else if (temp[2].equals("information")) | 114 | results.set(j, results.elementAt(j + 1)); |
162 | level = "0"; | 115 | results.set(j + 1, temp); |
163 | else | 116 | } |
164 | level = "2"; | 117 | } |
165 | type = temp[4]; | 118 | } |
166 | description = temp[5]; | 119 | } else if (ordType == 3) {//按照级别筛选 |
167 | cwe = temp[6]; | 120 | int memNum = results.size(); |
168 | DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); | 121 | for (int i = 0; i < memNum - 1; i++) { |
169 | stdCppcheck(node); | 122 | for (int j = 0; j < memNum - i - 1; j++) { |
170 | cppcheckplusResults.add(node); | 123 | if (results.elementAt(j).getLevel().hashCode() |
171 | } | 124 | > results.elementAt(j + 1).getLevel().hashCode()) { |
172 | } | 125 | DeflectRow temp = results.elementAt(j); |
126 | results.set(j, results.elementAt(j + 1)); | ||
127 | results.set(j + 1, temp); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | } | ||
173 | 133 | ||
174 | public void stdCppcheck(DeflectRow node) { | 134 | public void toRowsOfCppcheckResult(String input) {// |
175 | String cwe = node.getCwe(); | 135 | String[] temp = input.split("\\$"); |
176 | int cwenum = Integer.parseInt(cwe); | 136 | int size = temp.length; |
177 | switch(cwenum){ //cppcheck向flawfinder看齐 | 137 | String until = null; |
178 | case 134: | 138 | String file = null; |
179 | node.setLevel("4"); | 139 | String line = null; |
180 | node.setType("format"); | 140 | String level = null; |
181 | break; | 141 | String type = null; |
182 | case 367: | 142 | String cwe = null; |
183 | node.setLevel("4"); | 143 | String description = null; |
184 | node.setType("race"); | 144 | if (size > 6) { |
185 | break; | 145 | if (temp[1].length() == 0) { |
186 | case 120: | 146 | return; |
187 | node.setLevel("4"); | 147 | } |
188 | node.setType("buff"); | 148 | until = temp[0]; |
189 | break; | 149 | file = temp[1]; |
190 | case 78: | 150 | line = temp[2]; |
191 | node.setLevel("4"); | 151 | level = temp[3]; |
192 | node.setType("shell"); | 152 | if (temp[3].equals("error")) { |
193 | break; | 153 | level = "4"; |
194 | case 327: | 154 | } else if (temp[3].equals("warning")) { |
195 | node.setLevel("3"); | 155 | level = "3"; |
196 | node.setType("random"); | 156 | } else if (temp[2].equals("style")) { |
197 | break; | 157 | level = "1"; |
198 | case 119: | 158 | } else if (temp[2].equals("information")) { |
199 | node.setLevel("4"); | 159 | level = "0"; |
200 | node.setType("buffer"); | 160 | } else { |
201 | break; | 161 | level = "2"; |
202 | case 362: | 162 | } |
203 | node.setLevel("2"); | 163 | type = temp[4]; |
204 | node.setType("misc"); | 164 | description = temp[5]; |
205 | break; | 165 | cwe = temp[6]; |
206 | case 190: | 166 | DeflectRow node = |
207 | node.setLevel("2"); | 167 | new DeflectRow(until, file, line, level, type, cwe, description, |
208 | node.setType("integer"); | 168 | 0); |
209 | break; | 169 | stdCppcheck(node); |
210 | default: | 170 | cppcheckplusResults.add(node); |
211 | ; | 171 | } |
212 | } | 172 | } |
213 | } | 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 | 214 | ||
215 | public void toRowsOfClang(String input) { | 215 | public void toRowsOfClang(String input) { |
216 | String[] temp = input.split(":"); | 216 | String[] temp = input.split(":"); |
217 | int size = temp.length; | 217 | int size = temp.length; |
218 | String until = null; | 218 | String until = null; |
219 | String file = null; | 219 | String file = null; |
220 | String line = null; | 220 | String line = null; |
221 | String column = null; | 221 | String column = null; |
222 | String level = null; | 222 | String level = null; |
223 | String type = null; | 223 | String type = null; |
224 | String cwe = null; | 224 | String cwe = null; |
225 | String description = null; | 225 | String description = null; |
226 | if (size > 5) { | 226 | if (size > 5) { |
227 | until = "clang-tidy"; | 227 | until = "clang-tidy"; |
228 | file = temp[0] + ":" + temp[1]; | 228 | file = temp[0] + ":" + temp[1]; |
229 | line = temp[2]; | 229 | line = temp[2]; |
230 | column = temp[3]; | 230 | column = temp[3]; |
231 | level = temp[4];// warning,note, error | 231 | level = temp[4];// warning,note, error |
232 | type = ""; | 232 | type = ""; |
233 | description = temp[5]; | 233 | description = temp[5]; |
234 | cwe = "0"; | 234 | cwe = "0"; |
235 | // 标准化 | 235 | // 标准化 |
236 | DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); | 236 | DeflectRow node = |
237 | stdClang(node); | 237 | new DeflectRow(until, file, line, level, type, cwe, description, |
238 | clangResults.add(node); | 238 | 0); |
239 | } | 239 | stdClang(node); |
240 | } | 240 | clangResults.add(node); |
241 | } | ||
242 | } | ||
241 | 243 | ||
242 | public void stdClang(DeflectRow node) { | 244 | public void stdClang(DeflectRow node) { |
243 | String describ = node.getDescription(); | 245 | String describ = node.getDescription(); |
244 | int len = describ.length(); | 246 | int len = describ.length(); |
245 | boolean isFound = false; | 247 | boolean isFound = false; |
246 | for (int i = 0; i < stdclang.size(); i++) { | 248 | for (int i = 0; i < stdclang.size(); i++) { |
247 | if(len>stdclang.elementAt(i).len){ | 249 | if (len > stdclang.elementAt(i).len) { |
248 | if (describ.substring(1, stdclang.elementAt(i).len).equals(stdclang.elementAt(i).target)) { | 250 | if (describ.substring(1, stdclang.elementAt(i).len) |
249 | node.setCwe(stdclang.elementAt(i).cwe); | 251 | .equals(stdclang.elementAt(i).target)) { |
250 | node.setLevel(stdclang.elementAt(i).level); | 252 | node.setCwe(stdclang.elementAt(i).cwe); |
251 | node.setType(stdclang.elementAt(i).type); | 253 | node.setLevel(stdclang.elementAt(i).level); |
252 | isFound=true; | 254 | node.setType(stdclang.elementAt(i).type); |
253 | return; | 255 | isFound = true; |
254 | } | 256 | return; |
255 | } | 257 | } |
256 | } | 258 | } |
257 | if(!isFound){ | 259 | } |
258 | node.setCwe("未知"); | 260 | if (!isFound) { |
259 | node.setLevel("2"); | 261 | node.setCwe("未知"); |
260 | node.setType("other"); | 262 | node.setLevel("2"); |
261 | } | 263 | node.setType("other"); |
262 | } | 264 | } |
265 | } | ||
263 | 266 | ||
264 | 267 | ||
265 | public void toRowsOfFlawfinder(String csvFileName) {// csv | 268 | public void toRowsOfFlawfinder(String csvFileName) {// csv |
266 | 269 | ||
267 | String until = null; | 270 | String until = null; |
268 | // public String defObject = null; | 271 | // public String defObject = null; |
269 | String file = null; | 272 | String file = null; |
270 | String location = null; | 273 | String location = null; |
271 | String level = null; | 274 | String level = null; |
272 | String type = null; | 275 | String type = null; |
273 | String function = null; | 276 | String function = null; |
274 | String description = null; | 277 | String description = null; |
275 | DeflectRow node = new DeflectRow(until, file, location, level, type, function, description, 0); | 278 | DeflectRow node = |
276 | } | 279 | new DeflectRow(until, file, location, level, type, function, |
280 | description, 0); | ||
281 | } | ||
277 | 282 | ||
278 | public boolean isInteger(String str){ | 283 | public boolean isInteger(String str) { |
279 | Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); | 284 | Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); |
280 | return pattern.matcher(str).matches(); | 285 | return pattern.matcher(str).matches(); |
281 | } | 286 | } |
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 | 287 | ||
288 | public void toRowsOfflawfinder(String input) { | ||
289 | // File,Line,Column,Level,Category,Name,Warning,Suggestion,Note,CWEs,Context,Fingerprint | ||
290 | String[] temp = input.split(","); | ||
291 | int size = temp.length; | ||
292 | String until = null; | ||
293 | String file = null; | ||
294 | String line = null; | ||
295 | String column = null; | ||
296 | String level = null; | ||
297 | String category = null; | ||
298 | String name = null; | ||
299 | String warning = null; | ||
300 | String suggestion = null; | ||
301 | String note = null; | ||
302 | String cwe = null; | ||
303 | String context = null; | ||
304 | String fingerprint = null; | ||
305 | if (size > 11) { | ||
306 | if (!isInteger(temp[1])) { | ||
307 | return; | ||
308 | } | ||
309 | until = "flawfinder"; | ||
310 | file = temp[0]; | ||
311 | line = temp[1]; | ||
312 | column = temp[2]; | ||
313 | level = temp[3]; | ||
314 | category = temp[4]; | ||
315 | name = temp[5]; | ||
316 | warning = temp[6]; | ||
317 | suggestion = temp[7]; | ||
318 | note = temp[8]; | ||
319 | cwe = temp[9]; | ||
320 | context = temp[10]; | ||
321 | fingerprint = temp[11]; | ||
322 | DeflectRow node = | ||
323 | new DeflectRow(until, file, line, level, category, cwe, warning, | ||
324 | 0); | ||
325 | flawfinderResults.add(node); | ||
326 | } | ||
327 | } | ||
321 | } | 328 | } |
diff --git a/src/cppcheckplus/text/stdClangType.java b/src/cppcheckplus/text/stdClangType.java index 42e9c37..ccbe3f7 100644 --- a/src/cppcheckplus/text/stdClangType.java +++ b/src/cppcheckplus/text/stdClangType.java | |||
@@ -1,9 +1,9 @@ | |||
1 | package cppcheckplus.text; | 1 | package cppcheckplus.text; |
2 | 2 | ||
3 | public class stdClangType { | 3 | public class stdClangType { |
4 | public int len; | 4 | public int len; |
5 | public String cwe; | 5 | public String cwe; |
6 | public String type; | 6 | public String type; |
7 | public String level; | 7 | public String level; |
8 | public String target; | 8 | public String target; |
9 | } | 9 | } |
diff --git a/src/cppcheckplus/toolbar/MyToolBar.java b/src/cppcheckplus/toolbar/MyToolBar.java index e0473a6..26f14d2 100644 --- a/src/cppcheckplus/toolbar/MyToolBar.java +++ b/src/cppcheckplus/toolbar/MyToolBar.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.toolbar; | 1 | package cppcheckplus.toolbar; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Dimension; | 4 | import java.awt.Dimension; |
5 | import java.awt.FlowLayout; | 5 | import java.awt.FlowLayout; |
6 | import java.awt.Graphics; | 6 | import java.awt.Graphics; |
@@ -10,51 +10,50 @@ import javax.swing.BorderFactory; | |||
10 | import javax.swing.Icon; | 10 | import javax.swing.Icon; |
11 | import javax.swing.JPanel; | 11 | import javax.swing.JPanel; |
12 | 12 | ||
13 | import cppcheckplus.control.MyContorlUtil; | ||
14 | |||
15 | 13 | ||
16 | public class MyToolBar extends JPanel | 14 | public class MyToolBar extends JPanel { |
17 | { | 15 | private String backgroundImageURL; |
18 | private String backgroundImageURL; | 16 | private int preferredHeight; |
19 | private int preferredHeight; | 17 | private TexturePaint paint; |
20 | private TexturePaint paint; | 18 | private int buttonGap; |
21 | private int buttonGap; | 19 | |
22 | 20 | public MyToolBar() { | |
23 | public MyToolBar() | 21 | preferredHeight = |
24 | { | 22 | MyContorlUtil.getImageIcon("control/images/toolbar_background.png") |
25 | preferredHeight = MyContorlUtil.getImageIcon("control/images/toolbar_background.png").getIconHeight(); | 23 | .getIconHeight(); |
26 | paint = MyContorlUtil.createTexturePaint("control/images/toolbar_background.png"); | 24 | paint = MyContorlUtil.createTexturePaint( |
27 | buttonGap = 2; | 25 | "control/images/toolbar_background.png"); |
28 | init(); | 26 | buttonGap = 2; |
29 | } | 27 | init(); |
30 | 28 | } | |
31 | private void init() | 29 | |
32 | { | 30 | private void init() { |
33 | setLayout(new FlowLayout(3, buttonGap, 0)); | 31 | setLayout(new FlowLayout(3, buttonGap, 0)); |
34 | setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 5)); | 32 | setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 5)); |
35 | } | 33 | } |
36 | public void addButton(Icon icon, String tooltip,String actionCommand,boolean rover) | 34 | |
37 | { | 35 | public void addButton(Icon icon, String tooltip, String actionCommand, |
38 | MyToolBarButton barButton; | 36 | boolean rover) { |
39 | if (rover) | 37 | MyToolBarButton barButton; |
40 | barButton = new MyToolBarRoverButton(); | 38 | if (rover) { |
41 | else | 39 | barButton = new MyToolBarRoverButton(); |
42 | barButton = new MyToolBarButton(); | 40 | } else { |
43 | barButton.setIcon(icon); | 41 | barButton = new MyToolBarButton(); |
44 | barButton.setToolTipText(tooltip); | 42 | } |
45 | barButton.setActionCommand(actionCommand); | 43 | barButton.setIcon(icon); |
46 | add(barButton); | 44 | barButton.setToolTipText(tooltip); |
47 | } | 45 | barButton.setActionCommand(actionCommand); |
48 | protected void paintComponent(Graphics g) | 46 | add(barButton); |
49 | { | 47 | } |
50 | super.paintComponent(g); | 48 | |
51 | Graphics2D g2d = (Graphics2D)g; | 49 | protected void paintComponent(Graphics g) { |
52 | g2d.setPaint(paint); | 50 | super.paintComponent(g); |
53 | g2d.fillRect(0, 0, getWidth(), getHeight()); | 51 | Graphics2D g2d = (Graphics2D) g; |
54 | } | 52 | g2d.setPaint(paint); |
55 | 53 | g2d.fillRect(0, 0, getWidth(), getHeight()); | |
56 | public Dimension getPreferredSize() | 54 | } |
57 | { | 55 | |
58 | return new Dimension(super.getPreferredSize().width, preferredHeight); | 56 | public Dimension getPreferredSize() { |
59 | } | 57 | return new Dimension(super.getPreferredSize().width, preferredHeight); |
58 | } | ||
60 | } | 59 | } |
diff --git a/src/cppcheckplus/toolbar/MyToolBarButton.java b/src/cppcheckplus/toolbar/MyToolBarButton.java index d6fa386..32f5056 100644 --- a/src/cppcheckplus/toolbar/MyToolBarButton.java +++ b/src/cppcheckplus/toolbar/MyToolBarButton.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.toolbar; | 1 | package cppcheckplus.toolbar; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Color; | 4 | import java.awt.Color; |
5 | import java.awt.Component; | 5 | import java.awt.Component; |
6 | import java.awt.Dimension; | 6 | import java.awt.Dimension; |
@@ -13,85 +13,72 @@ import javax.swing.Icon; | |||
13 | import javax.swing.JButton; | 13 | import javax.swing.JButton; |
14 | import javax.swing.border.Border; | 14 | import javax.swing.border.Border; |
15 | 15 | ||
16 | import cppcheckplus.control.MyContorlUtil; | 16 | public class MyToolBarButton extends JButton { |
17 | 17 | private int buttonSize; | |
18 | public class MyToolBarButton extends JButton | 18 | private Color roverBorderColor; |
19 | { | 19 | private Border roverBorder; |
20 | private int buttonSize; | 20 | private Border emptyBorder; |
21 | private Color roverBorderColor; | ||
22 | private Border roverBorder; | ||
23 | private Border emptyBorder; | ||
24 | 21 | ||
25 | public MyToolBarButton() | 22 | public MyToolBarButton() { |
26 | { | 23 | super(); |
27 | super(); | 24 | buttonSize = 20; |
28 | buttonSize = 20; | 25 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; |
29 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; | 26 | roverBorder = new Border() { |
30 | roverBorder = new Border() { | ||
31 | 27 | ||
32 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | 28 | public void paintBorder(Component c, Graphics g, int x, int y, |
33 | { | 29 | int width, int height) { |
34 | g.setColor(roverBorderColor); | 30 | g.setColor(roverBorderColor); |
35 | g.drawRect(x, y, width - 1, height - 1); | 31 | g.drawRect(x, y, width - 1, height - 1); |
36 | } | 32 | } |
37 | 33 | ||
38 | public Insets getBorderInsets(Component c) | 34 | public Insets getBorderInsets(Component c) { |
39 | { | 35 | return new Insets(1, 1, 1, 1); |
40 | return new Insets(1, 1, 1, 1); | 36 | } |
41 | } | ||
42 | 37 | ||
43 | public boolean isBorderOpaque() | 38 | public boolean isBorderOpaque() { |
44 | { | 39 | return true; |
45 | return true; | 40 | } |
46 | } | 41 | }; |
47 | }; | 42 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); |
48 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); | 43 | init(); |
49 | init(); | 44 | } |
50 | } | ||
51 | 45 | ||
52 | private void init() | 46 | private void init() { |
53 | { | 47 | setVerticalAlignment(0); |
54 | setVerticalAlignment(0); | 48 | setFont(MyContorlUtil.FONT_12_BOLD); |
55 | setFont(MyContorlUtil.FONT_12_BOLD); | 49 | setOpaque(false); |
56 | setOpaque(false); | 50 | setBorder(emptyBorder); |
57 | setBorder(emptyBorder); | 51 | setContentAreaFilled(false); |
58 | setContentAreaFilled(false); | 52 | setFocusPainted(false); |
59 | setFocusPainted(false); | 53 | addMouseListener(new MouseAdapter() { |
60 | addMouseListener(new MouseAdapter() { | 54 | public void mouseEntered(MouseEvent e) { |
61 | public void mouseEntered(MouseEvent e) | 55 | setBorder(roverBorder); |
62 | { | 56 | } |
63 | setBorder(roverBorder); | ||
64 | } | ||
65 | 57 | ||
66 | public void mouseExited(MouseEvent e) | 58 | public void mouseExited(MouseEvent e) { |
67 | { | 59 | setBorder(emptyBorder); |
68 | setBorder(emptyBorder); | 60 | } |
69 | } | 61 | }); |
70 | }); | 62 | } |
71 | } | ||
72 | 63 | ||
73 | @Override | 64 | @Override |
74 | public void setIcon(Icon icon) | 65 | public void setIcon(Icon icon) { |
75 | { | 66 | super.setIcon(icon); |
76 | super.setIcon(icon); | 67 | if (icon == null) { |
77 | if (icon == null) | 68 | setPressedIcon(null); |
78 | { | 69 | setRolloverIcon(null); |
79 | setPressedIcon(null); | 70 | } else { |
80 | setRolloverIcon(null); | 71 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); |
81 | } else | 72 | setPressedIcon(pressedIcon); |
82 | { | 73 | } |
83 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); | 74 | } |
84 | setPressedIcon(pressedIcon); | ||
85 | } | ||
86 | } | ||
87 | 75 | ||
88 | 76 | ||
89 | @Override | 77 | @Override |
90 | public Dimension getPreferredSize() | 78 | public Dimension getPreferredSize() { |
91 | { | 79 | int width = super.getPreferredSize().width; |
92 | int width = super.getPreferredSize().width; | 80 | width = Math.max(width, buttonSize); |
93 | width = Math.max(width, buttonSize); | 81 | int height = buttonSize; |
94 | int height = buttonSize; | 82 | return new Dimension(width, height); |
95 | return new Dimension(width, height); | 83 | } |
96 | } | ||
97 | } | 84 | } |
diff --git a/src/cppcheckplus/toolbar/MyToolBarRoverButton.java b/src/cppcheckplus/toolbar/MyToolBarRoverButton.java index 9ab1dc8..79069f5 100644 --- a/src/cppcheckplus/toolbar/MyToolBarRoverButton.java +++ b/src/cppcheckplus/toolbar/MyToolBarRoverButton.java | |||
@@ -1,36 +1,30 @@ | |||
1 | |||
2 | package cppcheckplus.toolbar; | 1 | package cppcheckplus.toolbar; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.Color; | 4 | import java.awt.Color; |
5 | import javax.swing.Icon; | 5 | import javax.swing.Icon; |
6 | import javax.swing.ImageIcon; | 6 | import javax.swing.ImageIcon; |
7 | 7 | ||
8 | import cppcheckplus.control.MyContorlUtil; | ||
9 | |||
10 | 8 | ||
11 | public class MyToolBarRoverButton extends MyToolBarButton | 9 | public class MyToolBarRoverButton extends MyToolBarButton { |
12 | { | 10 | private Color roverDyeColor; |
13 | private Color roverDyeColor; | ||
14 | 11 | ||
15 | public MyToolBarRoverButton() | 12 | public MyToolBarRoverButton() { |
16 | { | 13 | roverDyeColor = new Color(86, 146, 61); |
17 | roverDyeColor = new Color(86, 146, 61); | 14 | } |
18 | } | ||
19 | 15 | ||
20 | public void setIcon(Icon icon) | 16 | public void setIcon(Icon icon) { |
21 | { | 17 | super.setIcon(icon); |
22 | super.setIcon(icon); | 18 | if (icon == null) { |
23 | if (icon == null) | 19 | setPressedIcon(null); |
24 | { | 20 | setRolloverIcon(null); |
25 | setPressedIcon(null); | 21 | } else { |
26 | setRolloverIcon(null); | 22 | java.awt.Image image = MyContorlUtil.iconToImage(icon); |
27 | } else | 23 | Icon roverIcon = MyContorlUtil.createDyedIcon(new ImageIcon(image), |
28 | { | 24 | roverDyeColor); |
29 | java.awt.Image image = MyContorlUtil.iconToImage(icon); | 25 | Icon pressedIcon = MyContorlUtil.createMovedIcon(roverIcon); |
30 | Icon roverIcon = MyContorlUtil.createDyedIcon(new ImageIcon(image), roverDyeColor); | 26 | setRolloverIcon(roverIcon); |
31 | Icon pressedIcon = MyContorlUtil.createMovedIcon(roverIcon); | 27 | setPressedIcon(pressedIcon); |
32 | setRolloverIcon(roverIcon); | 28 | } |
33 | setPressedIcon(pressedIcon); | 29 | } |
34 | } | ||
35 | } | ||
36 | } | 30 | } |
diff --git a/src/toolsconfig/clangTidy.java b/src/toolsconfig/clangTidy.java index d197393..8186603 100644 --- a/src/toolsconfig/clangTidy.java +++ b/src/toolsconfig/clangTidy.java | |||
@@ -1,7 +1,5 @@ | |||
1 | package toolsconfig; | 1 | package toolsconfig; |
2 | 2 | ||
3 | import cppcheckplus.control.UIFrame; | ||
4 | import cppcheckplus.text.ViewPanel; | ||
5 | import java.io.BufferedReader; | 3 | import java.io.BufferedReader; |
6 | import java.io.IOException; | 4 | import java.io.IOException; |
7 | import java.io.InputStream; | 5 | import java.io.InputStream; |
diff --git a/src/toolsconfig/flawfinder.java b/src/toolsconfig/flawfinder.java index 4ed19c2..0528eb6 100644 --- a/src/toolsconfig/flawfinder.java +++ b/src/toolsconfig/flawfinder.java | |||
@@ -1,13 +1,11 @@ | |||
1 | package toolsconfig; | 1 | package toolsconfig; |
2 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import cppcheckplus.text.ViewPanel; | ||
5 | import java.io.BufferedReader; | 3 | import java.io.BufferedReader; |
6 | import java.io.IOException; | 4 | import java.io.IOException; |
7 | import java.io.InputStream; | 5 | import java.io.InputStream; |
8 | import java.io.InputStreamReader; | 6 | import java.io.InputStreamReader; |
9 | 7 | ||
10 | public class flawfinder extends ToolsConfig{ | 8 | public class flawfinder extends ToolsConfig { |
11 | public flawfinder() { | 9 | public flawfinder() { |
12 | this.name = "flawfinder"; | 10 | this.name = "flawfinder"; |
13 | ToolsRegistry.registerTool(this.name, this); | 11 | ToolsRegistry.registerTool(this.name, this); |
diff --git a/src/toolsconfig/settings.xml b/src/toolsconfig/settings.xml index c0664d9..77dd785 100644 --- a/src/toolsconfig/settings.xml +++ b/src/toolsconfig/settings.xml | |||
@@ -1,7 +1,7 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?><settings> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?><settings> |
2 | <tool filePath="C:/Users/we-unite/Desktop/Project/Project/code/cppcheck/bin/debug/cppcheck.exe" para="--enable=all" toolName="cppcheck"> | 2 | <tool filePath="C:\\Users\\we-unite\\Desktop\\Project\\Project\\code\\cppcheck\\bin\\debug\\cppcheck.exe" para="--enable=all" toolName="cppcheck"> |
3 | </tool> | 3 | </tool> |
4 | <tool filePath="C:/Users/we-unite/Desktop/Project/Project/code/flawfinder-2.0.19/flawfinder-2.0.19/flawfinder.py" para="" toolName="flawfinder"> | 4 | <tool filePath="C:\\Users\\we-unite\\Desktop\\Project\\Project\\code\\flawfinder-2.0.19\\flawfinder-2.0.19\\flawfinder.py" para="" toolName="flawfinder"> |
5 | </tool> | 5 | </tool> |
6 | <tool filePath="clang-tidy.exe" para="-I C:\\Program Files\\LLVM\\lib\\clang\\17" toolName="clangTidy"> | 6 | <tool filePath="clang-tidy.exe" para="-I C:\\Program Files\\LLVM\\lib\\clang\\17" toolName="clangTidy"> |
7 | </tool> | 7 | </tool> |