KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > browser > WebBrowser


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.browser;
12
13 import org.eclipse.swt.widgets.*;
14
15 abstract class WebBrowser {
16     Browser browser;
17     CloseWindowListener[] closeWindowListeners = new CloseWindowListener[0];
18     LocationListener[] locationListeners = new LocationListener[0];
19     OpenWindowListener[] openWindowListeners = new OpenWindowListener[0];
20     ProgressListener[] progressListeners = new ProgressListener[0];
21     StatusTextListener[] statusTextListeners = new StatusTextListener[0];
22     TitleListener[] titleListeners = new TitleListener[0];
23     VisibilityWindowListener[] visibilityWindowListeners = new VisibilityWindowListener[0];
24     
25     static Runnable JavaDoc MozillaClearSessions;
26     static Runnable JavaDoc NativeClearSessions;
27
28 public void addCloseWindowListener (CloseWindowListener listener) {
29     CloseWindowListener[] newCloseWindowListeners = new CloseWindowListener[closeWindowListeners.length + 1];
30     System.arraycopy(closeWindowListeners, 0, newCloseWindowListeners, 0, closeWindowListeners.length);
31     closeWindowListeners = newCloseWindowListeners;
32     closeWindowListeners[closeWindowListeners.length - 1] = listener;
33 }
34
35 public void addLocationListener (LocationListener listener) {
36     LocationListener[] newLocationListeners = new LocationListener[locationListeners.length + 1];
37     System.arraycopy(locationListeners, 0, newLocationListeners, 0, locationListeners.length);
38     locationListeners = newLocationListeners;
39     locationListeners[locationListeners.length - 1] = listener;
40 }
41
42 public void addOpenWindowListener (OpenWindowListener listener) {
43     OpenWindowListener[] newOpenWindowListeners = new OpenWindowListener[openWindowListeners.length + 1];
44     System.arraycopy(openWindowListeners, 0, newOpenWindowListeners, 0, openWindowListeners.length);
45     openWindowListeners = newOpenWindowListeners;
46     openWindowListeners[openWindowListeners.length - 1] = listener;
47 }
48
49 public void addProgressListener (ProgressListener listener) {
50     ProgressListener[] newProgressListeners = new ProgressListener[progressListeners.length + 1];
51     System.arraycopy(progressListeners, 0, newProgressListeners, 0, progressListeners.length);
52     progressListeners = newProgressListeners;
53     progressListeners[progressListeners.length - 1] = listener;
54 }
55
56 public void addStatusTextListener (StatusTextListener listener) {
57     StatusTextListener[] newStatusTextListeners = new StatusTextListener[statusTextListeners.length + 1];
58     System.arraycopy(statusTextListeners, 0, newStatusTextListeners, 0, statusTextListeners.length);
59     statusTextListeners = newStatusTextListeners;
60     statusTextListeners[statusTextListeners.length - 1] = listener;
61 }
62
63 public void addTitleListener (TitleListener listener) {
64     TitleListener[] newTitleListeners = new TitleListener[titleListeners.length + 1];
65     System.arraycopy(titleListeners, 0, newTitleListeners, 0, titleListeners.length);
66     titleListeners = newTitleListeners;
67     titleListeners[titleListeners.length - 1] = listener;
68 }
69
70 public void addVisibilityWindowListener (VisibilityWindowListener listener) {
71     VisibilityWindowListener[] newVisibilityWindowListeners = new VisibilityWindowListener[visibilityWindowListeners.length + 1];
72     System.arraycopy(visibilityWindowListeners, 0, newVisibilityWindowListeners, 0, visibilityWindowListeners.length);
73     visibilityWindowListeners = newVisibilityWindowListeners;
74     visibilityWindowListeners[visibilityWindowListeners.length - 1] = listener;
75 }
76
77 public abstract boolean back ();
78
79 public static void clearSessions () {
80     if (NativeClearSessions != null) NativeClearSessions.run ();
81     if (MozillaClearSessions != null) MozillaClearSessions.run ();
82 }
83
84 public abstract void create (Composite parent, int style);
85
86 public abstract boolean execute (String JavaDoc script);
87
88 public abstract boolean forward ();
89
90 public abstract String JavaDoc getUrl ();
91
92 public Object JavaDoc getWebBrowser () {
93     return null;
94 }
95
96 public abstract boolean isBackEnabled ();
97
98 public boolean isFocusControl () {
99     return false;
100 }
101
102 public abstract boolean isForwardEnabled ();
103
104 public abstract void refresh ();
105
106 public void removeCloseWindowListener (CloseWindowListener listener) {
107     if (closeWindowListeners.length == 0) return;
108     int index = -1;
109     for (int i = 0; i < closeWindowListeners.length; i++) {
110         if (listener == closeWindowListeners[i]){
111             index = i;
112             break;
113         }
114     }
115     if (index == -1) return;
116     if (closeWindowListeners.length == 1) {
117         closeWindowListeners = new CloseWindowListener[0];
118         return;
119     }
120     CloseWindowListener[] newCloseWindowListeners = new CloseWindowListener[closeWindowListeners.length - 1];
121     System.arraycopy (closeWindowListeners, 0, newCloseWindowListeners, 0, index);
122     System.arraycopy (closeWindowListeners, index + 1, newCloseWindowListeners, index, closeWindowListeners.length - index - 1);
123     closeWindowListeners = newCloseWindowListeners;
124 }
125
126 public void removeLocationListener (LocationListener listener) {
127     if (locationListeners.length == 0) return;
128     int index = -1;
129     for (int i = 0; i < locationListeners.length; i++) {
130         if (listener == locationListeners[i]){
131             index = i;
132             break;
133         }
134     }
135     if (index == -1) return;
136     if (locationListeners.length == 1) {
137         locationListeners = new LocationListener[0];
138         return;
139     }
140     LocationListener[] newLocationListeners = new LocationListener[locationListeners.length - 1];
141     System.arraycopy (locationListeners, 0, newLocationListeners, 0, index);
142     System.arraycopy (locationListeners, index + 1, newLocationListeners, index, locationListeners.length - index - 1);
143     locationListeners = newLocationListeners;
144 }
145
146 public void removeOpenWindowListener (OpenWindowListener listener) {
147     if (openWindowListeners.length == 0) return;
148     int index = -1;
149     for (int i = 0; i < openWindowListeners.length; i++) {
150         if (listener == openWindowListeners[i]){
151             index = i;
152             break;
153         }
154     }
155     if (index == -1) return;
156     if (openWindowListeners.length == 1) {
157         openWindowListeners = new OpenWindowListener[0];
158         return;
159     }
160     OpenWindowListener[] newOpenWindowListeners = new OpenWindowListener[openWindowListeners.length - 1];
161     System.arraycopy (openWindowListeners, 0, newOpenWindowListeners, 0, index);
162     System.arraycopy (openWindowListeners, index + 1, newOpenWindowListeners, index, openWindowListeners.length - index - 1);
163     openWindowListeners = newOpenWindowListeners;
164 }
165
166 public void removeProgressListener (ProgressListener listener) {
167     if (progressListeners.length == 0) return;
168     int index = -1;
169     for (int i = 0; i < progressListeners.length; i++) {
170         if (listener == progressListeners[i]){
171             index = i;
172             break;
173         }
174     }
175     if (index == -1) return;
176     if (progressListeners.length == 1) {
177         progressListeners = new ProgressListener[0];
178         return;
179     }
180     ProgressListener[] newProgressListeners = new ProgressListener[progressListeners.length - 1];
181     System.arraycopy (progressListeners, 0, newProgressListeners, 0, index);
182     System.arraycopy (progressListeners, index + 1, newProgressListeners, index, progressListeners.length - index - 1);
183     progressListeners = newProgressListeners;
184 }
185
186 public void removeStatusTextListener (StatusTextListener listener) {
187     if (statusTextListeners.length == 0) return;
188     int index = -1;
189     for (int i = 0; i < statusTextListeners.length; i++) {
190         if (listener == statusTextListeners[i]){
191             index = i;
192             break;
193         }
194     }
195     if (index == -1) return;
196     if (statusTextListeners.length == 1) {
197         statusTextListeners = new StatusTextListener[0];
198         return;
199     }
200     StatusTextListener[] newStatusTextListeners = new StatusTextListener[statusTextListeners.length - 1];
201     System.arraycopy (statusTextListeners, 0, newStatusTextListeners, 0, index);
202     System.arraycopy (statusTextListeners, index + 1, newStatusTextListeners, index, statusTextListeners.length - index - 1);
203     statusTextListeners = newStatusTextListeners;
204 }
205
206 public void removeTitleListener (TitleListener listener) {
207     if (titleListeners.length == 0) return;
208     int index = -1;
209     for (int i = 0; i < titleListeners.length; i++) {
210         if (listener == titleListeners[i]){
211             index = i;
212             break;
213         }
214     }
215     if (index == -1) return;
216     if (titleListeners.length == 1) {
217         titleListeners = new TitleListener[0];
218         return;
219     }
220     TitleListener[] newTitleListeners = new TitleListener[titleListeners.length - 1];
221     System.arraycopy (titleListeners, 0, newTitleListeners, 0, index);
222     System.arraycopy (titleListeners, index + 1, newTitleListeners, index, titleListeners.length - index - 1);
223     titleListeners = newTitleListeners;
224 }
225
226 public void removeVisibilityWindowListener (VisibilityWindowListener listener) {
227     if (visibilityWindowListeners.length == 0) return;
228     int index = -1;
229     for (int i = 0; i < visibilityWindowListeners.length; i++) {
230         if (listener == visibilityWindowListeners[i]){
231             index = i;
232             break;
233         }
234     }
235     if (index == -1) return;
236     if (visibilityWindowListeners.length == 1) {
237         visibilityWindowListeners = new VisibilityWindowListener[0];
238         return;
239     }
240     VisibilityWindowListener[] newVisibilityWindowListeners = new VisibilityWindowListener[visibilityWindowListeners.length - 1];
241     System.arraycopy (visibilityWindowListeners, 0, newVisibilityWindowListeners, 0, index);
242     System.arraycopy (visibilityWindowListeners, index + 1, newVisibilityWindowListeners, index, visibilityWindowListeners.length - index - 1);
243     visibilityWindowListeners = newVisibilityWindowListeners;
244 }
245
246 public void setBrowser (Browser browser) {
247     this.browser = browser;
248 }
249
250 public abstract boolean setText (String JavaDoc html);
251
252 public abstract boolean setUrl (String JavaDoc url);
253
254 public abstract void stop ();
255 }
256
Popular Tags