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
18
19
20
21
22
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
36
37
38
39
40
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
52
53
54
55
56
57
58
59
60
61
62
63 }
64
65 public void release()
66 {
67
68
69
70
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();
83 }
84
85
86
87
88
89
90 }
91
92 public void setContent( String content, String contentType )
93 {
94 setContent( content, contentType, null );
95
96
97
98
99
100
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();
112 }
113
114
115
116
117
118
119
120 }
121
122 public String getContent()
123 {
124
125 return editorPane.getText();
126 }
127 }