diff options
Diffstat (limited to 'src/cppcheckplus/control/MyToolbarButton.java')
-rw-r--r-- | src/cppcheckplus/control/MyToolbarButton.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/cppcheckplus/control/MyToolbarButton.java b/src/cppcheckplus/control/MyToolbarButton.java new file mode 100644 index 0000000..e709296 --- /dev/null +++ b/src/cppcheckplus/control/MyToolbarButton.java | |||
@@ -0,0 +1,96 @@ | |||
1 | |||
2 | package cppcheckplus.control; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Component; | ||
6 | import java.awt.Dimension; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Insets; | ||
9 | import java.awt.event.MouseAdapter; | ||
10 | import java.awt.event.MouseEvent; | ||
11 | |||
12 | import javax.swing.BorderFactory; | ||
13 | import javax.swing.Icon; | ||
14 | import javax.swing.JButton; | ||
15 | import javax.swing.border.Border; | ||
16 | |||
17 | public class MyToolbarButton extends JButton | ||
18 | { | ||
19 | private int buttonSize; | ||
20 | private Color roverBorderColor; | ||
21 | private Border roverBorder; | ||
22 | private Border emptyBorder; | ||
23 | |||
24 | public MyToolbarButton() | ||
25 | { | ||
26 | super(); | ||
27 | buttonSize = 20; | ||
28 | roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; | ||
29 | roverBorder = new Border() { | ||
30 | |||
31 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | ||
32 | { | ||
33 | g.setColor(roverBorderColor); | ||
34 | g.drawRect(x, y, width - 1, height - 1); | ||
35 | } | ||
36 | |||
37 | public Insets getBorderInsets(Component c) | ||
38 | { | ||
39 | return new Insets(1, 1, 1, 1); | ||
40 | } | ||
41 | |||
42 | public boolean isBorderOpaque() | ||
43 | { | ||
44 | return true; | ||
45 | } | ||
46 | }; | ||
47 | emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); | ||
48 | init(); | ||
49 | } | ||
50 | |||
51 | private void init() | ||
52 | { | ||
53 | setVerticalAlignment(0); | ||
54 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
55 | setOpaque(false); | ||
56 | setBorder(emptyBorder); | ||
57 | setContentAreaFilled(false); | ||
58 | setFocusPainted(false); | ||
59 | addMouseListener(new MouseAdapter() { | ||
60 | public void mouseEntered(MouseEvent e) | ||
61 | { | ||
62 | setBorder(roverBorder); | ||
63 | } | ||
64 | |||
65 | public void mouseExited(MouseEvent e) | ||
66 | { | ||
67 | setBorder(emptyBorder); | ||
68 | } | ||
69 | }); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public void setIcon(Icon icon) | ||
74 | { | ||
75 | super.setIcon(icon); | ||
76 | if (icon == null) | ||
77 | { | ||
78 | setPressedIcon(null); | ||
79 | setRolloverIcon(null); | ||
80 | } else | ||
81 | { | ||
82 | Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); | ||
83 | setPressedIcon(pressedIcon); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
88 | @Override | ||
89 | public Dimension getPreferredSize() | ||
90 | { | ||
91 | int width = super.getPreferredSize().width; | ||
92 | width = Math.max(width, buttonSize); | ||
93 | int height = buttonSize; | ||
94 | return new Dimension(width, height); | ||
95 | } | ||
96 | } | ||