diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-10-29 22:49:21 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-10-29 22:49:21 +0000 |
commit | e36d2a50b5a1a677c7ecaf926e73a5dac386c1ef (patch) | |
tree | 9649a7997f35624c829eccad8c84c84e9c8e3fb9 /javax/swing/JEditorPane.java | |
parent | be24db70d4ff66302f560e12913f5b71acf3c12c (diff) | |
download | classpath-e36d2a50b5a1a677c7ecaf926e73a5dac386c1ef.tar.gz |
2006-10-29 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics for 2006/10/04-2006/10/29.
Diffstat (limited to 'javax/swing/JEditorPane.java')
-rw-r--r-- | javax/swing/JEditorPane.java | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/javax/swing/JEditorPane.java b/javax/swing/JEditorPane.java index a5efa07df..06844355a 100644 --- a/javax/swing/JEditorPane.java +++ b/javax/swing/JEditorPane.java @@ -47,6 +47,7 @@ import java.io.Reader; import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.util.HashMap; import javax.accessibility.AccessibleContext; @@ -508,7 +509,6 @@ public class JEditorPane extends JTextComponent private static final long serialVersionUID = 3140472492599046285L; - private URL page; private EditorKit editorKit; boolean focus_root; @@ -762,13 +762,19 @@ public class JEditorPane extends JTextComponent public URL getPage() { - return page; + return (URL) getDocument().getProperty(Document.StreamDescriptionProperty); } protected InputStream getStream(URL page) throws IOException { - return page.openStream(); + URLConnection conn = page.openConnection(); + // Try to detect the content type of the stream data. + String type = conn.getContentType(); + if (type != null) + setContentType(type); + InputStream stream = conn.getInputStream(); + return stream; } public String getText() @@ -799,10 +805,12 @@ public class JEditorPane extends JTextComponent 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) { @@ -921,15 +929,16 @@ public class JEditorPane extends JTextComponent 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); } /** |