View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.ui;
14  
15  import java.awt.BorderLayout;
16  
17  import javax.swing.JPanel;
18  
19  import com.eviware.soapui.support.StringUtils;
20  import com.eviware.soapui.support.components.BrowserComponent;
21  import com.eviware.soapui.ui.support.DefaultDesktopPanel;
22  
23  public class URLDesktopPanel extends DefaultDesktopPanel
24  {
25  	private BrowserComponent browser;
26  
27  	public URLDesktopPanel( String title, String description, String url )
28  	{
29  		super( title, description, new JPanel( new BorderLayout() ) );
30  
31  		JPanel panel = ( JPanel )getComponent();
32  
33  		browser = new BrowserComponent( true );
34  		panel.add( browser.getComponent(), BorderLayout.CENTER );
35  
36  		if( StringUtils.hasContent( url ) )
37  			navigate( url, null, true );
38  	}
39  
40  	public void navigate( String url, String errorUrl, boolean async )
41  	{
42  		if( async )
43  		{
44  			new Thread( new Navigator( url, errorUrl ) ).start();
45  		}
46  		else
47  		{
48  			browser.navigate( url, errorUrl );
49  		}
50  	}
51  
52  	public boolean onClose( boolean canCancel )
53  	{
54  		browser.release();
55  		return super.onClose( canCancel );
56  	}
57  
58  	private class Navigator implements Runnable
59  	{
60  		private final String url;
61  		private final String errorUrl;
62  
63  		public Navigator( String url, String errorUrl )
64  		{
65  			this.url = url;
66  			this.errorUrl = errorUrl;
67  		}
68  
69  		public void run()
70  		{
71  			browser.navigate( url, errorUrl );
72  		}
73  	}
74  }