source: josm/trunk/src/org/openstreetmap/josm/tools/UrlLabel.java@ 2284

Last change on this file since 2284 was 2250, checked in by Gubaer, 15 years ago

fixed #3653: History for anonymous users should not be clickable
fixed #3518: Provide a new feature for uploading the currently selected primitives

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import javax.swing.JEditorPane;
5import javax.swing.event.HyperlinkEvent;
6import javax.swing.event.HyperlinkListener;
7
8/**
9 * Label that contains a clickable link.
10 * @author Imi
11 */
12public class UrlLabel extends JEditorPane implements HyperlinkListener {
13
14 private String url = "";
15 private String description = "";
16
17 public UrlLabel() {
18 addHyperlinkListener(this);
19 setEditable(false);
20 setOpaque(false);
21 }
22
23 public UrlLabel(String url) {
24 this (url, url);
25 }
26
27 public UrlLabel(String url, String description) {
28 this();
29 setUrl(url);
30 setDescription(description);
31 refresh();
32 }
33
34 protected void refresh() {
35 setContentType("text/html");
36 if (url != null) {
37 setText("<html><a href=\""+url+"\">"+description+"</a></html>");
38 } else {
39 setText("<html>" + description + "</html>");
40 }
41 setToolTipText(url);
42 }
43
44 public void hyperlinkUpdate(HyperlinkEvent e) {
45 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
46 OpenBrowser.displayUrl(url);
47 }
48 }
49
50 public void setUrl(String url) {
51 this.url = url == null ? "" : url;
52 refresh();
53 }
54
55 public void setDescription(String description) {
56 this.description = description == null? "" : description;
57 refresh();
58 }
59}
Note: See TracBrowser for help on using the repository browser.