1 19 20 package org.netbeans.core; 21 22 import java.awt.BorderLayout ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.io.IOException ; 26 import java.io.ObjectInput ; 27 import java.io.ObjectOutput ; 28 import java.net.InetAddress ; 29 import java.net.URL ; 30 import java.util.logging.Level ; 31 import java.util.logging.Logger ; 32 import javax.swing.ImageIcon ; 33 import org.openide.awt.HtmlBrowser; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.NbBundle; 36 import org.openide.windows.CloneableTopComponent; 37 38 41 class HtmlBrowserComponent extends CloneableTopComponent implements PropertyChangeListener { 42 43 static final long serialVersionUID = 2912844785502987960L; 44 45 47 48 private HtmlBrowser browserComponent; 49 50 51 53 56 public HtmlBrowserComponent() { 57 this (true, true); 58 } 59 60 63 public HtmlBrowserComponent(boolean toolbar, boolean statusLine) { 64 this (null, toolbar, statusLine); 65 } 66 67 70 public HtmlBrowserComponent(HtmlBrowser.Factory fact, boolean toolbar, boolean statusLine) { 71 setName (""); setLayout (new BorderLayout ()); 73 add (browserComponent = new HtmlBrowser (fact, toolbar, statusLine), "Center"); 75 browserComponent.getBrowserImpl().addPropertyChangeListener (this); 76 77 if (browserComponent.getBrowserComponent() != null) { 79 putClientProperty("InternalBrowser", Boolean.TRUE); } 81 setToolTipText(NbBundle.getBundle(HtmlBrowser.class).getString("HINT_WebBrowser")); 82 } 83 84 public int getPersistenceType() { 85 return PERSISTENCE_ONLY_OPENED; 86 } 87 88 public void propertyChange (PropertyChangeEvent e) { 89 if (!HtmlBrowser.Impl.PROP_TITLE.equals (e.getPropertyName ())) return; 90 String title = browserComponent.getBrowserImpl().getTitle (); 91 if ((title == null) || (title.length () < 1)) return; 92 HtmlBrowserComponent.this.setName (title); 93 HtmlBrowserComponent.this.setDisplayName(title); 94 } 95 96 98 public void open() { 99 if (browserComponent.getBrowserComponent() == null) 101 return; 102 103 super.open(); 105 } 106 107 109 protected Object writeReplace () 110 throws java.io.ObjectStreamException { 111 return new BrowserReplacer (this); 112 } 113 114 117 public void readExternal (ObjectInput in) 118 throws IOException , ClassNotFoundException { 119 super.readExternal (in); 120 setStatusLineVisible (in.readBoolean ()); 121 setToolbarVisible (in.readBoolean ()); 122 browserComponent.setURL ((URL ) in.readObject ()); 123 } 124 125 127 protected CloneableTopComponent createClonedObject () { 128 HtmlBrowserComponent bc = new HtmlBrowserComponent(); bc.setURL (getDocumentURL ()); 130 return bc; 131 } 132 133 public HelpCtx getHelpCtx () { 134 return new HelpCtx(HtmlBrowserComponent.class); 135 } 136 137 protected void componentActivated () { 138 browserComponent.getBrowserImpl().getComponent ().requestFocusInWindow (); 139 super.componentActivated (); 140 } 141 142 public java.awt.Image getIcon () { 143 return new ImageIcon (HtmlBrowser.class.getResource ("/org/openide/resources/html/htmlView.gif")).getImage (); } 145 146 147 149 154 public void setURL (String str) { 155 browserComponent.setURL (str); 156 } 157 158 163 public void setURL (final URL url) { 164 browserComponent.setURL (url); 165 } 166 167 170 public final URL getDocumentURL () { 171 return browserComponent.getDocumentURL (); 172 } 173 174 177 public final void setEnableHome (boolean b) { 178 browserComponent.setEnableHome (b); 179 } 180 181 184 public final void setEnableLocation (boolean b) { 185 browserComponent.setEnableLocation (b); 186 } 187 188 191 public boolean isStatusLineVisible () { 192 return browserComponent.isStatusLineVisible (); 193 } 194 195 198 public void setStatusLineVisible (boolean v) { 199 browserComponent.setStatusLineVisible (v); 200 } 201 202 205 public boolean isToolbarVisible () { 206 return browserComponent.isToolbarVisible (); 207 } 208 209 212 public void setToolbarVisible (boolean v) { 213 browserComponent.setToolbarVisible (v); 214 } 215 216 protected java.lang.String preferredID() { 217 return "HtmlBrowserComponent"; } 219 220 public static final class BrowserReplacer implements java.io.Externalizable { 221 222 223 static final long serialVersionUID = 5915713034827048413L; 224 225 226 227 private transient HtmlBrowserComponent bComp = null; 228 transient boolean statLine; 229 transient boolean toolbar; 230 transient URL url; 231 232 public BrowserReplacer () { 233 } 234 235 public BrowserReplacer (HtmlBrowserComponent comp) { 236 bComp = comp; 237 } 238 239 240 243 public void writeExternal (ObjectOutput out) 244 throws IOException { 245 out.writeBoolean (bComp.isStatusLineVisible ()); 246 out.writeBoolean (bComp.isToolbarVisible ()); 247 out.writeObject (bComp.getDocumentURL ()); 248 } 249 250 253 public void readExternal (ObjectInput in) 254 throws IOException , ClassNotFoundException { 255 statLine = in.readBoolean (); 256 toolbar = in.readBoolean (); 257 url = (URL ) in.readObject (); 258 259 } 260 261 262 private Object readResolve () 263 throws java.io.ObjectStreamException { 264 try { 266 if ("http".equals(url.getProtocol()) && InetAddress.getByName (url.getHost ()).equals (InetAddress.getLocalHost ())) { 268 url.openStream (); 269 } 270 } 271 catch (java.net.UnknownHostException exc) {} 273 catch (java.lang.SecurityException exc) {} 274 catch (java.lang.NullPointerException exc) {} 275 276 catch (java.io.IOException exc) { 277 return null; 279 } 280 catch (java.lang.Exception exc) { 281 Logger.getLogger(HtmlBrowserComponent.class.getName()).log(Level.WARNING, null, exc); 283 } 284 285 bComp = new HtmlBrowserComponent(statLine, toolbar); 286 bComp.setURL (url); 287 return bComp; 288 } 289 290 } 292 } 293 | Popular Tags |