1 19 20 package org.netbeans.modules.jdic; 21 22 import java.beans.*; 23 import java.net.*; 24 25 import org.jdesktop.jdic.browser.*; 26 import org.openide.awt.HtmlBrowser.Impl; 27 import org.openide.util.NbBundle; 28 29 34 public class JdicBrowserImpl extends org.openide.awt.HtmlBrowser.Impl { 35 36 private WebBrowser webBrowser = null; 37 38 39 private PropertyChangeSupport pcs; 40 41 42 private URL url; 43 private String title = ""; private String statusMsg = ""; private boolean isForward = false; 46 private boolean isBackward = false; 47 48 51 public JdicBrowserImpl() { 52 pcs = new PropertyChangeSupport (this); 53 } 54 55 public boolean isHistory() { return false; } 56 public void showHistory() {} 57 58 public boolean isBackward() { 59 return isBackward; 60 } 61 62 public boolean isForward() { 63 return isForward; 64 } 65 66 70 public String getStatusMessage() { 71 return statusMsg; 72 } 73 74 public String getTitle() { 75 return title; 76 } 77 78 protected void setTitle (String title) { 79 this.title = title; 80 } 81 82 86 public URL getURL() { 87 return url; 88 } 89 90 public void stopLoading() { 91 webBrowser.stop(); 92 } 93 94 public void backward() { 95 if (webBrowser == null) { 96 init(); 97 } 98 webBrowser.back(); 99 } 100 101 public void forward() { 102 if (webBrowser == null) { 103 init(); 104 } 105 webBrowser.forward(); 106 } 107 108 111 public void reloadDocument() { 112 if (webBrowser == null) { 113 init(); 114 } 115 webBrowser.refresh(); 116 } 117 118 122 public synchronized void setURL(final URL url) { 123 this.url = url; 124 if (webBrowser == null) { 125 init(); 126 } 127 webBrowser.setURL(url); 128 } 129 130 134 public final java.awt.Component getComponent() { 135 if (webBrowser == null) { 136 init(); 137 } 138 return webBrowser; 139 } 140 141 private synchronized void init() { 142 if (webBrowser == null) { 143 try { 144 webBrowser = new WebBrowser(); 145 } catch (Exception e) { 147 return; 149 } 150 151 webBrowser.addWebBrowserListener(new WebBrowserListener() { 152 public void downloadStarted(WebBrowserEvent event) { 153 String oldMsg = statusMsg; 154 statusMsg = NbBundle.getMessage(JdicBrowserImpl.class, "MSG_Download_started"); pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg); 156 } 157 158 public void downloadCompleted(WebBrowserEvent event) { 159 String oldMsg = statusMsg; 161 statusMsg = NbBundle.getMessage(JdicBrowserImpl.class, "MSG_Download_completed"); pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg); 163 164 boolean oldFwd = isForward; 166 boolean oldBack = isBackward; 167 isForward = webBrowser.getStatus().isForwardEnabled(); 168 isBackward = webBrowser.getStatus().isBackEnabled(); 169 170 System.err.println("back: " + isBackward); 171 if (isForward != oldFwd) { 172 pcs.firePropertyChange(PROP_FORWARD, oldFwd, isForward); 173 } 174 if (isBackward != oldBack) { 175 pcs.firePropertyChange(PROP_BACKWARD, oldBack, isBackward); 176 } 177 178 URL old = url; 180 URL url = webBrowser.getURL(); 181 if (old != url) { 182 pcs.firePropertyChange(PROP_URL, old, url); 183 } 184 } 185 186 public void downloadProgress(WebBrowserEvent event) { 187 } 188 189 public void downloadError(WebBrowserEvent event) { 190 String oldMsg = statusMsg; 191 statusMsg = event.getData(); 192 pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg); 193 } 194 195 public void titleChange(WebBrowserEvent event) { 196 String old = title; 197 title = event.getData(); 198 pcs.firePropertyChange(Impl.PROP_TITLE, old, title); 199 } 200 201 public void statusTextChange(WebBrowserEvent event) { 202 String oldMsg = statusMsg; 203 statusMsg = event.getData(); 204 pcs.firePropertyChange(PROP_STATUS_MESSAGE, oldMsg, statusMsg); 205 } 206 }); 207 } 208 } 209 210 214 public void addPropertyChangeListener(PropertyChangeListener l) { 215 pcs.addPropertyChangeListener (l); 216 } 217 218 222 public void removePropertyChangeListener(PropertyChangeListener l) { 223 pcs.removePropertyChangeListener (l); 224 } 225 226 } 227 | Popular Tags |