View Javadoc

1   package baseCode.gui;
2   
3   import java.awt.event.MouseEvent;
4   import java.awt.event.MouseListener;
5   import java.io.IOException;
6   
7   import javax.swing.JLabel;
8   
9   import baseCode.util.BrowserLauncher;
10  
11  /***
12   * A clickable link label that contains a URL. When a mouse pointer is placed over it, it turns into a hand.
13   * 
14   * @author Will Braynen
15   * @version $Id: JLinkLabel.java,v 1.9 2004/08/11 21:22:02 hkl7 Exp $
16   */
17  public class JLinkLabel extends JLabel implements MouseListener {
18  
19  	protected String m_url = null;
20  
21  	protected String m_text = "";
22  
23  	/*** Creates a new instance of JLinkLabel */
24  	public JLinkLabel() {
25  		super();
26  	}
27  
28  	public JLinkLabel(String text) {
29  		this();
30  		setText(text);
31  	}
32  
33  	public JLinkLabel(String text, String url) {
34  		this();
35  		setText(text, url);
36  	}
37  
38  	public void setText(String text) {
39  		if (m_url != null) {
40  			setText(text, m_url);
41  		} else {
42  			setText(text, text);
43  		}
44  	}
45  
46  	/***
47  	 * @param url
48  	 */
49  	public void setURL(String url) {
50  		setText(m_text, url);
51  	}
52  
53  	/***
54  	 * @return
55  	 */
56  	public String getURL() {
57  		return m_url;
58  	}
59  
60  	public void setText(String text, String url) {
61  		m_text = text;
62  		m_url = url;
63  		super.setText("<html><a href=\"" + url + "\">" + text + "</a></html>");
64  	}
65  
66  	public String toString() {
67  		return "<html><a href=\"" + m_url + "\">" + m_text + "</a></html>";
68  	}
69  
70  	public void mouseClicked(MouseEvent e) {
71  		if (m_url != null) {
72  			try {
73  				BrowserLauncher.openURL(m_url);
74  			} catch (IOException ex) {
75  				GuiUtil.error("Could not open a web browser window.");
76  			}
77  		}
78  	}
79  
80  	public void mouseEntered(MouseEvent e) {
81  	}
82  
83  	public void mouseExited(MouseEvent e) {
84  	}
85  
86  	public void mousePressed(MouseEvent e) {
87  	}
88  
89  	public void mouseReleased(MouseEvent e) {
90  	}
91  
92  }