View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19  */
20  package org.devaki.nextobjects.ui.components;
21  import java.awt.Insets;
22  import java.awt.event.MouseAdapter;
23  import java.awt.event.MouseEvent;
24  import javax.swing.ImageIcon;
25  import javax.swing.JToggleButton;
26  import org.devaki.nextobjects.NextObjects;
27  /***
28   * This class overwrite the 'JToggleButton' component
29   * @param icon icon
30   * @param tooltipText tooltip text
31   * @param statusBarText  status bar text
32   * @param  isSelected pre select
33   */
34  public class CustomToggleButton extends JToggleButton
35  {
36      /***
37       * Create a 'CustomToggleButton' object
38       * @param icon Image icon
39       * @param tooltipText Tootip text
40       * @param statusBarText the status bar text
41       * @param isEnabled is enabled
42       * @param isSelected is selected
43       */
44      public CustomToggleButton(
45          final ImageIcon icon,
46          final String tooltipText,
47          final String statusBarText,
48          final boolean isEnabled,
49          final boolean isSelected)
50      {
51          super(icon, isSelected);
52          // If the parameter 'tooltipText' is not empty, set it as tooltip
53          if (tooltipText.length() != 0)
54          {
55              this.setToolTipText(tooltipText);
56          }
57          // Enable/Disable
58          this.setEnabled(isEnabled);
59          // Define margin between the image and the border
60          this.setMargin(new Insets(0, 0, 0, 0));
61          // Add a mouse listener to update the status bar of nextObjects when
62          // passing the mouse over the button
63          this.addMouseListener(new MouseAdapter()
64          {
65              public final void mouseEntered(final MouseEvent e)
66              {
67                  NextObjects.setStatusBarText(statusBarText);
68              }
69              public final void mouseExited(final MouseEvent e)
70              {
71                  NextObjects.setStatusBarText(" ");
72              }
73          });
74      }
75  }