Ignore:
Timestamp:
2019-03-02T22:39:06+01:00 (7 years ago)
Author:
Don-vip
Message:

add unit test for AboutAction

File:
1 edited

Legend:

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

    r13853 r14822  
    88import java.awt.event.MouseListener;
    99
     10import javax.swing.Icon;
    1011import javax.swing.JLabel;
    1112import javax.swing.SwingUtilities;
     
    2829     */
    2930    public UrlLabel() {
    30         addMouseListener(this);
    31         setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
     31        init("", "", 0);
    3232    }
    3333
     
    6262     * @param url The URL to use
    6363     * @param description The description to display
     64     * @param image The image to be displayed by the label instead of text
     65     * @since 14822
     66     */
     67    public UrlLabel(String url, String description, Icon image) {
     68        super(image);
     69        init(url, description, 0);
     70    }
     71
     72    /**
     73     * Constructs a new {@code UrlLabel} for the given URL, description and font increase.
     74     * @param url The URL to use
     75     * @param description The description to display
    6476     * @param fontPlus The font increase in 1/72 of an inch units.
    6577     */
    6678    public UrlLabel(String url, String description, int fontPlus) {
    67         this();
     79        init(url, description, fontPlus);
     80    }
     81
     82    private void init(String url, String description, int fontPlus) {
     83        addMouseListener(this);
    6884        setUrl(url);
    6985        setDescription(description);
     
    7692    protected final void refresh() {
    7793        if (url != null && !url.isEmpty()) {
    78             setText("<html><a href=\""+url+"\">"+description+"</a></html>");
    79             setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    80             setToolTipText(String.format("<html>%s<br/>%s</html>", url, tr("Right click = copy to clipboard")));
     94            refresh("<html><a href=\""+url+"\">"+description+"</a></html>",
     95                    Cursor.getPredefinedCursor(Cursor.HAND_CURSOR),
     96                    String.format("<html>%s<br/>%s</html>", url, tr("Right click = copy to clipboard")));
    8197        } else {
    82             setText("<html>" + description + "</html>");
    83             setCursor(null);
    84             setToolTipText(null);
     98            refresh("<html>" + description + "</html>", null, null);
    8599        }
     100    }
     101
     102    private void refresh(String text, Cursor cursor, String tooltip) {
     103        boolean hasImage = getIcon() != null;
     104        if (!hasImage) {
     105            setText(text);
     106        }
     107        setCursor(cursor);
     108        setToolTipText(tooltip);
    86109    }
    87110
Note: See TracChangeset for help on using the changeset viewer.