View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
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  }