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 (!browser.isBrowserInitialised()) {
43  		//	browser.initBrowser();
44  		//}
45  		if( async )
46  		{
47  			new Thread( new Navigator( url, errorUrl ) ).start();
48  		}
49  		else
50  		{
51  			browser.navigate( url, errorUrl );
52  		}
53  	}
54  
55  	public boolean onClose( boolean canCancel )
56  	{
57  		//browser.release();
58  		return super.onClose( canCancel );
59  	}
60  
61  	private class Navigator implements Runnable
62  	{
63  		private final String url;
64  		private final String errorUrl;
65  
66  		public Navigator( String url, String errorUrl )
67  		{
68  			this.url = url;
69  			this.errorUrl = errorUrl;
70  		}
71  
72  		public void run()
73  		{
74  			browser.navigate( url, errorUrl );
75  		}
76  	}
77  }