mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-26 09:48:56 -05:00
5c7f90540a
* update nekohtml to 1.9.13 * update jna to 3.2.3 * update ehcache to 1.7.0 * update mediainfo native libs to 0.7.24 * remove 32-bit mediainfo.dynlib for Mac because Java 6 is only available in 64-bit anyway
127 lines
2.4 KiB
Java
127 lines
2.4 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.ActionEvent;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
import java.net.URI;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.Icon;
|
|
import javax.swing.JButton;
|
|
|
|
|
|
public class LinkButton extends JButton {
|
|
|
|
private Color color = getForeground();
|
|
private Color rolloverColor = SystemColor.textHighlight;
|
|
|
|
|
|
public LinkButton(String text, Icon icon, URI uri) {
|
|
this(new OpenUriAction(text, icon, uri));
|
|
}
|
|
|
|
|
|
public LinkButton(Action action) {
|
|
setAction(action);
|
|
|
|
setFocusPainted(false);
|
|
setOpaque(false);
|
|
setContentAreaFilled(false);
|
|
setBorder(null);
|
|
|
|
setHorizontalAlignment(LEFT);
|
|
setIconTextGap(6);
|
|
setRolloverEnabled(true);
|
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
}
|
|
|
|
|
|
@Override
|
|
public void setRolloverEnabled(boolean enabled) {
|
|
super.setRolloverEnabled(enabled);
|
|
|
|
// always remove listener if there is one
|
|
removeMouseListener(rolloverListener);
|
|
|
|
if (enabled) {
|
|
// add listener again, if enabled
|
|
addMouseListener(rolloverListener);
|
|
}
|
|
}
|
|
|
|
|
|
public Color getColor() {
|
|
return color;
|
|
}
|
|
|
|
|
|
public void setColor(Color color) {
|
|
this.color = color;
|
|
this.setForeground(color);
|
|
}
|
|
|
|
|
|
public Color getRolloverColor() {
|
|
return rolloverColor;
|
|
}
|
|
|
|
|
|
public void setRolloverColor(Color rolloverColor) {
|
|
this.rolloverColor = rolloverColor;
|
|
}
|
|
|
|
|
|
protected final MouseListener rolloverListener = new MouseAdapter() {
|
|
|
|
@Override
|
|
public void mouseEntered(MouseEvent e) {
|
|
setForeground(rolloverColor);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void mouseExited(MouseEvent e) {
|
|
setForeground(color);
|
|
}
|
|
};
|
|
|
|
|
|
protected static class OpenUriAction extends AbstractAction {
|
|
|
|
public static final String URI = "uri";
|
|
|
|
|
|
public OpenUriAction(String text, Icon icon, URI uri) {
|
|
super(text, icon);
|
|
putValue(URI, uri);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent evt) {
|
|
try {
|
|
URI uri = (URI) getValue(URI);
|
|
|
|
if (uri != null) {
|
|
Desktop.getDesktop().browse(uri);
|
|
}
|
|
} catch (Exception e) {
|
|
// should not happen
|
|
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|