1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support.components;
14
15 import java.awt.Color;
16 import java.awt.Cursor;
17 import java.awt.Graphics;
18 import java.awt.Insets;
19 import java.awt.event.MouseAdapter;
20 import java.awt.event.MouseEvent;
21
22 import javax.swing.JLabel;
23
24 import com.eviware.soapui.support.Tools;
25
26 public class JHyperlinkLabel extends JLabel
27 {
28 private Color underlineColor = null;
29
30 public JHyperlinkLabel( String label )
31 {
32 super( label );
33
34 setForeground( Color.BLUE.darker() );
35 setCursor( new Cursor( Cursor.HAND_CURSOR ) );
36 addMouseListener( new HyperlinkLabelMouseAdapter() );
37 }
38
39 @Override
40 protected void paintComponent( Graphics g )
41 {
42 super.paintComponent( g );
43
44 g.setColor( underlineColor == null ? getForeground() : underlineColor );
45
46 Insets insets = getInsets();
47
48 int left = insets.left;
49 if( getIcon() != null )
50 left += getIcon().getIconWidth() + getIconTextGap();
51
52 g.drawLine( left, getHeight() - 1 - insets.bottom, ( int )getPreferredSize().getWidth() - insets.right,
53 getHeight() - 1 - insets.bottom );
54 }
55
56 public class HyperlinkLabelMouseAdapter extends MouseAdapter
57 {
58 @Override
59 public void mouseClicked( MouseEvent e )
60 {
61 Tools.openURL( getText() );
62 }
63 }
64
65 public Color getUnderlineColor()
66 {
67 return underlineColor;
68 }
69
70 public void setUnderlineColor( Color underlineColor )
71 {
72 this.underlineColor = underlineColor;
73 }
74 }