1 /***
2 *
3 */
4 package org.telscenter.pas.ui.browser.jdic;
5
6 import java.awt.Component;
7 import java.net.URL;
8
9 import org.jdesktop.jdic.browser.IWebBrowser;
10 import org.jdesktop.jdic.browser.WebBrowserEvent;
11 import org.jdesktop.jdic.browser.WebBrowserListener;
12 import org.telscenter.pas.ui.browser.IBrowser;
13 import org.telscenter.pas.ui.browser.NavigationPolicy;
14
15 /***
16 * @author aperritano
17 *
18 */
19 public class JDICBrowser implements IBrowser {
20
21 private IWebBrowser webBrowser ;
22 private String browserType;
23 protected String pageTitle;
24 /***
25 *
26 */
27 public JDICBrowser(IWebBrowser webBrowser,String browserType) {
28 this.browserType = browserType;
29 this.webBrowser = webBrowser;
30 initListeners();
31 }
32
33 protected void initListeners() {
34 this.webBrowser.addWebBrowserListener(new WebBrowserListener() {
35
36 public void documentCompleted(WebBrowserEvent event) {
37 System.out.println(".documentCompleted()");
38 System.out.println(event.getData());
39 }
40
41 public void downloadCompleted(WebBrowserEvent event) {
42 System.out.println(".downloadCompleted()");
43 System.out.println(event.getData());
44
45 }
46
47 public void downloadError(WebBrowserEvent event) {
48 System.out.println(".downloadError()");
49 System.out.println(event.toString());
50
51 }
52
53 public void downloadProgress(WebBrowserEvent event) {
54 System.out.println(".downloadProgress()");
55 System.out.println("PROGESS" + event.getData());
56 }
57
58 public void downloadStarted(WebBrowserEvent event) {
59 System.out.println(".downloadStarted()");
60 System.out.println(event.getData());
61 }
62
63 public void initializationCompleted(WebBrowserEvent event) {
64 System.out.println(".initializationCompleted()");
65 System.out.println(event.toString());
66 }
67
68 public void statusTextChange(WebBrowserEvent event) {
69
70
71 }
72
73 public void titleChange(WebBrowserEvent event) {
74 pageTitle = event.getData();
75 }});
76
77 }
78
79 public void back() {
80 webBrowser.back();
81 }
82
83 public void forward() {
84 webBrowser.forward();
85 }
86
87 public String getBrowserType() {
88 return browserType;
89 }
90
91 public Component getComponent() {
92 return (Component) webBrowser.asComponent();
93 }
94
95
96 public URL getUrl() {
97 return webBrowser.getURL();
98 }
99
100
101 public void refresh() {
102 webBrowser.refresh();
103 }
104
105
106 public void setNavigationPolicy(NavigationPolicy policy)
107 throws UnsupportedOperationException {
108 throw new UnsupportedOperationException("JDIC JDICWebBrowserTestUI does not yet support navigation policy");
109 }
110
111
112 /***
113 * This method will add a monitor thread which will stop the browser after a cetain amount
114 * of time.
115 */
116 public void setUrl(URL url) {
117 CompleteMonitor monitor = new CompleteMonitor();
118
119 webBrowser.addWebBrowserListener(monitor);
120
121 webBrowser.setURL(url);
122
123 monitor.start();
124 }
125
126
127 public void stop() {
128 webBrowser.stop();
129 }
130
131
132 public void setUrl(URL url, String postData) {
133 webBrowser.setURL(url, postData);
134 }
135
136 public String getPageTitle() {
137 return this.pageTitle;
138 }
139
140 class CompleteMonitor extends Thread
141 implements WebBrowserListener {
142
143 boolean docCompleted = false;
144
145 public void run() {
146 try {
147 sleep(3000);
148 } catch (InterruptedException e) {
149
150 e.printStackTrace();
151 }
152 if(!docCompleted){
153 webBrowser.stop();
154 webBrowser.refresh();
155 }
156 }
157
158 public void documentCompleted(WebBrowserEvent event) {
159 docCompleted = true;
160 webBrowser.removeWebBrowserListener(this);
161 }
162
163 public void downloadCompleted(WebBrowserEvent event) {}
164 public void downloadError(WebBrowserEvent event) {}
165 public void downloadProgress(WebBrowserEvent event) {}
166 public void downloadStarted(WebBrowserEvent event) {}
167 public void initializationCompleted(WebBrowserEvent event) {}
168 public void statusTextChange(WebBrowserEvent event) {}
169 public void titleChange(WebBrowserEvent event) {}
170
171 }
172 }