View Javadoc

1   package com.eviware.soapui.support.components;
2   
3   import com.eviware.soapui.support.DefaultHyperlinkListener;
4   import com.eviware.soapui.support.UISupport;
5   
6   import javax.swing.*;
7   import javax.swing.text.html.HTMLEditorKit;
8   import java.awt.*;
9   import java.io.ByteArrayInputStream;
10  import java.io.IOException;
11  import java.net.URL;
12  
13  public class BrowserComponent
14  {
15     private JEditorPane editorPane;
16     private JScrollPane scrollPane;
17  //   private WebBrowser browser;
18  //   private static WebBrowserFactory webBrowserFactory;
19  //
20  //   static
21  //   {
22  //      Xpcom.initialize( Xpcom.AWT );    
23  //   }
24  
25     public BrowserComponent()
26     {
27        editorPane = new JEditorPane();
28        editorPane.setEditorKit( new HTMLEditorKit() );
29        editorPane.setEditable( false );
30        editorPane.addHyperlinkListener( new DefaultHyperlinkListener( editorPane ) );
31     }
32  
33     public Component getComponent()
34     {
35  //      if( browser == null )
36  //      {
37  //         initBrowser();
38  //      }
39  //
40  //      return browser.getComponent();
41        if( scrollPane == null )
42        {
43           scrollPane = new JScrollPane( editorPane );
44           UISupport.addPreviewCorner( scrollPane, false );
45        }
46        return scrollPane;
47     }
48  
49     private void initBrowser()
50     {
51  //      if( webBrowserFactory == null )
52  //         webBrowserFactory = WebBrowserFactory.getInstance();
53  //
54  //      browser = webBrowserFactory.createBrowser();
55  //      browser.addStatusChangeListener( new StatusChangeListener() {
56  //         public void statusChanged( StatusChangeEvent event )
57  //         {
58  ////            System.out.println( "Status change: " + event );
59  //         }
60  //      } );
61  //
62  //      browser.deactivate();
63     }
64  
65     public void release()
66     {
67  //      if( browser != null )
68  //         browser.dispose();
69  //      
70  //      browser = null;
71     }
72  
73     public void setContent( String contentAsString, String contentType, String contextUri )
74     {
75        editorPane.setContentType( contentType );
76        try
77        {
78           editorPane.read( new ByteArrayInputStream( contentAsString.getBytes() ), editorPane.getEditorKit().createDefaultDocument() );
79        }
80        catch( IOException e )
81        {
82           e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
83        }
84  
85  //      if( browser == null )
86  //      {
87  //         initBrowser();
88  //      }
89  //      browser.setContentWithContext( contentAsString, contentType, contextUri );
90     }
91  
92     public void setContent( String content, String contentType )
93     {
94        setContent( content, contentType, null );
95  
96  //      if( browser == null )
97  //      {
98  //         initBrowser();
99  //      }
100 //      browser.setContent( content, contentType );
101    }
102 
103    public void navigate( String url )
104    {
105       try
106       {
107          editorPane.setPage( new URL( url ) );
108       }
109       catch( IOException e )
110       {
111          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
112       }
113 
114 //      if( browser == null )
115 //      {
116 //         initBrowser();
117 //      }
118 //
119 //      browser.navigate( url );
120    }
121 
122    public String getContent()
123    {
124 //      return browser == null ? null : XmlUtils.serialize( browser.getDocument() );
125       return editorPane.getText();
126    }
127 }