X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fcomponents%2FURLLabel.java;fp=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fcomponents%2FURLLabel.java;h=0be6b6d6947605e0274fcf3fcd717f0401b3b0f3;hb=0d0afe488300aca47d09ac7651f8185190afb21f;hp=be6bdd82793c32110e88c347b438cda80974e3fb;hpb=6afc62224f6f7e581b1d321e125ed97a6ec77dc1;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/gui/components/URLLabel.java b/src/net/sf/openrocket/gui/components/URLLabel.java index be6bdd82..0be6b6d6 100644 --- a/src/net/sf/openrocket/gui/components/URLLabel.java +++ b/src/net/sf/openrocket/gui/components/URLLabel.java @@ -1,13 +1,16 @@ package net.sf.openrocket.gui.components; +import java.awt.Color; +import java.awt.Cursor; import java.awt.Desktop; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.font.TextAttribute; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; - -import javax.swing.JLabel; +import java.util.HashMap; +import java.util.Map; /** * A label of a URL that is clickable. Clicking the URL will launch the URL in @@ -15,20 +18,39 @@ import javax.swing.JLabel; * * @author Sampo Niskanen */ -public class URLLabel extends JLabel { +public class URLLabel extends SelectableLabel { - private final String url; + /** + * Create a label showing the url it will direct to. + * + * @param url the URL. + */ + public URLLabel(String url) { + this(url, url); + } - public URLLabel(String urlLabel) { + /** + * Create a label with separate URL and label. + * + * @param url the URL clicking will open. + * @param label the label. + */ + public URLLabel(final String url, String label) { super(); - this.url = urlLabel; - + setText(label); if (Desktop.isDesktopSupported()) { - setText("" + url + ""); - + // Blue, underlined font + Map map = new HashMap(); + map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + this.setFont(this.getFont().deriveFont(map)); + this.setForeground(Color.BLUE); + + this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + this.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -43,9 +65,7 @@ public class URLLabel extends JLabel { } } }); - - } else { - setText(url); + } } }