Hi,

To make the jedit help system work better getPage() needs to return the
value as set by setPage(). This patch makes it so that the PageLoader
keeps a reference to the URL it is loading so it can be returned.

2006-12-03  Mark Wielaard  <[EMAIL PROTECTED]>

    * javax/swing/JEditorPane.java (PageLoader.in): Made a PageStream.
    (PageLoader.page): Made package local.
    (PageLoader.run): Don't reset loader.
    (PageLoader.cancel): New method.
    (loading): Renamed to loader.
    (getPage): Return loader.page.
    (setPage): Always set loader. Never reset to null.

jedit help system is still not perfect, but it is looking pretty good
now.

Committed,

Mark
Index: javax/swing/JEditorPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JEditorPane.java,v
retrieving revision 1.40
diff -u -r1.40 JEditorPane.java
--- javax/swing/JEditorPane.java	20 Nov 2006 10:41:18 -0000	1.40
+++ javax/swing/JEditorPane.java	3 Dec 2006 16:40:52 -0000
@@ -582,13 +582,13 @@
     implements Runnable
   {
     private Document doc;
-    private InputStream in;
+    private PageStream in;
     private URL old;
-    private URL page;
-    PageLoader(Document doc, InputStream in, int prio, URL old, URL page)
+    URL page;
+    PageLoader(Document doc, InputStream in, URL old, URL page)
     {
       this.doc = doc;
-      this.in = in;
+      this.in = new PageStream(in);
       this.old = old;
       this.page = page;
     }
@@ -598,10 +598,6 @@
       try
         {
           read(in, doc);
-          synchronized (JEditorPane.this)
-          {
-            loading = null;
-          }
         }
       catch (IOException ex)
         {
@@ -621,7 +617,12 @@
                 }
               });
             }
-      }
+         }
+     }
+
+     void cancel()
+     {
+       in.cancel();
      }
   }
 
@@ -640,7 +641,7 @@
   /**
    * The currently loading stream, if any.
    */
-  private PageStream loading;
+  private PageLoader loader;
 
   public JEditorPane()
   {
@@ -885,7 +886,7 @@
 
   public URL getPage()
   {
-    return (URL) getDocument().getProperty(Document.StreamDescriptionProperty);
+    return loader != null ? loader.page : null;
   }
 
   protected InputStream getStream(URL page)
@@ -1075,15 +1076,10 @@
             Document doc = editorKit.createDefaultDocument();
             doc.putProperty(Document.StreamDescriptionProperty, page);
 
-            // Cancel loading stream, if there is any.
-            synchronized (this)
-              {
-                if (loading != null)
-                  {
-                    loading.cancel();
-                    loading = null;
-                  }
-              }
+            if (loader != null)
+              loader.cancel();
+            loader = new PageLoader(doc, in, old, page);
+
             int prio = -1;
             if (doc instanceof AbstractDocument)
               {
@@ -1094,20 +1090,15 @@
               {
                 // Load asynchronously.
                 setDocument(doc);
-                synchronized (this)
-                  {
-                    loading = new PageStream(in);
-                  }
-                PageLoader loader = new PageLoader(doc, loading, prio, old,
-                                                   page);
-                Thread loadThread = new Thread(loader);
+                Thread loadThread = new Thread(loader,
+                                               "JEditorPane.PageLoader");
+                loadThread.setDaemon(true);
                 loadThread.setPriority(prio);
                 loadThread.start();
               }
             else
               {
                 // Load synchronously.
-                PageLoader loader = new PageLoader(doc, in, prio, old, page);
                 loader.run();
                 setDocument(doc);
               }

Reply via email to