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