01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.core.gui.base;
17:
18: import java.awt.Color;
19: import java.awt.Cursor;
20: import java.awt.Graphics;
21: import java.awt.Rectangle;
22: import java.awt.event.ActionListener;
23: import java.awt.event.MouseEvent;
24: import java.awt.event.MouseListener;
25:
26: import javax.swing.JLabel;
27:
28: /**
29: * Title:
30: * Description:
31: * Copyright: Copyright (c) 2001
32: * Company:
33: * @author
34: * @version 1.0
35: */
36: public class LinkLabel extends JLabel implements MouseListener {
37: boolean entered = false;
38: boolean mousehover;
39: ActionListener actionListener = null;
40:
41: public LinkLabel(String s) {
42: super (s);
43:
44: addMouseListener(this );
45:
46: //setFont( UIManager.getFont("TextField.font") );
47: setForeground(Color.blue);
48:
49: mousehover = false;
50: }
51:
52: public void mouseClicked(MouseEvent e) {
53: }
54:
55: public void mouseEntered(MouseEvent e) {
56: setCursor(new Cursor(Cursor.HAND_CURSOR));
57: entered = true;
58:
59: if (mousehover) {
60: repaint();
61: }
62: }
63:
64: public void mouseExited(MouseEvent e) {
65: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
66: entered = false;
67:
68: if (mousehover) {
69: repaint();
70: }
71: }
72:
73: public void mousePressed(MouseEvent e) {
74: }
75:
76: public void mouseReleased(MouseEvent e) {
77: }
78:
79: public void paint(Graphics g) {
80: super .paint(g);
81:
82: if (entered || !mousehover) {
83: Rectangle r = g.getClipBounds();
84:
85: g.drawLine(0, r.height
86: - this.getFontMetrics(this.getFont()).getDescent(),
87: this.getFontMetrics(this.getFont()).stringWidth(
88: this.getText()), r.height
89: - this.getFontMetrics(this.getFont())
90: .getDescent());
91: }
92: }
93: }
|