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, getHeight()-1-insets.bottom );
53 }
54
55 public class HyperlinkLabelMouseAdapter extends MouseAdapter
56 {
57 @Override
58 public void mouseClicked( MouseEvent e )
59 {
60 Tools.openURL( getText() );
61 }
62 }
63
64 public Color getUnderlineColor()
65 {
66 return underlineColor;
67 }
68
69 public void setUnderlineColor( Color underlineColor )
70 {
71 this.underlineColor = underlineColor;
72 }
73 }