diff options
Diffstat (limited to 'src/cppcheckplus/control/MyToolbarButton.java')
-rw-r--r-- | src/cppcheckplus/control/MyToolbarButton.java | 131 |
1 files changed, 59 insertions, 72 deletions
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 | } |