~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to extbrowser/jdic/src/org/netbeans/modules/jdic/JdicBrowserImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.jdic;
 
43
 
 
44
import java.beans.*;
 
45
import java.net.*;
 
46
 
 
47
import org.jdesktop.jdic.browser.*;
 
48
import org.openide.awt.HtmlBrowser.Impl;
 
49
import org.openide.util.NbBundle;
 
50
 
 
51
/**
 
52
 * JDIC browser support
 
53
 *
 
54
 * @author Martin Grebac
 
55
 */
 
56
public class JdicBrowserImpl extends org.openide.awt.HtmlBrowser.Impl {
 
57
 
 
58
    private WebBrowser webBrowser = null;
 
59
 
 
60
    /** standard helper variable */
 
61
    private PropertyChangeSupport pcs;
 
62
 
 
63
    /** requested URL */
 
64
    private URL url;
 
65
    private String title = "";      // NOI18N
 
66
    private String statusMsg = "";      // NOI18N
 
67
    private boolean isForward = false;
 
68
    private boolean isBackward = false;
 
69
    
 
70
    /** Default constructor. 
 
71
      * <p>Builds PropertyChangeSupport. 
 
72
      */
 
73
    public JdicBrowserImpl() {
 
74
        pcs = new PropertyChangeSupport (this);
 
75
    }
 
76
    
 
77
    public boolean isHistory() { return false; }
 
78
    public void showHistory() {}
 
79
 
 
80
    public boolean isBackward() { 
 
81
        return isBackward;
 
82
    }
 
83
    
 
84
    public boolean isForward() { 
 
85
        return isForward;
 
86
    }
 
87
 
 
88
    /** Returns status message representing status of html browser.
 
89
     *
 
90
     * @return status message.
 
91
     */
 
92
    public String getStatusMessage() {
 
93
        return statusMsg;
 
94
    }
 
95
        
 
96
    public String getTitle() {
 
97
        return title;
 
98
    }
 
99
 
 
100
    protected void setTitle (String title) {
 
101
        this.title = title;
 
102
    }
 
103
 
 
104
    /** Returns current URL.
 
105
     *
 
106
     * @return current URL.
 
107
     */
 
108
    public URL getURL() {
 
109
        return url;
 
110
    }
 
111
 
 
112
    public void stopLoading() { 
 
113
        webBrowser.stop();
 
114
    }
 
115
 
 
116
    public void backward() {
 
117
        if (webBrowser == null) {
 
118
            init();
 
119
        }
 
120
        webBrowser.back();
 
121
    }
 
122
    
 
123
    public void forward() {
 
124
        if (webBrowser == null) {
 
125
            init();
 
126
        }
 
127
        webBrowser.forward();
 
128
    }
 
129
 
 
130
    /** Call setURL again to force reloading.
 
131
     * Browser must be set to reload document and do not cache them.
 
132
     */
 
133
    public void reloadDocument() {
 
134
        if (webBrowser == null) {
 
135
            init();
 
136
        }
 
137
        webBrowser.refresh();
 
138
    }
 
139
            
 
140
    /** Sets current URL.
 
141
     *
 
142
     * @param url URL to show in the browser.
 
143
     */
 
144
    public synchronized void setURL(final URL url) {
 
145
        this.url = url;
 
146
        if (webBrowser == null) {
 
147
            init();
 
148
        }
 
149
        webBrowser.setURL(url);
 
150
    }
 
151
    
 
152
    /** Returns visual component of html browser.
 
153
     *
 
154
     * @return visual component of html browser.
 
155
     */
 
156
    public final java.awt.Component getComponent() {
 
157
        if (webBrowser == null) {
 
158
            init();
 
159
        }
 
160
        return webBrowser;
 
161
    }
 
162
    
 
163
    private synchronized void init() {
 
164
        if (webBrowser == null) {
 
165
            try {
 
166
                webBrowser = new WebBrowser();
 
167
                //webBrowser.setDebug(true); // debugging info to console
 
168
            } catch (Exception e) {
 
169
                // TODO
 
170
                return;
 
171
            }
 
172
 
 
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);
 
178
                }
 
179
 
 
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);
 
185
 
 
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();
 
191
 
 
192
                    System.err.println("back: " + isBackward);
 
193
                    if (isForward != oldFwd) {
 
194
                        pcs.firePropertyChange(PROP_FORWARD, oldFwd, isForward);
 
195
                    }
 
196
                    if (isBackward != oldBack) {
 
197
                        pcs.firePropertyChange(PROP_BACKWARD, oldBack, isBackward);
 
198
                    }
 
199
 
 
200
                    //update url
 
201
                    URL old = url;
 
202
                    URL url = webBrowser.getURL();
 
203
                    if (old != url) {
 
204
                        pcs.firePropertyChange(PROP_URL, old, url);
 
205
                    }
 
206
                }
 
207
 
 
208
                public void downloadProgress(WebBrowserEvent event) {
 
209
                }
 
210
 
 
211
                public void downloadError(WebBrowserEvent event) {
 
212
                    String oldMsg = statusMsg;
 
213
                    statusMsg = event.getData();
 
214
                    pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg);
 
215
                }
 
216
 
 
217
                public void titleChange(WebBrowserEvent event) {
 
218
                    String old = title;
 
219
                    title = event.getData();
 
220
                    pcs.firePropertyChange(Impl.PROP_TITLE, old, title);
 
221
                }  
 
222
 
 
223
                public void statusTextChange(WebBrowserEvent event) {
 
224
                    String oldMsg = statusMsg;
 
225
                    statusMsg = event.getData();
 
226
                    pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg);
 
227
                }  
 
228
            });
 
229
        }
 
230
    }
 
231
 
 
232
    /** Adds PropertyChangeListener to this browser.
 
233
     *
 
234
     * @param l Listener to add.
 
235
     */
 
236
    public void addPropertyChangeListener(PropertyChangeListener l) {
 
237
        pcs.addPropertyChangeListener (l);
 
238
    }
 
239
    
 
240
    /** Removes PropertyChangeListener from this browser.
 
241
     *
 
242
     * @param l Listener to remove.
 
243
     */
 
244
    public void removePropertyChangeListener(PropertyChangeListener l) {
 
245
        pcs.removePropertyChangeListener (l);
 
246
    }
 
247
    
 
248
}