Ticket #7325: UrlLabelCopy.patch
| File UrlLabelCopy.patch, 2.0 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/tools/UrlLabel.java
1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.awt.event.MouseEvent; 5 import java.awt.event.MouseListener; 4 6 import javax.swing.JEditorPane; 5 7 import javax.swing.event.HyperlinkEvent; 6 8 import javax.swing.event.HyperlinkListener; 9 import static org.openstreetmap.josm.tools.I18n.tr; 7 10 8 11 /** 9 12 * Label that contains a clickable link. 10 13 * @author Imi 11 14 */ 12 public class UrlLabel extends JEditorPane implements HyperlinkListener {15 public class UrlLabel extends JEditorPane implements HyperlinkListener, MouseListener { 13 16 14 17 private String url = ""; 15 18 private String description = ""; 16 19 17 20 public UrlLabel() { 18 21 addHyperlinkListener(this); 22 addMouseListener(this); 19 23 setEditable(false); 20 24 setOpaque(false); 21 25 } … … 38 42 } else { 39 43 setText("<html>" + description + "</html>"); 40 44 } 41 setToolTipText( url);45 setToolTipText(String.format("<html>%s<br/>%s</html>",url, tr("Right click = copy to clipboard"))); 42 46 } 43 47 44 48 public void hyperlinkUpdate(HyperlinkEvent e) { … … 68 72 this.description = this.description.replace("&", "&").replace(">", ">").replace("<", "<"); 69 73 refresh(); 70 74 } 75 76 @Override 77 public void mouseClicked(MouseEvent e) { } 78 @Override 79 public void mousePressed(MouseEvent e) { } 80 @Override 81 public void mouseEntered(MouseEvent e) { } 82 @Override 83 public void mouseExited(MouseEvent e) { } 84 85 @Override 86 public void mouseReleased(MouseEvent e) { 87 if (e.getButton() == MouseEvent.BUTTON3) { 88 Utils.copyToClipboard(url); 89 } 90 } 91 71 92 }
