This is an old patch that enables basic HTML loading from URLs in
JEditorPanes via setPage(URL).

2006-10-18  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/JEditorPane.java
        (page): Removed field. The page is now stored in the correct
        document property.
        (getPage): Fetch page URL from document property.
        (read): Set the document for this JEditorPane. Use a Reader
        for reading in the document.
        (setPage): Call getStream() to get the stream from which we read.
        Fire property change. Store page in document property.

/Roman

Index: javax/swing/JEditorPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JEditorPane.java,v
retrieving revision 1.35
diff -u -1 -5 -r1.35 JEditorPane.java
--- javax/swing/JEditorPane.java	31 Aug 2006 19:25:07 -0000	1.35
+++ javax/swing/JEditorPane.java	18 Oct 2006 09:54:59 -0000
@@ -496,31 +496,30 @@
      */
     public ViewFactory getViewFactory()
     {
       return new ViewFactory()
       {
         public View create(Element el)
         {
           return new WrappedPlainView(el);
         }
       };
     }
   }
 
   private static final long serialVersionUID = 3140472492599046285L;
   
-  private URL page;
   private EditorKit editorKit;
   
   boolean focus_root;
   
   // A mapping between content types and registered EditorKit types
   static HashMap registerMap;
   
   // A mapping between content types and used EditorKits
   HashMap editorMap;  
 
   public JEditorPane()
   {
     init();
     setEditorKit(createDefaultEditorKit());
   }
@@ -750,31 +749,31 @@
    *
    * @return <code>true</code> when a Viewport should force the width of
    *         this component to match the viewport width
    */
   public boolean getScrollableTracksViewportWidth()
   {
     // Tests show that this returns true when the parent is a JViewport
     // and has a width > minimum UI width.
     Container parent = getParent();
     return parent != null && parent instanceof JViewport
            && parent.getWidth() > getUI().getMinimumSize(this).width;
   }
 
   public URL getPage()
   {
-    return page;
+    return (URL) getDocument().getProperty(Document.StreamDescriptionProperty);
   }
 
   protected InputStream getStream(URL page)
     throws IOException
   {
     return page.openStream();
   }
 
   public String getText()
   {
     return super.getText();
   }
 
   public String getUIClassID()
   {
@@ -787,34 +786,36 @@
   }
 
   protected String paramString()
   {
     return "JEditorPane";
   }
 
   /**
    * This method initializes from a stream. 
    */
   public void read(InputStream in, Object desc) throws IOException
   {
     EditorKit kit = getEditorKit();
     if (kit instanceof HTMLEditorKit && desc instanceof HTMLDocument)
       {
-        Document doc = (Document) desc;
+        HTMLDocument doc = (HTMLDocument) desc;
+        setDocument(doc);
         try
           {
-            kit.read(in, doc, 0);
+            InputStreamReader reader = new InputStreamReader(in);
+            kit.read(reader, doc, 0);
           }
         catch (BadLocationException ex)
           {
             assert false : "BadLocationException must not be thrown here.";
           }
       }
     else
       {
         Reader inRead = new InputStreamReader(in);
         super.read(inRead, desc);
       }
   }
 
   /**
    * Establishes a binding between type and classname.  This enables
@@ -909,39 +910,40 @@
    * Sets the current URL being displayed.  
    */
   public void setPage(String url) throws IOException
   {
     setPage(new URL(url));
   }
 
   /**
    * Sets the current URL being displayed.  
    */
   public void setPage(URL page) throws IOException
   {
     if (page == null)
       throw new IOException("invalid url");
 
-    try
-      {
-	this.page = page;
-	getEditorKit().read(page.openStream(), getDocument(), 0);
-      }
-    catch (BadLocationException e)
+    URL old = getPage();;
+    InputStream in = getStream(page);
+    if (editorKit != null)
       {
-	// Ignored. '0' is always a valid offset.
+        Document doc = editorKit.createDefaultDocument();
+        doc.putProperty(Document.StreamDescriptionProperty, page);
+        read(in, doc);
+        setDocument(doc);
       }
+    firePropertyChange("page", old, page);
   }
 
   /**
    * Sets the text of the JEditorPane.  The argument <code>t</code>
    * is expected to be in the format of the current EditorKit.  This removes
    * the content of the current document and uses the EditorKit to read in the
    * new text.  This allows the EditorKit to handle the String rather than just
    * inserting in plain text.
    * 
    * @param t the text to display in this JEditorPane
    */
   public void setText(String t)
   {
     try
     {

Reply via email to