KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > LinkLabel


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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 JavaDoc;
19 import java.awt.Cursor JavaDoc;
20 import java.awt.Graphics JavaDoc;
21 import java.awt.Rectangle JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23 import java.awt.event.MouseEvent JavaDoc;
24 import java.awt.event.MouseListener JavaDoc;
25
26 import javax.swing.JLabel JavaDoc;
27
28
29 /**
30  * Title:
31  * Description:
32  * Copyright: Copyright (c) 2001
33  * Company:
34  * @author
35  * @version 1.0
36  */

37 public class LinkLabel extends JLabel JavaDoc implements MouseListener JavaDoc {
38     boolean entered = false;
39     boolean mousehover;
40     ActionListener JavaDoc actionListener = null;
41
42     public LinkLabel(String JavaDoc s) {
43         super(s);
44
45         addMouseListener(this);
46
47         //setFont( UIManager.getFont("TextField.font") );
48
setForeground(Color.blue);
49
50         mousehover = false;
51     }
52
53     public void mouseClicked(MouseEvent JavaDoc e) {
54     }
55
56     public void mouseEntered(MouseEvent JavaDoc e) {
57         setCursor(new Cursor JavaDoc(Cursor.HAND_CURSOR));
58         entered = true;
59
60         if (mousehover) {
61             repaint();
62         }
63     }
64
65     public void mouseExited(MouseEvent JavaDoc e) {
66         setCursor(new Cursor JavaDoc(Cursor.DEFAULT_CURSOR));
67         entered = false;
68
69         if (mousehover) {
70             repaint();
71         }
72     }
73
74     public void mousePressed(MouseEvent JavaDoc e) {
75     }
76
77     public void mouseReleased(MouseEvent JavaDoc e) {
78     }
79
80     public void paint(Graphics JavaDoc g) {
81         super.paint(g);
82
83         if (entered || !mousehover) {
84             Rectangle JavaDoc r = g.getClipBounds();
85
86             g.drawLine(0,
87                 r.height - this.getFontMetrics(this.getFont()).getDescent(),
88                 this.getFontMetrics(this.getFont()).stringWidth(this.getText()),
89                 r.height - this.getFontMetrics(this.getFont()).getDescent());
90         }
91     }
92 }
93
Popular Tags