Index: javax/swing/JEditorPane.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JEditorPane.java,v retrieving revision 1.14 diff -u -r1.14 JEditorPane.java --- javax/swing/JEditorPane.java 22 Oct 2004 18:16:00 -0000 1.14 +++ javax/swing/JEditorPane.java 10 Jan 2005 18:03:34 -0000 @@ -1,5 +1,5 @@ /* JEditorPane.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,6 +47,7 @@ import javax.accessibility.AccessibleContext; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import javax.swing.text.BadLocationException; import javax.swing.text.DefaultEditorKit; import javax.swing.text.EditorKit; import javax.swing.text.JTextComponent; @@ -56,29 +57,31 @@ { private static final long serialVersionUID = 3140472492599046285L; - URL page_url; - EditorKit kit; - String ctype = "text/plain"; + private URL page; + private EditorKit editorKit; + boolean focus_root; boolean manages_focus; public JEditorPane() { + setEditorKit(createDefaultEditorKit()); } public JEditorPane(String url) throws IOException { - setPage(url); + this(new URL(url)); } public JEditorPane(String type, String text) { - ctype = text; + setEditorKit(createEditorKitForContentType(type)); setText(text); } public JEditorPane(URL url) throws IOException { + this(); setPage(url); } @@ -112,12 +115,12 @@ public String getContentType() { - return ctype; + return getEditorKit().getContentType(); } public EditorKit getEditorKit() { - return kit; + return editorKit; } public static String getEditorKitClassNameForContentType(String type) @@ -127,7 +130,7 @@ public EditorKit getEditorKitForContentType(String type) { - return kit; + return editorKit; } /** @@ -150,7 +153,7 @@ public URL getPage() { - return page_url; + return page; } protected InputStream getStream(URL page) @@ -242,22 +245,41 @@ public void setContentType(String type) { - ctype = type; - invalidate(); - repaint(); - } - - public void setEditorKit(EditorKit kit) - { - this.kit = kit; + if (editorKit != null + && editorKit.getContentType().equals(type)) + return; + + EditorKit kit = getEditorKitForContentType(type); + + if (kit != null) + setEditorKit(kit); + } + + public void setEditorKit(EditorKit newValue) + { + if (editorKit == newValue) + return; + + if (editorKit != null) + editorKit.deinstall(this); + + EditorKit oldValue = editorKit; + editorKit = newValue; + + if (editorKit != null) + { + editorKit.install(this); + setDocument(editorKit.createDefaultDocument()); + } + + firePropertyChange("editorKit", oldValue, newValue); invalidate(); repaint(); } public void setEditorKitForContentType(String type, EditorKit k) { - ctype = type; - setEditorKit(k); + // FIXME: editorKitCache.put(type, kit); } /** @@ -265,6 +287,7 @@ */ public void setPage(String url) throws IOException { + setPage(new URL(url)); } /** @@ -272,6 +295,18 @@ */ 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) + { + // Ignored. '0' is always a valid offset. + } } public void setText(String t) Index: javax/swing/text/DefaultEditorKit.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultEditorKit.java,v retrieving revision 1.10 diff -u -r1.10 DefaultEditorKit.java --- javax/swing/text/DefaultEditorKit.java 22 Oct 2004 12:44:01 -0000 1.10 +++ javax/swing/text/DefaultEditorKit.java 10 Jan 2005 18:03:34 -0000 @@ -1,5 +1,5 @@ /* DefaultEditorKit.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,9 +40,12 @@ import java.awt.Toolkit; import java.awt.event.ActionEvent; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; @@ -84,6 +87,7 @@ { super(cutAction); } + public void actionPerformed(ActionEvent event) { } @@ -96,6 +100,7 @@ { super(defaultKeyTypedAction); } + public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); @@ -123,6 +128,7 @@ { super(insertBreakAction); } + public void actionPerformed(ActionEvent event) { } @@ -147,6 +153,7 @@ { super(insertTabAction); } + public void actionPerformed(ActionEvent event) { } @@ -159,6 +166,7 @@ { super(pasteAction); } + public void actionPerformed(ActionEvent event) { } @@ -364,22 +372,34 @@ return null; } - public void read(InputStream in, Document doc, int pos) + public void read(InputStream in, Document document, int offset) throws BadLocationException, IOException { + read(new InputStreamReader(in), document, offset); } - public void read(Reader in, Document doc, int pos) + public void read(Reader in, Document document, int offset) throws BadLocationException, IOException { + BufferedReader reader = new BufferedReader(in); + + String line; + StringBuffer content = new StringBuffer(); + + while ((line = reader.readLine()) != null) + content.append(line); + + document.insertString(offset, content.toString(), + SimpleAttributeSet.EMPTY); } - public void write(OutputStream out, Document doc, int pos, int len) + public void write(OutputStream out, Document document, int offset, int len) throws BadLocationException, IOException { + write(new OutputStreamWriter(out), document, offset, len); } - public void write(Writer out, Document doc, int pos, int len) + public void write(Writer out, Document document, int offset, int len) throws BadLocationException, IOException { }