1
2 package org.telscenter.pas.ui.browser.mozswing;
3
4 import java.awt.Component;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7 import java.util.Vector;
8
9 import org.mozilla.browser.IMozillaWindow;
10 import org.mozilla.browser.MozillaPanel;
11 import org.telscenter.pas.ui.browser.IBrowser;
12 import org.telscenter.pas.ui.browser.IBrowserListener;
13 import org.telscenter.pas.ui.browser.NavigationPolicy;
14
15 /***
16 * The Mozilla swing browser implementation
17 *
18 * @author aperritano
19 */
20 public class MozSwingBrowser implements IBrowser {
21
22 private MozillaPanel webBrowser ;
23 private String browserType;
24 protected String pageTitle;
25
26 protected Vector listeners = new Vector();
27
28 /***
29 * Contructor
30 *
31 * @param webBrowser - webBrowser window
32 * @param browserType - the type of browser it is
33 */
34 public MozSwingBrowser(MozillaPanel webBrowser,String browserType) {
35 this.browserType = browserType;
36 this.webBrowser = webBrowser;
37 initListeners();
38 }
39
40 /***
41 * Starts the listeners
42 */
43 protected void initListeners() {
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 }
78
79 /***
80 * to the back
81 */
82 public void back() {
83 webBrowser.goBack();
84 }
85
86 /***
87 * to the front
88 */
89 public void forward() {
90 webBrowser.goForward();
91 }
92
93 /***
94 * is it ie, mozilla?
95 *
96 * @return browserType - the type of browser
97 */
98 public String getBrowserType() {
99 return browserType;
100 }
101
102 /***
103 * Gets the browser component
104 *
105 * @return Component - the actucal componet to add to a layout
106 */
107 public Component getComponent() {
108 return (Component) webBrowser;
109 }
110
111
112 /***
113 * Gets the current url
114 *
115 * @return URL - the current url
116 */
117 public URL getUrl() {
118 String url = webBrowser.getUrl();
119 try {
120 return new URL(url);
121 } catch (MalformedURLException e) {
122 e.printStackTrace();
123 }
124 return null;
125 }
126
127 /***
128 * reloads the page
129 */
130 public void refresh() {
131 webBrowser.reload();
132 }
133
134 /***
135 * Gets the html of the current page
136 *
137 * @String - current html
138 */
139 public String getContent() {
140 return "not content";
141
142 }
143
144 /***
145 * Navigation policy
146 *
147 * @return policy - the navigation policy for this browser
148 */
149 public void setNavigationPolicy(NavigationPolicy policy)
150 throws UnsupportedOperationException {
151 throw new UnsupportedOperationException("MozSwing Browser does not yet support navigation policy");
152 }
153
154
155 /***
156 * This method will add a monitor thread which will stop the browser after a cetain amount
157 * of time.
158 */
159 public void setUrl(URL url) {
160 webBrowser.load(url.toString());
161 }
162
163
164 /***
165 * stop the current page loading
166 */
167 public void stop() {
168 webBrowser.stop();
169 }
170
171 /***
172 * Load a url with some postData
173 *
174 * @param url - the url to load
175 * @param postData - data associated with the POST
176 */
177 public void setUrl(URL url, String postData) {
178 webBrowser.load(url.toString());
179 }
180
181 /***
182 * Get the current page titl
183 *
184 * @return String = page title
185 */
186 public String getPageTitle() {
187 return "no title for now";
188 }
189
190 /***
191 * Adds a listener
192 *
193 * @param listener - listener to add
194 */
195 public void addBrowserListener(IBrowserListener listener) {
196 listeners.add(listener);
197 }
198
199 /***
200 * removes a listener
201 *
202 * @param listener - listener to remove
203 */
204 public void removeBrowserListener(IBrowserListener listener){
205 listeners.remove(listener);
206 }
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243 /***
244 * Sets html as the current page
245 *
246 * @param content - html to set
247 */
248 public void setContent(String content) {
249 webBrowser.loadHTML(content);
250
251 }
252 }