X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fcomponents%2FURLLabel.java;h=5d3f42a32143e96dd2b32558bfe8f189591c3c9b;hb=c72e1c03cc0d15e11368707c38721d506ce356b9;hp=be6bdd82793c32110e88c347b438cda80974e3fb;hpb=02f3d96a74beac56396117f4c8ea3497134ad139;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..5d3f42a3 100644 --- a/src/net/sf/openrocket/gui/components/URLLabel.java +++ b/src/net/sf/openrocket/gui/components/URLLabel.java @@ -1,13 +1,18 @@ 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 java.util.HashMap; +import java.util.Map; -import javax.swing.JLabel; +import net.sf.openrocket.util.BugException; /** * A label of a URL that is clickable. Clicking the URL will launch the URL in @@ -15,20 +20,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) { @@ -36,16 +60,14 @@ public class URLLabel extends JLabel { try { d.browse(new URI(url)); } catch (URISyntaxException e1) { - throw new RuntimeException("BUG: Illegal URL: " + url, e1); + throw new BugException("BUG: Illegal URL: " + url, e1); } catch (IOException e1) { System.err.println("Unable to launch browser:"); e1.printStackTrace(); } } }); - - } else { - setText(url); + } } }