1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.chainsaw;
18
19 import java.awt.Insets;
20 import java.awt.event.MouseEvent;
21 import java.awt.event.MouseListener;
22
23 import javax.swing.Action;
24 import javax.swing.JButton;
25 import javax.swing.border.BevelBorder;
26 import javax.swing.border.Border;
27 import javax.swing.border.EmptyBorder;
28 import javax.swing.border.SoftBevelBorder;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class SmallButton extends JButton implements MouseListener {
44 protected Border m_inactive = new EmptyBorder(3, 3, 3, 3);
45 protected Border m_border = m_inactive;
46 protected Border m_lowered = new SoftBevelBorder(BevelBorder.LOWERED);
47 protected Border m_raised = new SoftBevelBorder(BevelBorder.RAISED);
48 protected Insets m_ins = new Insets(4, 4, 4, 4);
49
50 public SmallButton() {
51 super();
52 setBorder(m_inactive);
53 setMargin(m_ins);
54 setRequestFocusEnabled(false);
55 addMouseListener(this);
56 }
57
58 public SmallButton(Action act) {
59 this();
60 setAction(act);
61 setRequestFocusEnabled(false);
62
63
64 addMouseListener(this);
65 }
66
67
68
69
70
71
72 public float getAlignmentY() {
73 return 0.5f;
74 }
75
76
77
78
79
80
81 public Border getBorder() {
82 return m_border;
83 }
84
85
86
87
88
89
90 public Insets getInsets() {
91 return m_ins;
92 }
93
94
95
96
97
98
99 public void mouseClicked(MouseEvent e) {
100 }
101
102
103
104
105
106
107 public void mouseEntered(MouseEvent e) {
108 if (isEnabled()) {
109 m_border = m_raised;
110 setBorder(m_raised);
111 }
112 }
113
114
115
116
117
118
119 public void mouseExited(MouseEvent e) {
120 m_border = m_inactive;
121 setBorder(m_inactive);
122 }
123
124
125
126
127
128
129 public void mousePressed(MouseEvent e) {
130
131 if (isEnabled()) {
132 m_border = m_lowered;
133 setBorder(m_lowered);
134 }
135 }
136
137
138
139
140
141
142 public void mouseReleased(MouseEvent e) {
143 m_border = m_inactive;
144 setBorder(m_inactive);
145 }
146 }