1 package org.devaki.nextobjects.ui.components;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.awt.Font;
22 import java.awt.Insets;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import javax.swing.ImageIcon;
26 import javax.swing.JButton;
27 import org.devaki.nextobjects.NextObjects;
28 /***
29 * This class Overwrite of the 'JButton' component
30 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
31 */
32 public class CustomButton extends JButton
33 {
34 /***
35 * Construct a CustomButton with text inside
36 * @param text Text to display
37 * @param tooltipText Text that appears as a Tool Tip
38 * @param isEnabled Is the button enabled or not
39 * @param isSmall Is the button font small or not
40 */
41 public CustomButton(
42 final String text,
43 final String tooltipText,
44 final boolean isEnabled,
45 final boolean isSmall)
46 {
47 super(text);
48
49 if (tooltipText.compareTo("") != 0)
50 {
51 this.setToolTipText(tooltipText);
52 }
53
54 this.setEnabled(isEnabled);
55
56 if (isSmall)
57 {
58 this.setFont(new Font("Dialog", Font.BOLD, 9));
59 this.setMargin(new Insets(0, 2, 0, 2));
60 }
61 }
62 /***
63 * Construct a CustomButton with an image inside
64 * @param icon Icon to display in the button
65 * @param tooltipText Text that appears as a Tool Tip
66 * @param isEnabled Is the button enabled or not
67 */
68 public CustomButton(
69 final ImageIcon icon,
70 final String tooltipText,
71 final boolean isEnabled)
72 {
73 super(icon);
74
75 if (tooltipText.compareTo("") != 0)
76 { this.setToolTipText(tooltipText);
77 }
78
79 this.setEnabled(isEnabled);
80
81 this.setMargin(new Insets(0, 0, 0, 0));
82 }
83 /***
84 * Construct a CustomButton with an image inside
85 * @param icon Icon to display in the button
86 * @param tooltipText Text that appears as a Tool Tip
87 * @param statusBarText the text of the status bar
88 * @param isEnabled Is the button enabled or not
89 */
90 public CustomButton(
91 final ImageIcon icon,
92 final String tooltipText,
93 final String statusBarText,
94 final boolean isEnabled)
95 {
96 super(icon);
97
98 if (tooltipText.compareTo("") != 0)
99 {
100 this.setToolTipText(tooltipText);
101 }
102
103 this.setEnabled(isEnabled);
104
105 this.setMargin(new Insets(0, 0, 0, 0));
106
107
108 this.addMouseListener(new MouseAdapter()
109 {
110 public final void mouseEntered(final MouseEvent e)
111 {
112 NextObjects.setStatusBarText(statusBarText);
113 }
114 public final void mouseExited(final MouseEvent e)
115 {
116 NextObjects.setStatusBarText(" ");
117 }
118 });
119 }
120 }