2007-12-23 14:28:04 -05:00
|
|
|
|
2008-03-16 14:23:12 -04:00
|
|
|
package net.sourceforge.tuned.ui;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Cursor;
|
|
|
|
import java.awt.Desktop;
|
|
|
|
import java.awt.SystemColor;
|
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
import java.awt.event.MouseListener;
|
|
|
|
import java.net.URL;
|
2008-02-23 16:33:09 -05:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
|
|
|
|
|
|
|
public class HyperlinkLabel extends JLabel {
|
|
|
|
|
|
|
|
private URL url;
|
|
|
|
private Color defaultColor;
|
|
|
|
|
|
|
|
|
|
|
|
public HyperlinkLabel(String label, URL url) {
|
|
|
|
super(label);
|
|
|
|
this.url = url;
|
|
|
|
defaultColor = getForeground();
|
|
|
|
addMouseListener(linker);
|
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
|
|
}
|
|
|
|
|
|
|
|
private MouseListener linker = new MouseAdapter() {
|
|
|
|
|
|
|
|
@Override
|
2008-02-23 16:33:09 -05:00
|
|
|
public void mouseClicked(MouseEvent event) {
|
2007-12-23 14:28:04 -05:00
|
|
|
try {
|
|
|
|
Desktop.getDesktop().browse(url.toURI());
|
2008-02-23 16:33:09 -05:00
|
|
|
} catch (Exception e) {
|
|
|
|
// should not happen
|
2008-03-15 21:05:06 -04:00
|
|
|
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseEntered(MouseEvent e) {
|
|
|
|
setForeground(SystemColor.textHighlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseExited(MouseEvent e) {
|
|
|
|
setForeground(defaultColor);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|