1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.component;
21
22 import java.awt.Graphics;
23 import java.awt.Insets;
24 import java.awt.event.MouseEvent;
25
26 import javax.swing.Action;
27 import javax.swing.JButton;
28
29 import org.xnap.gui.util.IconHelper;
30
31 /***
32 * This class provides a toolbar button with an appropriate sized icon.
33 */
34 public class XNapToolBarButton extends JButton
35 {
36
37
38
39
40
41 private boolean showBorder = false;
42 private boolean showMenuHint;
43
44
45
46 public XNapToolBarButton(Action action)
47 {
48 super(action);
49
50 String filename = (String)action.getValue(IconHelper.XNAP_ICON);
51 setIcon(IconHelper.getToolBarIcon(filename));
52
53 setText(null);
54 setMargin(new Insets(1, 1, 1, 1));
55
56 putClientProperty("hideActionText", new Boolean(true));
57 }
58
59
60
61 protected void paintBorder(Graphics g)
62 {
63 if (showBorder) {
64 super.paintBorder(g);
65 }
66 }
67
68 protected void processMouseEvent(MouseEvent e)
69 {
70 super.processMouseEvent(e);
71
72 if (e.getID() == MouseEvent.MOUSE_ENTERED) {
73 showBorder = true;
74 repaint();
75 }
76 else if (e.getID() == MouseEvent.MOUSE_EXITED) {
77 showBorder = false;
78 repaint();
79 }
80 }
81
82 }