01: /*
02: * LinkButton.java
03: *
04: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package org.underworldlabs.swing;
23:
24: import java.awt.Color;
25: import java.awt.Cursor;
26: import java.awt.event.MouseAdapter;
27: import java.awt.event.MouseEvent;
28: import javax.swing.BorderFactory;
29: import javax.swing.JButton;
30: import javax.swing.JComponent;
31: import javax.swing.border.Border;
32:
33: /* ----------------------------------------------------------
34: * CVS NOTE: Changes to the CVS repository prior to the
35: * release of version 3.0.0beta1 has meant a
36: * resetting of CVS revision numbers.
37: * ----------------------------------------------------------
38: */
39:
40: /**
41: * Simple button behaving/looking like a hyperlink item.
42: *
43: * @author Takis Diakoumis
44: * @version $Revision: 1.4 $
45: * @date $Date: 2006/05/14 06:56:07 $
46: */
47: public class LinkButton extends JButton {
48:
49: private static final Color LINK_COLOR = Color.blue;
50: private static final Border LINK_BORDER = BorderFactory
51: .createEmptyBorder(0, 0, 1, 0);
52: private static final Border HOVER_BORDER = BorderFactory
53: .createMatteBorder(0, 0, 1, 0, LINK_COLOR);
54:
55: /** Creates a new instance of LinkButton */
56: public LinkButton(String text) {
57: super (text);
58: setBorder(null);
59: setBorder(LINK_BORDER);
60: setForeground(LINK_COLOR);
61: setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
62: setFocusPainted(false);
63: setRequestFocusEnabled(false);
64: setContentAreaFilled(false);
65: addMouseListener(new LinkMouseListener());
66: }
67:
68: private class LinkMouseListener extends MouseAdapter {
69: public void mouseEntered(MouseEvent e) {
70: ((JComponent) e.getComponent()).setBorder(HOVER_BORDER);
71: }
72:
73: public void mouseReleased(MouseEvent e) {
74: ((JComponent) e.getComponent()).setBorder(HOVER_BORDER);
75: }
76:
77: public void mouseExited(MouseEvent e) {
78: ((JComponent) e.getComponent()).setBorder(LINK_BORDER);
79: }
80: };
81:
82: }
|