01: /*
02: * Created on 30/08/2005
03: *
04: * ============================================================================
05: * GNU Lesser General Public License
06: * ============================================================================
07: *
08: * Swing Components - visit http://sf.net/projects/gfd
09: *
10: * Copyright (C) 2004 Igor Regis da Silva Simões
11: *
12: * This library is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU Lesser General Public
14: * License as published by the Free Software Foundation; either
15: * version 2.1 of the License, or (at your option) any later version.
16: *
17: * This library is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20: * Lesser General Public License for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public
23: * License along with this library; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25: */
26: package br.com.gfpshare.beans;
27:
28: import java.awt.Dimension;
29: import java.awt.Insets;
30: import java.awt.event.MouseAdapter;
31: import java.awt.event.MouseEvent;
32:
33: import javax.swing.Icon;
34: import javax.swing.JButton;
35: import javax.swing.border.EtchedBorder;
36:
37: /**
38: * Classe que representa um botão customizado para Views
39: * @author Igor Regis da Silva Simoes
40: * @since 25/08/2005
41: */
42: public class ViewButton extends JButton {
43: public ViewButton(Icon icone, String toolTip) {
44: super (icone);
45: if (toolTip != null)
46: setToolTipText(toolTip);
47: final EtchedBorder borda = new EtchedBorder();
48: final Insets insets = borda.getBorderInsets(ViewButton.this );
49: ViewButton.this .setPreferredSize(new Dimension(icone
50: .getIconHeight()
51: + insets.top + insets.bottom, icone.getIconWidth()
52: + insets.left + insets.right));
53: setBorder(null);
54:
55: /**
56: * Registra listener que faz efeito de mouse hover
57: */
58: addMouseListener(new MouseAdapter() {
59: @Override
60: public void mouseEntered(MouseEvent e) {
61: ViewButton.this .setBorder(borda);
62: }
63:
64: @Override
65: public void mouseExited(MouseEvent e) {
66: ViewButton.this .setBorder(null);
67: ViewButton.this .setPreferredSize(new Dimension(
68: ViewButton.this.getHeight(), ViewButton.this
69: .getWidth()));
70: }
71: });
72: }
73: }
|