1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00
filebot/source/net/sourceforge/tuned/ui/HyperlinkLabel.java
Reinhard Pointner 4b4ca4fc68 * improved ui performance
* proper class visibility
2008-03-16 18:23:12 +00:00

59 lines
1.2 KiB
Java

package net.sourceforge.tuned.ui;
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;
import java.util.logging.Level;
import java.util.logging.Logger;
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
public void mouseClicked(MouseEvent event) {
try {
Desktop.getDesktop().browse(url.toURI());
} catch (Exception e) {
// should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
}
}
@Override
public void mouseEntered(MouseEvent e) {
setForeground(SystemColor.textHighlight);
}
@Override
public void mouseExited(MouseEvent e) {
setForeground(defaultColor);
}
};
}