View Javadoc

1   package org.devaki.nextobjects.ui.components;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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          // If the parameter 'tooltipText' is not empty, set it as tooltip
49          if (tooltipText.compareTo("") != 0)
50          {
51              this.setToolTipText(tooltipText);
52          }
53          // Enable/Disable
54          this.setEnabled(isEnabled);
55          // Adapt font and margin if the button needs to be small
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          // If the parameter 'tooltipText' is not empty, set it as tooltip
75          if (tooltipText.compareTo("") != 0)
76             { this.setToolTipText(tooltipText);
77             }
78          // Enable/Disable
79          this.setEnabled(isEnabled);
80          // Define margin between the image and the border
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          // If the parameter 'tooltipText' is not empty, set it as tooltip
98          if (tooltipText.compareTo("") != 0)
99          {
100             this.setToolTipText(tooltipText);
101         }
102         // Enable/Disable
103         this.setEnabled(isEnabled);
104         // Define margin between the image and the border
105         this.setMargin(new Insets(0, 0, 0, 0));
106         // Add a mouse listener to update the status bar of nextObjects when
107         // passing the mouse over the button
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 }