Changeset 5019 in josm


Ignore:
Timestamp:
2012-02-23T18:32:58+01:00 (8 years ago)
Author:
akks
Message:

fix #7325 - copy URL to clipboard by right click (UrlLabel component)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/UrlLabel.java

    r2512 r5019  
    22package org.openstreetmap.josm.tools;
    33
     4import java.awt.event.MouseEvent;
     5import java.awt.event.MouseListener;
    46import javax.swing.JEditorPane;
    57import javax.swing.event.HyperlinkEvent;
    68import javax.swing.event.HyperlinkListener;
     9import static org.openstreetmap.josm.tools.I18n.tr;
    710
    811/**
     
    1013 * @author Imi
    1114 */
    12 public class UrlLabel extends JEditorPane implements HyperlinkListener {
     15public class UrlLabel extends JEditorPane implements HyperlinkListener, MouseListener {
    1316
    1417    private String url = "";
     
    1720    public UrlLabel() {
    1821        addHyperlinkListener(this);
     22        addMouseListener(this);
    1923        setEditable(false);
    2024        setOpaque(false);
     
    3943            setText("<html>" + description + "</html>");
    4044        }
    41         setToolTipText(url);
     45        setToolTipText(String.format("<html>%s<br/>%s</html>",url, tr("Right click = copy to clipboard")));
    4246    }
    4347
     
    6973        refresh();
    7074    }
     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
    7192}
Note: See TracChangeset for help on using the changeset viewer.