create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / components / FlatButton.java
1 package net.sf.openrocket.gui.components;
2
3 import java.awt.event.MouseAdapter;
4 import java.awt.event.MouseEvent;
5
6 import javax.swing.Action;
7 import javax.swing.Icon;
8 import javax.swing.JButton;
9
10 /**
11  * A JButton that appears flat until you roll over it.
12  * 
13  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14  */
15 public class FlatButton extends JButton {
16         
17         public FlatButton() {
18                 super();
19                 initialize();
20         }
21         
22         public FlatButton(Icon icon) {
23                 super(icon);
24                 initialize();
25         }
26         
27         public FlatButton(String text) {
28                 super(text);
29                 initialize();
30         }
31         
32         public FlatButton(Action a) {
33                 super(a);
34                 initialize();
35         }
36         
37         public FlatButton(String text, Icon icon) {
38                 super(text, icon);
39                 initialize();
40         }
41         
42         
43         private void initialize() {
44                 this.addMouseListener(new MouseAdapter() {
45                         @Override
46                         public void mouseExited(MouseEvent e) {
47                                 flatten();
48                         }
49                         
50                         @Override
51                         public void mouseEntered(MouseEvent e) {
52                                 raise();
53                         }
54                 });
55                 flatten();
56         }
57         
58         
59         private void flatten() {
60                 this.setContentAreaFilled(false);
61                 this.setBorderPainted(false);
62         }
63         
64         private void raise() {
65                 this.setContentAreaFilled(true);
66                 this.setBorderPainted(true);
67         }
68         
69 }