2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.jdic;
47
import org.jdesktop.jdic.browser.*;
48
import org.openide.awt.HtmlBrowser.Impl;
49
import org.openide.util.NbBundle;
52
* JDIC browser support
54
* @author Martin Grebac
56
public class JdicBrowserImpl extends org.openide.awt.HtmlBrowser.Impl {
58
private WebBrowser webBrowser = null;
60
/** standard helper variable */
61
private PropertyChangeSupport pcs;
65
private String title = ""; // NOI18N
66
private String statusMsg = ""; // NOI18N
67
private boolean isForward = false;
68
private boolean isBackward = false;
70
/** Default constructor.
71
* <p>Builds PropertyChangeSupport.
73
public JdicBrowserImpl() {
74
pcs = new PropertyChangeSupport (this);
77
public boolean isHistory() { return false; }
78
public void showHistory() {}
80
public boolean isBackward() {
84
public boolean isForward() {
88
/** Returns status message representing status of html browser.
90
* @return status message.
92
public String getStatusMessage() {
96
public String getTitle() {
100
protected void setTitle (String title) {
104
/** Returns current URL.
106
* @return current URL.
108
public URL getURL() {
112
public void stopLoading() {
116
public void backward() {
117
if (webBrowser == null) {
123
public void forward() {
124
if (webBrowser == null) {
127
webBrowser.forward();
130
/** Call setURL again to force reloading.
131
* Browser must be set to reload document and do not cache them.
133
public void reloadDocument() {
134
if (webBrowser == null) {
137
webBrowser.refresh();
140
/** Sets current URL.
142
* @param url URL to show in the browser.
144
public synchronized void setURL(final URL url) {
146
if (webBrowser == null) {
149
webBrowser.setURL(url);
152
/** Returns visual component of html browser.
154
* @return visual component of html browser.
156
public final java.awt.Component getComponent() {
157
if (webBrowser == null) {
163
private synchronized void init() {
164
if (webBrowser == null) {
166
webBrowser = new WebBrowser();
167
//webBrowser.setDebug(true); // debugging info to console
168
} catch (Exception e) {
173
webBrowser.addWebBrowserListener(new WebBrowserListener() {
174
public void downloadStarted(WebBrowserEvent event) {
175
String oldMsg = statusMsg;
176
statusMsg = NbBundle.getMessage(JdicBrowserImpl.class, "MSG_Download_started"); //NOI18N
177
pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg);
180
public void downloadCompleted(WebBrowserEvent event) {
181
//update status message
182
String oldMsg = statusMsg;
183
statusMsg = NbBundle.getMessage(JdicBrowserImpl.class, "MSG_Download_completed"); //NOI18N
184
pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg);
186
//update fwd and back buttons' state
187
boolean oldFwd = isForward;
188
boolean oldBack = isBackward;
189
isForward = webBrowser.getStatus().isForwardEnabled();
190
isBackward = webBrowser.getStatus().isBackEnabled();
192
System.err.println("back: " + isBackward);
193
if (isForward != oldFwd) {
194
pcs.firePropertyChange(PROP_FORWARD, oldFwd, isForward);
196
if (isBackward != oldBack) {
197
pcs.firePropertyChange(PROP_BACKWARD, oldBack, isBackward);
202
URL url = webBrowser.getURL();
204
pcs.firePropertyChange(PROP_URL, old, url);
208
public void downloadProgress(WebBrowserEvent event) {
211
public void downloadError(WebBrowserEvent event) {
212
String oldMsg = statusMsg;
213
statusMsg = event.getData();
214
pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg);
217
public void titleChange(WebBrowserEvent event) {
219
title = event.getData();
220
pcs.firePropertyChange(Impl.PROP_TITLE, old, title);
223
public void statusTextChange(WebBrowserEvent event) {
224
String oldMsg = statusMsg;
225
statusMsg = event.getData();
226
pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg);
232
/** Adds PropertyChangeListener to this browser.
234
* @param l Listener to add.
236
public void addPropertyChangeListener(PropertyChangeListener l) {
237
pcs.addPropertyChangeListener (l);
240
/** Removes PropertyChangeListener from this browser.
242
* @param l Listener to remove.
244
public void removePropertyChangeListener(PropertyChangeListener l) {
245
pcs.removePropertyChangeListener (l);