updates for 0.9.3
[debian/openrocket] / src / net / sf / openrocket / gui / components / URLLabel.java
index be6bdd82793c32110e88c347b438cda80974e3fb..0be6b6d6947605e0274fcf3fcd717f0401b3b0f3 100644 (file)
@@ -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 <sampo.niskanen@iki.fi>
  */
-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("<html><a href=\"" + url + "\">" + url + "</a>");
-
+                       // Blue, underlined font
+                       Map<TextAttribute, Object> map = new HashMap<TextAttribute, Object>();
+                       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);
+
                }
        }
 }